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"
86 /* Enums for exception-handling support. */
87 enum exception_event_kind
94 /* Prototypes for local functions. */
96 static void enable_delete_command (char *, int);
98 static void enable_once_command (char *, int);
100 static void enable_count_command (char *, int);
102 static void disable_command (char *, int);
104 static void enable_command (char *, int);
106 static void map_breakpoint_numbers (const char *,
107 void (*) (struct breakpoint
*,
111 static void ignore_command (char *, int);
113 static int breakpoint_re_set_one (void *);
115 static void breakpoint_re_set_default (struct breakpoint
*);
118 create_sals_from_location_default (const struct event_location
*location
,
119 struct linespec_result
*canonical
,
120 enum bptype type_wanted
);
122 static void create_breakpoints_sal_default (struct gdbarch
*,
123 struct linespec_result
*,
124 gdb::unique_xmalloc_ptr
<char>,
125 gdb::unique_xmalloc_ptr
<char>,
127 enum bpdisp
, int, int,
129 const struct breakpoint_ops
*,
130 int, int, int, unsigned);
132 static std::vector
<symtab_and_line
> decode_location_default
133 (struct breakpoint
*b
, const struct event_location
*location
,
134 struct program_space
*search_pspace
);
136 static void clear_command (char *, int);
138 static void catch_command (char *, int);
140 static int can_use_hardware_watchpoint (struct value
*);
142 static void break_command_1 (char *, int, int);
144 static void mention (struct breakpoint
*);
146 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
148 const struct breakpoint_ops
*);
149 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
150 const struct symtab_and_line
*);
152 /* This function is used in gdbtk sources and thus can not be made
154 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
155 struct symtab_and_line
,
157 const struct breakpoint_ops
*);
159 static struct breakpoint
*
160 momentary_breakpoint_from_master (struct breakpoint
*orig
,
162 const struct breakpoint_ops
*ops
,
165 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
167 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
171 static void describe_other_breakpoints (struct gdbarch
*,
172 struct program_space
*, CORE_ADDR
,
173 struct obj_section
*, int);
175 static int watchpoint_locations_match (struct bp_location
*loc1
,
176 struct bp_location
*loc2
);
178 static int breakpoint_location_address_match (struct bp_location
*bl
,
179 struct address_space
*aspace
,
182 static int breakpoint_location_address_range_overlap (struct bp_location
*,
183 struct address_space
*,
186 static void info_breakpoints_command (char *, int);
188 static void info_watchpoints_command (char *, int);
190 static int breakpoint_1 (char *, int,
191 int (*) (const struct breakpoint
*));
193 static int breakpoint_cond_eval (void *);
195 static void cleanup_executing_breakpoints (void *);
197 static void commands_command (char *, int);
199 static void condition_command (char *, int);
201 static int remove_breakpoint (struct bp_location
*);
202 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
204 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
206 static int watchpoint_check (void *);
208 static void maintenance_info_breakpoints (char *, int);
210 static int hw_breakpoint_used_count (void);
212 static int hw_watchpoint_use_count (struct breakpoint
*);
214 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
216 int *other_type_used
);
218 static void hbreak_command (char *, int);
220 static void thbreak_command (char *, int);
222 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
225 static void stop_command (char *arg
, int from_tty
);
227 static void stopin_command (char *arg
, int from_tty
);
229 static void stopat_command (char *arg
, int from_tty
);
231 static void tcatch_command (char *arg
, int from_tty
);
233 static void free_bp_location (struct bp_location
*loc
);
234 static void incref_bp_location (struct bp_location
*loc
);
235 static void decref_bp_location (struct bp_location
**loc
);
237 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
239 /* update_global_location_list's modes of operation wrt to whether to
240 insert locations now. */
241 enum ugll_insert_mode
243 /* Don't insert any breakpoint locations into the inferior, only
244 remove already-inserted locations that no longer should be
245 inserted. Functions that delete a breakpoint or breakpoints
246 should specify this mode, so that deleting a breakpoint doesn't
247 have the side effect of inserting the locations of other
248 breakpoints that are marked not-inserted, but should_be_inserted
249 returns true on them.
251 This behavior is useful is situations close to tear-down -- e.g.,
252 after an exec, while the target still has execution, but
253 breakpoint shadows of the previous executable image should *NOT*
254 be restored to the new image; or before detaching, where the
255 target still has execution and wants to delete breakpoints from
256 GDB's lists, and all breakpoints had already been removed from
260 /* May insert breakpoints iff breakpoints_should_be_inserted_now
261 claims breakpoints should be inserted now. */
264 /* Insert locations now, irrespective of
265 breakpoints_should_be_inserted_now. E.g., say all threads are
266 stopped right now, and the user did "continue". We need to
267 insert breakpoints _before_ resuming the target, but
268 UGLL_MAY_INSERT wouldn't insert them, because
269 breakpoints_should_be_inserted_now returns false at that point,
270 as no thread is running yet. */
274 static void update_global_location_list (enum ugll_insert_mode
);
276 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
278 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
280 static void insert_breakpoint_locations (void);
282 static void info_tracepoints_command (char *, int);
284 static void delete_trace_command (char *, int);
286 static void enable_trace_command (char *, int);
288 static void disable_trace_command (char *, int);
290 static void trace_pass_command (char *, int);
292 static void set_tracepoint_count (int num
);
294 static int is_masked_watchpoint (const struct breakpoint
*b
);
296 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
298 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
301 static int strace_marker_p (struct breakpoint
*b
);
303 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
304 that are implemented on top of software or hardware breakpoints
305 (user breakpoints, internal and momentary breakpoints, etc.). */
306 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
308 /* Internal breakpoints class type. */
309 static struct breakpoint_ops internal_breakpoint_ops
;
311 /* Momentary breakpoints class type. */
312 static struct breakpoint_ops momentary_breakpoint_ops
;
314 /* The breakpoint_ops structure to be used in regular user created
316 struct breakpoint_ops bkpt_breakpoint_ops
;
318 /* Breakpoints set on probes. */
319 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
321 /* Dynamic printf class type. */
322 struct breakpoint_ops dprintf_breakpoint_ops
;
324 /* The style in which to perform a dynamic printf. This is a user
325 option because different output options have different tradeoffs;
326 if GDB does the printing, there is better error handling if there
327 is a problem with any of the arguments, but using an inferior
328 function lets you have special-purpose printers and sending of
329 output to the same place as compiled-in print functions. */
331 static const char dprintf_style_gdb
[] = "gdb";
332 static const char dprintf_style_call
[] = "call";
333 static const char dprintf_style_agent
[] = "agent";
334 static const char *const dprintf_style_enums
[] = {
340 static const char *dprintf_style
= dprintf_style_gdb
;
342 /* The function to use for dynamic printf if the preferred style is to
343 call into the inferior. The value is simply a string that is
344 copied into the command, so it can be anything that GDB can
345 evaluate to a callable address, not necessarily a function name. */
347 static char *dprintf_function
;
349 /* The channel to use for dynamic printf if the preferred style is to
350 call into the inferior; if a nonempty string, it will be passed to
351 the call as the first argument, with the format string as the
352 second. As with the dprintf function, this can be anything that
353 GDB knows how to evaluate, so in addition to common choices like
354 "stderr", this could be an app-specific expression like
355 "mystreams[curlogger]". */
357 static char *dprintf_channel
;
359 /* True if dprintf commands should continue to operate even if GDB
361 static int disconnected_dprintf
= 1;
363 /* A reference-counted struct command_line. This lets multiple
364 breakpoints share a single command list. */
365 struct counted_command_line
367 /* The reference count. */
370 /* The command list. */
371 struct command_line
*commands
;
374 struct command_line
*
375 breakpoint_commands (struct breakpoint
*b
)
377 return b
->commands
? b
->commands
->commands
: NULL
;
380 /* Flag indicating that a command has proceeded the inferior past the
381 current breakpoint. */
383 static int breakpoint_proceeded
;
386 bpdisp_text (enum bpdisp disp
)
388 /* NOTE: the following values are a part of MI protocol and
389 represent values of 'disp' field returned when inferior stops at
391 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
393 return bpdisps
[(int) disp
];
396 /* Prototypes for exported functions. */
397 /* If FALSE, gdb will not use hardware support for watchpoints, even
398 if such is available. */
399 static int can_use_hw_watchpoints
;
402 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
,
406 fprintf_filtered (file
,
407 _("Debugger's willingness to use "
408 "watchpoint hardware is %s.\n"),
412 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
413 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
414 for unrecognized breakpoint locations.
415 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
416 static enum auto_boolean pending_break_support
;
418 show_pending_break_support (struct ui_file
*file
, int from_tty
,
419 struct cmd_list_element
*c
,
422 fprintf_filtered (file
,
423 _("Debugger's behavior regarding "
424 "pending breakpoints is %s.\n"),
428 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
429 set with "break" but falling in read-only memory.
430 If 0, gdb will warn about such breakpoints, but won't automatically
431 use hardware breakpoints. */
432 static int automatic_hardware_breakpoints
;
434 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
435 struct cmd_list_element
*c
,
438 fprintf_filtered (file
,
439 _("Automatic usage of hardware breakpoints is %s.\n"),
443 /* If on, GDB keeps breakpoints inserted even if the inferior is
444 stopped, and immediately inserts any new breakpoints as soon as
445 they're created. If off (default), GDB keeps breakpoints off of
446 the target as long as possible. That is, it delays inserting
447 breakpoints until the next resume, and removes them again when the
448 target fully stops. This is a bit safer in case GDB crashes while
449 processing user input. */
450 static int always_inserted_mode
= 0;
453 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
, const char *value
)
456 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
460 /* See breakpoint.h. */
463 breakpoints_should_be_inserted_now (void)
465 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
467 /* If breakpoints are global, they should be inserted even if no
468 thread under gdb's control is running, or even if there are
469 no threads under GDB's control yet. */
472 else if (target_has_execution
)
474 struct thread_info
*tp
;
476 if (always_inserted_mode
)
478 /* The user wants breakpoints inserted even if all threads
483 if (threads_are_executing ())
486 /* Don't remove breakpoints yet if, even though all threads are
487 stopped, we still have events to process. */
488 ALL_NON_EXITED_THREADS (tp
)
490 && tp
->suspend
.waitstatus_pending_p
)
496 static const char condition_evaluation_both
[] = "host or target";
498 /* Modes for breakpoint condition evaluation. */
499 static const char condition_evaluation_auto
[] = "auto";
500 static const char condition_evaluation_host
[] = "host";
501 static const char condition_evaluation_target
[] = "target";
502 static const char *const condition_evaluation_enums
[] = {
503 condition_evaluation_auto
,
504 condition_evaluation_host
,
505 condition_evaluation_target
,
509 /* Global that holds the current mode for breakpoint condition evaluation. */
510 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
512 /* Global that we use to display information to the user (gets its value from
513 condition_evaluation_mode_1. */
514 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
516 /* Translate a condition evaluation mode MODE into either "host"
517 or "target". This is used mostly to translate from "auto" to the
518 real setting that is being used. It returns the translated
522 translate_condition_evaluation_mode (const char *mode
)
524 if (mode
== condition_evaluation_auto
)
526 if (target_supports_evaluation_of_breakpoint_conditions ())
527 return condition_evaluation_target
;
529 return condition_evaluation_host
;
535 /* Discovers what condition_evaluation_auto translates to. */
538 breakpoint_condition_evaluation_mode (void)
540 return translate_condition_evaluation_mode (condition_evaluation_mode
);
543 /* Return true if GDB should evaluate breakpoint conditions or false
547 gdb_evaluates_breakpoint_condition_p (void)
549 const char *mode
= breakpoint_condition_evaluation_mode ();
551 return (mode
== condition_evaluation_host
);
554 /* Are we executing breakpoint commands? */
555 static int executing_breakpoint_commands
;
557 /* Are overlay event breakpoints enabled? */
558 static int overlay_events_enabled
;
560 /* See description in breakpoint.h. */
561 int target_exact_watchpoints
= 0;
563 /* Walk the following statement or block through all breakpoints.
564 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
565 current breakpoint. */
567 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
569 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
570 for (B = breakpoint_chain; \
571 B ? (TMP=B->next, 1): 0; \
574 /* Similar iterator for the low-level breakpoints. SAFE variant is
575 not provided so update_global_location_list must not be called
576 while executing the block of ALL_BP_LOCATIONS. */
578 #define ALL_BP_LOCATIONS(B,BP_TMP) \
579 for (BP_TMP = bp_locations; \
580 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
583 /* Iterates through locations with address ADDRESS for the currently selected
584 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
585 to where the loop should start from.
586 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
587 appropriate location to start with. */
589 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
590 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
591 BP_LOCP_TMP = BP_LOCP_START; \
593 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
594 && (*BP_LOCP_TMP)->address == ADDRESS); \
597 /* Iterator for tracepoints only. */
599 #define ALL_TRACEPOINTS(B) \
600 for (B = breakpoint_chain; B; B = B->next) \
601 if (is_tracepoint (B))
603 /* Chains of all breakpoints defined. */
605 struct breakpoint
*breakpoint_chain
;
607 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
609 static struct bp_location
**bp_locations
;
611 /* Number of elements of BP_LOCATIONS. */
613 static unsigned bp_locations_count
;
615 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
616 ADDRESS for the current elements of BP_LOCATIONS which get a valid
617 result from bp_location_has_shadow. You can use it for roughly
618 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
619 an address you need to read. */
621 static CORE_ADDR bp_locations_placed_address_before_address_max
;
623 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
624 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
625 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
626 You can use it for roughly limiting the subrange of BP_LOCATIONS to
627 scan for shadow bytes for an address you need to read. */
629 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
631 /* The locations that no longer correspond to any breakpoint, unlinked
632 from the bp_locations array, but for which a hit may still be
633 reported by a target. */
634 VEC(bp_location_p
) *moribund_locations
= NULL
;
636 /* Number of last breakpoint made. */
638 static int breakpoint_count
;
640 /* The value of `breakpoint_count' before the last command that
641 created breakpoints. If the last (break-like) command created more
642 than one breakpoint, then the difference between BREAKPOINT_COUNT
643 and PREV_BREAKPOINT_COUNT is more than one. */
644 static int prev_breakpoint_count
;
646 /* Number of last tracepoint made. */
648 static int tracepoint_count
;
650 static struct cmd_list_element
*breakpoint_set_cmdlist
;
651 static struct cmd_list_element
*breakpoint_show_cmdlist
;
652 struct cmd_list_element
*save_cmdlist
;
654 /* See declaration at breakpoint.h. */
657 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
660 struct breakpoint
*b
= NULL
;
664 if (func (b
, user_data
) != 0)
671 /* Return whether a breakpoint is an active enabled breakpoint. */
673 breakpoint_enabled (struct breakpoint
*b
)
675 return (b
->enable_state
== bp_enabled
);
678 /* Set breakpoint count to NUM. */
681 set_breakpoint_count (int num
)
683 prev_breakpoint_count
= breakpoint_count
;
684 breakpoint_count
= num
;
685 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
688 /* Used by `start_rbreak_breakpoints' below, to record the current
689 breakpoint count before "rbreak" creates any breakpoint. */
690 static int rbreak_start_breakpoint_count
;
692 /* Called at the start an "rbreak" command to record the first
696 start_rbreak_breakpoints (void)
698 rbreak_start_breakpoint_count
= breakpoint_count
;
701 /* Called at the end of an "rbreak" command to record the last
705 end_rbreak_breakpoints (void)
707 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
710 /* Used in run_command to zero the hit count when a new run starts. */
713 clear_breakpoint_hit_counts (void)
715 struct breakpoint
*b
;
721 /* Allocate a new counted_command_line with reference count of 1.
722 The new structure owns COMMANDS. */
724 static struct counted_command_line
*
725 alloc_counted_command_line (struct command_line
*commands
)
727 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
730 result
->commands
= commands
;
735 /* Increment reference count. This does nothing if CMD is NULL. */
738 incref_counted_command_line (struct counted_command_line
*cmd
)
744 /* Decrement reference count. If the reference count reaches 0,
745 destroy the counted_command_line. Sets *CMDP to NULL. This does
746 nothing if *CMDP is NULL. */
749 decref_counted_command_line (struct counted_command_line
**cmdp
)
753 if (--(*cmdp
)->refc
== 0)
755 free_command_lines (&(*cmdp
)->commands
);
762 /* A cleanup function that calls decref_counted_command_line. */
765 do_cleanup_counted_command_line (void *arg
)
767 decref_counted_command_line ((struct counted_command_line
**) arg
);
770 /* Create a cleanup that calls decref_counted_command_line on the
773 static struct cleanup
*
774 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
776 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
780 /* Return the breakpoint with the specified number, or NULL
781 if the number does not refer to an existing breakpoint. */
784 get_breakpoint (int num
)
786 struct breakpoint
*b
;
789 if (b
->number
== num
)
797 /* Mark locations as "conditions have changed" in case the target supports
798 evaluating conditions on its side. */
801 mark_breakpoint_modified (struct breakpoint
*b
)
803 struct bp_location
*loc
;
805 /* This is only meaningful if the target is
806 evaluating conditions and if the user has
807 opted for condition evaluation on the target's
809 if (gdb_evaluates_breakpoint_condition_p ()
810 || !target_supports_evaluation_of_breakpoint_conditions ())
813 if (!is_breakpoint (b
))
816 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
817 loc
->condition_changed
= condition_modified
;
820 /* Mark location as "conditions have changed" in case the target supports
821 evaluating conditions on its side. */
824 mark_breakpoint_location_modified (struct bp_location
*loc
)
826 /* This is only meaningful if the target is
827 evaluating conditions and if the user has
828 opted for condition evaluation on the target's
830 if (gdb_evaluates_breakpoint_condition_p ()
831 || !target_supports_evaluation_of_breakpoint_conditions ())
835 if (!is_breakpoint (loc
->owner
))
838 loc
->condition_changed
= condition_modified
;
841 /* Sets the condition-evaluation mode using the static global
842 condition_evaluation_mode. */
845 set_condition_evaluation_mode (char *args
, int from_tty
,
846 struct cmd_list_element
*c
)
848 const char *old_mode
, *new_mode
;
850 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
851 && !target_supports_evaluation_of_breakpoint_conditions ())
853 condition_evaluation_mode_1
= condition_evaluation_mode
;
854 warning (_("Target does not support breakpoint condition evaluation.\n"
855 "Using host evaluation mode instead."));
859 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
860 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
862 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
863 settings was "auto". */
864 condition_evaluation_mode
= condition_evaluation_mode_1
;
866 /* Only update the mode if the user picked a different one. */
867 if (new_mode
!= old_mode
)
869 struct bp_location
*loc
, **loc_tmp
;
870 /* If the user switched to a different evaluation mode, we
871 need to synch the changes with the target as follows:
873 "host" -> "target": Send all (valid) conditions to the target.
874 "target" -> "host": Remove all the conditions from the target.
877 if (new_mode
== condition_evaluation_target
)
879 /* Mark everything modified and synch conditions with the
881 ALL_BP_LOCATIONS (loc
, loc_tmp
)
882 mark_breakpoint_location_modified (loc
);
886 /* Manually mark non-duplicate locations to synch conditions
887 with the target. We do this to remove all the conditions the
888 target knows about. */
889 ALL_BP_LOCATIONS (loc
, loc_tmp
)
890 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
891 loc
->needs_update
= 1;
895 update_global_location_list (UGLL_MAY_INSERT
);
901 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
902 what "auto" is translating to. */
905 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
906 struct cmd_list_element
*c
, const char *value
)
908 if (condition_evaluation_mode
== condition_evaluation_auto
)
909 fprintf_filtered (file
,
910 _("Breakpoint condition evaluation "
911 "mode is %s (currently %s).\n"),
913 breakpoint_condition_evaluation_mode ());
915 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
919 /* A comparison function for bp_location AP and BP that is used by
920 bsearch. This comparison function only cares about addresses, unlike
921 the more general bp_locations_compare function. */
924 bp_locations_compare_addrs (const void *ap
, const void *bp
)
926 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
927 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
929 if (a
->address
== b
->address
)
932 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
935 /* Helper function to skip all bp_locations with addresses
936 less than ADDRESS. It returns the first bp_location that
937 is greater than or equal to ADDRESS. If none is found, just
940 static struct bp_location
**
941 get_first_locp_gte_addr (CORE_ADDR address
)
943 struct bp_location dummy_loc
;
944 struct bp_location
*dummy_locp
= &dummy_loc
;
945 struct bp_location
**locp_found
= NULL
;
947 /* Initialize the dummy location's address field. */
948 dummy_loc
.address
= address
;
950 /* Find a close match to the first location at ADDRESS. */
951 locp_found
= ((struct bp_location
**)
952 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
953 sizeof (struct bp_location
**),
954 bp_locations_compare_addrs
));
956 /* Nothing was found, nothing left to do. */
957 if (locp_found
== NULL
)
960 /* We may have found a location that is at ADDRESS but is not the first in the
961 location's list. Go backwards (if possible) and locate the first one. */
962 while ((locp_found
- 1) >= bp_locations
963 && (*(locp_found
- 1))->address
== address
)
970 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
973 xfree (b
->cond_string
);
974 b
->cond_string
= NULL
;
976 if (is_watchpoint (b
))
978 struct watchpoint
*w
= (struct watchpoint
*) b
;
980 w
->cond_exp
.reset ();
984 struct bp_location
*loc
;
986 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
990 /* No need to free the condition agent expression
991 bytecode (if we have one). We will handle this
992 when we go through update_global_location_list. */
999 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1003 const char *arg
= exp
;
1005 /* I don't know if it matters whether this is the string the user
1006 typed in or the decompiled expression. */
1007 b
->cond_string
= xstrdup (arg
);
1008 b
->condition_not_parsed
= 0;
1010 if (is_watchpoint (b
))
1012 struct watchpoint
*w
= (struct watchpoint
*) b
;
1014 innermost_block
= NULL
;
1016 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1018 error (_("Junk at end of expression"));
1019 w
->cond_exp_valid_block
= innermost_block
;
1023 struct bp_location
*loc
;
1025 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1029 parse_exp_1 (&arg
, loc
->address
,
1030 block_for_pc (loc
->address
), 0);
1032 error (_("Junk at end of expression"));
1036 mark_breakpoint_modified (b
);
1038 observer_notify_breakpoint_modified (b
);
1041 /* Completion for the "condition" command. */
1044 condition_completer (struct cmd_list_element
*cmd
,
1045 completion_tracker
&tracker
,
1046 const char *text
, const char *word
)
1050 text
= skip_spaces_const (text
);
1051 space
= skip_to_space_const (text
);
1055 struct breakpoint
*b
;
1056 VEC (char_ptr
) *result
= NULL
;
1060 /* We don't support completion of history indices. */
1061 if (!isdigit (text
[1]))
1062 complete_internalvar (tracker
, &text
[1]);
1066 /* We're completing the breakpoint number. */
1067 len
= strlen (text
);
1073 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1075 if (strncmp (number
, text
, len
) == 0)
1077 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
1078 tracker
.add_completion (std::move (copy
));
1085 /* We're completing the expression part. */
1086 text
= skip_spaces_const (space
);
1087 expression_completer (cmd
, tracker
, text
, word
);
1090 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1093 condition_command (char *arg
, int from_tty
)
1095 struct breakpoint
*b
;
1100 error_no_arg (_("breakpoint number"));
1103 bnum
= get_number (&p
);
1105 error (_("Bad breakpoint argument: '%s'"), arg
);
1108 if (b
->number
== bnum
)
1110 /* Check if this breakpoint has a "stop" method implemented in an
1111 extension language. This method and conditions entered into GDB
1112 from the CLI are mutually exclusive. */
1113 const struct extension_language_defn
*extlang
1114 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1116 if (extlang
!= NULL
)
1118 error (_("Only one stop condition allowed. There is currently"
1119 " a %s stop condition defined for this breakpoint."),
1120 ext_lang_capitalized_name (extlang
));
1122 set_breakpoint_condition (b
, p
, from_tty
);
1124 if (is_breakpoint (b
))
1125 update_global_location_list (UGLL_MAY_INSERT
);
1130 error (_("No breakpoint number %d."), bnum
);
1133 /* Check that COMMAND do not contain commands that are suitable
1134 only for tracepoints and not suitable for ordinary breakpoints.
1135 Throw if any such commands is found. */
1138 check_no_tracepoint_commands (struct command_line
*commands
)
1140 struct command_line
*c
;
1142 for (c
= commands
; c
; c
= c
->next
)
1146 if (c
->control_type
== while_stepping_control
)
1147 error (_("The 'while-stepping' command can "
1148 "only be used for tracepoints"));
1150 for (i
= 0; i
< c
->body_count
; ++i
)
1151 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1153 /* Not that command parsing removes leading whitespace and comment
1154 lines and also empty lines. So, we only need to check for
1155 command directly. */
1156 if (strstr (c
->line
, "collect ") == c
->line
)
1157 error (_("The 'collect' command can only be used for tracepoints"));
1159 if (strstr (c
->line
, "teval ") == c
->line
)
1160 error (_("The 'teval' command can only be used for tracepoints"));
1164 struct longjmp_breakpoint
: public breakpoint
1166 ~longjmp_breakpoint () override
;
1169 /* Encapsulate tests for different types of tracepoints. */
1172 is_tracepoint_type (bptype type
)
1174 return (type
== bp_tracepoint
1175 || type
== bp_fast_tracepoint
1176 || type
== bp_static_tracepoint
);
1180 is_longjmp_type (bptype type
)
1182 return type
== bp_longjmp
|| type
== bp_exception
;
1186 is_tracepoint (const struct breakpoint
*b
)
1188 return is_tracepoint_type (b
->type
);
1191 /* Factory function to create an appropriate instance of breakpoint given
1194 static std::unique_ptr
<breakpoint
>
1195 new_breakpoint_from_type (bptype type
)
1199 if (is_tracepoint_type (type
))
1200 b
= new tracepoint ();
1201 else if (is_longjmp_type (type
))
1202 b
= new longjmp_breakpoint ();
1204 b
= new breakpoint ();
1206 return std::unique_ptr
<breakpoint
> (b
);
1209 /* A helper function that validates that COMMANDS are valid for a
1210 breakpoint. This function will throw an exception if a problem is
1214 validate_commands_for_breakpoint (struct breakpoint
*b
,
1215 struct command_line
*commands
)
1217 if (is_tracepoint (b
))
1219 struct tracepoint
*t
= (struct tracepoint
*) b
;
1220 struct command_line
*c
;
1221 struct command_line
*while_stepping
= 0;
1223 /* Reset the while-stepping step count. The previous commands
1224 might have included a while-stepping action, while the new
1228 /* We need to verify that each top-level element of commands is
1229 valid for tracepoints, that there's at most one
1230 while-stepping element, and that the while-stepping's body
1231 has valid tracing commands excluding nested while-stepping.
1232 We also need to validate the tracepoint action line in the
1233 context of the tracepoint --- validate_actionline actually
1234 has side effects, like setting the tracepoint's
1235 while-stepping STEP_COUNT, in addition to checking if the
1236 collect/teval actions parse and make sense in the
1237 tracepoint's context. */
1238 for (c
= commands
; c
; c
= c
->next
)
1240 if (c
->control_type
== while_stepping_control
)
1242 if (b
->type
== bp_fast_tracepoint
)
1243 error (_("The 'while-stepping' command "
1244 "cannot be used for fast tracepoint"));
1245 else if (b
->type
== bp_static_tracepoint
)
1246 error (_("The 'while-stepping' command "
1247 "cannot be used for static tracepoint"));
1250 error (_("The 'while-stepping' command "
1251 "can be used only once"));
1256 validate_actionline (c
->line
, b
);
1260 struct command_line
*c2
;
1262 gdb_assert (while_stepping
->body_count
== 1);
1263 c2
= while_stepping
->body_list
[0];
1264 for (; c2
; c2
= c2
->next
)
1266 if (c2
->control_type
== while_stepping_control
)
1267 error (_("The 'while-stepping' command cannot be nested"));
1273 check_no_tracepoint_commands (commands
);
1277 /* Return a vector of all the static tracepoints set at ADDR. The
1278 caller is responsible for releasing the vector. */
1281 static_tracepoints_here (CORE_ADDR addr
)
1283 struct breakpoint
*b
;
1284 VEC(breakpoint_p
) *found
= 0;
1285 struct bp_location
*loc
;
1288 if (b
->type
== bp_static_tracepoint
)
1290 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1291 if (loc
->address
== addr
)
1292 VEC_safe_push(breakpoint_p
, found
, b
);
1298 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1299 validate that only allowed commands are included. */
1302 breakpoint_set_commands (struct breakpoint
*b
,
1303 command_line_up
&&commands
)
1305 validate_commands_for_breakpoint (b
, commands
.get ());
1307 decref_counted_command_line (&b
->commands
);
1308 b
->commands
= alloc_counted_command_line (commands
.release ());
1309 observer_notify_breakpoint_modified (b
);
1312 /* Set the internal `silent' flag on the breakpoint. Note that this
1313 is not the same as the "silent" that may appear in the breakpoint's
1317 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1319 int old_silent
= b
->silent
;
1322 if (old_silent
!= silent
)
1323 observer_notify_breakpoint_modified (b
);
1326 /* Set the thread for this breakpoint. If THREAD is -1, make the
1327 breakpoint work for any thread. */
1330 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1332 int old_thread
= b
->thread
;
1335 if (old_thread
!= thread
)
1336 observer_notify_breakpoint_modified (b
);
1339 /* Set the task for this breakpoint. If TASK is 0, make the
1340 breakpoint work for any task. */
1343 breakpoint_set_task (struct breakpoint
*b
, int task
)
1345 int old_task
= b
->task
;
1348 if (old_task
!= task
)
1349 observer_notify_breakpoint_modified (b
);
1353 check_tracepoint_command (char *line
, void *closure
)
1355 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1357 validate_actionline (line
, b
);
1360 /* A structure used to pass information through
1361 map_breakpoint_numbers. */
1363 struct commands_info
1365 /* True if the command was typed at a tty. */
1368 /* The breakpoint range spec. */
1371 /* Non-NULL if the body of the commands are being read from this
1372 already-parsed command. */
1373 struct command_line
*control
;
1375 /* The command lines read from the user, or NULL if they have not
1377 struct counted_command_line
*cmd
;
1380 /* A callback for map_breakpoint_numbers that sets the commands for
1381 commands_command. */
1384 do_map_commands_command (struct breakpoint
*b
, void *data
)
1386 struct commands_info
*info
= (struct commands_info
*) data
;
1388 if (info
->cmd
== NULL
)
1392 if (info
->control
!= NULL
)
1393 l
= copy_command_lines (info
->control
->body_list
[0]);
1396 struct cleanup
*old_chain
;
1399 str
= xstrprintf (_("Type commands for breakpoint(s) "
1400 "%s, one per line."),
1403 old_chain
= make_cleanup (xfree
, str
);
1405 l
= read_command_lines (str
,
1408 ? check_tracepoint_command
: 0),
1411 do_cleanups (old_chain
);
1414 info
->cmd
= alloc_counted_command_line (l
.release ());
1417 /* If a breakpoint was on the list more than once, we don't need to
1419 if (b
->commands
!= info
->cmd
)
1421 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1422 incref_counted_command_line (info
->cmd
);
1423 decref_counted_command_line (&b
->commands
);
1424 b
->commands
= info
->cmd
;
1425 observer_notify_breakpoint_modified (b
);
1430 commands_command_1 (const char *arg
, int from_tty
,
1431 struct command_line
*control
)
1433 struct cleanup
*cleanups
;
1434 struct commands_info info
;
1436 info
.from_tty
= from_tty
;
1437 info
.control
= control
;
1439 /* If we read command lines from the user, then `info' will hold an
1440 extra reference to the commands that we must clean up. */
1441 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1443 std::string new_arg
;
1445 if (arg
== NULL
|| !*arg
)
1447 if (breakpoint_count
- prev_breakpoint_count
> 1)
1448 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1450 else if (breakpoint_count
> 0)
1451 new_arg
= string_printf ("%d", breakpoint_count
);
1456 info
.arg
= new_arg
.c_str ();
1458 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1460 if (info
.cmd
== NULL
)
1461 error (_("No breakpoints specified."));
1463 do_cleanups (cleanups
);
1467 commands_command (char *arg
, int from_tty
)
1469 commands_command_1 (arg
, from_tty
, NULL
);
1472 /* Like commands_command, but instead of reading the commands from
1473 input stream, takes them from an already parsed command structure.
1475 This is used by cli-script.c to DTRT with breakpoint commands
1476 that are part of if and while bodies. */
1477 enum command_control_type
1478 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1480 commands_command_1 (arg
, 0, cmd
);
1481 return simple_control
;
1484 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1487 bp_location_has_shadow (struct bp_location
*bl
)
1489 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1493 if (bl
->target_info
.shadow_len
== 0)
1494 /* BL isn't valid, or doesn't shadow memory. */
1499 /* Update BUF, which is LEN bytes read from the target address
1500 MEMADDR, by replacing a memory breakpoint with its shadowed
1503 If READBUF is not NULL, this buffer must not overlap with the of
1504 the breakpoint location's shadow_contents buffer. Otherwise, a
1505 failed assertion internal error will be raised. */
1508 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1509 const gdb_byte
*writebuf_org
,
1510 ULONGEST memaddr
, LONGEST len
,
1511 struct bp_target_info
*target_info
,
1512 struct gdbarch
*gdbarch
)
1514 /* Now do full processing of the found relevant range of elements. */
1515 CORE_ADDR bp_addr
= 0;
1519 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1520 current_program_space
->aspace
, 0))
1522 /* The breakpoint is inserted in a different address space. */
1526 /* Addresses and length of the part of the breakpoint that
1528 bp_addr
= target_info
->placed_address
;
1529 bp_size
= target_info
->shadow_len
;
1531 if (bp_addr
+ bp_size
<= memaddr
)
1533 /* The breakpoint is entirely before the chunk of memory we are
1538 if (bp_addr
>= memaddr
+ len
)
1540 /* The breakpoint is entirely after the chunk of memory we are
1545 /* Offset within shadow_contents. */
1546 if (bp_addr
< memaddr
)
1548 /* Only copy the second part of the breakpoint. */
1549 bp_size
-= memaddr
- bp_addr
;
1550 bptoffset
= memaddr
- bp_addr
;
1554 if (bp_addr
+ bp_size
> memaddr
+ len
)
1556 /* Only copy the first part of the breakpoint. */
1557 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1560 if (readbuf
!= NULL
)
1562 /* Verify that the readbuf buffer does not overlap with the
1563 shadow_contents buffer. */
1564 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1565 || readbuf
>= (target_info
->shadow_contents
1566 + target_info
->shadow_len
));
1568 /* Update the read buffer with this inserted breakpoint's
1570 memcpy (readbuf
+ bp_addr
- memaddr
,
1571 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1575 const unsigned char *bp
;
1576 CORE_ADDR addr
= target_info
->reqstd_address
;
1579 /* Update the shadow with what we want to write to memory. */
1580 memcpy (target_info
->shadow_contents
+ bptoffset
,
1581 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1583 /* Determine appropriate breakpoint contents and size for this
1585 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1587 /* Update the final write buffer with this inserted
1588 breakpoint's INSN. */
1589 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1593 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1594 by replacing any memory breakpoints with their shadowed contents.
1596 If READBUF is not NULL, this buffer must not overlap with any of
1597 the breakpoint location's shadow_contents buffers. Otherwise,
1598 a failed assertion internal error will be raised.
1600 The range of shadowed area by each bp_location is:
1601 bl->address - bp_locations_placed_address_before_address_max
1602 up to bl->address + bp_locations_shadow_len_after_address_max
1603 The range we were requested to resolve shadows for is:
1604 memaddr ... memaddr + len
1605 Thus the safe cutoff boundaries for performance optimization are
1606 memaddr + len <= (bl->address
1607 - bp_locations_placed_address_before_address_max)
1609 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1612 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1613 const gdb_byte
*writebuf_org
,
1614 ULONGEST memaddr
, LONGEST len
)
1616 /* Left boundary, right boundary and median element of our binary
1618 unsigned bc_l
, bc_r
, bc
;
1620 /* Find BC_L which is a leftmost element which may affect BUF
1621 content. It is safe to report lower value but a failure to
1622 report higher one. */
1625 bc_r
= bp_locations_count
;
1626 while (bc_l
+ 1 < bc_r
)
1628 struct bp_location
*bl
;
1630 bc
= (bc_l
+ bc_r
) / 2;
1631 bl
= bp_locations
[bc
];
1633 /* Check first BL->ADDRESS will not overflow due to the added
1634 constant. Then advance the left boundary only if we are sure
1635 the BC element can in no way affect the BUF content (MEMADDR
1636 to MEMADDR + LEN range).
1638 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1639 offset so that we cannot miss a breakpoint with its shadow
1640 range tail still reaching MEMADDR. */
1642 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1644 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1651 /* Due to the binary search above, we need to make sure we pick the
1652 first location that's at BC_L's address. E.g., if there are
1653 multiple locations at the same address, BC_L may end up pointing
1654 at a duplicate location, and miss the "master"/"inserted"
1655 location. Say, given locations L1, L2 and L3 at addresses A and
1658 L1@A, L2@A, L3@B, ...
1660 BC_L could end up pointing at location L2, while the "master"
1661 location could be L1. Since the `loc->inserted' flag is only set
1662 on "master" locations, we'd forget to restore the shadow of L1
1665 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1668 /* Now do full processing of the found relevant range of elements. */
1670 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1672 struct bp_location
*bl
= bp_locations
[bc
];
1674 /* bp_location array has BL->OWNER always non-NULL. */
1675 if (bl
->owner
->type
== bp_none
)
1676 warning (_("reading through apparently deleted breakpoint #%d?"),
1679 /* Performance optimization: any further element can no longer affect BUF
1682 if (bl
->address
>= bp_locations_placed_address_before_address_max
1683 && memaddr
+ len
<= (bl
->address
1684 - bp_locations_placed_address_before_address_max
))
1687 if (!bp_location_has_shadow (bl
))
1690 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1691 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1697 /* Return true if BPT is either a software breakpoint or a hardware
1701 is_breakpoint (const struct breakpoint
*bpt
)
1703 return (bpt
->type
== bp_breakpoint
1704 || bpt
->type
== bp_hardware_breakpoint
1705 || bpt
->type
== bp_dprintf
);
1708 /* Return true if BPT is of any hardware watchpoint kind. */
1711 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1713 return (bpt
->type
== bp_hardware_watchpoint
1714 || bpt
->type
== bp_read_watchpoint
1715 || bpt
->type
== bp_access_watchpoint
);
1718 /* Return true if BPT is of any watchpoint kind, hardware or
1722 is_watchpoint (const struct breakpoint
*bpt
)
1724 return (is_hardware_watchpoint (bpt
)
1725 || bpt
->type
== bp_watchpoint
);
1728 /* Returns true if the current thread and its running state are safe
1729 to evaluate or update watchpoint B. Watchpoints on local
1730 expressions need to be evaluated in the context of the thread that
1731 was current when the watchpoint was created, and, that thread needs
1732 to be stopped to be able to select the correct frame context.
1733 Watchpoints on global expressions can be evaluated on any thread,
1734 and in any state. It is presently left to the target allowing
1735 memory accesses when threads are running. */
1738 watchpoint_in_thread_scope (struct watchpoint
*b
)
1740 return (b
->pspace
== current_program_space
1741 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1742 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1743 && !is_executing (inferior_ptid
))));
1746 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1747 associated bp_watchpoint_scope breakpoint. */
1750 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1752 if (w
->related_breakpoint
!= w
)
1754 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1755 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1756 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1757 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1758 w
->related_breakpoint
= w
;
1760 w
->disposition
= disp_del_at_next_stop
;
1763 /* Extract a bitfield value from value VAL using the bit parameters contained in
1766 static struct value
*
1767 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1769 struct value
*bit_val
;
1774 bit_val
= allocate_value (value_type (val
));
1776 unpack_value_bitfield (bit_val
,
1779 value_contents_for_printing (val
),
1786 /* Allocate a dummy location and add it to B, which must be a software
1787 watchpoint. This is required because even if a software watchpoint
1788 is not watching any memory, bpstat_stop_status requires a location
1789 to be able to report stops. */
1792 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1793 struct program_space
*pspace
)
1795 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1797 b
->loc
= allocate_bp_location (b
);
1798 b
->loc
->pspace
= pspace
;
1799 b
->loc
->address
= -1;
1800 b
->loc
->length
= -1;
1803 /* Returns true if B is a software watchpoint that is not watching any
1804 memory (e.g., "watch $pc"). */
1807 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1809 return (b
->type
== bp_watchpoint
1811 && b
->loc
->next
== NULL
1812 && b
->loc
->address
== -1
1813 && b
->loc
->length
== -1);
1816 /* Assuming that B is a watchpoint:
1817 - Reparse watchpoint expression, if REPARSE is non-zero
1818 - Evaluate expression and store the result in B->val
1819 - Evaluate the condition if there is one, and store the result
1821 - Update the list of values that must be watched in B->loc.
1823 If the watchpoint disposition is disp_del_at_next_stop, then do
1824 nothing. If this is local watchpoint that is out of scope, delete
1827 Even with `set breakpoint always-inserted on' the watchpoints are
1828 removed + inserted on each stop here. Normal breakpoints must
1829 never be removed because they might be missed by a running thread
1830 when debugging in non-stop mode. On the other hand, hardware
1831 watchpoints (is_hardware_watchpoint; processed here) are specific
1832 to each LWP since they are stored in each LWP's hardware debug
1833 registers. Therefore, such LWP must be stopped first in order to
1834 be able to modify its hardware watchpoints.
1836 Hardware watchpoints must be reset exactly once after being
1837 presented to the user. It cannot be done sooner, because it would
1838 reset the data used to present the watchpoint hit to the user. And
1839 it must not be done later because it could display the same single
1840 watchpoint hit during multiple GDB stops. Note that the latter is
1841 relevant only to the hardware watchpoint types bp_read_watchpoint
1842 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1843 not user-visible - its hit is suppressed if the memory content has
1846 The following constraints influence the location where we can reset
1847 hardware watchpoints:
1849 * target_stopped_by_watchpoint and target_stopped_data_address are
1850 called several times when GDB stops.
1853 * Multiple hardware watchpoints can be hit at the same time,
1854 causing GDB to stop. GDB only presents one hardware watchpoint
1855 hit at a time as the reason for stopping, and all the other hits
1856 are presented later, one after the other, each time the user
1857 requests the execution to be resumed. Execution is not resumed
1858 for the threads still having pending hit event stored in
1859 LWP_INFO->STATUS. While the watchpoint is already removed from
1860 the inferior on the first stop the thread hit event is kept being
1861 reported from its cached value by linux_nat_stopped_data_address
1862 until the real thread resume happens after the watchpoint gets
1863 presented and thus its LWP_INFO->STATUS gets reset.
1865 Therefore the hardware watchpoint hit can get safely reset on the
1866 watchpoint removal from inferior. */
1869 update_watchpoint (struct watchpoint
*b
, int reparse
)
1871 int within_current_scope
;
1872 struct frame_id saved_frame_id
;
1875 /* If this is a local watchpoint, we only want to check if the
1876 watchpoint frame is in scope if the current thread is the thread
1877 that was used to create the watchpoint. */
1878 if (!watchpoint_in_thread_scope (b
))
1881 if (b
->disposition
== disp_del_at_next_stop
)
1886 /* Determine if the watchpoint is within scope. */
1887 if (b
->exp_valid_block
== NULL
)
1888 within_current_scope
= 1;
1891 struct frame_info
*fi
= get_current_frame ();
1892 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1893 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1895 /* If we're at a point where the stack has been destroyed
1896 (e.g. in a function epilogue), unwinding may not work
1897 properly. Do not attempt to recreate locations at this
1898 point. See similar comments in watchpoint_check. */
1899 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1902 /* Save the current frame's ID so we can restore it after
1903 evaluating the watchpoint expression on its own frame. */
1904 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1905 took a frame parameter, so that we didn't have to change the
1908 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1910 fi
= frame_find_by_id (b
->watchpoint_frame
);
1911 within_current_scope
= (fi
!= NULL
);
1912 if (within_current_scope
)
1916 /* We don't free locations. They are stored in the bp_location array
1917 and update_global_location_list will eventually delete them and
1918 remove breakpoints if needed. */
1921 if (within_current_scope
&& reparse
)
1926 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1927 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1928 /* If the meaning of expression itself changed, the old value is
1929 no longer relevant. We don't want to report a watchpoint hit
1930 to the user when the old value and the new value may actually
1931 be completely different objects. */
1932 value_free (b
->val
);
1936 /* Note that unlike with breakpoints, the watchpoint's condition
1937 expression is stored in the breakpoint object, not in the
1938 locations (re)created below. */
1939 if (b
->cond_string
!= NULL
)
1941 b
->cond_exp
.reset ();
1944 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1948 /* If we failed to parse the expression, for example because
1949 it refers to a global variable in a not-yet-loaded shared library,
1950 don't try to insert watchpoint. We don't automatically delete
1951 such watchpoint, though, since failure to parse expression
1952 is different from out-of-scope watchpoint. */
1953 if (!target_has_execution
)
1955 /* Without execution, memory can't change. No use to try and
1956 set watchpoint locations. The watchpoint will be reset when
1957 the target gains execution, through breakpoint_re_set. */
1958 if (!can_use_hw_watchpoints
)
1960 if (b
->ops
->works_in_software_mode (b
))
1961 b
->type
= bp_watchpoint
;
1963 error (_("Can't set read/access watchpoint when "
1964 "hardware watchpoints are disabled."));
1967 else if (within_current_scope
&& b
->exp
)
1970 struct value
*val_chain
, *v
, *result
, *next
;
1971 struct program_space
*frame_pspace
;
1973 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1975 /* Avoid setting b->val if it's already set. The meaning of
1976 b->val is 'the last value' user saw, and we should update
1977 it only if we reported that last value to user. As it
1978 happens, the code that reports it updates b->val directly.
1979 We don't keep track of the memory value for masked
1981 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1983 if (b
->val_bitsize
!= 0)
1985 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1993 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1995 /* Look at each value on the value chain. */
1996 for (v
= val_chain
; v
; v
= value_next (v
))
1998 /* If it's a memory location, and GDB actually needed
1999 its contents to evaluate the expression, then we
2000 must watch it. If the first value returned is
2001 still lazy, that means an error occurred reading it;
2002 watch it anyway in case it becomes readable. */
2003 if (VALUE_LVAL (v
) == lval_memory
2004 && (v
== val_chain
|| ! value_lazy (v
)))
2006 struct type
*vtype
= check_typedef (value_type (v
));
2008 /* We only watch structs and arrays if user asked
2009 for it explicitly, never if they just happen to
2010 appear in the middle of some value chain. */
2012 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2013 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2016 enum target_hw_bp_type type
;
2017 struct bp_location
*loc
, **tmp
;
2018 int bitpos
= 0, bitsize
= 0;
2020 if (value_bitsize (v
) != 0)
2022 /* Extract the bit parameters out from the bitfield
2024 bitpos
= value_bitpos (v
);
2025 bitsize
= value_bitsize (v
);
2027 else if (v
== result
&& b
->val_bitsize
!= 0)
2029 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2030 lvalue whose bit parameters are saved in the fields
2031 VAL_BITPOS and VAL_BITSIZE. */
2032 bitpos
= b
->val_bitpos
;
2033 bitsize
= b
->val_bitsize
;
2036 addr
= value_address (v
);
2039 /* Skip the bytes that don't contain the bitfield. */
2044 if (b
->type
== bp_read_watchpoint
)
2046 else if (b
->type
== bp_access_watchpoint
)
2049 loc
= allocate_bp_location (b
);
2050 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2053 loc
->gdbarch
= get_type_arch (value_type (v
));
2055 loc
->pspace
= frame_pspace
;
2056 loc
->address
= addr
;
2060 /* Just cover the bytes that make up the bitfield. */
2061 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2064 loc
->length
= TYPE_LENGTH (value_type (v
));
2066 loc
->watchpoint_type
= type
;
2071 /* Change the type of breakpoint between hardware assisted or
2072 an ordinary watchpoint depending on the hardware support
2073 and free hardware slots. REPARSE is set when the inferior
2078 enum bp_loc_type loc_type
;
2079 struct bp_location
*bl
;
2081 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2085 int i
, target_resources_ok
, other_type_used
;
2088 /* Use an exact watchpoint when there's only one memory region to be
2089 watched, and only one debug register is needed to watch it. */
2090 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2092 /* We need to determine how many resources are already
2093 used for all other hardware watchpoints plus this one
2094 to see if we still have enough resources to also fit
2095 this watchpoint in as well. */
2097 /* If this is a software watchpoint, we try to turn it
2098 to a hardware one -- count resources as if B was of
2099 hardware watchpoint type. */
2101 if (type
== bp_watchpoint
)
2102 type
= bp_hardware_watchpoint
;
2104 /* This watchpoint may or may not have been placed on
2105 the list yet at this point (it won't be in the list
2106 if we're trying to create it for the first time,
2107 through watch_command), so always account for it
2110 /* Count resources used by all watchpoints except B. */
2111 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2113 /* Add in the resources needed for B. */
2114 i
+= hw_watchpoint_use_count (b
);
2117 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2118 if (target_resources_ok
<= 0)
2120 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2122 if (target_resources_ok
== 0 && !sw_mode
)
2123 error (_("Target does not support this type of "
2124 "hardware watchpoint."));
2125 else if (target_resources_ok
< 0 && !sw_mode
)
2126 error (_("There are not enough available hardware "
2127 "resources for this watchpoint."));
2129 /* Downgrade to software watchpoint. */
2130 b
->type
= bp_watchpoint
;
2134 /* If this was a software watchpoint, we've just
2135 found we have enough resources to turn it to a
2136 hardware watchpoint. Otherwise, this is a
2141 else if (!b
->ops
->works_in_software_mode (b
))
2143 if (!can_use_hw_watchpoints
)
2144 error (_("Can't set read/access watchpoint when "
2145 "hardware watchpoints are disabled."));
2147 error (_("Expression cannot be implemented with "
2148 "read/access watchpoint."));
2151 b
->type
= bp_watchpoint
;
2153 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2154 : bp_loc_hardware_watchpoint
);
2155 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2156 bl
->loc_type
= loc_type
;
2159 for (v
= val_chain
; v
; v
= next
)
2161 next
= value_next (v
);
2166 /* If a software watchpoint is not watching any memory, then the
2167 above left it without any location set up. But,
2168 bpstat_stop_status requires a location to be able to report
2169 stops, so make sure there's at least a dummy one. */
2170 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2171 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2173 else if (!within_current_scope
)
2175 printf_filtered (_("\
2176 Watchpoint %d deleted because the program has left the block\n\
2177 in which its expression is valid.\n"),
2179 watchpoint_del_at_next_stop (b
);
2182 /* Restore the selected frame. */
2184 select_frame (frame_find_by_id (saved_frame_id
));
2188 /* Returns 1 iff breakpoint location should be
2189 inserted in the inferior. We don't differentiate the type of BL's owner
2190 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2191 breakpoint_ops is not defined, because in insert_bp_location,
2192 tracepoint's insert_location will not be called. */
2194 should_be_inserted (struct bp_location
*bl
)
2196 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2199 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2202 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2205 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2208 /* This is set for example, when we're attached to the parent of a
2209 vfork, and have detached from the child. The child is running
2210 free, and we expect it to do an exec or exit, at which point the
2211 OS makes the parent schedulable again (and the target reports
2212 that the vfork is done). Until the child is done with the shared
2213 memory region, do not insert breakpoints in the parent, otherwise
2214 the child could still trip on the parent's breakpoints. Since
2215 the parent is blocked anyway, it won't miss any breakpoint. */
2216 if (bl
->pspace
->breakpoints_not_allowed
)
2219 /* Don't insert a breakpoint if we're trying to step past its
2220 location, except if the breakpoint is a single-step breakpoint,
2221 and the breakpoint's thread is the thread which is stepping past
2223 if ((bl
->loc_type
== bp_loc_software_breakpoint
2224 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2225 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2227 /* The single-step breakpoint may be inserted at the location
2228 we're trying to step if the instruction branches to itself.
2229 However, the instruction won't be executed at all and it may
2230 break the semantics of the instruction, for example, the
2231 instruction is a conditional branch or updates some flags.
2232 We can't fix it unless GDB is able to emulate the instruction
2233 or switch to displaced stepping. */
2234 && !(bl
->owner
->type
== bp_single_step
2235 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2239 fprintf_unfiltered (gdb_stdlog
,
2240 "infrun: skipping breakpoint: "
2241 "stepping past insn at: %s\n",
2242 paddress (bl
->gdbarch
, bl
->address
));
2247 /* Don't insert watchpoints if we're trying to step past the
2248 instruction that triggered one. */
2249 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2250 && stepping_past_nonsteppable_watchpoint ())
2254 fprintf_unfiltered (gdb_stdlog
,
2255 "infrun: stepping past non-steppable watchpoint. "
2256 "skipping watchpoint at %s:%d\n",
2257 paddress (bl
->gdbarch
, bl
->address
),
2266 /* Same as should_be_inserted but does the check assuming
2267 that the location is not duplicated. */
2270 unduplicated_should_be_inserted (struct bp_location
*bl
)
2273 const int save_duplicate
= bl
->duplicate
;
2276 result
= should_be_inserted (bl
);
2277 bl
->duplicate
= save_duplicate
;
2281 /* Parses a conditional described by an expression COND into an
2282 agent expression bytecode suitable for evaluation
2283 by the bytecode interpreter. Return NULL if there was
2284 any error during parsing. */
2286 static agent_expr_up
2287 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2292 agent_expr_up aexpr
;
2294 /* We don't want to stop processing, so catch any errors
2295 that may show up. */
2298 aexpr
= gen_eval_for_expr (scope
, cond
);
2301 CATCH (ex
, RETURN_MASK_ERROR
)
2303 /* If we got here, it means the condition could not be parsed to a valid
2304 bytecode expression and thus can't be evaluated on the target's side.
2305 It's no use iterating through the conditions. */
2309 /* We have a valid agent expression. */
2313 /* Based on location BL, create a list of breakpoint conditions to be
2314 passed on to the target. If we have duplicated locations with different
2315 conditions, we will add such conditions to the list. The idea is that the
2316 target will evaluate the list of conditions and will only notify GDB when
2317 one of them is true. */
2320 build_target_condition_list (struct bp_location
*bl
)
2322 struct bp_location
**locp
= NULL
, **loc2p
;
2323 int null_condition_or_parse_error
= 0;
2324 int modified
= bl
->needs_update
;
2325 struct bp_location
*loc
;
2327 /* Release conditions left over from a previous insert. */
2328 bl
->target_info
.conditions
.clear ();
2330 /* This is only meaningful if the target is
2331 evaluating conditions and if the user has
2332 opted for condition evaluation on the target's
2334 if (gdb_evaluates_breakpoint_condition_p ()
2335 || !target_supports_evaluation_of_breakpoint_conditions ())
2338 /* Do a first pass to check for locations with no assigned
2339 conditions or conditions that fail to parse to a valid agent expression
2340 bytecode. If any of these happen, then it's no use to send conditions
2341 to the target since this location will always trigger and generate a
2342 response back to GDB. */
2343 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2346 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2350 /* Re-parse the conditions since something changed. In that
2351 case we already freed the condition bytecodes (see
2352 force_breakpoint_reinsertion). We just
2353 need to parse the condition to bytecodes again. */
2354 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2358 /* If we have a NULL bytecode expression, it means something
2359 went wrong or we have a null condition expression. */
2360 if (!loc
->cond_bytecode
)
2362 null_condition_or_parse_error
= 1;
2368 /* If any of these happened, it means we will have to evaluate the conditions
2369 for the location's address on gdb's side. It is no use keeping bytecodes
2370 for all the other duplicate locations, thus we free all of them here.
2372 This is so we have a finer control over which locations' conditions are
2373 being evaluated by GDB or the remote stub. */
2374 if (null_condition_or_parse_error
)
2376 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2379 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2381 /* Only go as far as the first NULL bytecode is
2383 if (!loc
->cond_bytecode
)
2386 loc
->cond_bytecode
.reset ();
2391 /* No NULL conditions or failed bytecode generation. Build a condition list
2392 for this location's address. */
2393 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2397 && is_breakpoint (loc
->owner
)
2398 && loc
->pspace
->num
== bl
->pspace
->num
2399 && loc
->owner
->enable_state
== bp_enabled
2402 /* Add the condition to the vector. This will be used later
2403 to send the conditions to the target. */
2404 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2411 /* Parses a command described by string CMD into an agent expression
2412 bytecode suitable for evaluation by the bytecode interpreter.
2413 Return NULL if there was any error during parsing. */
2415 static agent_expr_up
2416 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2418 struct cleanup
*old_cleanups
= 0;
2419 struct expression
**argvec
;
2420 const char *cmdrest
;
2421 const char *format_start
, *format_end
;
2422 struct format_piece
*fpieces
;
2424 struct gdbarch
*gdbarch
= get_current_arch ();
2431 if (*cmdrest
== ',')
2433 cmdrest
= skip_spaces_const (cmdrest
);
2435 if (*cmdrest
++ != '"')
2436 error (_("No format string following the location"));
2438 format_start
= cmdrest
;
2440 fpieces
= parse_format_string (&cmdrest
);
2442 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2444 format_end
= cmdrest
;
2446 if (*cmdrest
++ != '"')
2447 error (_("Bad format string, non-terminated '\"'."));
2449 cmdrest
= skip_spaces_const (cmdrest
);
2451 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2452 error (_("Invalid argument syntax"));
2454 if (*cmdrest
== ',')
2456 cmdrest
= skip_spaces_const (cmdrest
);
2458 /* For each argument, make an expression. */
2460 argvec
= (struct expression
**) alloca (strlen (cmd
)
2461 * sizeof (struct expression
*));
2464 while (*cmdrest
!= '\0')
2469 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2470 argvec
[nargs
++] = expr
.release ();
2472 if (*cmdrest
== ',')
2476 agent_expr_up aexpr
;
2478 /* We don't want to stop processing, so catch any errors
2479 that may show up. */
2482 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2483 format_start
, format_end
- format_start
,
2484 fpieces
, nargs
, argvec
);
2486 CATCH (ex
, RETURN_MASK_ERROR
)
2488 /* If we got here, it means the command could not be parsed to a valid
2489 bytecode expression and thus can't be evaluated on the target's side.
2490 It's no use iterating through the other commands. */
2494 do_cleanups (old_cleanups
);
2496 /* We have a valid agent expression, return it. */
2500 /* Based on location BL, create a list of breakpoint commands to be
2501 passed on to the target. If we have duplicated locations with
2502 different commands, we will add any such to the list. */
2505 build_target_command_list (struct bp_location
*bl
)
2507 struct bp_location
**locp
= NULL
, **loc2p
;
2508 int null_command_or_parse_error
= 0;
2509 int modified
= bl
->needs_update
;
2510 struct bp_location
*loc
;
2512 /* Clear commands left over from a previous insert. */
2513 bl
->target_info
.tcommands
.clear ();
2515 if (!target_can_run_breakpoint_commands ())
2518 /* For now, limit to agent-style dprintf breakpoints. */
2519 if (dprintf_style
!= dprintf_style_agent
)
2522 /* For now, if we have any duplicate location that isn't a dprintf,
2523 don't install the target-side commands, as that would make the
2524 breakpoint not be reported to the core, and we'd lose
2526 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2529 if (is_breakpoint (loc
->owner
)
2530 && loc
->pspace
->num
== bl
->pspace
->num
2531 && loc
->owner
->type
!= bp_dprintf
)
2535 /* Do a first pass to check for locations with no assigned
2536 conditions or conditions that fail to parse to a valid agent expression
2537 bytecode. If any of these happen, then it's no use to send conditions
2538 to the target since this location will always trigger and generate a
2539 response back to GDB. */
2540 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2543 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2547 /* Re-parse the commands since something changed. In that
2548 case we already freed the command bytecodes (see
2549 force_breakpoint_reinsertion). We just
2550 need to parse the command to bytecodes again. */
2552 = parse_cmd_to_aexpr (bl
->address
,
2553 loc
->owner
->extra_string
);
2556 /* If we have a NULL bytecode expression, it means something
2557 went wrong or we have a null command expression. */
2558 if (!loc
->cmd_bytecode
)
2560 null_command_or_parse_error
= 1;
2566 /* If anything failed, then we're not doing target-side commands,
2568 if (null_command_or_parse_error
)
2570 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2573 if (is_breakpoint (loc
->owner
)
2574 && loc
->pspace
->num
== bl
->pspace
->num
)
2576 /* Only go as far as the first NULL bytecode is
2578 if (loc
->cmd_bytecode
== NULL
)
2581 loc
->cmd_bytecode
.reset ();
2586 /* No NULL commands or failed bytecode generation. Build a command list
2587 for this location's address. */
2588 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2591 if (loc
->owner
->extra_string
2592 && is_breakpoint (loc
->owner
)
2593 && loc
->pspace
->num
== bl
->pspace
->num
2594 && loc
->owner
->enable_state
== bp_enabled
2597 /* Add the command to the vector. This will be used later
2598 to send the commands to the target. */
2599 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2603 bl
->target_info
.persist
= 0;
2604 /* Maybe flag this location as persistent. */
2605 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2606 bl
->target_info
.persist
= 1;
2609 /* Return the kind of breakpoint on address *ADDR. Get the kind
2610 of breakpoint according to ADDR except single-step breakpoint.
2611 Get the kind of single-step breakpoint according to the current
2615 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2617 if (bl
->owner
->type
== bp_single_step
)
2619 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2620 struct regcache
*regcache
;
2622 regcache
= get_thread_regcache (thr
->ptid
);
2624 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2628 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2631 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2632 location. Any error messages are printed to TMP_ERROR_STREAM; and
2633 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2634 Returns 0 for success, 1 if the bp_location type is not supported or
2637 NOTE drow/2003-09-09: This routine could be broken down to an
2638 object-style method for each breakpoint or catchpoint type. */
2640 insert_bp_location (struct bp_location
*bl
,
2641 struct ui_file
*tmp_error_stream
,
2642 int *disabled_breaks
,
2643 int *hw_breakpoint_error
,
2644 int *hw_bp_error_explained_already
)
2646 enum errors bp_err
= GDB_NO_ERROR
;
2647 const char *bp_err_message
= NULL
;
2649 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2652 /* Note we don't initialize bl->target_info, as that wipes out
2653 the breakpoint location's shadow_contents if the breakpoint
2654 is still inserted at that location. This in turn breaks
2655 target_read_memory which depends on these buffers when
2656 a memory read is requested at the breakpoint location:
2657 Once the target_info has been wiped, we fail to see that
2658 we have a breakpoint inserted at that address and thus
2659 read the breakpoint instead of returning the data saved in
2660 the breakpoint location's shadow contents. */
2661 bl
->target_info
.reqstd_address
= bl
->address
;
2662 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2663 bl
->target_info
.length
= bl
->length
;
2665 /* When working with target-side conditions, we must pass all the conditions
2666 for the same breakpoint address down to the target since GDB will not
2667 insert those locations. With a list of breakpoint conditions, the target
2668 can decide when to stop and notify GDB. */
2670 if (is_breakpoint (bl
->owner
))
2672 build_target_condition_list (bl
);
2673 build_target_command_list (bl
);
2674 /* Reset the modification marker. */
2675 bl
->needs_update
= 0;
2678 if (bl
->loc_type
== bp_loc_software_breakpoint
2679 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2681 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2683 /* If the explicitly specified breakpoint type
2684 is not hardware breakpoint, check the memory map to see
2685 if the breakpoint address is in read only memory or not.
2687 Two important cases are:
2688 - location type is not hardware breakpoint, memory
2689 is readonly. We change the type of the location to
2690 hardware breakpoint.
2691 - location type is hardware breakpoint, memory is
2692 read-write. This means we've previously made the
2693 location hardware one, but then the memory map changed,
2696 When breakpoints are removed, remove_breakpoints will use
2697 location types we've just set here, the only possible
2698 problem is that memory map has changed during running
2699 program, but it's not going to work anyway with current
2701 struct mem_region
*mr
2702 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2706 if (automatic_hardware_breakpoints
)
2708 enum bp_loc_type new_type
;
2710 if (mr
->attrib
.mode
!= MEM_RW
)
2711 new_type
= bp_loc_hardware_breakpoint
;
2713 new_type
= bp_loc_software_breakpoint
;
2715 if (new_type
!= bl
->loc_type
)
2717 static int said
= 0;
2719 bl
->loc_type
= new_type
;
2722 fprintf_filtered (gdb_stdout
,
2723 _("Note: automatically using "
2724 "hardware breakpoints for "
2725 "read-only addresses.\n"));
2730 else if (bl
->loc_type
== bp_loc_software_breakpoint
2731 && mr
->attrib
.mode
!= MEM_RW
)
2733 fprintf_unfiltered (tmp_error_stream
,
2734 _("Cannot insert breakpoint %d.\n"
2735 "Cannot set software breakpoint "
2736 "at read-only address %s\n"),
2738 paddress (bl
->gdbarch
, bl
->address
));
2744 /* First check to see if we have to handle an overlay. */
2745 if (overlay_debugging
== ovly_off
2746 || bl
->section
== NULL
2747 || !(section_is_overlay (bl
->section
)))
2749 /* No overlay handling: just set the breakpoint. */
2754 val
= bl
->owner
->ops
->insert_location (bl
);
2756 bp_err
= GENERIC_ERROR
;
2758 CATCH (e
, RETURN_MASK_ALL
)
2761 bp_err_message
= e
.message
;
2767 /* This breakpoint is in an overlay section.
2768 Shall we set a breakpoint at the LMA? */
2769 if (!overlay_events_enabled
)
2771 /* Yes -- overlay event support is not active,
2772 so we must try to set a breakpoint at the LMA.
2773 This will not work for a hardware breakpoint. */
2774 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2775 warning (_("hardware breakpoint %d not supported in overlay!"),
2779 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2781 /* Set a software (trap) breakpoint at the LMA. */
2782 bl
->overlay_target_info
= bl
->target_info
;
2783 bl
->overlay_target_info
.reqstd_address
= addr
;
2785 /* No overlay handling: just set the breakpoint. */
2790 bl
->overlay_target_info
.kind
2791 = breakpoint_kind (bl
, &addr
);
2792 bl
->overlay_target_info
.placed_address
= addr
;
2793 val
= target_insert_breakpoint (bl
->gdbarch
,
2794 &bl
->overlay_target_info
);
2796 bp_err
= GENERIC_ERROR
;
2798 CATCH (e
, RETURN_MASK_ALL
)
2801 bp_err_message
= e
.message
;
2805 if (bp_err
!= GDB_NO_ERROR
)
2806 fprintf_unfiltered (tmp_error_stream
,
2807 "Overlay breakpoint %d "
2808 "failed: in ROM?\n",
2812 /* Shall we set a breakpoint at the VMA? */
2813 if (section_is_mapped (bl
->section
))
2815 /* Yes. This overlay section is mapped into memory. */
2820 val
= bl
->owner
->ops
->insert_location (bl
);
2822 bp_err
= GENERIC_ERROR
;
2824 CATCH (e
, RETURN_MASK_ALL
)
2827 bp_err_message
= e
.message
;
2833 /* No. This breakpoint will not be inserted.
2834 No error, but do not mark the bp as 'inserted'. */
2839 if (bp_err
!= GDB_NO_ERROR
)
2841 /* Can't set the breakpoint. */
2843 /* In some cases, we might not be able to insert a
2844 breakpoint in a shared library that has already been
2845 removed, but we have not yet processed the shlib unload
2846 event. Unfortunately, some targets that implement
2847 breakpoint insertion themselves can't tell why the
2848 breakpoint insertion failed (e.g., the remote target
2849 doesn't define error codes), so we must treat generic
2850 errors as memory errors. */
2851 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2852 && bl
->loc_type
== bp_loc_software_breakpoint
2853 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2854 || shared_objfile_contains_address_p (bl
->pspace
,
2857 /* See also: disable_breakpoints_in_shlibs. */
2858 bl
->shlib_disabled
= 1;
2859 observer_notify_breakpoint_modified (bl
->owner
);
2860 if (!*disabled_breaks
)
2862 fprintf_unfiltered (tmp_error_stream
,
2863 "Cannot insert breakpoint %d.\n",
2865 fprintf_unfiltered (tmp_error_stream
,
2866 "Temporarily disabling shared "
2867 "library breakpoints:\n");
2869 *disabled_breaks
= 1;
2870 fprintf_unfiltered (tmp_error_stream
,
2871 "breakpoint #%d\n", bl
->owner
->number
);
2876 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2878 *hw_breakpoint_error
= 1;
2879 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2880 fprintf_unfiltered (tmp_error_stream
,
2881 "Cannot insert hardware breakpoint %d%s",
2882 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2883 if (bp_err_message
!= NULL
)
2884 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2888 if (bp_err_message
== NULL
)
2891 = memory_error_message (TARGET_XFER_E_IO
,
2892 bl
->gdbarch
, bl
->address
);
2894 fprintf_unfiltered (tmp_error_stream
,
2895 "Cannot insert breakpoint %d.\n"
2897 bl
->owner
->number
, message
.c_str ());
2901 fprintf_unfiltered (tmp_error_stream
,
2902 "Cannot insert breakpoint %d: %s\n",
2917 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2918 /* NOTE drow/2003-09-08: This state only exists for removing
2919 watchpoints. It's not clear that it's necessary... */
2920 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2924 gdb_assert (bl
->owner
->ops
!= NULL
2925 && bl
->owner
->ops
->insert_location
!= NULL
);
2927 val
= bl
->owner
->ops
->insert_location (bl
);
2929 /* If trying to set a read-watchpoint, and it turns out it's not
2930 supported, try emulating one with an access watchpoint. */
2931 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2933 struct bp_location
*loc
, **loc_temp
;
2935 /* But don't try to insert it, if there's already another
2936 hw_access location that would be considered a duplicate
2938 ALL_BP_LOCATIONS (loc
, loc_temp
)
2940 && loc
->watchpoint_type
== hw_access
2941 && watchpoint_locations_match (bl
, loc
))
2945 bl
->target_info
= loc
->target_info
;
2946 bl
->watchpoint_type
= hw_access
;
2953 bl
->watchpoint_type
= hw_access
;
2954 val
= bl
->owner
->ops
->insert_location (bl
);
2957 /* Back to the original value. */
2958 bl
->watchpoint_type
= hw_read
;
2962 bl
->inserted
= (val
== 0);
2965 else if (bl
->owner
->type
== bp_catchpoint
)
2969 gdb_assert (bl
->owner
->ops
!= NULL
2970 && bl
->owner
->ops
->insert_location
!= NULL
);
2972 val
= bl
->owner
->ops
->insert_location (bl
);
2975 bl
->owner
->enable_state
= bp_disabled
;
2979 Error inserting catchpoint %d: Your system does not support this type\n\
2980 of catchpoint."), bl
->owner
->number
);
2982 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2985 bl
->inserted
= (val
== 0);
2987 /* We've already printed an error message if there was a problem
2988 inserting this catchpoint, and we've disabled the catchpoint,
2989 so just return success. */
2996 /* This function is called when program space PSPACE is about to be
2997 deleted. It takes care of updating breakpoints to not reference
3001 breakpoint_program_space_exit (struct program_space
*pspace
)
3003 struct breakpoint
*b
, *b_temp
;
3004 struct bp_location
*loc
, **loc_temp
;
3006 /* Remove any breakpoint that was set through this program space. */
3007 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
3009 if (b
->pspace
== pspace
)
3010 delete_breakpoint (b
);
3013 /* Breakpoints set through other program spaces could have locations
3014 bound to PSPACE as well. Remove those. */
3015 ALL_BP_LOCATIONS (loc
, loc_temp
)
3017 struct bp_location
*tmp
;
3019 if (loc
->pspace
== pspace
)
3021 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3022 if (loc
->owner
->loc
== loc
)
3023 loc
->owner
->loc
= loc
->next
;
3025 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3026 if (tmp
->next
== loc
)
3028 tmp
->next
= loc
->next
;
3034 /* Now update the global location list to permanently delete the
3035 removed locations above. */
3036 update_global_location_list (UGLL_DONT_INSERT
);
3039 /* Make sure all breakpoints are inserted in inferior.
3040 Throws exception on any error.
3041 A breakpoint that is already inserted won't be inserted
3042 again, so calling this function twice is safe. */
3044 insert_breakpoints (void)
3046 struct breakpoint
*bpt
;
3048 ALL_BREAKPOINTS (bpt
)
3049 if (is_hardware_watchpoint (bpt
))
3051 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3053 update_watchpoint (w
, 0 /* don't reparse. */);
3056 /* Updating watchpoints creates new locations, so update the global
3057 location list. Explicitly tell ugll to insert locations and
3058 ignore breakpoints_always_inserted_mode. */
3059 update_global_location_list (UGLL_INSERT
);
3062 /* Invoke CALLBACK for each of bp_location. */
3065 iterate_over_bp_locations (walk_bp_location_callback callback
)
3067 struct bp_location
*loc
, **loc_tmp
;
3069 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3071 callback (loc
, NULL
);
3075 /* This is used when we need to synch breakpoint conditions between GDB and the
3076 target. It is the case with deleting and disabling of breakpoints when using
3077 always-inserted mode. */
3080 update_inserted_breakpoint_locations (void)
3082 struct bp_location
*bl
, **blp_tmp
;
3085 int disabled_breaks
= 0;
3086 int hw_breakpoint_error
= 0;
3087 int hw_bp_details_reported
= 0;
3089 string_file tmp_error_stream
;
3091 /* Explicitly mark the warning -- this will only be printed if
3092 there was an error. */
3093 tmp_error_stream
.puts ("Warning:\n");
3095 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3097 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3099 /* We only want to update software breakpoints and hardware
3101 if (!is_breakpoint (bl
->owner
))
3104 /* We only want to update locations that are already inserted
3105 and need updating. This is to avoid unwanted insertion during
3106 deletion of breakpoints. */
3107 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3110 switch_to_program_space_and_thread (bl
->pspace
);
3112 /* For targets that support global breakpoints, there's no need
3113 to select an inferior to insert breakpoint to. In fact, even
3114 if we aren't attached to any process yet, we should still
3115 insert breakpoints. */
3116 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3117 && ptid_equal (inferior_ptid
, null_ptid
))
3120 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3121 &hw_breakpoint_error
, &hw_bp_details_reported
);
3128 target_terminal_ours_for_output ();
3129 error_stream (tmp_error_stream
);
3133 /* Used when starting or continuing the program. */
3136 insert_breakpoint_locations (void)
3138 struct breakpoint
*bpt
;
3139 struct bp_location
*bl
, **blp_tmp
;
3142 int disabled_breaks
= 0;
3143 int hw_breakpoint_error
= 0;
3144 int hw_bp_error_explained_already
= 0;
3146 string_file tmp_error_stream
;
3148 /* Explicitly mark the warning -- this will only be printed if
3149 there was an error. */
3150 tmp_error_stream
.puts ("Warning:\n");
3152 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3154 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3156 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3159 /* There is no point inserting thread-specific breakpoints if
3160 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3161 has BL->OWNER always non-NULL. */
3162 if (bl
->owner
->thread
!= -1
3163 && !valid_global_thread_id (bl
->owner
->thread
))
3166 switch_to_program_space_and_thread (bl
->pspace
);
3168 /* For targets that support global breakpoints, there's no need
3169 to select an inferior to insert breakpoint to. In fact, even
3170 if we aren't attached to any process yet, we should still
3171 insert breakpoints. */
3172 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3173 && ptid_equal (inferior_ptid
, null_ptid
))
3176 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3177 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3182 /* If we failed to insert all locations of a watchpoint, remove
3183 them, as half-inserted watchpoint is of limited use. */
3184 ALL_BREAKPOINTS (bpt
)
3186 int some_failed
= 0;
3187 struct bp_location
*loc
;
3189 if (!is_hardware_watchpoint (bpt
))
3192 if (!breakpoint_enabled (bpt
))
3195 if (bpt
->disposition
== disp_del_at_next_stop
)
3198 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3199 if (!loc
->inserted
&& should_be_inserted (loc
))
3206 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3208 remove_breakpoint (loc
);
3210 hw_breakpoint_error
= 1;
3211 tmp_error_stream
.printf ("Could not insert "
3212 "hardware watchpoint %d.\n",
3220 /* If a hardware breakpoint or watchpoint was inserted, add a
3221 message about possibly exhausted resources. */
3222 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3224 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3225 You may have requested too many hardware breakpoints/watchpoints.\n");
3227 target_terminal_ours_for_output ();
3228 error_stream (tmp_error_stream
);
3232 /* Used when the program stops.
3233 Returns zero if successful, or non-zero if there was a problem
3234 removing a breakpoint location. */
3237 remove_breakpoints (void)
3239 struct bp_location
*bl
, **blp_tmp
;
3242 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3244 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3245 val
|= remove_breakpoint (bl
);
3250 /* When a thread exits, remove breakpoints that are related to
3254 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3256 struct breakpoint
*b
, *b_tmp
;
3258 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3260 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3262 b
->disposition
= disp_del_at_next_stop
;
3264 printf_filtered (_("\
3265 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3266 b
->number
, print_thread_id (tp
));
3268 /* Hide it from the user. */
3274 /* Remove breakpoints of process PID. */
3277 remove_breakpoints_pid (int pid
)
3279 struct bp_location
*bl
, **blp_tmp
;
3281 struct inferior
*inf
= find_inferior_pid (pid
);
3283 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3285 if (bl
->pspace
!= inf
->pspace
)
3288 if (bl
->inserted
&& !bl
->target_info
.persist
)
3290 val
= remove_breakpoint (bl
);
3299 reattach_breakpoints (int pid
)
3301 struct bp_location
*bl
, **blp_tmp
;
3303 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3304 struct inferior
*inf
;
3305 struct thread_info
*tp
;
3307 tp
= any_live_thread_of_process (pid
);
3311 inf
= find_inferior_pid (pid
);
3313 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3314 inferior_ptid
= tp
->ptid
;
3316 string_file tmp_error_stream
;
3318 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3320 if (bl
->pspace
!= inf
->pspace
)
3326 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3334 static int internal_breakpoint_number
= -1;
3336 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3337 If INTERNAL is non-zero, the breakpoint number will be populated
3338 from internal_breakpoint_number and that variable decremented.
3339 Otherwise the breakpoint number will be populated from
3340 breakpoint_count and that value incremented. Internal breakpoints
3341 do not set the internal var bpnum. */
3343 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3346 b
->number
= internal_breakpoint_number
--;
3349 set_breakpoint_count (breakpoint_count
+ 1);
3350 b
->number
= breakpoint_count
;
3354 static struct breakpoint
*
3355 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3356 CORE_ADDR address
, enum bptype type
,
3357 const struct breakpoint_ops
*ops
)
3359 symtab_and_line sal
;
3361 sal
.section
= find_pc_overlay (sal
.pc
);
3362 sal
.pspace
= current_program_space
;
3364 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3365 b
->number
= internal_breakpoint_number
--;
3366 b
->disposition
= disp_donttouch
;
3371 static const char *const longjmp_names
[] =
3373 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3375 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3377 /* Per-objfile data private to breakpoint.c. */
3378 struct breakpoint_objfile_data
3380 /* Minimal symbol for "_ovly_debug_event" (if any). */
3381 struct bound_minimal_symbol overlay_msym
;
3383 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3384 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3386 /* True if we have looked for longjmp probes. */
3387 int longjmp_searched
;
3389 /* SystemTap probe points for longjmp (if any). */
3390 VEC (probe_p
) *longjmp_probes
;
3392 /* Minimal symbol for "std::terminate()" (if any). */
3393 struct bound_minimal_symbol terminate_msym
;
3395 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3396 struct bound_minimal_symbol exception_msym
;
3398 /* True if we have looked for exception probes. */
3399 int exception_searched
;
3401 /* SystemTap probe points for unwinding (if any). */
3402 VEC (probe_p
) *exception_probes
;
3405 static const struct objfile_data
*breakpoint_objfile_key
;
3407 /* Minimal symbol not found sentinel. */
3408 static struct minimal_symbol msym_not_found
;
3410 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3413 msym_not_found_p (const struct minimal_symbol
*msym
)
3415 return msym
== &msym_not_found
;
3418 /* Return per-objfile data needed by breakpoint.c.
3419 Allocate the data if necessary. */
3421 static struct breakpoint_objfile_data
*
3422 get_breakpoint_objfile_data (struct objfile
*objfile
)
3424 struct breakpoint_objfile_data
*bp_objfile_data
;
3426 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3427 objfile_data (objfile
, breakpoint_objfile_key
));
3428 if (bp_objfile_data
== NULL
)
3431 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3433 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3434 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3436 return bp_objfile_data
;
3440 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3442 struct breakpoint_objfile_data
*bp_objfile_data
3443 = (struct breakpoint_objfile_data
*) data
;
3445 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3446 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3450 create_overlay_event_breakpoint (void)
3452 struct objfile
*objfile
;
3453 const char *const func_name
= "_ovly_debug_event";
3455 ALL_OBJFILES (objfile
)
3457 struct breakpoint
*b
;
3458 struct breakpoint_objfile_data
*bp_objfile_data
;
3460 struct explicit_location explicit_loc
;
3462 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3464 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3467 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3469 struct bound_minimal_symbol m
;
3471 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3472 if (m
.minsym
== NULL
)
3474 /* Avoid future lookups in this objfile. */
3475 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3478 bp_objfile_data
->overlay_msym
= m
;
3481 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3482 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3484 &internal_breakpoint_ops
);
3485 initialize_explicit_location (&explicit_loc
);
3486 explicit_loc
.function_name
= ASTRDUP (func_name
);
3487 b
->location
= new_explicit_location (&explicit_loc
);
3489 if (overlay_debugging
== ovly_auto
)
3491 b
->enable_state
= bp_enabled
;
3492 overlay_events_enabled
= 1;
3496 b
->enable_state
= bp_disabled
;
3497 overlay_events_enabled
= 0;
3503 create_longjmp_master_breakpoint (void)
3505 struct program_space
*pspace
;
3507 scoped_restore_current_program_space restore_pspace
;
3509 ALL_PSPACES (pspace
)
3511 struct objfile
*objfile
;
3513 set_current_program_space (pspace
);
3515 ALL_OBJFILES (objfile
)
3518 struct gdbarch
*gdbarch
;
3519 struct breakpoint_objfile_data
*bp_objfile_data
;
3521 gdbarch
= get_objfile_arch (objfile
);
3523 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3525 if (!bp_objfile_data
->longjmp_searched
)
3529 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3532 /* We are only interested in checking one element. */
3533 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3535 if (!can_evaluate_probe_arguments (p
))
3537 /* We cannot use the probe interface here, because it does
3538 not know how to evaluate arguments. */
3539 VEC_free (probe_p
, ret
);
3543 bp_objfile_data
->longjmp_probes
= ret
;
3544 bp_objfile_data
->longjmp_searched
= 1;
3547 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3550 struct probe
*probe
;
3551 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3554 VEC_iterate (probe_p
,
3555 bp_objfile_data
->longjmp_probes
,
3559 struct breakpoint
*b
;
3561 b
= create_internal_breakpoint (gdbarch
,
3562 get_probe_address (probe
,
3565 &internal_breakpoint_ops
);
3566 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3567 b
->enable_state
= bp_disabled
;
3573 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3576 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3578 struct breakpoint
*b
;
3579 const char *func_name
;
3581 struct explicit_location explicit_loc
;
3583 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3586 func_name
= longjmp_names
[i
];
3587 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3589 struct bound_minimal_symbol m
;
3591 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3592 if (m
.minsym
== NULL
)
3594 /* Prevent future lookups in this objfile. */
3595 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3598 bp_objfile_data
->longjmp_msym
[i
] = m
;
3601 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3602 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3603 &internal_breakpoint_ops
);
3604 initialize_explicit_location (&explicit_loc
);
3605 explicit_loc
.function_name
= ASTRDUP (func_name
);
3606 b
->location
= new_explicit_location (&explicit_loc
);
3607 b
->enable_state
= bp_disabled
;
3613 /* Create a master std::terminate breakpoint. */
3615 create_std_terminate_master_breakpoint (void)
3617 struct program_space
*pspace
;
3618 const char *const func_name
= "std::terminate()";
3620 scoped_restore_current_program_space restore_pspace
;
3622 ALL_PSPACES (pspace
)
3624 struct objfile
*objfile
;
3627 set_current_program_space (pspace
);
3629 ALL_OBJFILES (objfile
)
3631 struct breakpoint
*b
;
3632 struct breakpoint_objfile_data
*bp_objfile_data
;
3633 struct explicit_location explicit_loc
;
3635 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3637 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3640 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3642 struct bound_minimal_symbol m
;
3644 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3645 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3646 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3648 /* Prevent future lookups in this objfile. */
3649 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3652 bp_objfile_data
->terminate_msym
= m
;
3655 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3656 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3657 bp_std_terminate_master
,
3658 &internal_breakpoint_ops
);
3659 initialize_explicit_location (&explicit_loc
);
3660 explicit_loc
.function_name
= ASTRDUP (func_name
);
3661 b
->location
= new_explicit_location (&explicit_loc
);
3662 b
->enable_state
= bp_disabled
;
3667 /* Install a master breakpoint on the unwinder's debug hook. */
3670 create_exception_master_breakpoint (void)
3672 struct objfile
*objfile
;
3673 const char *const func_name
= "_Unwind_DebugHook";
3675 ALL_OBJFILES (objfile
)
3677 struct breakpoint
*b
;
3678 struct gdbarch
*gdbarch
;
3679 struct breakpoint_objfile_data
*bp_objfile_data
;
3681 struct explicit_location explicit_loc
;
3683 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3685 /* We prefer the SystemTap probe point if it exists. */
3686 if (!bp_objfile_data
->exception_searched
)
3690 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3694 /* We are only interested in checking one element. */
3695 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3697 if (!can_evaluate_probe_arguments (p
))
3699 /* We cannot use the probe interface here, because it does
3700 not know how to evaluate arguments. */
3701 VEC_free (probe_p
, ret
);
3705 bp_objfile_data
->exception_probes
= ret
;
3706 bp_objfile_data
->exception_searched
= 1;
3709 if (bp_objfile_data
->exception_probes
!= NULL
)
3711 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3713 struct probe
*probe
;
3716 VEC_iterate (probe_p
,
3717 bp_objfile_data
->exception_probes
,
3721 struct breakpoint
*b
;
3723 b
= create_internal_breakpoint (gdbarch
,
3724 get_probe_address (probe
,
3726 bp_exception_master
,
3727 &internal_breakpoint_ops
);
3728 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3729 b
->enable_state
= bp_disabled
;
3735 /* Otherwise, try the hook function. */
3737 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3740 gdbarch
= get_objfile_arch (objfile
);
3742 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3744 struct bound_minimal_symbol debug_hook
;
3746 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3747 if (debug_hook
.minsym
== NULL
)
3749 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3753 bp_objfile_data
->exception_msym
= debug_hook
;
3756 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3757 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3759 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3760 &internal_breakpoint_ops
);
3761 initialize_explicit_location (&explicit_loc
);
3762 explicit_loc
.function_name
= ASTRDUP (func_name
);
3763 b
->location
= new_explicit_location (&explicit_loc
);
3764 b
->enable_state
= bp_disabled
;
3768 /* Does B have a location spec? */
3771 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3773 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3777 update_breakpoints_after_exec (void)
3779 struct breakpoint
*b
, *b_tmp
;
3780 struct bp_location
*bploc
, **bplocp_tmp
;
3782 /* We're about to delete breakpoints from GDB's lists. If the
3783 INSERTED flag is true, GDB will try to lift the breakpoints by
3784 writing the breakpoints' "shadow contents" back into memory. The
3785 "shadow contents" are NOT valid after an exec, so GDB should not
3786 do that. Instead, the target is responsible from marking
3787 breakpoints out as soon as it detects an exec. We don't do that
3788 here instead, because there may be other attempts to delete
3789 breakpoints after detecting an exec and before reaching here. */
3790 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3791 if (bploc
->pspace
== current_program_space
)
3792 gdb_assert (!bploc
->inserted
);
3794 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3796 if (b
->pspace
!= current_program_space
)
3799 /* Solib breakpoints must be explicitly reset after an exec(). */
3800 if (b
->type
== bp_shlib_event
)
3802 delete_breakpoint (b
);
3806 /* JIT breakpoints must be explicitly reset after an exec(). */
3807 if (b
->type
== bp_jit_event
)
3809 delete_breakpoint (b
);
3813 /* Thread event breakpoints must be set anew after an exec(),
3814 as must overlay event and longjmp master breakpoints. */
3815 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3816 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3817 || b
->type
== bp_exception_master
)
3819 delete_breakpoint (b
);
3823 /* Step-resume breakpoints are meaningless after an exec(). */
3824 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3826 delete_breakpoint (b
);
3830 /* Just like single-step breakpoints. */
3831 if (b
->type
== bp_single_step
)
3833 delete_breakpoint (b
);
3837 /* Longjmp and longjmp-resume breakpoints are also meaningless
3839 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3840 || b
->type
== bp_longjmp_call_dummy
3841 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3843 delete_breakpoint (b
);
3847 if (b
->type
== bp_catchpoint
)
3849 /* For now, none of the bp_catchpoint breakpoints need to
3850 do anything at this point. In the future, if some of
3851 the catchpoints need to something, we will need to add
3852 a new method, and call this method from here. */
3856 /* bp_finish is a special case. The only way we ought to be able
3857 to see one of these when an exec() has happened, is if the user
3858 caught a vfork, and then said "finish". Ordinarily a finish just
3859 carries them to the call-site of the current callee, by setting
3860 a temporary bp there and resuming. But in this case, the finish
3861 will carry them entirely through the vfork & exec.
3863 We don't want to allow a bp_finish to remain inserted now. But
3864 we can't safely delete it, 'cause finish_command has a handle to
3865 the bp on a bpstat, and will later want to delete it. There's a
3866 chance (and I've seen it happen) that if we delete the bp_finish
3867 here, that its storage will get reused by the time finish_command
3868 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3869 We really must allow finish_command to delete a bp_finish.
3871 In the absence of a general solution for the "how do we know
3872 it's safe to delete something others may have handles to?"
3873 problem, what we'll do here is just uninsert the bp_finish, and
3874 let finish_command delete it.
3876 (We know the bp_finish is "doomed" in the sense that it's
3877 momentary, and will be deleted as soon as finish_command sees
3878 the inferior stopped. So it doesn't matter that the bp's
3879 address is probably bogus in the new a.out, unlike e.g., the
3880 solib breakpoints.) */
3882 if (b
->type
== bp_finish
)
3887 /* Without a symbolic address, we have little hope of the
3888 pre-exec() address meaning the same thing in the post-exec()
3890 if (breakpoint_event_location_empty_p (b
))
3892 delete_breakpoint (b
);
3899 detach_breakpoints (ptid_t ptid
)
3901 struct bp_location
*bl
, **blp_tmp
;
3903 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3904 struct inferior
*inf
= current_inferior ();
3906 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3907 error (_("Cannot detach breakpoints of inferior_ptid"));
3909 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3910 inferior_ptid
= ptid
;
3911 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3913 if (bl
->pspace
!= inf
->pspace
)
3916 /* This function must physically remove breakpoints locations
3917 from the specified ptid, without modifying the breakpoint
3918 package's state. Locations of type bp_loc_other are only
3919 maintained at GDB side. So, there is no need to remove
3920 these bp_loc_other locations. Moreover, removing these
3921 would modify the breakpoint package's state. */
3922 if (bl
->loc_type
== bp_loc_other
)
3926 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3932 /* Remove the breakpoint location BL from the current address space.
3933 Note that this is used to detach breakpoints from a child fork.
3934 When we get here, the child isn't in the inferior list, and neither
3935 do we have objects to represent its address space --- we should
3936 *not* look at bl->pspace->aspace here. */
3939 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3943 /* BL is never in moribund_locations by our callers. */
3944 gdb_assert (bl
->owner
!= NULL
);
3946 /* The type of none suggests that owner is actually deleted.
3947 This should not ever happen. */
3948 gdb_assert (bl
->owner
->type
!= bp_none
);
3950 if (bl
->loc_type
== bp_loc_software_breakpoint
3951 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3953 /* "Normal" instruction breakpoint: either the standard
3954 trap-instruction bp (bp_breakpoint), or a
3955 bp_hardware_breakpoint. */
3957 /* First check to see if we have to handle an overlay. */
3958 if (overlay_debugging
== ovly_off
3959 || bl
->section
== NULL
3960 || !(section_is_overlay (bl
->section
)))
3962 /* No overlay handling: just remove the breakpoint. */
3964 /* If we're trying to uninsert a memory breakpoint that we
3965 know is set in a dynamic object that is marked
3966 shlib_disabled, then either the dynamic object was
3967 removed with "remove-symbol-file" or with
3968 "nosharedlibrary". In the former case, we don't know
3969 whether another dynamic object might have loaded over the
3970 breakpoint's address -- the user might well let us know
3971 about it next with add-symbol-file (the whole point of
3972 add-symbol-file is letting the user manually maintain a
3973 list of dynamically loaded objects). If we have the
3974 breakpoint's shadow memory, that is, this is a software
3975 breakpoint managed by GDB, check whether the breakpoint
3976 is still inserted in memory, to avoid overwriting wrong
3977 code with stale saved shadow contents. Note that HW
3978 breakpoints don't have shadow memory, as they're
3979 implemented using a mechanism that is not dependent on
3980 being able to modify the target's memory, and as such
3981 they should always be removed. */
3982 if (bl
->shlib_disabled
3983 && bl
->target_info
.shadow_len
!= 0
3984 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3987 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3991 /* This breakpoint is in an overlay section.
3992 Did we set a breakpoint at the LMA? */
3993 if (!overlay_events_enabled
)
3995 /* Yes -- overlay event support is not active, so we
3996 should have set a breakpoint at the LMA. Remove it.
3998 /* Ignore any failures: if the LMA is in ROM, we will
3999 have already warned when we failed to insert it. */
4000 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4001 target_remove_hw_breakpoint (bl
->gdbarch
,
4002 &bl
->overlay_target_info
);
4004 target_remove_breakpoint (bl
->gdbarch
,
4005 &bl
->overlay_target_info
,
4008 /* Did we set a breakpoint at the VMA?
4009 If so, we will have marked the breakpoint 'inserted'. */
4012 /* Yes -- remove it. Previously we did not bother to
4013 remove the breakpoint if the section had been
4014 unmapped, but let's not rely on that being safe. We
4015 don't know what the overlay manager might do. */
4017 /* However, we should remove *software* breakpoints only
4018 if the section is still mapped, or else we overwrite
4019 wrong code with the saved shadow contents. */
4020 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4021 || section_is_mapped (bl
->section
))
4022 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4028 /* No -- not inserted, so no need to remove. No error. */
4033 /* In some cases, we might not be able to remove a breakpoint in
4034 a shared library that has already been removed, but we have
4035 not yet processed the shlib unload event. Similarly for an
4036 unloaded add-symbol-file object - the user might not yet have
4037 had the chance to remove-symbol-file it. shlib_disabled will
4038 be set if the library/object has already been removed, but
4039 the breakpoint hasn't been uninserted yet, e.g., after
4040 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4041 always-inserted mode. */
4043 && (bl
->loc_type
== bp_loc_software_breakpoint
4044 && (bl
->shlib_disabled
4045 || solib_name_from_address (bl
->pspace
, bl
->address
)
4046 || shared_objfile_contains_address_p (bl
->pspace
,
4052 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4054 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4056 gdb_assert (bl
->owner
->ops
!= NULL
4057 && bl
->owner
->ops
->remove_location
!= NULL
);
4059 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4060 bl
->owner
->ops
->remove_location (bl
, reason
);
4062 /* Failure to remove any of the hardware watchpoints comes here. */
4063 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4064 warning (_("Could not remove hardware watchpoint %d."),
4067 else if (bl
->owner
->type
== bp_catchpoint
4068 && breakpoint_enabled (bl
->owner
)
4071 gdb_assert (bl
->owner
->ops
!= NULL
4072 && bl
->owner
->ops
->remove_location
!= NULL
);
4074 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4078 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4085 remove_breakpoint (struct bp_location
*bl
)
4087 /* BL is never in moribund_locations by our callers. */
4088 gdb_assert (bl
->owner
!= NULL
);
4090 /* The type of none suggests that owner is actually deleted.
4091 This should not ever happen. */
4092 gdb_assert (bl
->owner
->type
!= bp_none
);
4094 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4096 switch_to_program_space_and_thread (bl
->pspace
);
4098 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4101 /* Clear the "inserted" flag in all breakpoints. */
4104 mark_breakpoints_out (void)
4106 struct bp_location
*bl
, **blp_tmp
;
4108 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4109 if (bl
->pspace
== current_program_space
)
4113 /* Clear the "inserted" flag in all breakpoints and delete any
4114 breakpoints which should go away between runs of the program.
4116 Plus other such housekeeping that has to be done for breakpoints
4119 Note: this function gets called at the end of a run (by
4120 generic_mourn_inferior) and when a run begins (by
4121 init_wait_for_inferior). */
4126 breakpoint_init_inferior (enum inf_context context
)
4128 struct breakpoint
*b
, *b_tmp
;
4129 struct bp_location
*bl
;
4131 struct program_space
*pspace
= current_program_space
;
4133 /* If breakpoint locations are shared across processes, then there's
4135 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4138 mark_breakpoints_out ();
4140 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4142 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4148 case bp_longjmp_call_dummy
:
4150 /* If the call dummy breakpoint is at the entry point it will
4151 cause problems when the inferior is rerun, so we better get
4154 case bp_watchpoint_scope
:
4156 /* Also get rid of scope breakpoints. */
4158 case bp_shlib_event
:
4160 /* Also remove solib event breakpoints. Their addresses may
4161 have changed since the last time we ran the program.
4162 Actually we may now be debugging against different target;
4163 and so the solib backend that installed this breakpoint may
4164 not be used in by the target. E.g.,
4166 (gdb) file prog-linux
4167 (gdb) run # native linux target
4170 (gdb) file prog-win.exe
4171 (gdb) tar rem :9999 # remote Windows gdbserver.
4174 case bp_step_resume
:
4176 /* Also remove step-resume breakpoints. */
4178 case bp_single_step
:
4180 /* Also remove single-step breakpoints. */
4182 delete_breakpoint (b
);
4186 case bp_hardware_watchpoint
:
4187 case bp_read_watchpoint
:
4188 case bp_access_watchpoint
:
4190 struct watchpoint
*w
= (struct watchpoint
*) b
;
4192 /* Likewise for watchpoints on local expressions. */
4193 if (w
->exp_valid_block
!= NULL
)
4194 delete_breakpoint (b
);
4197 /* Get rid of existing locations, which are no longer
4198 valid. New ones will be created in
4199 update_watchpoint, when the inferior is restarted.
4200 The next update_global_location_list call will
4201 garbage collect them. */
4204 if (context
== inf_starting
)
4206 /* Reset val field to force reread of starting value in
4207 insert_breakpoints. */
4209 value_free (w
->val
);
4221 /* Get rid of the moribund locations. */
4222 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4223 decref_bp_location (&bl
);
4224 VEC_free (bp_location_p
, moribund_locations
);
4227 /* These functions concern about actual breakpoints inserted in the
4228 target --- to e.g. check if we need to do decr_pc adjustment or if
4229 we need to hop over the bkpt --- so we check for address space
4230 match, not program space. */
4232 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4233 exists at PC. It returns ordinary_breakpoint_here if it's an
4234 ordinary breakpoint, or permanent_breakpoint_here if it's a
4235 permanent breakpoint.
4236 - When continuing from a location with an ordinary breakpoint, we
4237 actually single step once before calling insert_breakpoints.
4238 - When continuing from a location with a permanent breakpoint, we
4239 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4240 the target, to advance the PC past the breakpoint. */
4242 enum breakpoint_here
4243 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4245 struct bp_location
*bl
, **blp_tmp
;
4246 int any_breakpoint_here
= 0;
4248 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4250 if (bl
->loc_type
!= bp_loc_software_breakpoint
4251 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4254 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4255 if ((breakpoint_enabled (bl
->owner
)
4257 && breakpoint_location_address_match (bl
, aspace
, pc
))
4259 if (overlay_debugging
4260 && section_is_overlay (bl
->section
)
4261 && !section_is_mapped (bl
->section
))
4262 continue; /* unmapped overlay -- can't be a match */
4263 else if (bl
->permanent
)
4264 return permanent_breakpoint_here
;
4266 any_breakpoint_here
= 1;
4270 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4273 /* See breakpoint.h. */
4276 breakpoint_in_range_p (struct address_space
*aspace
,
4277 CORE_ADDR addr
, ULONGEST len
)
4279 struct bp_location
*bl
, **blp_tmp
;
4281 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4283 if (bl
->loc_type
!= bp_loc_software_breakpoint
4284 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4287 if ((breakpoint_enabled (bl
->owner
)
4289 && breakpoint_location_address_range_overlap (bl
, aspace
,
4292 if (overlay_debugging
4293 && section_is_overlay (bl
->section
)
4294 && !section_is_mapped (bl
->section
))
4296 /* Unmapped overlay -- can't be a match. */
4307 /* Return true if there's a moribund breakpoint at PC. */
4310 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4312 struct bp_location
*loc
;
4315 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4316 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4322 /* Returns non-zero iff BL is inserted at PC, in address space
4326 bp_location_inserted_here_p (struct bp_location
*bl
,
4327 struct address_space
*aspace
, CORE_ADDR pc
)
4330 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4333 if (overlay_debugging
4334 && section_is_overlay (bl
->section
)
4335 && !section_is_mapped (bl
->section
))
4336 return 0; /* unmapped overlay -- can't be a match */
4343 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4346 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4348 struct bp_location
**blp
, **blp_tmp
= NULL
;
4350 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4352 struct bp_location
*bl
= *blp
;
4354 if (bl
->loc_type
!= bp_loc_software_breakpoint
4355 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4358 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4364 /* This function returns non-zero iff there is a software breakpoint
4368 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4371 struct bp_location
**blp
, **blp_tmp
= NULL
;
4373 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4375 struct bp_location
*bl
= *blp
;
4377 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4380 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4387 /* See breakpoint.h. */
4390 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4393 struct bp_location
**blp
, **blp_tmp
= NULL
;
4395 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4397 struct bp_location
*bl
= *blp
;
4399 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4402 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4410 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4411 CORE_ADDR addr
, ULONGEST len
)
4413 struct breakpoint
*bpt
;
4415 ALL_BREAKPOINTS (bpt
)
4417 struct bp_location
*loc
;
4419 if (bpt
->type
!= bp_hardware_watchpoint
4420 && bpt
->type
!= bp_access_watchpoint
)
4423 if (!breakpoint_enabled (bpt
))
4426 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4427 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4431 /* Check for intersection. */
4432 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4433 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4442 /* bpstat stuff. External routines' interfaces are documented
4446 is_catchpoint (struct breakpoint
*ep
)
4448 return (ep
->type
== bp_catchpoint
);
4451 /* Frees any storage that is part of a bpstat. Does not walk the
4455 bpstat_free (bpstat bs
)
4457 if (bs
->old_val
!= NULL
)
4458 value_free (bs
->old_val
);
4459 decref_counted_command_line (&bs
->commands
);
4460 decref_bp_location (&bs
->bp_location_at
);
4464 /* Clear a bpstat so that it says we are not at any breakpoint.
4465 Also free any storage that is part of a bpstat. */
4468 bpstat_clear (bpstat
*bsp
)
4485 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4486 is part of the bpstat is copied as well. */
4489 bpstat_copy (bpstat bs
)
4493 bpstat retval
= NULL
;
4498 for (; bs
!= NULL
; bs
= bs
->next
)
4500 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4501 memcpy (tmp
, bs
, sizeof (*tmp
));
4502 incref_counted_command_line (tmp
->commands
);
4503 incref_bp_location (tmp
->bp_location_at
);
4504 if (bs
->old_val
!= NULL
)
4506 tmp
->old_val
= value_copy (bs
->old_val
);
4507 release_value (tmp
->old_val
);
4511 /* This is the first thing in the chain. */
4521 /* Find the bpstat associated with this breakpoint. */
4524 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4529 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4531 if (bsp
->breakpoint_at
== breakpoint
)
4537 /* See breakpoint.h. */
4540 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4542 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4544 if (bsp
->breakpoint_at
== NULL
)
4546 /* A moribund location can never explain a signal other than
4548 if (sig
== GDB_SIGNAL_TRAP
)
4553 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4562 /* Put in *NUM the breakpoint number of the first breakpoint we are
4563 stopped at. *BSP upon return is a bpstat which points to the
4564 remaining breakpoints stopped at (but which is not guaranteed to be
4565 good for anything but further calls to bpstat_num).
4567 Return 0 if passed a bpstat which does not indicate any breakpoints.
4568 Return -1 if stopped at a breakpoint that has been deleted since
4570 Return 1 otherwise. */
4573 bpstat_num (bpstat
*bsp
, int *num
)
4575 struct breakpoint
*b
;
4578 return 0; /* No more breakpoint values */
4580 /* We assume we'll never have several bpstats that correspond to a
4581 single breakpoint -- otherwise, this function might return the
4582 same number more than once and this will look ugly. */
4583 b
= (*bsp
)->breakpoint_at
;
4584 *bsp
= (*bsp
)->next
;
4586 return -1; /* breakpoint that's been deleted since */
4588 *num
= b
->number
; /* We have its number */
4592 /* See breakpoint.h. */
4595 bpstat_clear_actions (void)
4597 struct thread_info
*tp
;
4600 if (ptid_equal (inferior_ptid
, null_ptid
))
4603 tp
= find_thread_ptid (inferior_ptid
);
4607 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4609 decref_counted_command_line (&bs
->commands
);
4611 if (bs
->old_val
!= NULL
)
4613 value_free (bs
->old_val
);
4619 /* Called when a command is about to proceed the inferior. */
4622 breakpoint_about_to_proceed (void)
4624 if (!ptid_equal (inferior_ptid
, null_ptid
))
4626 struct thread_info
*tp
= inferior_thread ();
4628 /* Allow inferior function calls in breakpoint commands to not
4629 interrupt the command list. When the call finishes
4630 successfully, the inferior will be standing at the same
4631 breakpoint as if nothing happened. */
4632 if (tp
->control
.in_infcall
)
4636 breakpoint_proceeded
= 1;
4639 /* Stub for cleaning up our state if we error-out of a breakpoint
4642 cleanup_executing_breakpoints (void *ignore
)
4644 executing_breakpoint_commands
= 0;
4647 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4648 or its equivalent. */
4651 command_line_is_silent (struct command_line
*cmd
)
4653 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4656 /* Execute all the commands associated with all the breakpoints at
4657 this location. Any of these commands could cause the process to
4658 proceed beyond this point, etc. We look out for such changes by
4659 checking the global "breakpoint_proceeded" after each command.
4661 Returns true if a breakpoint command resumed the inferior. In that
4662 case, it is the caller's responsibility to recall it again with the
4663 bpstat of the current thread. */
4666 bpstat_do_actions_1 (bpstat
*bsp
)
4669 struct cleanup
*old_chain
;
4672 /* Avoid endless recursion if a `source' command is contained
4674 if (executing_breakpoint_commands
)
4677 executing_breakpoint_commands
= 1;
4678 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4680 scoped_restore preventer
= prevent_dont_repeat ();
4682 /* This pointer will iterate over the list of bpstat's. */
4685 breakpoint_proceeded
= 0;
4686 for (; bs
!= NULL
; bs
= bs
->next
)
4688 struct counted_command_line
*ccmd
;
4689 struct command_line
*cmd
;
4690 struct cleanup
*this_cmd_tree_chain
;
4692 /* Take ownership of the BSP's command tree, if it has one.
4694 The command tree could legitimately contain commands like
4695 'step' and 'next', which call clear_proceed_status, which
4696 frees stop_bpstat's command tree. To make sure this doesn't
4697 free the tree we're executing out from under us, we need to
4698 take ownership of the tree ourselves. Since a given bpstat's
4699 commands are only executed once, we don't need to copy it; we
4700 can clear the pointer in the bpstat, and make sure we free
4701 the tree when we're done. */
4702 ccmd
= bs
->commands
;
4703 bs
->commands
= NULL
;
4704 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4705 cmd
= ccmd
? ccmd
->commands
: NULL
;
4706 if (command_line_is_silent (cmd
))
4708 /* The action has been already done by bpstat_stop_status. */
4714 execute_control_command (cmd
);
4716 if (breakpoint_proceeded
)
4722 /* We can free this command tree now. */
4723 do_cleanups (this_cmd_tree_chain
);
4725 if (breakpoint_proceeded
)
4727 if (current_ui
->async
)
4728 /* If we are in async mode, then the target might be still
4729 running, not stopped at any breakpoint, so nothing for
4730 us to do here -- just return to the event loop. */
4733 /* In sync mode, when execute_control_command returns
4734 we're already standing on the next breakpoint.
4735 Breakpoint commands for that stop were not run, since
4736 execute_command does not run breakpoint commands --
4737 only command_line_handler does, but that one is not
4738 involved in execution of breakpoint commands. So, we
4739 can now execute breakpoint commands. It should be
4740 noted that making execute_command do bpstat actions is
4741 not an option -- in this case we'll have recursive
4742 invocation of bpstat for each breakpoint with a
4743 command, and can easily blow up GDB stack. Instead, we
4744 return true, which will trigger the caller to recall us
4745 with the new stop_bpstat. */
4750 do_cleanups (old_chain
);
4755 bpstat_do_actions (void)
4757 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4759 /* Do any commands attached to breakpoint we are stopped at. */
4760 while (!ptid_equal (inferior_ptid
, null_ptid
)
4761 && target_has_execution
4762 && !is_exited (inferior_ptid
)
4763 && !is_executing (inferior_ptid
))
4764 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4765 and only return when it is stopped at the next breakpoint, we
4766 keep doing breakpoint actions until it returns false to
4767 indicate the inferior was not resumed. */
4768 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4771 discard_cleanups (cleanup_if_error
);
4774 /* Print out the (old or new) value associated with a watchpoint. */
4777 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4780 fprintf_unfiltered (stream
, _("<unreadable>"));
4783 struct value_print_options opts
;
4784 get_user_print_options (&opts
);
4785 value_print (val
, stream
, &opts
);
4789 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4790 debugging multiple threads. */
4793 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4795 if (uiout
->is_mi_like_p ())
4800 if (show_thread_that_caused_stop ())
4803 struct thread_info
*thr
= inferior_thread ();
4805 uiout
->text ("Thread ");
4806 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4808 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4811 uiout
->text (" \"");
4812 uiout
->field_fmt ("name", "%s", name
);
4816 uiout
->text (" hit ");
4820 /* Generic routine for printing messages indicating why we
4821 stopped. The behavior of this function depends on the value
4822 'print_it' in the bpstat structure. Under some circumstances we
4823 may decide not to print anything here and delegate the task to
4826 static enum print_stop_action
4827 print_bp_stop_message (bpstat bs
)
4829 switch (bs
->print_it
)
4832 /* Nothing should be printed for this bpstat entry. */
4833 return PRINT_UNKNOWN
;
4837 /* We still want to print the frame, but we already printed the
4838 relevant messages. */
4839 return PRINT_SRC_AND_LOC
;
4842 case print_it_normal
:
4844 struct breakpoint
*b
= bs
->breakpoint_at
;
4846 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4847 which has since been deleted. */
4849 return PRINT_UNKNOWN
;
4851 /* Normal case. Call the breakpoint's print_it method. */
4852 return b
->ops
->print_it (bs
);
4857 internal_error (__FILE__
, __LINE__
,
4858 _("print_bp_stop_message: unrecognized enum value"));
4863 /* A helper function that prints a shared library stopped event. */
4866 print_solib_event (int is_catchpoint
)
4869 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4871 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4875 if (any_added
|| any_deleted
)
4876 current_uiout
->text (_("Stopped due to shared library event:\n"));
4878 current_uiout
->text (_("Stopped due to shared library event (no "
4879 "libraries added or removed)\n"));
4882 if (current_uiout
->is_mi_like_p ())
4883 current_uiout
->field_string ("reason",
4884 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4891 current_uiout
->text (_(" Inferior unloaded "));
4892 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4894 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4899 current_uiout
->text (" ");
4900 current_uiout
->field_string ("library", name
);
4901 current_uiout
->text ("\n");
4907 struct so_list
*iter
;
4910 current_uiout
->text (_(" Inferior loaded "));
4911 ui_out_emit_list
list_emitter (current_uiout
, "added");
4913 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4918 current_uiout
->text (" ");
4919 current_uiout
->field_string ("library", iter
->so_name
);
4920 current_uiout
->text ("\n");
4925 /* Print a message indicating what happened. This is called from
4926 normal_stop(). The input to this routine is the head of the bpstat
4927 list - a list of the eventpoints that caused this stop. KIND is
4928 the target_waitkind for the stopping event. This
4929 routine calls the generic print routine for printing a message
4930 about reasons for stopping. This will print (for example) the
4931 "Breakpoint n," part of the output. The return value of this
4934 PRINT_UNKNOWN: Means we printed nothing.
4935 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4936 code to print the location. An example is
4937 "Breakpoint 1, " which should be followed by
4939 PRINT_SRC_ONLY: Means we printed something, but there is no need
4940 to also print the location part of the message.
4941 An example is the catch/throw messages, which
4942 don't require a location appended to the end.
4943 PRINT_NOTHING: We have done some printing and we don't need any
4944 further info to be printed. */
4946 enum print_stop_action
4947 bpstat_print (bpstat bs
, int kind
)
4949 enum print_stop_action val
;
4951 /* Maybe another breakpoint in the chain caused us to stop.
4952 (Currently all watchpoints go on the bpstat whether hit or not.
4953 That probably could (should) be changed, provided care is taken
4954 with respect to bpstat_explains_signal). */
4955 for (; bs
; bs
= bs
->next
)
4957 val
= print_bp_stop_message (bs
);
4958 if (val
== PRINT_SRC_ONLY
4959 || val
== PRINT_SRC_AND_LOC
4960 || val
== PRINT_NOTHING
)
4964 /* If we had hit a shared library event breakpoint,
4965 print_bp_stop_message would print out this message. If we hit an
4966 OS-level shared library event, do the same thing. */
4967 if (kind
== TARGET_WAITKIND_LOADED
)
4969 print_solib_event (0);
4970 return PRINT_NOTHING
;
4973 /* We reached the end of the chain, or we got a null BS to start
4974 with and nothing was printed. */
4975 return PRINT_UNKNOWN
;
4978 /* Evaluate the expression EXP and return 1 if value is zero.
4979 This returns the inverse of the condition because it is called
4980 from catch_errors which returns 0 if an exception happened, and if an
4981 exception happens we want execution to stop.
4982 The argument is a "struct expression *" that has been cast to a
4983 "void *" to make it pass through catch_errors. */
4986 breakpoint_cond_eval (void *exp
)
4988 struct value
*mark
= value_mark ();
4989 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4991 value_free_to_mark (mark
);
4995 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4998 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5002 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5004 **bs_link_pointer
= bs
;
5005 *bs_link_pointer
= &bs
->next
;
5006 bs
->breakpoint_at
= bl
->owner
;
5007 bs
->bp_location_at
= bl
;
5008 incref_bp_location (bl
);
5009 /* If the condition is false, etc., don't do the commands. */
5010 bs
->commands
= NULL
;
5012 bs
->print_it
= print_it_normal
;
5016 /* The target has stopped with waitstatus WS. Check if any hardware
5017 watchpoints have triggered, according to the target. */
5020 watchpoints_triggered (struct target_waitstatus
*ws
)
5022 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5024 struct breakpoint
*b
;
5026 if (!stopped_by_watchpoint
)
5028 /* We were not stopped by a watchpoint. Mark all watchpoints
5029 as not triggered. */
5031 if (is_hardware_watchpoint (b
))
5033 struct watchpoint
*w
= (struct watchpoint
*) b
;
5035 w
->watchpoint_triggered
= watch_triggered_no
;
5041 if (!target_stopped_data_address (¤t_target
, &addr
))
5043 /* We were stopped by a watchpoint, but we don't know where.
5044 Mark all watchpoints as unknown. */
5046 if (is_hardware_watchpoint (b
))
5048 struct watchpoint
*w
= (struct watchpoint
*) b
;
5050 w
->watchpoint_triggered
= watch_triggered_unknown
;
5056 /* The target could report the data address. Mark watchpoints
5057 affected by this data address as triggered, and all others as not
5061 if (is_hardware_watchpoint (b
))
5063 struct watchpoint
*w
= (struct watchpoint
*) b
;
5064 struct bp_location
*loc
;
5066 w
->watchpoint_triggered
= watch_triggered_no
;
5067 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5069 if (is_masked_watchpoint (b
))
5071 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5072 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5074 if (newaddr
== start
)
5076 w
->watchpoint_triggered
= watch_triggered_yes
;
5080 /* Exact match not required. Within range is sufficient. */
5081 else if (target_watchpoint_addr_within_range (¤t_target
,
5085 w
->watchpoint_triggered
= watch_triggered_yes
;
5094 /* Possible return values for watchpoint_check (this can't be an enum
5095 because of check_errors). */
5096 /* The watchpoint has been deleted. */
5097 #define WP_DELETED 1
5098 /* The value has changed. */
5099 #define WP_VALUE_CHANGED 2
5100 /* The value has not changed. */
5101 #define WP_VALUE_NOT_CHANGED 3
5102 /* Ignore this watchpoint, no matter if the value changed or not. */
5105 #define BP_TEMPFLAG 1
5106 #define BP_HARDWAREFLAG 2
5108 /* Evaluate watchpoint condition expression and check if its value
5111 P should be a pointer to struct bpstat, but is defined as a void *
5112 in order for this function to be usable with catch_errors. */
5115 watchpoint_check (void *p
)
5117 bpstat bs
= (bpstat
) p
;
5118 struct watchpoint
*b
;
5119 struct frame_info
*fr
;
5120 int within_current_scope
;
5122 /* BS is built from an existing struct breakpoint. */
5123 gdb_assert (bs
->breakpoint_at
!= NULL
);
5124 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5126 /* If this is a local watchpoint, we only want to check if the
5127 watchpoint frame is in scope if the current thread is the thread
5128 that was used to create the watchpoint. */
5129 if (!watchpoint_in_thread_scope (b
))
5132 if (b
->exp_valid_block
== NULL
)
5133 within_current_scope
= 1;
5136 struct frame_info
*frame
= get_current_frame ();
5137 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5138 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5140 /* stack_frame_destroyed_p() returns a non-zero value if we're
5141 still in the function but the stack frame has already been
5142 invalidated. Since we can't rely on the values of local
5143 variables after the stack has been destroyed, we are treating
5144 the watchpoint in that state as `not changed' without further
5145 checking. Don't mark watchpoints as changed if the current
5146 frame is in an epilogue - even if they are in some other
5147 frame, our view of the stack is likely to be wrong and
5148 frame_find_by_id could error out. */
5149 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5152 fr
= frame_find_by_id (b
->watchpoint_frame
);
5153 within_current_scope
= (fr
!= NULL
);
5155 /* If we've gotten confused in the unwinder, we might have
5156 returned a frame that can't describe this variable. */
5157 if (within_current_scope
)
5159 struct symbol
*function
;
5161 function
= get_frame_function (fr
);
5162 if (function
== NULL
5163 || !contained_in (b
->exp_valid_block
,
5164 SYMBOL_BLOCK_VALUE (function
)))
5165 within_current_scope
= 0;
5168 if (within_current_scope
)
5169 /* If we end up stopping, the current frame will get selected
5170 in normal_stop. So this call to select_frame won't affect
5175 if (within_current_scope
)
5177 /* We use value_{,free_to_}mark because it could be a *long*
5178 time before we return to the command level and call
5179 free_all_values. We can't call free_all_values because we
5180 might be in the middle of evaluating a function call. */
5184 struct value
*new_val
;
5186 if (is_masked_watchpoint (b
))
5187 /* Since we don't know the exact trigger address (from
5188 stopped_data_address), just tell the user we've triggered
5189 a mask watchpoint. */
5190 return WP_VALUE_CHANGED
;
5192 mark
= value_mark ();
5193 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5195 if (b
->val_bitsize
!= 0)
5196 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5198 /* We use value_equal_contents instead of value_equal because
5199 the latter coerces an array to a pointer, thus comparing just
5200 the address of the array instead of its contents. This is
5201 not what we want. */
5202 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5203 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5205 if (new_val
!= NULL
)
5207 release_value (new_val
);
5208 value_free_to_mark (mark
);
5210 bs
->old_val
= b
->val
;
5213 return WP_VALUE_CHANGED
;
5217 /* Nothing changed. */
5218 value_free_to_mark (mark
);
5219 return WP_VALUE_NOT_CHANGED
;
5224 /* This seems like the only logical thing to do because
5225 if we temporarily ignored the watchpoint, then when
5226 we reenter the block in which it is valid it contains
5227 garbage (in the case of a function, it may have two
5228 garbage values, one before and one after the prologue).
5229 So we can't even detect the first assignment to it and
5230 watch after that (since the garbage may or may not equal
5231 the first value assigned). */
5232 /* We print all the stop information in
5233 breakpoint_ops->print_it, but in this case, by the time we
5234 call breakpoint_ops->print_it this bp will be deleted
5235 already. So we have no choice but print the information
5238 SWITCH_THRU_ALL_UIS ()
5240 struct ui_out
*uiout
= current_uiout
;
5242 if (uiout
->is_mi_like_p ())
5244 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5245 uiout
->text ("\nWatchpoint ");
5246 uiout
->field_int ("wpnum", b
->number
);
5247 uiout
->text (" deleted because the program has left the block in\n"
5248 "which its expression is valid.\n");
5251 /* Make sure the watchpoint's commands aren't executed. */
5252 decref_counted_command_line (&b
->commands
);
5253 watchpoint_del_at_next_stop (b
);
5259 /* Return true if it looks like target has stopped due to hitting
5260 breakpoint location BL. This function does not check if we should
5261 stop, only if BL explains the stop. */
5264 bpstat_check_location (const struct bp_location
*bl
,
5265 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5266 const struct target_waitstatus
*ws
)
5268 struct breakpoint
*b
= bl
->owner
;
5270 /* BL is from an existing breakpoint. */
5271 gdb_assert (b
!= NULL
);
5273 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5276 /* Determine if the watched values have actually changed, and we
5277 should stop. If not, set BS->stop to 0. */
5280 bpstat_check_watchpoint (bpstat bs
)
5282 const struct bp_location
*bl
;
5283 struct watchpoint
*b
;
5285 /* BS is built for existing struct breakpoint. */
5286 bl
= bs
->bp_location_at
;
5287 gdb_assert (bl
!= NULL
);
5288 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5289 gdb_assert (b
!= NULL
);
5292 int must_check_value
= 0;
5294 if (b
->type
== bp_watchpoint
)
5295 /* For a software watchpoint, we must always check the
5297 must_check_value
= 1;
5298 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5299 /* We have a hardware watchpoint (read, write, or access)
5300 and the target earlier reported an address watched by
5302 must_check_value
= 1;
5303 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5304 && b
->type
== bp_hardware_watchpoint
)
5305 /* We were stopped by a hardware watchpoint, but the target could
5306 not report the data address. We must check the watchpoint's
5307 value. Access and read watchpoints are out of luck; without
5308 a data address, we can't figure it out. */
5309 must_check_value
= 1;
5311 if (must_check_value
)
5314 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5316 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5317 int e
= catch_errors (watchpoint_check
, bs
, message
,
5319 do_cleanups (cleanups
);
5323 /* We've already printed what needs to be printed. */
5324 bs
->print_it
= print_it_done
;
5328 bs
->print_it
= print_it_noop
;
5331 case WP_VALUE_CHANGED
:
5332 if (b
->type
== bp_read_watchpoint
)
5334 /* There are two cases to consider here:
5336 1. We're watching the triggered memory for reads.
5337 In that case, trust the target, and always report
5338 the watchpoint hit to the user. Even though
5339 reads don't cause value changes, the value may
5340 have changed since the last time it was read, and
5341 since we're not trapping writes, we will not see
5342 those, and as such we should ignore our notion of
5345 2. We're watching the triggered memory for both
5346 reads and writes. There are two ways this may
5349 2.1. This is a target that can't break on data
5350 reads only, but can break on accesses (reads or
5351 writes), such as e.g., x86. We detect this case
5352 at the time we try to insert read watchpoints.
5354 2.2. Otherwise, the target supports read
5355 watchpoints, but, the user set an access or write
5356 watchpoint watching the same memory as this read
5359 If we're watching memory writes as well as reads,
5360 ignore watchpoint hits when we find that the
5361 value hasn't changed, as reads don't cause
5362 changes. This still gives false positives when
5363 the program writes the same value to memory as
5364 what there was already in memory (we will confuse
5365 it for a read), but it's much better than
5368 int other_write_watchpoint
= 0;
5370 if (bl
->watchpoint_type
== hw_read
)
5372 struct breakpoint
*other_b
;
5374 ALL_BREAKPOINTS (other_b
)
5375 if (other_b
->type
== bp_hardware_watchpoint
5376 || other_b
->type
== bp_access_watchpoint
)
5378 struct watchpoint
*other_w
=
5379 (struct watchpoint
*) other_b
;
5381 if (other_w
->watchpoint_triggered
5382 == watch_triggered_yes
)
5384 other_write_watchpoint
= 1;
5390 if (other_write_watchpoint
5391 || bl
->watchpoint_type
== hw_access
)
5393 /* We're watching the same memory for writes,
5394 and the value changed since the last time we
5395 updated it, so this trap must be for a write.
5397 bs
->print_it
= print_it_noop
;
5402 case WP_VALUE_NOT_CHANGED
:
5403 if (b
->type
== bp_hardware_watchpoint
5404 || b
->type
== bp_watchpoint
)
5406 /* Don't stop: write watchpoints shouldn't fire if
5407 the value hasn't changed. */
5408 bs
->print_it
= print_it_noop
;
5416 /* Error from catch_errors. */
5418 SWITCH_THRU_ALL_UIS ()
5420 printf_filtered (_("Watchpoint %d deleted.\n"),
5423 watchpoint_del_at_next_stop (b
);
5424 /* We've already printed what needs to be printed. */
5425 bs
->print_it
= print_it_done
;
5430 else /* must_check_value == 0 */
5432 /* This is a case where some watchpoint(s) triggered, but
5433 not at the address of this watchpoint, or else no
5434 watchpoint triggered after all. So don't print
5435 anything for this watchpoint. */
5436 bs
->print_it
= print_it_noop
;
5442 /* For breakpoints that are currently marked as telling gdb to stop,
5443 check conditions (condition proper, frame, thread and ignore count)
5444 of breakpoint referred to by BS. If we should not stop for this
5445 breakpoint, set BS->stop to 0. */
5448 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5450 const struct bp_location
*bl
;
5451 struct breakpoint
*b
;
5452 int value_is_zero
= 0;
5453 struct expression
*cond
;
5455 gdb_assert (bs
->stop
);
5457 /* BS is built for existing struct breakpoint. */
5458 bl
= bs
->bp_location_at
;
5459 gdb_assert (bl
!= NULL
);
5460 b
= bs
->breakpoint_at
;
5461 gdb_assert (b
!= NULL
);
5463 /* Even if the target evaluated the condition on its end and notified GDB, we
5464 need to do so again since GDB does not know if we stopped due to a
5465 breakpoint or a single step breakpoint. */
5467 if (frame_id_p (b
->frame_id
)
5468 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5474 /* If this is a thread/task-specific breakpoint, don't waste cpu
5475 evaluating the condition if this isn't the specified
5477 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5478 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5485 /* Evaluate extension language breakpoints that have a "stop" method
5487 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5489 if (is_watchpoint (b
))
5491 struct watchpoint
*w
= (struct watchpoint
*) b
;
5493 cond
= w
->cond_exp
.get ();
5496 cond
= bl
->cond
.get ();
5498 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5500 int within_current_scope
= 1;
5501 struct watchpoint
* w
;
5503 /* We use value_mark and value_free_to_mark because it could
5504 be a long time before we return to the command level and
5505 call free_all_values. We can't call free_all_values
5506 because we might be in the middle of evaluating a
5508 struct value
*mark
= value_mark ();
5510 if (is_watchpoint (b
))
5511 w
= (struct watchpoint
*) b
;
5515 /* Need to select the frame, with all that implies so that
5516 the conditions will have the right context. Because we
5517 use the frame, we will not see an inlined function's
5518 variables when we arrive at a breakpoint at the start
5519 of the inlined function; the current frame will be the
5521 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5522 select_frame (get_current_frame ());
5525 struct frame_info
*frame
;
5527 /* For local watchpoint expressions, which particular
5528 instance of a local is being watched matters, so we
5529 keep track of the frame to evaluate the expression
5530 in. To evaluate the condition however, it doesn't
5531 really matter which instantiation of the function
5532 where the condition makes sense triggers the
5533 watchpoint. This allows an expression like "watch
5534 global if q > 10" set in `func', catch writes to
5535 global on all threads that call `func', or catch
5536 writes on all recursive calls of `func' by a single
5537 thread. We simply always evaluate the condition in
5538 the innermost frame that's executing where it makes
5539 sense to evaluate the condition. It seems
5541 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5543 select_frame (frame
);
5545 within_current_scope
= 0;
5547 if (within_current_scope
)
5549 = catch_errors (breakpoint_cond_eval
, cond
,
5550 "Error in testing breakpoint condition:\n",
5554 warning (_("Watchpoint condition cannot be tested "
5555 "in the current scope"));
5556 /* If we failed to set the right context for this
5557 watchpoint, unconditionally report it. */
5560 /* FIXME-someday, should give breakpoint #. */
5561 value_free_to_mark (mark
);
5564 if (cond
&& value_is_zero
)
5568 else if (b
->ignore_count
> 0)
5572 /* Increase the hit count even though we don't stop. */
5574 observer_notify_breakpoint_modified (b
);
5578 /* Returns true if we need to track moribund locations of LOC's type
5579 on the current target. */
5582 need_moribund_for_location_type (struct bp_location
*loc
)
5584 return ((loc
->loc_type
== bp_loc_software_breakpoint
5585 && !target_supports_stopped_by_sw_breakpoint ())
5586 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5587 && !target_supports_stopped_by_hw_breakpoint ()));
5591 /* Get a bpstat associated with having just stopped at address
5592 BP_ADDR in thread PTID.
5594 Determine whether we stopped at a breakpoint, etc, or whether we
5595 don't understand this stop. Result is a chain of bpstat's such
5598 if we don't understand the stop, the result is a null pointer.
5600 if we understand why we stopped, the result is not null.
5602 Each element of the chain refers to a particular breakpoint or
5603 watchpoint at which we have stopped. (We may have stopped for
5604 several reasons concurrently.)
5606 Each element of the chain has valid next, breakpoint_at,
5607 commands, FIXME??? fields. */
5610 bpstat_stop_status (struct address_space
*aspace
,
5611 CORE_ADDR bp_addr
, ptid_t ptid
,
5612 const struct target_waitstatus
*ws
)
5614 struct breakpoint
*b
= NULL
;
5615 struct bp_location
*bl
;
5616 struct bp_location
*loc
;
5617 /* First item of allocated bpstat's. */
5618 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5619 /* Pointer to the last thing in the chain currently. */
5622 int need_remove_insert
;
5625 /* First, build the bpstat chain with locations that explain a
5626 target stop, while being careful to not set the target running,
5627 as that may invalidate locations (in particular watchpoint
5628 locations are recreated). Resuming will happen here with
5629 breakpoint conditions or watchpoint expressions that include
5630 inferior function calls. */
5634 if (!breakpoint_enabled (b
))
5637 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5639 /* For hardware watchpoints, we look only at the first
5640 location. The watchpoint_check function will work on the
5641 entire expression, not the individual locations. For
5642 read watchpoints, the watchpoints_triggered function has
5643 checked all locations already. */
5644 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5647 if (!bl
->enabled
|| bl
->shlib_disabled
)
5650 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5653 /* Come here if it's a watchpoint, or if the break address
5656 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5659 /* Assume we stop. Should we find a watchpoint that is not
5660 actually triggered, or if the condition of the breakpoint
5661 evaluates as false, we'll reset 'stop' to 0. */
5665 /* If this is a scope breakpoint, mark the associated
5666 watchpoint as triggered so that we will handle the
5667 out-of-scope event. We'll get to the watchpoint next
5669 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5671 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5673 w
->watchpoint_triggered
= watch_triggered_yes
;
5678 /* Check if a moribund breakpoint explains the stop. */
5679 if (!target_supports_stopped_by_sw_breakpoint ()
5680 || !target_supports_stopped_by_hw_breakpoint ())
5682 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5684 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5685 && need_moribund_for_location_type (loc
))
5687 bs
= bpstat_alloc (loc
, &bs_link
);
5688 /* For hits of moribund locations, we should just proceed. */
5691 bs
->print_it
= print_it_noop
;
5696 /* A bit of special processing for shlib breakpoints. We need to
5697 process solib loading here, so that the lists of loaded and
5698 unloaded libraries are correct before we handle "catch load" and
5700 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5702 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5704 handle_solib_event ();
5709 /* Now go through the locations that caused the target to stop, and
5710 check whether we're interested in reporting this stop to higher
5711 layers, or whether we should resume the target transparently. */
5715 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5720 b
= bs
->breakpoint_at
;
5721 b
->ops
->check_status (bs
);
5724 bpstat_check_breakpoint_conditions (bs
, ptid
);
5729 observer_notify_breakpoint_modified (b
);
5731 /* We will stop here. */
5732 if (b
->disposition
== disp_disable
)
5734 --(b
->enable_count
);
5735 if (b
->enable_count
<= 0)
5736 b
->enable_state
= bp_disabled
;
5741 bs
->commands
= b
->commands
;
5742 incref_counted_command_line (bs
->commands
);
5743 if (command_line_is_silent (bs
->commands
5744 ? bs
->commands
->commands
: NULL
))
5747 b
->ops
->after_condition_true (bs
);
5752 /* Print nothing for this entry if we don't stop or don't
5754 if (!bs
->stop
|| !bs
->print
)
5755 bs
->print_it
= print_it_noop
;
5758 /* If we aren't stopping, the value of some hardware watchpoint may
5759 not have changed, but the intermediate memory locations we are
5760 watching may have. Don't bother if we're stopping; this will get
5762 need_remove_insert
= 0;
5763 if (! bpstat_causes_stop (bs_head
))
5764 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5766 && bs
->breakpoint_at
5767 && is_hardware_watchpoint (bs
->breakpoint_at
))
5769 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5771 update_watchpoint (w
, 0 /* don't reparse. */);
5772 need_remove_insert
= 1;
5775 if (need_remove_insert
)
5776 update_global_location_list (UGLL_MAY_INSERT
);
5777 else if (removed_any
)
5778 update_global_location_list (UGLL_DONT_INSERT
);
5784 handle_jit_event (void)
5786 struct frame_info
*frame
;
5787 struct gdbarch
*gdbarch
;
5790 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5792 /* Switch terminal for any messages produced by
5793 breakpoint_re_set. */
5794 target_terminal_ours_for_output ();
5796 frame
= get_current_frame ();
5797 gdbarch
= get_frame_arch (frame
);
5799 jit_event_handler (gdbarch
);
5801 target_terminal_inferior ();
5804 /* Prepare WHAT final decision for infrun. */
5806 /* Decide what infrun needs to do with this bpstat. */
5809 bpstat_what (bpstat bs_head
)
5811 struct bpstat_what retval
;
5814 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5815 retval
.call_dummy
= STOP_NONE
;
5816 retval
.is_longjmp
= 0;
5818 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5820 /* Extract this BS's action. After processing each BS, we check
5821 if its action overrides all we've seem so far. */
5822 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5825 if (bs
->breakpoint_at
== NULL
)
5827 /* I suspect this can happen if it was a momentary
5828 breakpoint which has since been deleted. */
5832 bptype
= bs
->breakpoint_at
->type
;
5839 case bp_hardware_breakpoint
:
5840 case bp_single_step
:
5843 case bp_shlib_event
:
5847 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5849 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5852 this_action
= BPSTAT_WHAT_SINGLE
;
5855 case bp_hardware_watchpoint
:
5856 case bp_read_watchpoint
:
5857 case bp_access_watchpoint
:
5861 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5863 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5867 /* There was a watchpoint, but we're not stopping.
5868 This requires no further action. */
5872 case bp_longjmp_call_dummy
:
5876 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5877 retval
.is_longjmp
= bptype
!= bp_exception
;
5880 this_action
= BPSTAT_WHAT_SINGLE
;
5882 case bp_longjmp_resume
:
5883 case bp_exception_resume
:
5886 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5887 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5890 this_action
= BPSTAT_WHAT_SINGLE
;
5892 case bp_step_resume
:
5894 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5897 /* It is for the wrong frame. */
5898 this_action
= BPSTAT_WHAT_SINGLE
;
5901 case bp_hp_step_resume
:
5903 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5906 /* It is for the wrong frame. */
5907 this_action
= BPSTAT_WHAT_SINGLE
;
5910 case bp_watchpoint_scope
:
5911 case bp_thread_event
:
5912 case bp_overlay_event
:
5913 case bp_longjmp_master
:
5914 case bp_std_terminate_master
:
5915 case bp_exception_master
:
5916 this_action
= BPSTAT_WHAT_SINGLE
;
5922 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5924 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5928 /* There was a catchpoint, but we're not stopping.
5929 This requires no further action. */
5933 this_action
= BPSTAT_WHAT_SINGLE
;
5936 /* Make sure the action is stop (silent or noisy),
5937 so infrun.c pops the dummy frame. */
5938 retval
.call_dummy
= STOP_STACK_DUMMY
;
5939 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5941 case bp_std_terminate
:
5942 /* Make sure the action is stop (silent or noisy),
5943 so infrun.c pops the dummy frame. */
5944 retval
.call_dummy
= STOP_STD_TERMINATE
;
5945 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5948 case bp_fast_tracepoint
:
5949 case bp_static_tracepoint
:
5950 /* Tracepoint hits should not be reported back to GDB, and
5951 if one got through somehow, it should have been filtered
5953 internal_error (__FILE__
, __LINE__
,
5954 _("bpstat_what: tracepoint encountered"));
5956 case bp_gnu_ifunc_resolver
:
5957 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5958 this_action
= BPSTAT_WHAT_SINGLE
;
5960 case bp_gnu_ifunc_resolver_return
:
5961 /* The breakpoint will be removed, execution will restart from the
5962 PC of the former breakpoint. */
5963 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5968 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5970 this_action
= BPSTAT_WHAT_SINGLE
;
5974 internal_error (__FILE__
, __LINE__
,
5975 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5978 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5985 bpstat_run_callbacks (bpstat bs_head
)
5989 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5991 struct breakpoint
*b
= bs
->breakpoint_at
;
5998 handle_jit_event ();
6000 case bp_gnu_ifunc_resolver
:
6001 gnu_ifunc_resolver_stop (b
);
6003 case bp_gnu_ifunc_resolver_return
:
6004 gnu_ifunc_resolver_return_stop (b
);
6010 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6011 without hardware support). This isn't related to a specific bpstat,
6012 just to things like whether watchpoints are set. */
6015 bpstat_should_step (void)
6017 struct breakpoint
*b
;
6020 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6026 bpstat_causes_stop (bpstat bs
)
6028 for (; bs
!= NULL
; bs
= bs
->next
)
6037 /* Compute a string of spaces suitable to indent the next line
6038 so it starts at the position corresponding to the table column
6039 named COL_NAME in the currently active table of UIOUT. */
6042 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6044 static char wrap_indent
[80];
6045 int i
, total_width
, width
, align
;
6049 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6051 if (strcmp (text
, col_name
) == 0)
6053 gdb_assert (total_width
< sizeof wrap_indent
);
6054 memset (wrap_indent
, ' ', total_width
);
6055 wrap_indent
[total_width
] = 0;
6060 total_width
+= width
+ 1;
6066 /* Determine if the locations of this breakpoint will have their conditions
6067 evaluated by the target, host or a mix of both. Returns the following:
6069 "host": Host evals condition.
6070 "host or target": Host or Target evals condition.
6071 "target": Target evals condition.
6075 bp_condition_evaluator (struct breakpoint
*b
)
6077 struct bp_location
*bl
;
6078 char host_evals
= 0;
6079 char target_evals
= 0;
6084 if (!is_breakpoint (b
))
6087 if (gdb_evaluates_breakpoint_condition_p ()
6088 || !target_supports_evaluation_of_breakpoint_conditions ())
6089 return condition_evaluation_host
;
6091 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6093 if (bl
->cond_bytecode
)
6099 if (host_evals
&& target_evals
)
6100 return condition_evaluation_both
;
6101 else if (target_evals
)
6102 return condition_evaluation_target
;
6104 return condition_evaluation_host
;
6107 /* Determine the breakpoint location's condition evaluator. This is
6108 similar to bp_condition_evaluator, but for locations. */
6111 bp_location_condition_evaluator (struct bp_location
*bl
)
6113 if (bl
&& !is_breakpoint (bl
->owner
))
6116 if (gdb_evaluates_breakpoint_condition_p ()
6117 || !target_supports_evaluation_of_breakpoint_conditions ())
6118 return condition_evaluation_host
;
6120 if (bl
&& bl
->cond_bytecode
)
6121 return condition_evaluation_target
;
6123 return condition_evaluation_host
;
6126 /* Print the LOC location out of the list of B->LOC locations. */
6129 print_breakpoint_location (struct breakpoint
*b
,
6130 struct bp_location
*loc
)
6132 struct ui_out
*uiout
= current_uiout
;
6134 scoped_restore_current_program_space restore_pspace
;
6136 if (loc
!= NULL
&& loc
->shlib_disabled
)
6140 set_current_program_space (loc
->pspace
);
6142 if (b
->display_canonical
)
6143 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6144 else if (loc
&& loc
->symtab
)
6147 = find_pc_sect_function (loc
->address
, loc
->section
);
6150 uiout
->text ("in ");
6151 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6153 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6154 uiout
->text ("at ");
6156 uiout
->field_string ("file",
6157 symtab_to_filename_for_display (loc
->symtab
));
6160 if (uiout
->is_mi_like_p ())
6161 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6163 uiout
->field_int ("line", loc
->line_number
);
6169 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6171 uiout
->field_stream ("at", stb
);
6175 uiout
->field_string ("pending",
6176 event_location_to_string (b
->location
.get ()));
6177 /* If extra_string is available, it could be holding a condition
6178 or dprintf arguments. In either case, make sure it is printed,
6179 too, but only for non-MI streams. */
6180 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6182 if (b
->type
== bp_dprintf
)
6186 uiout
->text (b
->extra_string
);
6190 if (loc
&& is_breakpoint (b
)
6191 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6192 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6195 uiout
->field_string ("evaluated-by",
6196 bp_location_condition_evaluator (loc
));
6202 bptype_string (enum bptype type
)
6204 struct ep_type_description
6207 const char *description
;
6209 static struct ep_type_description bptypes
[] =
6211 {bp_none
, "?deleted?"},
6212 {bp_breakpoint
, "breakpoint"},
6213 {bp_hardware_breakpoint
, "hw breakpoint"},
6214 {bp_single_step
, "sw single-step"},
6215 {bp_until
, "until"},
6216 {bp_finish
, "finish"},
6217 {bp_watchpoint
, "watchpoint"},
6218 {bp_hardware_watchpoint
, "hw watchpoint"},
6219 {bp_read_watchpoint
, "read watchpoint"},
6220 {bp_access_watchpoint
, "acc watchpoint"},
6221 {bp_longjmp
, "longjmp"},
6222 {bp_longjmp_resume
, "longjmp resume"},
6223 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6224 {bp_exception
, "exception"},
6225 {bp_exception_resume
, "exception resume"},
6226 {bp_step_resume
, "step resume"},
6227 {bp_hp_step_resume
, "high-priority step resume"},
6228 {bp_watchpoint_scope
, "watchpoint scope"},
6229 {bp_call_dummy
, "call dummy"},
6230 {bp_std_terminate
, "std::terminate"},
6231 {bp_shlib_event
, "shlib events"},
6232 {bp_thread_event
, "thread events"},
6233 {bp_overlay_event
, "overlay events"},
6234 {bp_longjmp_master
, "longjmp master"},
6235 {bp_std_terminate_master
, "std::terminate master"},
6236 {bp_exception_master
, "exception master"},
6237 {bp_catchpoint
, "catchpoint"},
6238 {bp_tracepoint
, "tracepoint"},
6239 {bp_fast_tracepoint
, "fast tracepoint"},
6240 {bp_static_tracepoint
, "static tracepoint"},
6241 {bp_dprintf
, "dprintf"},
6242 {bp_jit_event
, "jit events"},
6243 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6244 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6247 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6248 || ((int) type
!= bptypes
[(int) type
].type
))
6249 internal_error (__FILE__
, __LINE__
,
6250 _("bptypes table does not describe type #%d."),
6253 return bptypes
[(int) type
].description
;
6256 /* For MI, output a field named 'thread-groups' with a list as the value.
6257 For CLI, prefix the list with the string 'inf'. */
6260 output_thread_groups (struct ui_out
*uiout
,
6261 const char *field_name
,
6265 int is_mi
= uiout
->is_mi_like_p ();
6269 /* For backward compatibility, don't display inferiors in CLI unless
6270 there are several. Always display them for MI. */
6271 if (!is_mi
&& mi_only
)
6274 ui_out_emit_list
list_emitter (uiout
, field_name
);
6276 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6282 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6283 uiout
->field_string (NULL
, mi_group
);
6288 uiout
->text (" inf ");
6292 uiout
->text (plongest (inf
));
6297 /* Print B to gdb_stdout. */
6300 print_one_breakpoint_location (struct breakpoint
*b
,
6301 struct bp_location
*loc
,
6303 struct bp_location
**last_loc
,
6306 struct command_line
*l
;
6307 static char bpenables
[] = "nynny";
6309 struct ui_out
*uiout
= current_uiout
;
6310 int header_of_multiple
= 0;
6311 int part_of_multiple
= (loc
!= NULL
);
6312 struct value_print_options opts
;
6314 get_user_print_options (&opts
);
6316 gdb_assert (!loc
|| loc_number
!= 0);
6317 /* See comment in print_one_breakpoint concerning treatment of
6318 breakpoints with single disabled location. */
6321 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6322 header_of_multiple
= 1;
6330 if (part_of_multiple
)
6333 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6334 uiout
->field_string ("number", formatted
);
6339 uiout
->field_int ("number", b
->number
);
6344 if (part_of_multiple
)
6345 uiout
->field_skip ("type");
6347 uiout
->field_string ("type", bptype_string (b
->type
));
6351 if (part_of_multiple
)
6352 uiout
->field_skip ("disp");
6354 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6359 if (part_of_multiple
)
6360 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6362 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6367 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6369 /* Although the print_one can possibly print all locations,
6370 calling it here is not likely to get any nice result. So,
6371 make sure there's just one location. */
6372 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6373 b
->ops
->print_one (b
, last_loc
);
6379 internal_error (__FILE__
, __LINE__
,
6380 _("print_one_breakpoint: bp_none encountered\n"));
6384 case bp_hardware_watchpoint
:
6385 case bp_read_watchpoint
:
6386 case bp_access_watchpoint
:
6388 struct watchpoint
*w
= (struct watchpoint
*) b
;
6390 /* Field 4, the address, is omitted (which makes the columns
6391 not line up too nicely with the headers, but the effect
6392 is relatively readable). */
6393 if (opts
.addressprint
)
6394 uiout
->field_skip ("addr");
6396 uiout
->field_string ("what", w
->exp_string
);
6401 case bp_hardware_breakpoint
:
6402 case bp_single_step
:
6406 case bp_longjmp_resume
:
6407 case bp_longjmp_call_dummy
:
6409 case bp_exception_resume
:
6410 case bp_step_resume
:
6411 case bp_hp_step_resume
:
6412 case bp_watchpoint_scope
:
6414 case bp_std_terminate
:
6415 case bp_shlib_event
:
6416 case bp_thread_event
:
6417 case bp_overlay_event
:
6418 case bp_longjmp_master
:
6419 case bp_std_terminate_master
:
6420 case bp_exception_master
:
6422 case bp_fast_tracepoint
:
6423 case bp_static_tracepoint
:
6426 case bp_gnu_ifunc_resolver
:
6427 case bp_gnu_ifunc_resolver_return
:
6428 if (opts
.addressprint
)
6431 if (header_of_multiple
)
6432 uiout
->field_string ("addr", "<MULTIPLE>");
6433 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6434 uiout
->field_string ("addr", "<PENDING>");
6436 uiout
->field_core_addr ("addr",
6437 loc
->gdbarch
, loc
->address
);
6440 if (!header_of_multiple
)
6441 print_breakpoint_location (b
, loc
);
6448 if (loc
!= NULL
&& !header_of_multiple
)
6450 struct inferior
*inf
;
6451 VEC(int) *inf_num
= NULL
;
6456 if (inf
->pspace
== loc
->pspace
)
6457 VEC_safe_push (int, inf_num
, inf
->num
);
6460 /* For backward compatibility, don't display inferiors in CLI unless
6461 there are several. Always display for MI. */
6463 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6464 && (number_of_program_spaces () > 1
6465 || number_of_inferiors () > 1)
6466 /* LOC is for existing B, it cannot be in
6467 moribund_locations and thus having NULL OWNER. */
6468 && loc
->owner
->type
!= bp_catchpoint
))
6470 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6471 VEC_free (int, inf_num
);
6474 if (!part_of_multiple
)
6476 if (b
->thread
!= -1)
6478 /* FIXME: This seems to be redundant and lost here; see the
6479 "stop only in" line a little further down. */
6480 uiout
->text (" thread ");
6481 uiout
->field_int ("thread", b
->thread
);
6483 else if (b
->task
!= 0)
6485 uiout
->text (" task ");
6486 uiout
->field_int ("task", b
->task
);
6492 if (!part_of_multiple
)
6493 b
->ops
->print_one_detail (b
, uiout
);
6495 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6498 uiout
->text ("\tstop only in stack frame at ");
6499 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6501 uiout
->field_core_addr ("frame",
6502 b
->gdbarch
, b
->frame_id
.stack_addr
);
6506 if (!part_of_multiple
&& b
->cond_string
)
6509 if (is_tracepoint (b
))
6510 uiout
->text ("\ttrace only if ");
6512 uiout
->text ("\tstop only if ");
6513 uiout
->field_string ("cond", b
->cond_string
);
6515 /* Print whether the target is doing the breakpoint's condition
6516 evaluation. If GDB is doing the evaluation, don't print anything. */
6517 if (is_breakpoint (b
)
6518 && breakpoint_condition_evaluation_mode ()
6519 == condition_evaluation_target
)
6522 uiout
->field_string ("evaluated-by",
6523 bp_condition_evaluator (b
));
6524 uiout
->text (" evals)");
6529 if (!part_of_multiple
&& b
->thread
!= -1)
6531 /* FIXME should make an annotation for this. */
6532 uiout
->text ("\tstop only in thread ");
6533 if (uiout
->is_mi_like_p ())
6534 uiout
->field_int ("thread", b
->thread
);
6537 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6539 uiout
->field_string ("thread", print_thread_id (thr
));
6544 if (!part_of_multiple
)
6548 /* FIXME should make an annotation for this. */
6549 if (is_catchpoint (b
))
6550 uiout
->text ("\tcatchpoint");
6551 else if (is_tracepoint (b
))
6552 uiout
->text ("\ttracepoint");
6554 uiout
->text ("\tbreakpoint");
6555 uiout
->text (" already hit ");
6556 uiout
->field_int ("times", b
->hit_count
);
6557 if (b
->hit_count
== 1)
6558 uiout
->text (" time\n");
6560 uiout
->text (" times\n");
6564 /* Output the count also if it is zero, but only if this is mi. */
6565 if (uiout
->is_mi_like_p ())
6566 uiout
->field_int ("times", b
->hit_count
);
6570 if (!part_of_multiple
&& b
->ignore_count
)
6573 uiout
->text ("\tignore next ");
6574 uiout
->field_int ("ignore", b
->ignore_count
);
6575 uiout
->text (" hits\n");
6578 /* Note that an enable count of 1 corresponds to "enable once"
6579 behavior, which is reported by the combination of enablement and
6580 disposition, so we don't need to mention it here. */
6581 if (!part_of_multiple
&& b
->enable_count
> 1)
6584 uiout
->text ("\tdisable after ");
6585 /* Tweak the wording to clarify that ignore and enable counts
6586 are distinct, and have additive effect. */
6587 if (b
->ignore_count
)
6588 uiout
->text ("additional ");
6590 uiout
->text ("next ");
6591 uiout
->field_int ("enable", b
->enable_count
);
6592 uiout
->text (" hits\n");
6595 if (!part_of_multiple
&& is_tracepoint (b
))
6597 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6599 if (tp
->traceframe_usage
)
6601 uiout
->text ("\ttrace buffer usage ");
6602 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6603 uiout
->text (" bytes\n");
6607 l
= b
->commands
? b
->commands
->commands
: NULL
;
6608 if (!part_of_multiple
&& l
)
6611 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6612 print_command_lines (uiout
, l
, 4);
6615 if (is_tracepoint (b
))
6617 struct tracepoint
*t
= (struct tracepoint
*) b
;
6619 if (!part_of_multiple
&& t
->pass_count
)
6621 annotate_field (10);
6622 uiout
->text ("\tpass count ");
6623 uiout
->field_int ("pass", t
->pass_count
);
6624 uiout
->text (" \n");
6627 /* Don't display it when tracepoint or tracepoint location is
6629 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6631 annotate_field (11);
6633 if (uiout
->is_mi_like_p ())
6634 uiout
->field_string ("installed",
6635 loc
->inserted
? "y" : "n");
6641 uiout
->text ("\tnot ");
6642 uiout
->text ("installed on target\n");
6647 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6649 if (is_watchpoint (b
))
6651 struct watchpoint
*w
= (struct watchpoint
*) b
;
6653 uiout
->field_string ("original-location", w
->exp_string
);
6655 else if (b
->location
!= NULL
6656 && event_location_to_string (b
->location
.get ()) != NULL
)
6657 uiout
->field_string ("original-location",
6658 event_location_to_string (b
->location
.get ()));
6663 print_one_breakpoint (struct breakpoint
*b
,
6664 struct bp_location
**last_loc
,
6667 struct ui_out
*uiout
= current_uiout
;
6670 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6672 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6675 /* If this breakpoint has custom print function,
6676 it's already printed. Otherwise, print individual
6677 locations, if any. */
6678 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6680 /* If breakpoint has a single location that is disabled, we
6681 print it as if it had several locations, since otherwise it's
6682 hard to represent "breakpoint enabled, location disabled"
6685 Note that while hardware watchpoints have several locations
6686 internally, that's not a property exposed to user. */
6688 && !is_hardware_watchpoint (b
)
6689 && (b
->loc
->next
|| !b
->loc
->enabled
))
6691 struct bp_location
*loc
;
6694 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6696 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6697 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6704 breakpoint_address_bits (struct breakpoint
*b
)
6706 int print_address_bits
= 0;
6707 struct bp_location
*loc
;
6709 /* Software watchpoints that aren't watching memory don't have an
6710 address to print. */
6711 if (is_no_memory_software_watchpoint (b
))
6714 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6718 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6719 if (addr_bit
> print_address_bits
)
6720 print_address_bits
= addr_bit
;
6723 return print_address_bits
;
6726 struct captured_breakpoint_query_args
6732 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6734 struct captured_breakpoint_query_args
*args
6735 = (struct captured_breakpoint_query_args
*) data
;
6736 struct breakpoint
*b
;
6737 struct bp_location
*dummy_loc
= NULL
;
6741 if (args
->bnum
== b
->number
)
6743 print_one_breakpoint (b
, &dummy_loc
, 0);
6751 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6752 char **error_message
)
6754 struct captured_breakpoint_query_args args
;
6757 /* For the moment we don't trust print_one_breakpoint() to not throw
6759 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6760 error_message
, RETURN_MASK_ALL
) < 0)
6766 /* Return true if this breakpoint was set by the user, false if it is
6767 internal or momentary. */
6770 user_breakpoint_p (struct breakpoint
*b
)
6772 return b
->number
> 0;
6775 /* See breakpoint.h. */
6778 pending_breakpoint_p (struct breakpoint
*b
)
6780 return b
->loc
== NULL
;
6783 /* Print information on user settable breakpoint (watchpoint, etc)
6784 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6785 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6786 FILTER is non-NULL, call it on each breakpoint and only include the
6787 ones for which it returns non-zero. Return the total number of
6788 breakpoints listed. */
6791 breakpoint_1 (char *args
, int allflag
,
6792 int (*filter
) (const struct breakpoint
*))
6794 struct breakpoint
*b
;
6795 struct bp_location
*last_loc
= NULL
;
6796 int nr_printable_breakpoints
;
6797 struct value_print_options opts
;
6798 int print_address_bits
= 0;
6799 int print_type_col_width
= 14;
6800 struct ui_out
*uiout
= current_uiout
;
6802 get_user_print_options (&opts
);
6804 /* Compute the number of rows in the table, as well as the size
6805 required for address fields. */
6806 nr_printable_breakpoints
= 0;
6809 /* If we have a filter, only list the breakpoints it accepts. */
6810 if (filter
&& !filter (b
))
6813 /* If we have an "args" string, it is a list of breakpoints to
6814 accept. Skip the others. */
6815 if (args
!= NULL
&& *args
!= '\0')
6817 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6819 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6823 if (allflag
|| user_breakpoint_p (b
))
6825 int addr_bit
, type_len
;
6827 addr_bit
= breakpoint_address_bits (b
);
6828 if (addr_bit
> print_address_bits
)
6829 print_address_bits
= addr_bit
;
6831 type_len
= strlen (bptype_string (b
->type
));
6832 if (type_len
> print_type_col_width
)
6833 print_type_col_width
= type_len
;
6835 nr_printable_breakpoints
++;
6840 ui_out_emit_table
table_emitter (uiout
,
6841 opts
.addressprint
? 6 : 5,
6842 nr_printable_breakpoints
,
6845 if (nr_printable_breakpoints
> 0)
6846 annotate_breakpoints_headers ();
6847 if (nr_printable_breakpoints
> 0)
6849 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6850 if (nr_printable_breakpoints
> 0)
6852 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6853 if (nr_printable_breakpoints
> 0)
6855 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6856 if (nr_printable_breakpoints
> 0)
6858 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6859 if (opts
.addressprint
)
6861 if (nr_printable_breakpoints
> 0)
6863 if (print_address_bits
<= 32)
6864 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6866 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6868 if (nr_printable_breakpoints
> 0)
6870 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6871 uiout
->table_body ();
6872 if (nr_printable_breakpoints
> 0)
6873 annotate_breakpoints_table ();
6878 /* If we have a filter, only list the breakpoints it accepts. */
6879 if (filter
&& !filter (b
))
6882 /* If we have an "args" string, it is a list of breakpoints to
6883 accept. Skip the others. */
6885 if (args
!= NULL
&& *args
!= '\0')
6887 if (allflag
) /* maintenance info breakpoint */
6889 if (parse_and_eval_long (args
) != b
->number
)
6892 else /* all others */
6894 if (!number_is_in_list (args
, b
->number
))
6898 /* We only print out user settable breakpoints unless the
6900 if (allflag
|| user_breakpoint_p (b
))
6901 print_one_breakpoint (b
, &last_loc
, allflag
);
6905 if (nr_printable_breakpoints
== 0)
6907 /* If there's a filter, let the caller decide how to report
6911 if (args
== NULL
|| *args
== '\0')
6912 uiout
->message ("No breakpoints or watchpoints.\n");
6914 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6920 if (last_loc
&& !server_command
)
6921 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6924 /* FIXME? Should this be moved up so that it is only called when
6925 there have been breakpoints? */
6926 annotate_breakpoints_table_end ();
6928 return nr_printable_breakpoints
;
6931 /* Display the value of default-collect in a way that is generally
6932 compatible with the breakpoint list. */
6935 default_collect_info (void)
6937 struct ui_out
*uiout
= current_uiout
;
6939 /* If it has no value (which is frequently the case), say nothing; a
6940 message like "No default-collect." gets in user's face when it's
6942 if (!*default_collect
)
6945 /* The following phrase lines up nicely with per-tracepoint collect
6947 uiout
->text ("default collect ");
6948 uiout
->field_string ("default-collect", default_collect
);
6949 uiout
->text (" \n");
6953 info_breakpoints_command (char *args
, int from_tty
)
6955 breakpoint_1 (args
, 0, NULL
);
6957 default_collect_info ();
6961 info_watchpoints_command (char *args
, int from_tty
)
6963 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6964 struct ui_out
*uiout
= current_uiout
;
6966 if (num_printed
== 0)
6968 if (args
== NULL
|| *args
== '\0')
6969 uiout
->message ("No watchpoints.\n");
6971 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6976 maintenance_info_breakpoints (char *args
, int from_tty
)
6978 breakpoint_1 (args
, 1, NULL
);
6980 default_collect_info ();
6984 breakpoint_has_pc (struct breakpoint
*b
,
6985 struct program_space
*pspace
,
6986 CORE_ADDR pc
, struct obj_section
*section
)
6988 struct bp_location
*bl
= b
->loc
;
6990 for (; bl
; bl
= bl
->next
)
6992 if (bl
->pspace
== pspace
6993 && bl
->address
== pc
6994 && (!overlay_debugging
|| bl
->section
== section
))
7000 /* Print a message describing any user-breakpoints set at PC. This
7001 concerns with logical breakpoints, so we match program spaces, not
7005 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7006 struct program_space
*pspace
, CORE_ADDR pc
,
7007 struct obj_section
*section
, int thread
)
7010 struct breakpoint
*b
;
7013 others
+= (user_breakpoint_p (b
)
7014 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7018 printf_filtered (_("Note: breakpoint "));
7019 else /* if (others == ???) */
7020 printf_filtered (_("Note: breakpoints "));
7022 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7025 printf_filtered ("%d", b
->number
);
7026 if (b
->thread
== -1 && thread
!= -1)
7027 printf_filtered (" (all threads)");
7028 else if (b
->thread
!= -1)
7029 printf_filtered (" (thread %d)", b
->thread
);
7030 printf_filtered ("%s%s ",
7031 ((b
->enable_state
== bp_disabled
7032 || b
->enable_state
== bp_call_disabled
)
7036 : ((others
== 1) ? " and" : ""));
7038 printf_filtered (_("also set at pc "));
7039 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7040 printf_filtered (".\n");
7045 /* Return true iff it is meaningful to use the address member of
7046 BPT locations. For some breakpoint types, the locations' address members
7047 are irrelevant and it makes no sense to attempt to compare them to other
7048 addresses (or use them for any other purpose either).
7050 More specifically, each of the following breakpoint types will
7051 always have a zero valued location address and we don't want to mark
7052 breakpoints of any of these types to be a duplicate of an actual
7053 breakpoint location at address zero:
7061 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7063 enum bptype type
= bpt
->type
;
7065 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7068 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7069 true if LOC1 and LOC2 represent the same watchpoint location. */
7072 watchpoint_locations_match (struct bp_location
*loc1
,
7073 struct bp_location
*loc2
)
7075 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7076 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7078 /* Both of them must exist. */
7079 gdb_assert (w1
!= NULL
);
7080 gdb_assert (w2
!= NULL
);
7082 /* If the target can evaluate the condition expression in hardware,
7083 then we we need to insert both watchpoints even if they are at
7084 the same place. Otherwise the watchpoint will only trigger when
7085 the condition of whichever watchpoint was inserted evaluates to
7086 true, not giving a chance for GDB to check the condition of the
7087 other watchpoint. */
7089 && target_can_accel_watchpoint_condition (loc1
->address
,
7091 loc1
->watchpoint_type
,
7092 w1
->cond_exp
.get ()))
7094 && target_can_accel_watchpoint_condition (loc2
->address
,
7096 loc2
->watchpoint_type
,
7097 w2
->cond_exp
.get ())))
7100 /* Note that this checks the owner's type, not the location's. In
7101 case the target does not support read watchpoints, but does
7102 support access watchpoints, we'll have bp_read_watchpoint
7103 watchpoints with hw_access locations. Those should be considered
7104 duplicates of hw_read locations. The hw_read locations will
7105 become hw_access locations later. */
7106 return (loc1
->owner
->type
== loc2
->owner
->type
7107 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7108 && loc1
->address
== loc2
->address
7109 && loc1
->length
== loc2
->length
);
7112 /* See breakpoint.h. */
7115 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7116 struct address_space
*aspace2
, CORE_ADDR addr2
)
7118 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7119 || aspace1
== aspace2
)
7123 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7124 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7125 matches ASPACE2. On targets that have global breakpoints, the address
7126 space doesn't really matter. */
7129 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7130 int len1
, struct address_space
*aspace2
,
7133 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7134 || aspace1
== aspace2
)
7135 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7138 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7139 a ranged breakpoint. In most targets, a match happens only if ASPACE
7140 matches the breakpoint's address space. On targets that have global
7141 breakpoints, the address space doesn't really matter. */
7144 breakpoint_location_address_match (struct bp_location
*bl
,
7145 struct address_space
*aspace
,
7148 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7151 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7152 bl
->address
, bl
->length
,
7156 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7157 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7158 match happens only if ASPACE matches the breakpoint's address
7159 space. On targets that have global breakpoints, the address space
7160 doesn't really matter. */
7163 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7164 struct address_space
*aspace
,
7165 CORE_ADDR addr
, int len
)
7167 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7168 || bl
->pspace
->aspace
== aspace
)
7170 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7172 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7178 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7179 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7180 true, otherwise returns false. */
7183 tracepoint_locations_match (struct bp_location
*loc1
,
7184 struct bp_location
*loc2
)
7186 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7187 /* Since tracepoint locations are never duplicated with others', tracepoint
7188 locations at the same address of different tracepoints are regarded as
7189 different locations. */
7190 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7195 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7196 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7197 represent the same location. */
7200 breakpoint_locations_match (struct bp_location
*loc1
,
7201 struct bp_location
*loc2
)
7203 int hw_point1
, hw_point2
;
7205 /* Both of them must not be in moribund_locations. */
7206 gdb_assert (loc1
->owner
!= NULL
);
7207 gdb_assert (loc2
->owner
!= NULL
);
7209 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7210 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7212 if (hw_point1
!= hw_point2
)
7215 return watchpoint_locations_match (loc1
, loc2
);
7216 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7217 return tracepoint_locations_match (loc1
, loc2
);
7219 /* We compare bp_location.length in order to cover ranged breakpoints. */
7220 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7221 loc2
->pspace
->aspace
, loc2
->address
)
7222 && loc1
->length
== loc2
->length
);
7226 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7227 int bnum
, int have_bnum
)
7229 /* The longest string possibly returned by hex_string_custom
7230 is 50 chars. These must be at least that big for safety. */
7234 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7235 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7237 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7238 bnum
, astr1
, astr2
);
7240 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7243 /* Adjust a breakpoint's address to account for architectural
7244 constraints on breakpoint placement. Return the adjusted address.
7245 Note: Very few targets require this kind of adjustment. For most
7246 targets, this function is simply the identity function. */
7249 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7250 CORE_ADDR bpaddr
, enum bptype bptype
)
7252 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7254 /* Very few targets need any kind of breakpoint adjustment. */
7257 else if (bptype
== bp_watchpoint
7258 || bptype
== bp_hardware_watchpoint
7259 || bptype
== bp_read_watchpoint
7260 || bptype
== bp_access_watchpoint
7261 || bptype
== bp_catchpoint
)
7263 /* Watchpoints and the various bp_catch_* eventpoints should not
7264 have their addresses modified. */
7267 else if (bptype
== bp_single_step
)
7269 /* Single-step breakpoints should not have their addresses
7270 modified. If there's any architectural constrain that
7271 applies to this address, then it should have already been
7272 taken into account when the breakpoint was created in the
7273 first place. If we didn't do this, stepping through e.g.,
7274 Thumb-2 IT blocks would break. */
7279 CORE_ADDR adjusted_bpaddr
;
7281 /* Some targets have architectural constraints on the placement
7282 of breakpoint instructions. Obtain the adjusted address. */
7283 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7285 /* An adjusted breakpoint address can significantly alter
7286 a user's expectations. Print a warning if an adjustment
7288 if (adjusted_bpaddr
!= bpaddr
)
7289 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7291 return adjusted_bpaddr
;
7295 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7297 bp_location
*loc
= this;
7299 gdb_assert (ops
!= NULL
);
7303 loc
->cond_bytecode
= NULL
;
7304 loc
->shlib_disabled
= 0;
7307 switch (owner
->type
)
7310 case bp_single_step
:
7314 case bp_longjmp_resume
:
7315 case bp_longjmp_call_dummy
:
7317 case bp_exception_resume
:
7318 case bp_step_resume
:
7319 case bp_hp_step_resume
:
7320 case bp_watchpoint_scope
:
7322 case bp_std_terminate
:
7323 case bp_shlib_event
:
7324 case bp_thread_event
:
7325 case bp_overlay_event
:
7327 case bp_longjmp_master
:
7328 case bp_std_terminate_master
:
7329 case bp_exception_master
:
7330 case bp_gnu_ifunc_resolver
:
7331 case bp_gnu_ifunc_resolver_return
:
7333 loc
->loc_type
= bp_loc_software_breakpoint
;
7334 mark_breakpoint_location_modified (loc
);
7336 case bp_hardware_breakpoint
:
7337 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7338 mark_breakpoint_location_modified (loc
);
7340 case bp_hardware_watchpoint
:
7341 case bp_read_watchpoint
:
7342 case bp_access_watchpoint
:
7343 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7348 case bp_fast_tracepoint
:
7349 case bp_static_tracepoint
:
7350 loc
->loc_type
= bp_loc_other
;
7353 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7359 /* Allocate a struct bp_location. */
7361 static struct bp_location
*
7362 allocate_bp_location (struct breakpoint
*bpt
)
7364 return bpt
->ops
->allocate_location (bpt
);
7368 free_bp_location (struct bp_location
*loc
)
7370 loc
->ops
->dtor (loc
);
7374 /* Increment reference count. */
7377 incref_bp_location (struct bp_location
*bl
)
7382 /* Decrement reference count. If the reference count reaches 0,
7383 destroy the bp_location. Sets *BLP to NULL. */
7386 decref_bp_location (struct bp_location
**blp
)
7388 gdb_assert ((*blp
)->refc
> 0);
7390 if (--(*blp
)->refc
== 0)
7391 free_bp_location (*blp
);
7395 /* Add breakpoint B at the end of the global breakpoint chain. */
7398 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7400 struct breakpoint
*b1
;
7401 struct breakpoint
*result
= b
.get ();
7403 /* Add this breakpoint to the end of the chain so that a list of
7404 breakpoints will come out in order of increasing numbers. */
7406 b1
= breakpoint_chain
;
7408 breakpoint_chain
= b
.release ();
7413 b1
->next
= b
.release ();
7419 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7422 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7423 struct gdbarch
*gdbarch
,
7425 const struct breakpoint_ops
*ops
)
7427 gdb_assert (ops
!= NULL
);
7431 b
->gdbarch
= gdbarch
;
7432 b
->language
= current_language
->la_language
;
7433 b
->input_radix
= input_radix
;
7434 b
->related_breakpoint
= b
;
7437 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7438 that has type BPTYPE and has no locations as yet. */
7440 static struct breakpoint
*
7441 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7443 const struct breakpoint_ops
*ops
)
7445 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7447 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7448 return add_to_breakpoint_chain (std::move (b
));
7451 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7452 resolutions should be made as the user specified the location explicitly
7456 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7458 gdb_assert (loc
->owner
!= NULL
);
7460 if (loc
->owner
->type
== bp_breakpoint
7461 || loc
->owner
->type
== bp_hardware_breakpoint
7462 || is_tracepoint (loc
->owner
))
7465 const char *function_name
;
7466 CORE_ADDR func_addr
;
7468 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7469 &func_addr
, NULL
, &is_gnu_ifunc
);
7471 if (is_gnu_ifunc
&& !explicit_loc
)
7473 struct breakpoint
*b
= loc
->owner
;
7475 gdb_assert (loc
->pspace
== current_program_space
);
7476 if (gnu_ifunc_resolve_name (function_name
,
7477 &loc
->requested_address
))
7479 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7480 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7481 loc
->requested_address
,
7484 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7485 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7487 /* Create only the whole new breakpoint of this type but do not
7488 mess more complicated breakpoints with multiple locations. */
7489 b
->type
= bp_gnu_ifunc_resolver
;
7490 /* Remember the resolver's address for use by the return
7492 loc
->related_address
= func_addr
;
7497 loc
->function_name
= xstrdup (function_name
);
7501 /* Attempt to determine architecture of location identified by SAL. */
7503 get_sal_arch (struct symtab_and_line sal
)
7506 return get_objfile_arch (sal
.section
->objfile
);
7508 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7513 /* Low level routine for partially initializing a breakpoint of type
7514 BPTYPE. The newly created breakpoint's address, section, source
7515 file name, and line number are provided by SAL.
7517 It is expected that the caller will complete the initialization of
7518 the newly created breakpoint struct as well as output any status
7519 information regarding the creation of a new breakpoint. */
7522 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7523 struct symtab_and_line sal
, enum bptype bptype
,
7524 const struct breakpoint_ops
*ops
)
7526 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7528 add_location_to_breakpoint (b
, &sal
);
7530 if (bptype
!= bp_catchpoint
)
7531 gdb_assert (sal
.pspace
!= NULL
);
7533 /* Store the program space that was used to set the breakpoint,
7534 except for ordinary breakpoints, which are independent of the
7536 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7537 b
->pspace
= sal
.pspace
;
7540 /* set_raw_breakpoint is a low level routine for allocating and
7541 partially initializing a breakpoint of type BPTYPE. The newly
7542 created breakpoint's address, section, source file name, and line
7543 number are provided by SAL. The newly created and partially
7544 initialized breakpoint is added to the breakpoint chain and
7545 is also returned as the value of this function.
7547 It is expected that the caller will complete the initialization of
7548 the newly created breakpoint struct as well as output any status
7549 information regarding the creation of a new breakpoint. In
7550 particular, set_raw_breakpoint does NOT set the breakpoint
7551 number! Care should be taken to not allow an error to occur
7552 prior to completing the initialization of the breakpoint. If this
7553 should happen, a bogus breakpoint will be left on the chain. */
7556 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7557 struct symtab_and_line sal
, enum bptype bptype
,
7558 const struct breakpoint_ops
*ops
)
7560 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7562 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7563 return add_to_breakpoint_chain (std::move (b
));
7566 /* Call this routine when stepping and nexting to enable a breakpoint
7567 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7568 initiated the operation. */
7571 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7573 struct breakpoint
*b
, *b_tmp
;
7574 int thread
= tp
->global_num
;
7576 /* To avoid having to rescan all objfile symbols at every step,
7577 we maintain a list of continually-inserted but always disabled
7578 longjmp "master" breakpoints. Here, we simply create momentary
7579 clones of those and enable them for the requested thread. */
7580 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7581 if (b
->pspace
== current_program_space
7582 && (b
->type
== bp_longjmp_master
7583 || b
->type
== bp_exception_master
))
7585 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7586 struct breakpoint
*clone
;
7588 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7589 after their removal. */
7590 clone
= momentary_breakpoint_from_master (b
, type
,
7591 &momentary_breakpoint_ops
, 1);
7592 clone
->thread
= thread
;
7595 tp
->initiating_frame
= frame
;
7598 /* Delete all longjmp breakpoints from THREAD. */
7600 delete_longjmp_breakpoint (int thread
)
7602 struct breakpoint
*b
, *b_tmp
;
7604 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7605 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7607 if (b
->thread
== thread
)
7608 delete_breakpoint (b
);
7613 delete_longjmp_breakpoint_at_next_stop (int thread
)
7615 struct breakpoint
*b
, *b_tmp
;
7617 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7618 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7620 if (b
->thread
== thread
)
7621 b
->disposition
= disp_del_at_next_stop
;
7625 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7626 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7627 pointer to any of them. Return NULL if this system cannot place longjmp
7631 set_longjmp_breakpoint_for_call_dummy (void)
7633 struct breakpoint
*b
, *retval
= NULL
;
7636 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7638 struct breakpoint
*new_b
;
7640 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7641 &momentary_breakpoint_ops
,
7643 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7645 /* Link NEW_B into the chain of RETVAL breakpoints. */
7647 gdb_assert (new_b
->related_breakpoint
== new_b
);
7650 new_b
->related_breakpoint
= retval
;
7651 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7652 retval
= retval
->related_breakpoint
;
7653 retval
->related_breakpoint
= new_b
;
7659 /* Verify all existing dummy frames and their associated breakpoints for
7660 TP. Remove those which can no longer be found in the current frame
7663 You should call this function only at places where it is safe to currently
7664 unwind the whole stack. Failed stack unwind would discard live dummy
7668 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7670 struct breakpoint
*b
, *b_tmp
;
7672 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7673 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7675 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7677 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7678 dummy_b
= dummy_b
->related_breakpoint
;
7679 if (dummy_b
->type
!= bp_call_dummy
7680 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7683 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7685 while (b
->related_breakpoint
!= b
)
7687 if (b_tmp
== b
->related_breakpoint
)
7688 b_tmp
= b
->related_breakpoint
->next
;
7689 delete_breakpoint (b
->related_breakpoint
);
7691 delete_breakpoint (b
);
7696 enable_overlay_breakpoints (void)
7698 struct breakpoint
*b
;
7701 if (b
->type
== bp_overlay_event
)
7703 b
->enable_state
= bp_enabled
;
7704 update_global_location_list (UGLL_MAY_INSERT
);
7705 overlay_events_enabled
= 1;
7710 disable_overlay_breakpoints (void)
7712 struct breakpoint
*b
;
7715 if (b
->type
== bp_overlay_event
)
7717 b
->enable_state
= bp_disabled
;
7718 update_global_location_list (UGLL_DONT_INSERT
);
7719 overlay_events_enabled
= 0;
7723 /* Set an active std::terminate breakpoint for each std::terminate
7724 master breakpoint. */
7726 set_std_terminate_breakpoint (void)
7728 struct breakpoint
*b
, *b_tmp
;
7730 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7731 if (b
->pspace
== current_program_space
7732 && b
->type
== bp_std_terminate_master
)
7734 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7735 &momentary_breakpoint_ops
, 1);
7739 /* Delete all the std::terminate breakpoints. */
7741 delete_std_terminate_breakpoint (void)
7743 struct breakpoint
*b
, *b_tmp
;
7745 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7746 if (b
->type
== bp_std_terminate
)
7747 delete_breakpoint (b
);
7751 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7753 struct breakpoint
*b
;
7755 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7756 &internal_breakpoint_ops
);
7758 b
->enable_state
= bp_enabled
;
7759 /* location has to be used or breakpoint_re_set will delete me. */
7760 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7762 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7767 struct lang_and_radix
7773 /* Create a breakpoint for JIT code registration and unregistration. */
7776 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7778 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7779 &internal_breakpoint_ops
);
7782 /* Remove JIT code registration and unregistration breakpoint(s). */
7785 remove_jit_event_breakpoints (void)
7787 struct breakpoint
*b
, *b_tmp
;
7789 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7790 if (b
->type
== bp_jit_event
7791 && b
->loc
->pspace
== current_program_space
)
7792 delete_breakpoint (b
);
7796 remove_solib_event_breakpoints (void)
7798 struct breakpoint
*b
, *b_tmp
;
7800 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7801 if (b
->type
== bp_shlib_event
7802 && b
->loc
->pspace
== current_program_space
)
7803 delete_breakpoint (b
);
7806 /* See breakpoint.h. */
7809 remove_solib_event_breakpoints_at_next_stop (void)
7811 struct breakpoint
*b
, *b_tmp
;
7813 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7814 if (b
->type
== bp_shlib_event
7815 && b
->loc
->pspace
== current_program_space
)
7816 b
->disposition
= disp_del_at_next_stop
;
7819 /* Helper for create_solib_event_breakpoint /
7820 create_and_insert_solib_event_breakpoint. Allows specifying which
7821 INSERT_MODE to pass through to update_global_location_list. */
7823 static struct breakpoint
*
7824 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7825 enum ugll_insert_mode insert_mode
)
7827 struct breakpoint
*b
;
7829 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7830 &internal_breakpoint_ops
);
7831 update_global_location_list_nothrow (insert_mode
);
7836 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7838 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7841 /* See breakpoint.h. */
7844 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7846 struct breakpoint
*b
;
7848 /* Explicitly tell update_global_location_list to insert
7850 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7851 if (!b
->loc
->inserted
)
7853 delete_breakpoint (b
);
7859 /* Disable any breakpoints that are on code in shared libraries. Only
7860 apply to enabled breakpoints, disabled ones can just stay disabled. */
7863 disable_breakpoints_in_shlibs (void)
7865 struct bp_location
*loc
, **locp_tmp
;
7867 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7869 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7870 struct breakpoint
*b
= loc
->owner
;
7872 /* We apply the check to all breakpoints, including disabled for
7873 those with loc->duplicate set. This is so that when breakpoint
7874 becomes enabled, or the duplicate is removed, gdb will try to
7875 insert all breakpoints. If we don't set shlib_disabled here,
7876 we'll try to insert those breakpoints and fail. */
7877 if (((b
->type
== bp_breakpoint
)
7878 || (b
->type
== bp_jit_event
)
7879 || (b
->type
== bp_hardware_breakpoint
)
7880 || (is_tracepoint (b
)))
7881 && loc
->pspace
== current_program_space
7882 && !loc
->shlib_disabled
7883 && solib_name_from_address (loc
->pspace
, loc
->address
)
7886 loc
->shlib_disabled
= 1;
7891 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7892 notification of unloaded_shlib. Only apply to enabled breakpoints,
7893 disabled ones can just stay disabled. */
7896 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7898 struct bp_location
*loc
, **locp_tmp
;
7899 int disabled_shlib_breaks
= 0;
7901 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7903 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7904 struct breakpoint
*b
= loc
->owner
;
7906 if (solib
->pspace
== loc
->pspace
7907 && !loc
->shlib_disabled
7908 && (((b
->type
== bp_breakpoint
7909 || b
->type
== bp_jit_event
7910 || b
->type
== bp_hardware_breakpoint
)
7911 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7912 || loc
->loc_type
== bp_loc_software_breakpoint
))
7913 || is_tracepoint (b
))
7914 && solib_contains_address_p (solib
, loc
->address
))
7916 loc
->shlib_disabled
= 1;
7917 /* At this point, we cannot rely on remove_breakpoint
7918 succeeding so we must mark the breakpoint as not inserted
7919 to prevent future errors occurring in remove_breakpoints. */
7922 /* This may cause duplicate notifications for the same breakpoint. */
7923 observer_notify_breakpoint_modified (b
);
7925 if (!disabled_shlib_breaks
)
7927 target_terminal_ours_for_output ();
7928 warning (_("Temporarily disabling breakpoints "
7929 "for unloaded shared library \"%s\""),
7932 disabled_shlib_breaks
= 1;
7937 /* Disable any breakpoints and tracepoints in OBJFILE upon
7938 notification of free_objfile. Only apply to enabled breakpoints,
7939 disabled ones can just stay disabled. */
7942 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7944 struct breakpoint
*b
;
7946 if (objfile
== NULL
)
7949 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7950 managed by the user with add-symbol-file/remove-symbol-file.
7951 Similarly to how breakpoints in shared libraries are handled in
7952 response to "nosharedlibrary", mark breakpoints in such modules
7953 shlib_disabled so they end up uninserted on the next global
7954 location list update. Shared libraries not loaded by the user
7955 aren't handled here -- they're already handled in
7956 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7957 solib_unloaded observer. We skip objfiles that are not
7958 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7960 if ((objfile
->flags
& OBJF_SHARED
) == 0
7961 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7966 struct bp_location
*loc
;
7967 int bp_modified
= 0;
7969 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7972 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7974 CORE_ADDR loc_addr
= loc
->address
;
7976 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7977 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7980 if (loc
->shlib_disabled
!= 0)
7983 if (objfile
->pspace
!= loc
->pspace
)
7986 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7987 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7990 if (is_addr_in_objfile (loc_addr
, objfile
))
7992 loc
->shlib_disabled
= 1;
7993 /* At this point, we don't know whether the object was
7994 unmapped from the inferior or not, so leave the
7995 inserted flag alone. We'll handle failure to
7996 uninsert quietly, in case the object was indeed
7999 mark_breakpoint_location_modified (loc
);
8006 observer_notify_breakpoint_modified (b
);
8010 /* FORK & VFORK catchpoints. */
8012 /* An instance of this type is used to represent a fork or vfork
8013 catchpoint. A breakpoint is really of this type iff its ops pointer points
8014 to CATCH_FORK_BREAKPOINT_OPS. */
8016 struct fork_catchpoint
: public breakpoint
8018 /* Process id of a child process whose forking triggered this
8019 catchpoint. This field is only valid immediately after this
8020 catchpoint has triggered. */
8021 ptid_t forked_inferior_pid
;
8024 /* Implement the "insert" breakpoint_ops method for fork
8028 insert_catch_fork (struct bp_location
*bl
)
8030 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8033 /* Implement the "remove" breakpoint_ops method for fork
8037 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8039 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8042 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8046 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8047 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8048 const struct target_waitstatus
*ws
)
8050 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8052 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8055 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8059 /* Implement the "print_it" breakpoint_ops method for fork
8062 static enum print_stop_action
8063 print_it_catch_fork (bpstat bs
)
8065 struct ui_out
*uiout
= current_uiout
;
8066 struct breakpoint
*b
= bs
->breakpoint_at
;
8067 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8069 annotate_catchpoint (b
->number
);
8070 maybe_print_thread_hit_breakpoint (uiout
);
8071 if (b
->disposition
== disp_del
)
8072 uiout
->text ("Temporary catchpoint ");
8074 uiout
->text ("Catchpoint ");
8075 if (uiout
->is_mi_like_p ())
8077 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8078 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8080 uiout
->field_int ("bkptno", b
->number
);
8081 uiout
->text (" (forked process ");
8082 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8083 uiout
->text ("), ");
8084 return PRINT_SRC_AND_LOC
;
8087 /* Implement the "print_one" breakpoint_ops method for fork
8091 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8093 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8094 struct value_print_options opts
;
8095 struct ui_out
*uiout
= current_uiout
;
8097 get_user_print_options (&opts
);
8099 /* Field 4, the address, is omitted (which makes the columns not
8100 line up too nicely with the headers, but the effect is relatively
8102 if (opts
.addressprint
)
8103 uiout
->field_skip ("addr");
8105 uiout
->text ("fork");
8106 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8108 uiout
->text (", process ");
8109 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8113 if (uiout
->is_mi_like_p ())
8114 uiout
->field_string ("catch-type", "fork");
8117 /* Implement the "print_mention" breakpoint_ops method for fork
8121 print_mention_catch_fork (struct breakpoint
*b
)
8123 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8126 /* Implement the "print_recreate" breakpoint_ops method for fork
8130 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8132 fprintf_unfiltered (fp
, "catch fork");
8133 print_recreate_thread (b
, fp
);
8136 /* The breakpoint_ops structure to be used in fork catchpoints. */
8138 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8140 /* Implement the "insert" breakpoint_ops method for vfork
8144 insert_catch_vfork (struct bp_location
*bl
)
8146 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8149 /* Implement the "remove" breakpoint_ops method for vfork
8153 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8155 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8158 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8162 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8163 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8164 const struct target_waitstatus
*ws
)
8166 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8168 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8171 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8175 /* Implement the "print_it" breakpoint_ops method for vfork
8178 static enum print_stop_action
8179 print_it_catch_vfork (bpstat bs
)
8181 struct ui_out
*uiout
= current_uiout
;
8182 struct breakpoint
*b
= bs
->breakpoint_at
;
8183 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8185 annotate_catchpoint (b
->number
);
8186 maybe_print_thread_hit_breakpoint (uiout
);
8187 if (b
->disposition
== disp_del
)
8188 uiout
->text ("Temporary catchpoint ");
8190 uiout
->text ("Catchpoint ");
8191 if (uiout
->is_mi_like_p ())
8193 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8194 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8196 uiout
->field_int ("bkptno", b
->number
);
8197 uiout
->text (" (vforked process ");
8198 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8199 uiout
->text ("), ");
8200 return PRINT_SRC_AND_LOC
;
8203 /* Implement the "print_one" breakpoint_ops method for vfork
8207 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8209 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8210 struct value_print_options opts
;
8211 struct ui_out
*uiout
= current_uiout
;
8213 get_user_print_options (&opts
);
8214 /* Field 4, the address, is omitted (which makes the columns not
8215 line up too nicely with the headers, but the effect is relatively
8217 if (opts
.addressprint
)
8218 uiout
->field_skip ("addr");
8220 uiout
->text ("vfork");
8221 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8223 uiout
->text (", process ");
8224 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8228 if (uiout
->is_mi_like_p ())
8229 uiout
->field_string ("catch-type", "vfork");
8232 /* Implement the "print_mention" breakpoint_ops method for vfork
8236 print_mention_catch_vfork (struct breakpoint
*b
)
8238 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8241 /* Implement the "print_recreate" breakpoint_ops method for vfork
8245 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8247 fprintf_unfiltered (fp
, "catch vfork");
8248 print_recreate_thread (b
, fp
);
8251 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8253 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8255 /* An instance of this type is used to represent an solib catchpoint.
8256 A breakpoint is really of this type iff its ops pointer points to
8257 CATCH_SOLIB_BREAKPOINT_OPS. */
8259 struct solib_catchpoint
: public breakpoint
8261 ~solib_catchpoint () override
;
8263 /* True for "catch load", false for "catch unload". */
8264 unsigned char is_load
;
8266 /* Regular expression to match, if any. COMPILED is only valid when
8267 REGEX is non-NULL. */
8269 std::unique_ptr
<compiled_regex
> compiled
;
8272 solib_catchpoint::~solib_catchpoint ()
8274 xfree (this->regex
);
8278 insert_catch_solib (struct bp_location
*ignore
)
8284 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8290 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8291 struct address_space
*aspace
,
8293 const struct target_waitstatus
*ws
)
8295 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8296 struct breakpoint
*other
;
8298 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8301 ALL_BREAKPOINTS (other
)
8303 struct bp_location
*other_bl
;
8305 if (other
== bl
->owner
)
8308 if (other
->type
!= bp_shlib_event
)
8311 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8314 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8316 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8325 check_status_catch_solib (struct bpstats
*bs
)
8327 struct solib_catchpoint
*self
8328 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8333 struct so_list
*iter
;
8336 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8341 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8350 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8355 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8361 bs
->print_it
= print_it_noop
;
8364 static enum print_stop_action
8365 print_it_catch_solib (bpstat bs
)
8367 struct breakpoint
*b
= bs
->breakpoint_at
;
8368 struct ui_out
*uiout
= current_uiout
;
8370 annotate_catchpoint (b
->number
);
8371 maybe_print_thread_hit_breakpoint (uiout
);
8372 if (b
->disposition
== disp_del
)
8373 uiout
->text ("Temporary catchpoint ");
8375 uiout
->text ("Catchpoint ");
8376 uiout
->field_int ("bkptno", b
->number
);
8378 if (uiout
->is_mi_like_p ())
8379 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8380 print_solib_event (1);
8381 return PRINT_SRC_AND_LOC
;
8385 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8387 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8388 struct value_print_options opts
;
8389 struct ui_out
*uiout
= current_uiout
;
8392 get_user_print_options (&opts
);
8393 /* Field 4, the address, is omitted (which makes the columns not
8394 line up too nicely with the headers, but the effect is relatively
8396 if (opts
.addressprint
)
8399 uiout
->field_skip ("addr");
8406 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8408 msg
= xstrdup (_("load of library"));
8413 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8415 msg
= xstrdup (_("unload of library"));
8417 uiout
->field_string ("what", msg
);
8420 if (uiout
->is_mi_like_p ())
8421 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8425 print_mention_catch_solib (struct breakpoint
*b
)
8427 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8429 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8430 self
->is_load
? "load" : "unload");
8434 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8436 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8438 fprintf_unfiltered (fp
, "%s %s",
8439 b
->disposition
== disp_del
? "tcatch" : "catch",
8440 self
->is_load
? "load" : "unload");
8442 fprintf_unfiltered (fp
, " %s", self
->regex
);
8443 fprintf_unfiltered (fp
, "\n");
8446 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8448 /* Shared helper function (MI and CLI) for creating and installing
8449 a shared object event catchpoint. If IS_LOAD is non-zero then
8450 the events to be caught are load events, otherwise they are
8451 unload events. If IS_TEMP is non-zero the catchpoint is a
8452 temporary one. If ENABLED is non-zero the catchpoint is
8453 created in an enabled state. */
8456 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8458 struct gdbarch
*gdbarch
= get_current_arch ();
8462 arg
= skip_spaces_const (arg
);
8464 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8468 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8469 _("Invalid regexp")));
8470 c
->regex
= xstrdup (arg
);
8473 c
->is_load
= is_load
;
8474 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8475 &catch_solib_breakpoint_ops
);
8477 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8479 install_breakpoint (0, std::move (c
), 1);
8482 /* A helper function that does all the work for "catch load" and
8486 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8487 struct cmd_list_element
*command
)
8490 const int enabled
= 1;
8492 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8494 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8498 catch_load_command_1 (char *arg
, int from_tty
,
8499 struct cmd_list_element
*command
)
8501 catch_load_or_unload (arg
, from_tty
, 1, command
);
8505 catch_unload_command_1 (char *arg
, int from_tty
,
8506 struct cmd_list_element
*command
)
8508 catch_load_or_unload (arg
, from_tty
, 0, command
);
8511 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8512 is non-zero, then make the breakpoint temporary. If COND_STRING is
8513 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8514 the breakpoint_ops structure associated to the catchpoint. */
8517 init_catchpoint (struct breakpoint
*b
,
8518 struct gdbarch
*gdbarch
, int tempflag
,
8519 const char *cond_string
,
8520 const struct breakpoint_ops
*ops
)
8522 symtab_and_line sal
;
8523 sal
.pspace
= current_program_space
;
8525 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8527 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8528 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8532 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8534 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8535 set_breakpoint_number (internal
, b
);
8536 if (is_tracepoint (b
))
8537 set_tracepoint_count (breakpoint_count
);
8540 observer_notify_breakpoint_created (b
);
8543 update_global_location_list (UGLL_MAY_INSERT
);
8547 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8548 int tempflag
, const char *cond_string
,
8549 const struct breakpoint_ops
*ops
)
8551 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8553 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8555 c
->forked_inferior_pid
= null_ptid
;
8557 install_breakpoint (0, std::move (c
), 1);
8560 /* Exec catchpoints. */
8562 /* An instance of this type is used to represent an exec catchpoint.
8563 A breakpoint is really of this type iff its ops pointer points to
8564 CATCH_EXEC_BREAKPOINT_OPS. */
8566 struct exec_catchpoint
: public breakpoint
8568 ~exec_catchpoint () override
;
8570 /* Filename of a program whose exec triggered this catchpoint.
8571 This field is only valid immediately after this catchpoint has
8573 char *exec_pathname
;
8576 /* Exec catchpoint destructor. */
8578 exec_catchpoint::~exec_catchpoint ()
8580 xfree (this->exec_pathname
);
8584 insert_catch_exec (struct bp_location
*bl
)
8586 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8590 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8592 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8596 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8597 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8598 const struct target_waitstatus
*ws
)
8600 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8602 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8605 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8609 static enum print_stop_action
8610 print_it_catch_exec (bpstat bs
)
8612 struct ui_out
*uiout
= current_uiout
;
8613 struct breakpoint
*b
= bs
->breakpoint_at
;
8614 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8616 annotate_catchpoint (b
->number
);
8617 maybe_print_thread_hit_breakpoint (uiout
);
8618 if (b
->disposition
== disp_del
)
8619 uiout
->text ("Temporary catchpoint ");
8621 uiout
->text ("Catchpoint ");
8622 if (uiout
->is_mi_like_p ())
8624 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8625 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8627 uiout
->field_int ("bkptno", b
->number
);
8628 uiout
->text (" (exec'd ");
8629 uiout
->field_string ("new-exec", c
->exec_pathname
);
8630 uiout
->text ("), ");
8632 return PRINT_SRC_AND_LOC
;
8636 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8638 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8639 struct value_print_options opts
;
8640 struct ui_out
*uiout
= current_uiout
;
8642 get_user_print_options (&opts
);
8644 /* Field 4, the address, is omitted (which makes the columns
8645 not line up too nicely with the headers, but the effect
8646 is relatively readable). */
8647 if (opts
.addressprint
)
8648 uiout
->field_skip ("addr");
8650 uiout
->text ("exec");
8651 if (c
->exec_pathname
!= NULL
)
8653 uiout
->text (", program \"");
8654 uiout
->field_string ("what", c
->exec_pathname
);
8655 uiout
->text ("\" ");
8658 if (uiout
->is_mi_like_p ())
8659 uiout
->field_string ("catch-type", "exec");
8663 print_mention_catch_exec (struct breakpoint
*b
)
8665 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8668 /* Implement the "print_recreate" breakpoint_ops method for exec
8672 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8674 fprintf_unfiltered (fp
, "catch exec");
8675 print_recreate_thread (b
, fp
);
8678 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8681 hw_breakpoint_used_count (void)
8684 struct breakpoint
*b
;
8685 struct bp_location
*bl
;
8689 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8690 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8692 /* Special types of hardware breakpoints may use more than
8694 i
+= b
->ops
->resources_needed (bl
);
8701 /* Returns the resources B would use if it were a hardware
8705 hw_watchpoint_use_count (struct breakpoint
*b
)
8708 struct bp_location
*bl
;
8710 if (!breakpoint_enabled (b
))
8713 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8715 /* Special types of hardware watchpoints may use more than
8717 i
+= b
->ops
->resources_needed (bl
);
8723 /* Returns the sum the used resources of all hardware watchpoints of
8724 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8725 the sum of the used resources of all hardware watchpoints of other
8726 types _not_ TYPE. */
8729 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8730 enum bptype type
, int *other_type_used
)
8733 struct breakpoint
*b
;
8735 *other_type_used
= 0;
8740 if (!breakpoint_enabled (b
))
8743 if (b
->type
== type
)
8744 i
+= hw_watchpoint_use_count (b
);
8745 else if (is_hardware_watchpoint (b
))
8746 *other_type_used
= 1;
8753 disable_watchpoints_before_interactive_call_start (void)
8755 struct breakpoint
*b
;
8759 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8761 b
->enable_state
= bp_call_disabled
;
8762 update_global_location_list (UGLL_DONT_INSERT
);
8768 enable_watchpoints_after_interactive_call_stop (void)
8770 struct breakpoint
*b
;
8774 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8776 b
->enable_state
= bp_enabled
;
8777 update_global_location_list (UGLL_MAY_INSERT
);
8783 disable_breakpoints_before_startup (void)
8785 current_program_space
->executing_startup
= 1;
8786 update_global_location_list (UGLL_DONT_INSERT
);
8790 enable_breakpoints_after_startup (void)
8792 current_program_space
->executing_startup
= 0;
8793 breakpoint_re_set ();
8796 /* Create a new single-step breakpoint for thread THREAD, with no
8799 static struct breakpoint
*
8800 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8802 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8804 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8805 &momentary_breakpoint_ops
);
8807 b
->disposition
= disp_donttouch
;
8808 b
->frame_id
= null_frame_id
;
8811 gdb_assert (b
->thread
!= 0);
8813 return add_to_breakpoint_chain (std::move (b
));
8816 /* Set a momentary breakpoint of type TYPE at address specified by
8817 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8821 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8822 struct frame_id frame_id
, enum bptype type
)
8824 struct breakpoint
*b
;
8826 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8828 gdb_assert (!frame_id_artificial_p (frame_id
));
8830 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8831 b
->enable_state
= bp_enabled
;
8832 b
->disposition
= disp_donttouch
;
8833 b
->frame_id
= frame_id
;
8835 /* If we're debugging a multi-threaded program, then we want
8836 momentary breakpoints to be active in only a single thread of
8838 if (in_thread_list (inferior_ptid
))
8839 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8841 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8846 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8847 The new breakpoint will have type TYPE, use OPS as its
8848 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8850 static struct breakpoint
*
8851 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8853 const struct breakpoint_ops
*ops
,
8856 struct breakpoint
*copy
;
8858 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8859 copy
->loc
= allocate_bp_location (copy
);
8860 set_breakpoint_location_function (copy
->loc
, 1);
8862 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8863 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8864 copy
->loc
->address
= orig
->loc
->address
;
8865 copy
->loc
->section
= orig
->loc
->section
;
8866 copy
->loc
->pspace
= orig
->loc
->pspace
;
8867 copy
->loc
->probe
= orig
->loc
->probe
;
8868 copy
->loc
->line_number
= orig
->loc
->line_number
;
8869 copy
->loc
->symtab
= orig
->loc
->symtab
;
8870 copy
->loc
->enabled
= loc_enabled
;
8871 copy
->frame_id
= orig
->frame_id
;
8872 copy
->thread
= orig
->thread
;
8873 copy
->pspace
= orig
->pspace
;
8875 copy
->enable_state
= bp_enabled
;
8876 copy
->disposition
= disp_donttouch
;
8877 copy
->number
= internal_breakpoint_number
--;
8879 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8883 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8887 clone_momentary_breakpoint (struct breakpoint
*orig
)
8889 /* If there's nothing to clone, then return nothing. */
8893 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8897 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8900 struct symtab_and_line sal
;
8902 sal
= find_pc_line (pc
, 0);
8904 sal
.section
= find_pc_overlay (pc
);
8905 sal
.explicit_pc
= 1;
8907 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8911 /* Tell the user we have just set a breakpoint B. */
8914 mention (struct breakpoint
*b
)
8916 b
->ops
->print_mention (b
);
8917 if (current_uiout
->is_mi_like_p ())
8919 printf_filtered ("\n");
8923 static int bp_loc_is_permanent (struct bp_location
*loc
);
8925 static struct bp_location
*
8926 add_location_to_breakpoint (struct breakpoint
*b
,
8927 const struct symtab_and_line
*sal
)
8929 struct bp_location
*loc
, **tmp
;
8930 CORE_ADDR adjusted_address
;
8931 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8933 if (loc_gdbarch
== NULL
)
8934 loc_gdbarch
= b
->gdbarch
;
8936 /* Adjust the breakpoint's address prior to allocating a location.
8937 Once we call allocate_bp_location(), that mostly uninitialized
8938 location will be placed on the location chain. Adjustment of the
8939 breakpoint may cause target_read_memory() to be called and we do
8940 not want its scan of the location chain to find a breakpoint and
8941 location that's only been partially initialized. */
8942 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8945 /* Sort the locations by their ADDRESS. */
8946 loc
= allocate_bp_location (b
);
8947 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8948 tmp
= &((*tmp
)->next
))
8953 loc
->requested_address
= sal
->pc
;
8954 loc
->address
= adjusted_address
;
8955 loc
->pspace
= sal
->pspace
;
8956 loc
->probe
.probe
= sal
->probe
;
8957 loc
->probe
.objfile
= sal
->objfile
;
8958 gdb_assert (loc
->pspace
!= NULL
);
8959 loc
->section
= sal
->section
;
8960 loc
->gdbarch
= loc_gdbarch
;
8961 loc
->line_number
= sal
->line
;
8962 loc
->symtab
= sal
->symtab
;
8964 set_breakpoint_location_function (loc
,
8965 sal
->explicit_pc
|| sal
->explicit_line
);
8967 /* While by definition, permanent breakpoints are already present in the
8968 code, we don't mark the location as inserted. Normally one would expect
8969 that GDB could rely on that breakpoint instruction to stop the program,
8970 thus removing the need to insert its own breakpoint, except that executing
8971 the breakpoint instruction can kill the target instead of reporting a
8972 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8973 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8974 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8975 breakpoint be inserted normally results in QEMU knowing about the GDB
8976 breakpoint, and thus trap before the breakpoint instruction is executed.
8977 (If GDB later needs to continue execution past the permanent breakpoint,
8978 it manually increments the PC, thus avoiding executing the breakpoint
8980 if (bp_loc_is_permanent (loc
))
8987 /* See breakpoint.h. */
8990 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8994 const gdb_byte
*bpoint
;
8995 gdb_byte
*target_mem
;
8996 struct cleanup
*cleanup
;
9000 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9002 /* Software breakpoints unsupported? */
9006 target_mem
= (gdb_byte
*) alloca (len
);
9008 /* Enable the automatic memory restoration from breakpoints while
9009 we read the memory. Otherwise we could say about our temporary
9010 breakpoints they are permanent. */
9011 cleanup
= make_show_memory_breakpoints_cleanup (0);
9013 if (target_read_memory (address
, target_mem
, len
) == 0
9014 && memcmp (target_mem
, bpoint
, len
) == 0)
9017 do_cleanups (cleanup
);
9022 /* Return 1 if LOC is pointing to a permanent breakpoint,
9023 return 0 otherwise. */
9026 bp_loc_is_permanent (struct bp_location
*loc
)
9028 gdb_assert (loc
!= NULL
);
9030 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9031 attempt to read from the addresses the locations of these breakpoint types
9032 point to. program_breakpoint_here_p, below, will attempt to read
9034 if (!breakpoint_address_is_meaningful (loc
->owner
))
9037 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9038 switch_to_program_space_and_thread (loc
->pspace
);
9039 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9042 /* Build a command list for the dprintf corresponding to the current
9043 settings of the dprintf style options. */
9046 update_dprintf_command_list (struct breakpoint
*b
)
9048 char *dprintf_args
= b
->extra_string
;
9049 char *printf_line
= NULL
;
9054 dprintf_args
= skip_spaces (dprintf_args
);
9056 /* Allow a comma, as it may have terminated a location, but don't
9058 if (*dprintf_args
== ',')
9060 dprintf_args
= skip_spaces (dprintf_args
);
9062 if (*dprintf_args
!= '"')
9063 error (_("Bad format string, missing '\"'."));
9065 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9066 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9067 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9069 if (!dprintf_function
)
9070 error (_("No function supplied for dprintf call"));
9072 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9073 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9078 printf_line
= xstrprintf ("call (void) %s (%s)",
9082 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9084 if (target_can_run_breakpoint_commands ())
9085 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9088 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9089 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9093 internal_error (__FILE__
, __LINE__
,
9094 _("Invalid dprintf style."));
9096 gdb_assert (printf_line
!= NULL
);
9097 /* Manufacture a printf sequence. */
9099 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9101 printf_cmd_line
->control_type
= simple_control
;
9102 printf_cmd_line
->body_count
= 0;
9103 printf_cmd_line
->body_list
= NULL
;
9104 printf_cmd_line
->next
= NULL
;
9105 printf_cmd_line
->line
= printf_line
;
9107 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9111 /* Update all dprintf commands, making their command lists reflect
9112 current style settings. */
9115 update_dprintf_commands (char *args
, int from_tty
,
9116 struct cmd_list_element
*c
)
9118 struct breakpoint
*b
;
9122 if (b
->type
== bp_dprintf
)
9123 update_dprintf_command_list (b
);
9127 /* Create a breakpoint with SAL as location. Use LOCATION
9128 as a description of the location, and COND_STRING
9129 as condition expression. If LOCATION is NULL then create an
9130 "address location" from the address in the SAL. */
9133 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9134 gdb::array_view
<const symtab_and_line
> sals
,
9135 event_location_up
&&location
,
9136 gdb::unique_xmalloc_ptr
<char> filter
,
9137 gdb::unique_xmalloc_ptr
<char> cond_string
,
9138 gdb::unique_xmalloc_ptr
<char> extra_string
,
9139 enum bptype type
, enum bpdisp disposition
,
9140 int thread
, int task
, int ignore_count
,
9141 const struct breakpoint_ops
*ops
, int from_tty
,
9142 int enabled
, int internal
, unsigned flags
,
9143 int display_canonical
)
9147 if (type
== bp_hardware_breakpoint
)
9149 int target_resources_ok
;
9151 i
= hw_breakpoint_used_count ();
9152 target_resources_ok
=
9153 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9155 if (target_resources_ok
== 0)
9156 error (_("No hardware breakpoint support in the target."));
9157 else if (target_resources_ok
< 0)
9158 error (_("Hardware breakpoints used exceeds limit."));
9161 gdb_assert (!sals
.empty ());
9163 for (const auto &sal
: sals
)
9165 struct bp_location
*loc
;
9169 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9171 loc_gdbarch
= gdbarch
;
9173 describe_other_breakpoints (loc_gdbarch
,
9174 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9177 if (&sal
== &sals
[0])
9179 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9183 b
->cond_string
= cond_string
.release ();
9184 b
->extra_string
= extra_string
.release ();
9185 b
->ignore_count
= ignore_count
;
9186 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9187 b
->disposition
= disposition
;
9189 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9190 b
->loc
->inserted
= 1;
9192 if (type
== bp_static_tracepoint
)
9194 struct tracepoint
*t
= (struct tracepoint
*) b
;
9195 struct static_tracepoint_marker marker
;
9197 if (strace_marker_p (b
))
9199 /* We already know the marker exists, otherwise, we
9200 wouldn't see a sal for it. */
9202 = &event_location_to_string (b
->location
.get ())[3];
9206 p
= skip_spaces_const (p
);
9208 endp
= skip_to_space_const (p
);
9210 marker_str
= savestring (p
, endp
- p
);
9211 t
->static_trace_marker_id
= marker_str
;
9213 printf_filtered (_("Probed static tracepoint "
9215 t
->static_trace_marker_id
);
9217 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9219 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9220 release_static_tracepoint_marker (&marker
);
9222 printf_filtered (_("Probed static tracepoint "
9224 t
->static_trace_marker_id
);
9227 warning (_("Couldn't determine the static "
9228 "tracepoint marker to probe"));
9235 loc
= add_location_to_breakpoint (b
, &sal
);
9236 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9242 const char *arg
= b
->cond_string
;
9244 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9245 block_for_pc (loc
->address
), 0);
9247 error (_("Garbage '%s' follows condition"), arg
);
9250 /* Dynamic printf requires and uses additional arguments on the
9251 command line, otherwise it's an error. */
9252 if (type
== bp_dprintf
)
9254 if (b
->extra_string
)
9255 update_dprintf_command_list (b
);
9257 error (_("Format string required"));
9259 else if (b
->extra_string
)
9260 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9263 b
->display_canonical
= display_canonical
;
9264 if (location
!= NULL
)
9265 b
->location
= std::move (location
);
9267 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9268 b
->filter
= filter
.release ();
9272 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9273 gdb::array_view
<const symtab_and_line
> sals
,
9274 event_location_up
&&location
,
9275 gdb::unique_xmalloc_ptr
<char> filter
,
9276 gdb::unique_xmalloc_ptr
<char> cond_string
,
9277 gdb::unique_xmalloc_ptr
<char> extra_string
,
9278 enum bptype type
, enum bpdisp disposition
,
9279 int thread
, int task
, int ignore_count
,
9280 const struct breakpoint_ops
*ops
, int from_tty
,
9281 int enabled
, int internal
, unsigned flags
,
9282 int display_canonical
)
9284 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9286 init_breakpoint_sal (b
.get (), gdbarch
,
9287 sals
, std::move (location
),
9289 std::move (cond_string
),
9290 std::move (extra_string
),
9292 thread
, task
, ignore_count
,
9294 enabled
, internal
, flags
,
9297 install_breakpoint (internal
, std::move (b
), 0);
9300 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9301 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9302 value. COND_STRING, if not NULL, specified the condition to be
9303 used for all breakpoints. Essentially the only case where
9304 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9305 function. In that case, it's still not possible to specify
9306 separate conditions for different overloaded functions, so
9307 we take just a single condition string.
9309 NOTE: If the function succeeds, the caller is expected to cleanup
9310 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9311 array contents). If the function fails (error() is called), the
9312 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9313 COND and SALS arrays and each of those arrays contents. */
9316 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9317 struct linespec_result
*canonical
,
9318 gdb::unique_xmalloc_ptr
<char> cond_string
,
9319 gdb::unique_xmalloc_ptr
<char> extra_string
,
9320 enum bptype type
, enum bpdisp disposition
,
9321 int thread
, int task
, int ignore_count
,
9322 const struct breakpoint_ops
*ops
, int from_tty
,
9323 int enabled
, int internal
, unsigned flags
)
9325 if (canonical
->pre_expanded
)
9326 gdb_assert (canonical
->lsals
.size () == 1);
9328 for (const auto &lsal
: canonical
->lsals
)
9330 /* Note that 'location' can be NULL in the case of a plain
9331 'break', without arguments. */
9332 event_location_up location
9333 = (canonical
->location
!= NULL
9334 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9335 gdb::unique_xmalloc_ptr
<char> filter_string
9336 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9338 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9339 std::move (location
),
9340 std::move (filter_string
),
9341 std::move (cond_string
),
9342 std::move (extra_string
),
9344 thread
, task
, ignore_count
, ops
,
9345 from_tty
, enabled
, internal
, flags
,
9346 canonical
->special_display
);
9350 /* Parse LOCATION which is assumed to be a SAL specification possibly
9351 followed by conditionals. On return, SALS contains an array of SAL
9352 addresses found. LOCATION points to the end of the SAL (for
9353 linespec locations).
9355 The array and the line spec strings are allocated on the heap, it is
9356 the caller's responsibility to free them. */
9359 parse_breakpoint_sals (const struct event_location
*location
,
9360 struct linespec_result
*canonical
)
9362 struct symtab_and_line cursal
;
9364 if (event_location_type (location
) == LINESPEC_LOCATION
)
9366 const char *address
= get_linespec_location (location
);
9368 if (address
== NULL
)
9370 /* The last displayed codepoint, if it's valid, is our default
9371 breakpoint address. */
9372 if (last_displayed_sal_is_valid ())
9374 /* Set sal's pspace, pc, symtab, and line to the values
9375 corresponding to the last call to print_frame_info.
9376 Be sure to reinitialize LINE with NOTCURRENT == 0
9377 as the breakpoint line number is inappropriate otherwise.
9378 find_pc_line would adjust PC, re-set it back. */
9379 symtab_and_line sal
= get_last_displayed_sal ();
9380 CORE_ADDR pc
= sal
.pc
;
9382 sal
= find_pc_line (pc
, 0);
9384 /* "break" without arguments is equivalent to "break *PC"
9385 where PC is the last displayed codepoint's address. So
9386 make sure to set sal.explicit_pc to prevent GDB from
9387 trying to expand the list of sals to include all other
9388 instances with the same symtab and line. */
9390 sal
.explicit_pc
= 1;
9392 struct linespec_sals lsal
;
9394 lsal
.canonical
= NULL
;
9396 canonical
->lsals
.push_back (std::move (lsal
));
9400 error (_("No default breakpoint address now."));
9404 /* Force almost all breakpoints to be in terms of the
9405 current_source_symtab (which is decode_line_1's default).
9406 This should produce the results we want almost all of the
9407 time while leaving default_breakpoint_* alone.
9409 ObjC: However, don't match an Objective-C method name which
9410 may have a '+' or '-' succeeded by a '['. */
9411 cursal
= get_current_source_symtab_and_line ();
9412 if (last_displayed_sal_is_valid ())
9414 const char *address
= NULL
;
9416 if (event_location_type (location
) == LINESPEC_LOCATION
)
9417 address
= get_linespec_location (location
);
9421 && strchr ("+-", address
[0]) != NULL
9422 && address
[1] != '['))
9424 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9425 get_last_displayed_symtab (),
9426 get_last_displayed_line (),
9427 canonical
, NULL
, NULL
);
9432 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9433 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9437 /* Convert each SAL into a real PC. Verify that the PC can be
9438 inserted as a breakpoint. If it can't throw an error. */
9441 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9443 for (auto &sal
: sals
)
9444 resolve_sal_pc (&sal
);
9447 /* Fast tracepoints may have restrictions on valid locations. For
9448 instance, a fast tracepoint using a jump instead of a trap will
9449 likely have to overwrite more bytes than a trap would, and so can
9450 only be placed where the instruction is longer than the jump, or a
9451 multi-instruction sequence does not have a jump into the middle of
9455 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9456 gdb::array_view
<const symtab_and_line
> sals
)
9460 struct cleanup
*old_chain
;
9462 for (const auto &sal
: sals
)
9464 struct gdbarch
*sarch
;
9466 sarch
= get_sal_arch (sal
);
9467 /* We fall back to GDBARCH if there is no architecture
9468 associated with SAL. */
9471 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9472 old_chain
= make_cleanup (xfree
, msg
);
9475 error (_("May not have a fast tracepoint at %s%s"),
9476 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9478 do_cleanups (old_chain
);
9482 /* Given TOK, a string specification of condition and thread, as
9483 accepted by the 'break' command, extract the condition
9484 string and thread number and set *COND_STRING and *THREAD.
9485 PC identifies the context at which the condition should be parsed.
9486 If no condition is found, *COND_STRING is set to NULL.
9487 If no thread is found, *THREAD is set to -1. */
9490 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9491 char **cond_string
, int *thread
, int *task
,
9494 *cond_string
= NULL
;
9501 const char *end_tok
;
9503 const char *cond_start
= NULL
;
9504 const char *cond_end
= NULL
;
9506 tok
= skip_spaces_const (tok
);
9508 if ((*tok
== '"' || *tok
== ',') && rest
)
9510 *rest
= savestring (tok
, strlen (tok
));
9514 end_tok
= skip_to_space_const (tok
);
9516 toklen
= end_tok
- tok
;
9518 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9520 tok
= cond_start
= end_tok
+ 1;
9521 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9523 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9525 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9528 struct thread_info
*thr
;
9531 thr
= parse_thread_id (tok
, &tmptok
);
9533 error (_("Junk after thread keyword."));
9534 *thread
= thr
->global_num
;
9537 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9542 *task
= strtol (tok
, &tmptok
, 0);
9544 error (_("Junk after task keyword."));
9545 if (!valid_task_id (*task
))
9546 error (_("Unknown task %d."), *task
);
9551 *rest
= savestring (tok
, strlen (tok
));
9555 error (_("Junk at end of arguments."));
9559 /* Decode a static tracepoint marker spec. */
9561 static std::vector
<symtab_and_line
>
9562 decode_static_tracepoint_spec (const char **arg_p
)
9564 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9565 struct cleanup
*old_chain
;
9566 const char *p
= &(*arg_p
)[3];
9571 p
= skip_spaces_const (p
);
9573 endp
= skip_to_space_const (p
);
9575 marker_str
= savestring (p
, endp
- p
);
9576 old_chain
= make_cleanup (xfree
, marker_str
);
9578 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9579 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9580 error (_("No known static tracepoint marker named %s"), marker_str
);
9582 std::vector
<symtab_and_line
> sals
;
9583 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9585 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9587 struct static_tracepoint_marker
*marker
;
9589 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9591 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9592 sal
.pc
= marker
->address
;
9593 sals
.push_back (sal
);
9595 release_static_tracepoint_marker (marker
);
9598 do_cleanups (old_chain
);
9604 /* See breakpoint.h. */
9607 create_breakpoint (struct gdbarch
*gdbarch
,
9608 const struct event_location
*location
,
9609 const char *cond_string
,
9610 int thread
, const char *extra_string
,
9612 int tempflag
, enum bptype type_wanted
,
9614 enum auto_boolean pending_break_support
,
9615 const struct breakpoint_ops
*ops
,
9616 int from_tty
, int enabled
, int internal
,
9619 struct linespec_result canonical
;
9620 struct cleanup
*bkpt_chain
= NULL
;
9623 int prev_bkpt_count
= breakpoint_count
;
9625 gdb_assert (ops
!= NULL
);
9627 /* If extra_string isn't useful, set it to NULL. */
9628 if (extra_string
!= NULL
&& *extra_string
== '\0')
9629 extra_string
= NULL
;
9633 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9635 CATCH (e
, RETURN_MASK_ERROR
)
9637 /* If caller is interested in rc value from parse, set
9639 if (e
.error
== NOT_FOUND_ERROR
)
9641 /* If pending breakpoint support is turned off, throw
9644 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9645 throw_exception (e
);
9647 exception_print (gdb_stderr
, e
);
9649 /* If pending breakpoint support is auto query and the user
9650 selects no, then simply return the error code. */
9651 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9652 && !nquery (_("Make %s pending on future shared library load? "),
9653 bptype_string (type_wanted
)))
9656 /* At this point, either the user was queried about setting
9657 a pending breakpoint and selected yes, or pending
9658 breakpoint behavior is on and thus a pending breakpoint
9659 is defaulted on behalf of the user. */
9663 throw_exception (e
);
9667 if (!pending
&& canonical
.lsals
.empty ())
9670 /* ----------------------------- SNIP -----------------------------
9671 Anything added to the cleanup chain beyond this point is assumed
9672 to be part of a breakpoint. If the breakpoint create succeeds
9673 then the memory is not reclaimed. */
9674 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9676 /* Resolve all line numbers to PC's and verify that the addresses
9677 are ok for the target. */
9680 for (auto &lsal
: canonical
.lsals
)
9681 breakpoint_sals_to_pc (lsal
.sals
);
9684 /* Fast tracepoints may have additional restrictions on location. */
9685 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9687 for (const auto &lsal
: canonical
.lsals
)
9688 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9691 /* Verify that condition can be parsed, before setting any
9692 breakpoints. Allocate a separate condition expression for each
9696 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9697 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9704 const linespec_sals
&lsal
= canonical
.lsals
[0];
9706 /* Here we only parse 'arg' to separate condition
9707 from thread number, so parsing in context of first
9708 sal is OK. When setting the breakpoint we'll
9709 re-parse it in context of each sal. */
9711 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9712 &cond
, &thread
, &task
, &rest
);
9713 cond_string_copy
.reset (cond
);
9714 extra_string_copy
.reset (rest
);
9718 if (type_wanted
!= bp_dprintf
9719 && extra_string
!= NULL
&& *extra_string
!= '\0')
9720 error (_("Garbage '%s' at end of location"), extra_string
);
9722 /* Create a private copy of condition string. */
9724 cond_string_copy
.reset (xstrdup (cond_string
));
9725 /* Create a private copy of any extra string. */
9727 extra_string_copy
.reset (xstrdup (extra_string
));
9730 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9731 std::move (cond_string_copy
),
9732 std::move (extra_string_copy
),
9734 tempflag
? disp_del
: disp_donttouch
,
9735 thread
, task
, ignore_count
, ops
,
9736 from_tty
, enabled
, internal
, flags
);
9740 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9742 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9743 b
->location
= copy_event_location (location
);
9746 b
->cond_string
= NULL
;
9749 /* Create a private copy of condition string. */
9750 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9754 /* Create a private copy of any extra string. */
9755 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9756 b
->ignore_count
= ignore_count
;
9757 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9758 b
->condition_not_parsed
= 1;
9759 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9760 if ((type_wanted
!= bp_breakpoint
9761 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9762 b
->pspace
= current_program_space
;
9764 install_breakpoint (internal
, std::move (b
), 0);
9767 if (canonical
.lsals
.size () > 1)
9769 warning (_("Multiple breakpoints were set.\nUse the "
9770 "\"delete\" command to delete unwanted breakpoints."));
9771 prev_breakpoint_count
= prev_bkpt_count
;
9774 /* That's it. Discard the cleanups for data inserted into the
9776 discard_cleanups (bkpt_chain
);
9778 /* error call may happen here - have BKPT_CHAIN already discarded. */
9779 update_global_location_list (UGLL_MAY_INSERT
);
9784 /* Set a breakpoint.
9785 ARG is a string describing breakpoint address,
9786 condition, and thread.
9787 FLAG specifies if a breakpoint is hardware on,
9788 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9792 break_command_1 (char *arg
, int flag
, int from_tty
)
9794 int tempflag
= flag
& BP_TEMPFLAG
;
9795 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9796 ? bp_hardware_breakpoint
9798 struct breakpoint_ops
*ops
;
9800 event_location_up location
= string_to_event_location (&arg
, current_language
);
9802 /* Matching breakpoints on probes. */
9803 if (location
!= NULL
9804 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9805 ops
= &bkpt_probe_breakpoint_ops
;
9807 ops
= &bkpt_breakpoint_ops
;
9809 create_breakpoint (get_current_arch (),
9811 NULL
, 0, arg
, 1 /* parse arg */,
9812 tempflag
, type_wanted
,
9813 0 /* Ignore count */,
9814 pending_break_support
,
9822 /* Helper function for break_command_1 and disassemble_command. */
9825 resolve_sal_pc (struct symtab_and_line
*sal
)
9829 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9831 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9832 error (_("No line %d in file \"%s\"."),
9833 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9836 /* If this SAL corresponds to a breakpoint inserted using a line
9837 number, then skip the function prologue if necessary. */
9838 if (sal
->explicit_line
)
9839 skip_prologue_sal (sal
);
9842 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9844 const struct blockvector
*bv
;
9845 const struct block
*b
;
9848 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9849 SYMTAB_COMPUNIT (sal
->symtab
));
9852 sym
= block_linkage_function (b
);
9855 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9856 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9861 /* It really is worthwhile to have the section, so we'll
9862 just have to look harder. This case can be executed
9863 if we have line numbers but no functions (as can
9864 happen in assembly source). */
9866 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9867 switch_to_program_space_and_thread (sal
->pspace
);
9869 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9871 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9878 break_command (char *arg
, int from_tty
)
9880 break_command_1 (arg
, 0, from_tty
);
9884 tbreak_command (char *arg
, int from_tty
)
9886 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9890 hbreak_command (char *arg
, int from_tty
)
9892 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9896 thbreak_command (char *arg
, int from_tty
)
9898 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9902 stop_command (char *arg
, int from_tty
)
9904 printf_filtered (_("Specify the type of breakpoint to set.\n\
9905 Usage: stop in <function | address>\n\
9906 stop at <line>\n"));
9910 stopin_command (char *arg
, int from_tty
)
9914 if (arg
== (char *) NULL
)
9916 else if (*arg
!= '*')
9921 /* Look for a ':'. If this is a line number specification, then
9922 say it is bad, otherwise, it should be an address or
9923 function/method name. */
9924 while (*argptr
&& !hasColon
)
9926 hasColon
= (*argptr
== ':');
9931 badInput
= (*argptr
!= ':'); /* Not a class::method */
9933 badInput
= isdigit (*arg
); /* a simple line number */
9937 printf_filtered (_("Usage: stop in <function | address>\n"));
9939 break_command_1 (arg
, 0, from_tty
);
9943 stopat_command (char *arg
, int from_tty
)
9947 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9954 /* Look for a ':'. If there is a '::' then get out, otherwise
9955 it is probably a line number. */
9956 while (*argptr
&& !hasColon
)
9958 hasColon
= (*argptr
== ':');
9963 badInput
= (*argptr
== ':'); /* we have class::method */
9965 badInput
= !isdigit (*arg
); /* not a line number */
9969 printf_filtered (_("Usage: stop at <line>\n"));
9971 break_command_1 (arg
, 0, from_tty
);
9974 /* The dynamic printf command is mostly like a regular breakpoint, but
9975 with a prewired command list consisting of a single output command,
9976 built from extra arguments supplied on the dprintf command
9980 dprintf_command (char *arg
, int from_tty
)
9982 event_location_up location
= string_to_event_location (&arg
, current_language
);
9984 /* If non-NULL, ARG should have been advanced past the location;
9985 the next character must be ','. */
9988 if (arg
[0] != ',' || arg
[1] == '\0')
9989 error (_("Format string required"));
9992 /* Skip the comma. */
9997 create_breakpoint (get_current_arch (),
9999 NULL
, 0, arg
, 1 /* parse arg */,
10001 0 /* Ignore count */,
10002 pending_break_support
,
10003 &dprintf_breakpoint_ops
,
10011 agent_printf_command (char *arg
, int from_tty
)
10013 error (_("May only run agent-printf on the target"));
10016 /* Implement the "breakpoint_hit" breakpoint_ops method for
10017 ranged breakpoints. */
10020 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10021 struct address_space
*aspace
,
10023 const struct target_waitstatus
*ws
)
10025 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10026 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10029 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10030 bl
->length
, aspace
, bp_addr
);
10033 /* Implement the "resources_needed" breakpoint_ops method for
10034 ranged breakpoints. */
10037 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10039 return target_ranged_break_num_registers ();
10042 /* Implement the "print_it" breakpoint_ops method for
10043 ranged breakpoints. */
10045 static enum print_stop_action
10046 print_it_ranged_breakpoint (bpstat bs
)
10048 struct breakpoint
*b
= bs
->breakpoint_at
;
10049 struct bp_location
*bl
= b
->loc
;
10050 struct ui_out
*uiout
= current_uiout
;
10052 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10054 /* Ranged breakpoints have only one location. */
10055 gdb_assert (bl
&& bl
->next
== NULL
);
10057 annotate_breakpoint (b
->number
);
10059 maybe_print_thread_hit_breakpoint (uiout
);
10061 if (b
->disposition
== disp_del
)
10062 uiout
->text ("Temporary ranged breakpoint ");
10064 uiout
->text ("Ranged breakpoint ");
10065 if (uiout
->is_mi_like_p ())
10067 uiout
->field_string ("reason",
10068 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10069 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10071 uiout
->field_int ("bkptno", b
->number
);
10072 uiout
->text (", ");
10074 return PRINT_SRC_AND_LOC
;
10077 /* Implement the "print_one" breakpoint_ops method for
10078 ranged breakpoints. */
10081 print_one_ranged_breakpoint (struct breakpoint
*b
,
10082 struct bp_location
**last_loc
)
10084 struct bp_location
*bl
= b
->loc
;
10085 struct value_print_options opts
;
10086 struct ui_out
*uiout
= current_uiout
;
10088 /* Ranged breakpoints have only one location. */
10089 gdb_assert (bl
&& bl
->next
== NULL
);
10091 get_user_print_options (&opts
);
10093 if (opts
.addressprint
)
10094 /* We don't print the address range here, it will be printed later
10095 by print_one_detail_ranged_breakpoint. */
10096 uiout
->field_skip ("addr");
10097 annotate_field (5);
10098 print_breakpoint_location (b
, bl
);
10102 /* Implement the "print_one_detail" breakpoint_ops method for
10103 ranged breakpoints. */
10106 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10107 struct ui_out
*uiout
)
10109 CORE_ADDR address_start
, address_end
;
10110 struct bp_location
*bl
= b
->loc
;
10115 address_start
= bl
->address
;
10116 address_end
= address_start
+ bl
->length
- 1;
10118 uiout
->text ("\taddress range: ");
10119 stb
.printf ("[%s, %s]",
10120 print_core_address (bl
->gdbarch
, address_start
),
10121 print_core_address (bl
->gdbarch
, address_end
));
10122 uiout
->field_stream ("addr", stb
);
10123 uiout
->text ("\n");
10126 /* Implement the "print_mention" breakpoint_ops method for
10127 ranged breakpoints. */
10130 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10132 struct bp_location
*bl
= b
->loc
;
10133 struct ui_out
*uiout
= current_uiout
;
10136 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10138 if (uiout
->is_mi_like_p ())
10141 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10142 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10143 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10146 /* Implement the "print_recreate" breakpoint_ops method for
10147 ranged breakpoints. */
10150 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10152 fprintf_unfiltered (fp
, "break-range %s, %s",
10153 event_location_to_string (b
->location
.get ()),
10154 event_location_to_string (b
->location_range_end
.get ()));
10155 print_recreate_thread (b
, fp
);
10158 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10160 static struct breakpoint_ops ranged_breakpoint_ops
;
10162 /* Find the address where the end of the breakpoint range should be
10163 placed, given the SAL of the end of the range. This is so that if
10164 the user provides a line number, the end of the range is set to the
10165 last instruction of the given line. */
10168 find_breakpoint_range_end (struct symtab_and_line sal
)
10172 /* If the user provided a PC value, use it. Otherwise,
10173 find the address of the end of the given location. */
10174 if (sal
.explicit_pc
)
10181 ret
= find_line_pc_range (sal
, &start
, &end
);
10183 error (_("Could not find location of the end of the range."));
10185 /* find_line_pc_range returns the start of the next line. */
10192 /* Implement the "break-range" CLI command. */
10195 break_range_command (char *arg
, int from_tty
)
10197 char *arg_start
, *addr_string_start
;
10198 struct linespec_result canonical_start
, canonical_end
;
10199 int bp_count
, can_use_bp
, length
;
10201 struct breakpoint
*b
;
10202 struct cleanup
*cleanup_bkpt
;
10204 /* We don't support software ranged breakpoints. */
10205 if (target_ranged_break_num_registers () < 0)
10206 error (_("This target does not support hardware ranged breakpoints."));
10208 bp_count
= hw_breakpoint_used_count ();
10209 bp_count
+= target_ranged_break_num_registers ();
10210 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10212 if (can_use_bp
< 0)
10213 error (_("Hardware breakpoints used exceeds limit."));
10215 arg
= skip_spaces (arg
);
10216 if (arg
== NULL
|| arg
[0] == '\0')
10217 error(_("No address range specified."));
10220 event_location_up start_location
= string_to_event_location (&arg
,
10222 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10225 error (_("Too few arguments."));
10226 else if (canonical_start
.lsals
.empty ())
10227 error (_("Could not find location of the beginning of the range."));
10229 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10231 if (canonical_start
.lsals
.size () > 1
10232 || lsal_start
.sals
.size () != 1)
10233 error (_("Cannot create a ranged breakpoint with multiple locations."));
10235 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10236 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10237 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10239 arg
++; /* Skip the comma. */
10240 arg
= skip_spaces (arg
);
10242 /* Parse the end location. */
10246 /* We call decode_line_full directly here instead of using
10247 parse_breakpoint_sals because we need to specify the start location's
10248 symtab and line as the default symtab and line for the end of the
10249 range. This makes it possible to have ranges like "foo.c:27, +14",
10250 where +14 means 14 lines from the start location. */
10251 event_location_up end_location
= string_to_event_location (&arg
,
10253 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10254 sal_start
.symtab
, sal_start
.line
,
10255 &canonical_end
, NULL
, NULL
);
10257 if (canonical_end
.lsals
.empty ())
10258 error (_("Could not find location of the end of the range."));
10260 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10261 if (canonical_end
.lsals
.size () > 1
10262 || lsal_end
.sals
.size () != 1)
10263 error (_("Cannot create a ranged breakpoint with multiple locations."));
10265 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10267 end
= find_breakpoint_range_end (sal_end
);
10268 if (sal_start
.pc
> end
)
10269 error (_("Invalid address range, end precedes start."));
10271 length
= end
- sal_start
.pc
+ 1;
10273 /* Length overflowed. */
10274 error (_("Address range too large."));
10275 else if (length
== 1)
10277 /* This range is simple enough to be handled by
10278 the `hbreak' command. */
10279 hbreak_command (addr_string_start
, 1);
10281 do_cleanups (cleanup_bkpt
);
10286 /* Now set up the breakpoint. */
10287 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10288 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10289 set_breakpoint_count (breakpoint_count
+ 1);
10290 b
->number
= breakpoint_count
;
10291 b
->disposition
= disp_donttouch
;
10292 b
->location
= std::move (start_location
);
10293 b
->location_range_end
= std::move (end_location
);
10294 b
->loc
->length
= length
;
10296 do_cleanups (cleanup_bkpt
);
10299 observer_notify_breakpoint_created (b
);
10300 update_global_location_list (UGLL_MAY_INSERT
);
10303 /* Return non-zero if EXP is verified as constant. Returned zero
10304 means EXP is variable. Also the constant detection may fail for
10305 some constant expressions and in such case still falsely return
10309 watchpoint_exp_is_const (const struct expression
*exp
)
10311 int i
= exp
->nelts
;
10317 /* We are only interested in the descriptor of each element. */
10318 operator_length (exp
, i
, &oplenp
, &argsp
);
10321 switch (exp
->elts
[i
].opcode
)
10331 case BINOP_LOGICAL_AND
:
10332 case BINOP_LOGICAL_OR
:
10333 case BINOP_BITWISE_AND
:
10334 case BINOP_BITWISE_IOR
:
10335 case BINOP_BITWISE_XOR
:
10337 case BINOP_NOTEQUAL
:
10364 case OP_OBJC_NSSTRING
:
10367 case UNOP_LOGICAL_NOT
:
10368 case UNOP_COMPLEMENT
:
10373 case UNOP_CAST_TYPE
:
10374 case UNOP_REINTERPRET_CAST
:
10375 case UNOP_DYNAMIC_CAST
:
10376 /* Unary, binary and ternary operators: We have to check
10377 their operands. If they are constant, then so is the
10378 result of that operation. For instance, if A and B are
10379 determined to be constants, then so is "A + B".
10381 UNOP_IND is one exception to the rule above, because the
10382 value of *ADDR is not necessarily a constant, even when
10387 /* Check whether the associated symbol is a constant.
10389 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10390 possible that a buggy compiler could mark a variable as
10391 constant even when it is not, and TYPE_CONST would return
10392 true in this case, while SYMBOL_CLASS wouldn't.
10394 We also have to check for function symbols because they
10395 are always constant. */
10397 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10399 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10400 && SYMBOL_CLASS (s
) != LOC_CONST
10401 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10406 /* The default action is to return 0 because we are using
10407 the optimistic approach here: If we don't know something,
10408 then it is not a constant. */
10417 /* Watchpoint destructor. */
10419 watchpoint::~watchpoint ()
10421 xfree (this->exp_string
);
10422 xfree (this->exp_string_reparse
);
10423 value_free (this->val
);
10426 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10429 re_set_watchpoint (struct breakpoint
*b
)
10431 struct watchpoint
*w
= (struct watchpoint
*) b
;
10433 /* Watchpoint can be either on expression using entirely global
10434 variables, or it can be on local variables.
10436 Watchpoints of the first kind are never auto-deleted, and even
10437 persist across program restarts. Since they can use variables
10438 from shared libraries, we need to reparse expression as libraries
10439 are loaded and unloaded.
10441 Watchpoints on local variables can also change meaning as result
10442 of solib event. For example, if a watchpoint uses both a local
10443 and a global variables in expression, it's a local watchpoint,
10444 but unloading of a shared library will make the expression
10445 invalid. This is not a very common use case, but we still
10446 re-evaluate expression, to avoid surprises to the user.
10448 Note that for local watchpoints, we re-evaluate it only if
10449 watchpoints frame id is still valid. If it's not, it means the
10450 watchpoint is out of scope and will be deleted soon. In fact,
10451 I'm not sure we'll ever be called in this case.
10453 If a local watchpoint's frame id is still valid, then
10454 w->exp_valid_block is likewise valid, and we can safely use it.
10456 Don't do anything about disabled watchpoints, since they will be
10457 reevaluated again when enabled. */
10458 update_watchpoint (w
, 1 /* reparse */);
10461 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10464 insert_watchpoint (struct bp_location
*bl
)
10466 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10467 int length
= w
->exact
? 1 : bl
->length
;
10469 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10470 w
->cond_exp
.get ());
10473 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10476 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10478 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10479 int length
= w
->exact
? 1 : bl
->length
;
10481 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10482 w
->cond_exp
.get ());
10486 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10487 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10488 const struct target_waitstatus
*ws
)
10490 struct breakpoint
*b
= bl
->owner
;
10491 struct watchpoint
*w
= (struct watchpoint
*) b
;
10493 /* Continuable hardware watchpoints are treated as non-existent if the
10494 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10495 some data address). Otherwise gdb won't stop on a break instruction
10496 in the code (not from a breakpoint) when a hardware watchpoint has
10497 been defined. Also skip watchpoints which we know did not trigger
10498 (did not match the data address). */
10499 if (is_hardware_watchpoint (b
)
10500 && w
->watchpoint_triggered
== watch_triggered_no
)
10507 check_status_watchpoint (bpstat bs
)
10509 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10511 bpstat_check_watchpoint (bs
);
10514 /* Implement the "resources_needed" breakpoint_ops method for
10515 hardware watchpoints. */
10518 resources_needed_watchpoint (const struct bp_location
*bl
)
10520 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10521 int length
= w
->exact
? 1 : bl
->length
;
10523 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10526 /* Implement the "works_in_software_mode" breakpoint_ops method for
10527 hardware watchpoints. */
10530 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10532 /* Read and access watchpoints only work with hardware support. */
10533 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10536 static enum print_stop_action
10537 print_it_watchpoint (bpstat bs
)
10539 struct cleanup
*old_chain
;
10540 struct breakpoint
*b
;
10541 enum print_stop_action result
;
10542 struct watchpoint
*w
;
10543 struct ui_out
*uiout
= current_uiout
;
10545 gdb_assert (bs
->bp_location_at
!= NULL
);
10547 b
= bs
->breakpoint_at
;
10548 w
= (struct watchpoint
*) b
;
10550 old_chain
= make_cleanup (null_cleanup
, NULL
);
10552 annotate_watchpoint (b
->number
);
10553 maybe_print_thread_hit_breakpoint (uiout
);
10559 case bp_watchpoint
:
10560 case bp_hardware_watchpoint
:
10561 if (uiout
->is_mi_like_p ())
10562 uiout
->field_string
10563 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10565 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10566 uiout
->text ("\nOld value = ");
10567 watchpoint_value_print (bs
->old_val
, &stb
);
10568 uiout
->field_stream ("old", stb
);
10569 uiout
->text ("\nNew value = ");
10570 watchpoint_value_print (w
->val
, &stb
);
10571 uiout
->field_stream ("new", stb
);
10572 uiout
->text ("\n");
10573 /* More than one watchpoint may have been triggered. */
10574 result
= PRINT_UNKNOWN
;
10577 case bp_read_watchpoint
:
10578 if (uiout
->is_mi_like_p ())
10579 uiout
->field_string
10580 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10582 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10583 uiout
->text ("\nValue = ");
10584 watchpoint_value_print (w
->val
, &stb
);
10585 uiout
->field_stream ("value", stb
);
10586 uiout
->text ("\n");
10587 result
= PRINT_UNKNOWN
;
10590 case bp_access_watchpoint
:
10591 if (bs
->old_val
!= NULL
)
10593 if (uiout
->is_mi_like_p ())
10594 uiout
->field_string
10596 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10598 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10599 uiout
->text ("\nOld value = ");
10600 watchpoint_value_print (bs
->old_val
, &stb
);
10601 uiout
->field_stream ("old", stb
);
10602 uiout
->text ("\nNew value = ");
10607 if (uiout
->is_mi_like_p ())
10608 uiout
->field_string
10610 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10611 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10612 uiout
->text ("\nValue = ");
10614 watchpoint_value_print (w
->val
, &stb
);
10615 uiout
->field_stream ("new", stb
);
10616 uiout
->text ("\n");
10617 result
= PRINT_UNKNOWN
;
10620 result
= PRINT_UNKNOWN
;
10623 do_cleanups (old_chain
);
10627 /* Implement the "print_mention" breakpoint_ops method for hardware
10631 print_mention_watchpoint (struct breakpoint
*b
)
10633 struct watchpoint
*w
= (struct watchpoint
*) b
;
10634 struct ui_out
*uiout
= current_uiout
;
10635 const char *tuple_name
;
10639 case bp_watchpoint
:
10640 uiout
->text ("Watchpoint ");
10641 tuple_name
= "wpt";
10643 case bp_hardware_watchpoint
:
10644 uiout
->text ("Hardware watchpoint ");
10645 tuple_name
= "wpt";
10647 case bp_read_watchpoint
:
10648 uiout
->text ("Hardware read watchpoint ");
10649 tuple_name
= "hw-rwpt";
10651 case bp_access_watchpoint
:
10652 uiout
->text ("Hardware access (read/write) watchpoint ");
10653 tuple_name
= "hw-awpt";
10656 internal_error (__FILE__
, __LINE__
,
10657 _("Invalid hardware watchpoint type."));
10660 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10661 uiout
->field_int ("number", b
->number
);
10662 uiout
->text (": ");
10663 uiout
->field_string ("exp", w
->exp_string
);
10666 /* Implement the "print_recreate" breakpoint_ops method for
10670 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10672 struct watchpoint
*w
= (struct watchpoint
*) b
;
10676 case bp_watchpoint
:
10677 case bp_hardware_watchpoint
:
10678 fprintf_unfiltered (fp
, "watch");
10680 case bp_read_watchpoint
:
10681 fprintf_unfiltered (fp
, "rwatch");
10683 case bp_access_watchpoint
:
10684 fprintf_unfiltered (fp
, "awatch");
10687 internal_error (__FILE__
, __LINE__
,
10688 _("Invalid watchpoint type."));
10691 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10692 print_recreate_thread (b
, fp
);
10695 /* Implement the "explains_signal" breakpoint_ops method for
10699 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10701 /* A software watchpoint cannot cause a signal other than
10702 GDB_SIGNAL_TRAP. */
10703 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10709 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10711 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10713 /* Implement the "insert" breakpoint_ops method for
10714 masked hardware watchpoints. */
10717 insert_masked_watchpoint (struct bp_location
*bl
)
10719 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10721 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10722 bl
->watchpoint_type
);
10725 /* Implement the "remove" breakpoint_ops method for
10726 masked hardware watchpoints. */
10729 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10731 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10733 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10734 bl
->watchpoint_type
);
10737 /* Implement the "resources_needed" breakpoint_ops method for
10738 masked hardware watchpoints. */
10741 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10743 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10745 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10748 /* Implement the "works_in_software_mode" breakpoint_ops method for
10749 masked hardware watchpoints. */
10752 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10757 /* Implement the "print_it" breakpoint_ops method for
10758 masked hardware watchpoints. */
10760 static enum print_stop_action
10761 print_it_masked_watchpoint (bpstat bs
)
10763 struct breakpoint
*b
= bs
->breakpoint_at
;
10764 struct ui_out
*uiout
= current_uiout
;
10766 /* Masked watchpoints have only one location. */
10767 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10769 annotate_watchpoint (b
->number
);
10770 maybe_print_thread_hit_breakpoint (uiout
);
10774 case bp_hardware_watchpoint
:
10775 if (uiout
->is_mi_like_p ())
10776 uiout
->field_string
10777 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10780 case bp_read_watchpoint
:
10781 if (uiout
->is_mi_like_p ())
10782 uiout
->field_string
10783 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10786 case bp_access_watchpoint
:
10787 if (uiout
->is_mi_like_p ())
10788 uiout
->field_string
10790 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10793 internal_error (__FILE__
, __LINE__
,
10794 _("Invalid hardware watchpoint type."));
10798 uiout
->text (_("\n\
10799 Check the underlying instruction at PC for the memory\n\
10800 address and value which triggered this watchpoint.\n"));
10801 uiout
->text ("\n");
10803 /* More than one watchpoint may have been triggered. */
10804 return PRINT_UNKNOWN
;
10807 /* Implement the "print_one_detail" breakpoint_ops method for
10808 masked hardware watchpoints. */
10811 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10812 struct ui_out
*uiout
)
10814 struct watchpoint
*w
= (struct watchpoint
*) b
;
10816 /* Masked watchpoints have only one location. */
10817 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10819 uiout
->text ("\tmask ");
10820 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10821 uiout
->text ("\n");
10824 /* Implement the "print_mention" breakpoint_ops method for
10825 masked hardware watchpoints. */
10828 print_mention_masked_watchpoint (struct breakpoint
*b
)
10830 struct watchpoint
*w
= (struct watchpoint
*) b
;
10831 struct ui_out
*uiout
= current_uiout
;
10832 const char *tuple_name
;
10836 case bp_hardware_watchpoint
:
10837 uiout
->text ("Masked hardware watchpoint ");
10838 tuple_name
= "wpt";
10840 case bp_read_watchpoint
:
10841 uiout
->text ("Masked hardware read watchpoint ");
10842 tuple_name
= "hw-rwpt";
10844 case bp_access_watchpoint
:
10845 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10846 tuple_name
= "hw-awpt";
10849 internal_error (__FILE__
, __LINE__
,
10850 _("Invalid hardware watchpoint type."));
10853 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10854 uiout
->field_int ("number", b
->number
);
10855 uiout
->text (": ");
10856 uiout
->field_string ("exp", w
->exp_string
);
10859 /* Implement the "print_recreate" breakpoint_ops method for
10860 masked hardware watchpoints. */
10863 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10865 struct watchpoint
*w
= (struct watchpoint
*) b
;
10870 case bp_hardware_watchpoint
:
10871 fprintf_unfiltered (fp
, "watch");
10873 case bp_read_watchpoint
:
10874 fprintf_unfiltered (fp
, "rwatch");
10876 case bp_access_watchpoint
:
10877 fprintf_unfiltered (fp
, "awatch");
10880 internal_error (__FILE__
, __LINE__
,
10881 _("Invalid hardware watchpoint type."));
10884 sprintf_vma (tmp
, w
->hw_wp_mask
);
10885 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10886 print_recreate_thread (b
, fp
);
10889 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10891 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10893 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10896 is_masked_watchpoint (const struct breakpoint
*b
)
10898 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10901 /* accessflag: hw_write: watch write,
10902 hw_read: watch read,
10903 hw_access: watch access (read or write) */
10905 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10906 int just_location
, int internal
)
10908 struct breakpoint
*scope_breakpoint
= NULL
;
10909 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10910 struct value
*val
, *mark
, *result
;
10911 int saved_bitpos
= 0, saved_bitsize
= 0;
10912 const char *exp_start
= NULL
;
10913 const char *exp_end
= NULL
;
10914 const char *tok
, *end_tok
;
10916 const char *cond_start
= NULL
;
10917 const char *cond_end
= NULL
;
10918 enum bptype bp_type
;
10921 /* Flag to indicate whether we are going to use masks for
10922 the hardware watchpoint. */
10924 CORE_ADDR mask
= 0;
10926 struct cleanup
*back_to
;
10928 /* Make sure that we actually have parameters to parse. */
10929 if (arg
!= NULL
&& arg
[0] != '\0')
10931 const char *value_start
;
10933 exp_end
= arg
+ strlen (arg
);
10935 /* Look for "parameter value" pairs at the end
10936 of the arguments string. */
10937 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10939 /* Skip whitespace at the end of the argument list. */
10940 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10943 /* Find the beginning of the last token.
10944 This is the value of the parameter. */
10945 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10947 value_start
= tok
+ 1;
10949 /* Skip whitespace. */
10950 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10955 /* Find the beginning of the second to last token.
10956 This is the parameter itself. */
10957 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10960 toklen
= end_tok
- tok
+ 1;
10962 if (toklen
== 6 && startswith (tok
, "thread"))
10964 struct thread_info
*thr
;
10965 /* At this point we've found a "thread" token, which means
10966 the user is trying to set a watchpoint that triggers
10967 only in a specific thread. */
10971 error(_("You can specify only one thread."));
10973 /* Extract the thread ID from the next token. */
10974 thr
= parse_thread_id (value_start
, &endp
);
10976 /* Check if the user provided a valid thread ID. */
10977 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10978 invalid_thread_id_error (value_start
);
10980 thread
= thr
->global_num
;
10982 else if (toklen
== 4 && startswith (tok
, "mask"))
10984 /* We've found a "mask" token, which means the user wants to
10985 create a hardware watchpoint that is going to have the mask
10987 struct value
*mask_value
, *mark
;
10990 error(_("You can specify only one mask."));
10992 use_mask
= just_location
= 1;
10994 mark
= value_mark ();
10995 mask_value
= parse_to_comma_and_eval (&value_start
);
10996 mask
= value_as_address (mask_value
);
10997 value_free_to_mark (mark
);
11000 /* We didn't recognize what we found. We should stop here. */
11003 /* Truncate the string and get rid of the "parameter value" pair before
11004 the arguments string is parsed by the parse_exp_1 function. */
11011 /* Parse the rest of the arguments. From here on out, everything
11012 is in terms of a newly allocated string instead of the original
11014 innermost_block
= NULL
;
11015 expression
= savestring (arg
, exp_end
- arg
);
11016 back_to
= make_cleanup (xfree
, expression
);
11017 exp_start
= arg
= expression
;
11018 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11020 /* Remove trailing whitespace from the expression before saving it.
11021 This makes the eventual display of the expression string a bit
11023 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11026 /* Checking if the expression is not constant. */
11027 if (watchpoint_exp_is_const (exp
.get ()))
11031 len
= exp_end
- exp_start
;
11032 while (len
> 0 && isspace (exp_start
[len
- 1]))
11034 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11037 exp_valid_block
= innermost_block
;
11038 mark
= value_mark ();
11039 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11041 if (val
!= NULL
&& just_location
)
11043 saved_bitpos
= value_bitpos (val
);
11044 saved_bitsize
= value_bitsize (val
);
11051 exp_valid_block
= NULL
;
11052 val
= value_addr (result
);
11053 release_value (val
);
11054 value_free_to_mark (mark
);
11058 ret
= target_masked_watch_num_registers (value_as_address (val
),
11061 error (_("This target does not support masked watchpoints."));
11062 else if (ret
== -2)
11063 error (_("Invalid mask or memory region."));
11066 else if (val
!= NULL
)
11067 release_value (val
);
11069 tok
= skip_spaces_const (arg
);
11070 end_tok
= skip_to_space_const (tok
);
11072 toklen
= end_tok
- tok
;
11073 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11075 innermost_block
= NULL
;
11076 tok
= cond_start
= end_tok
+ 1;
11077 parse_exp_1 (&tok
, 0, 0, 0);
11079 /* The watchpoint expression may not be local, but the condition
11080 may still be. E.g.: `watch global if local > 0'. */
11081 cond_exp_valid_block
= innermost_block
;
11086 error (_("Junk at end of command."));
11088 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11090 /* Save this because create_internal_breakpoint below invalidates
11092 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11094 /* If the expression is "local", then set up a "watchpoint scope"
11095 breakpoint at the point where we've left the scope of the watchpoint
11096 expression. Create the scope breakpoint before the watchpoint, so
11097 that we will encounter it first in bpstat_stop_status. */
11098 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11100 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11102 if (frame_id_p (caller_frame_id
))
11104 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11105 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11108 = create_internal_breakpoint (caller_arch
, caller_pc
,
11109 bp_watchpoint_scope
,
11110 &momentary_breakpoint_ops
);
11112 /* create_internal_breakpoint could invalidate WP_FRAME. */
11115 scope_breakpoint
->enable_state
= bp_enabled
;
11117 /* Automatically delete the breakpoint when it hits. */
11118 scope_breakpoint
->disposition
= disp_del
;
11120 /* Only break in the proper frame (help with recursion). */
11121 scope_breakpoint
->frame_id
= caller_frame_id
;
11123 /* Set the address at which we will stop. */
11124 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11125 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11126 scope_breakpoint
->loc
->address
11127 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11128 scope_breakpoint
->loc
->requested_address
,
11129 scope_breakpoint
->type
);
11133 /* Now set up the breakpoint. We create all watchpoints as hardware
11134 watchpoints here even if hardware watchpoints are turned off, a call
11135 to update_watchpoint later in this function will cause the type to
11136 drop back to bp_watchpoint (software watchpoint) if required. */
11138 if (accessflag
== hw_read
)
11139 bp_type
= bp_read_watchpoint
;
11140 else if (accessflag
== hw_access
)
11141 bp_type
= bp_access_watchpoint
;
11143 bp_type
= bp_hardware_watchpoint
;
11145 std::unique_ptr
<watchpoint
> w (new watchpoint ());
11148 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11149 &masked_watchpoint_breakpoint_ops
);
11151 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11152 &watchpoint_breakpoint_ops
);
11153 w
->thread
= thread
;
11154 w
->disposition
= disp_donttouch
;
11155 w
->pspace
= current_program_space
;
11156 w
->exp
= std::move (exp
);
11157 w
->exp_valid_block
= exp_valid_block
;
11158 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11161 struct type
*t
= value_type (val
);
11162 CORE_ADDR addr
= value_as_address (val
);
11164 w
->exp_string_reparse
11165 = current_language
->la_watch_location_expression (t
, addr
).release ();
11167 w
->exp_string
= xstrprintf ("-location %.*s",
11168 (int) (exp_end
- exp_start
), exp_start
);
11171 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11175 w
->hw_wp_mask
= mask
;
11180 w
->val_bitpos
= saved_bitpos
;
11181 w
->val_bitsize
= saved_bitsize
;
11186 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11188 w
->cond_string
= 0;
11190 if (frame_id_p (watchpoint_frame
))
11192 w
->watchpoint_frame
= watchpoint_frame
;
11193 w
->watchpoint_thread
= inferior_ptid
;
11197 w
->watchpoint_frame
= null_frame_id
;
11198 w
->watchpoint_thread
= null_ptid
;
11201 if (scope_breakpoint
!= NULL
)
11203 /* The scope breakpoint is related to the watchpoint. We will
11204 need to act on them together. */
11205 w
->related_breakpoint
= scope_breakpoint
;
11206 scope_breakpoint
->related_breakpoint
= w
.get ();
11209 if (!just_location
)
11210 value_free_to_mark (mark
);
11212 /* Finally update the new watchpoint. This creates the locations
11213 that should be inserted. */
11214 update_watchpoint (w
.get (), 1);
11216 install_breakpoint (internal
, std::move (w
), 1);
11217 do_cleanups (back_to
);
11220 /* Return count of debug registers needed to watch the given expression.
11221 If the watchpoint cannot be handled in hardware return zero. */
11224 can_use_hardware_watchpoint (struct value
*v
)
11226 int found_memory_cnt
= 0;
11227 struct value
*head
= v
;
11229 /* Did the user specifically forbid us to use hardware watchpoints? */
11230 if (!can_use_hw_watchpoints
)
11233 /* Make sure that the value of the expression depends only upon
11234 memory contents, and values computed from them within GDB. If we
11235 find any register references or function calls, we can't use a
11236 hardware watchpoint.
11238 The idea here is that evaluating an expression generates a series
11239 of values, one holding the value of every subexpression. (The
11240 expression a*b+c has five subexpressions: a, b, a*b, c, and
11241 a*b+c.) GDB's values hold almost enough information to establish
11242 the criteria given above --- they identify memory lvalues,
11243 register lvalues, computed values, etcetera. So we can evaluate
11244 the expression, and then scan the chain of values that leaves
11245 behind to decide whether we can detect any possible change to the
11246 expression's final value using only hardware watchpoints.
11248 However, I don't think that the values returned by inferior
11249 function calls are special in any way. So this function may not
11250 notice that an expression involving an inferior function call
11251 can't be watched with hardware watchpoints. FIXME. */
11252 for (; v
; v
= value_next (v
))
11254 if (VALUE_LVAL (v
) == lval_memory
)
11256 if (v
!= head
&& value_lazy (v
))
11257 /* A lazy memory lvalue in the chain is one that GDB never
11258 needed to fetch; we either just used its address (e.g.,
11259 `a' in `a.b') or we never needed it at all (e.g., `a'
11260 in `a,b'). This doesn't apply to HEAD; if that is
11261 lazy then it was not readable, but watch it anyway. */
11265 /* Ahh, memory we actually used! Check if we can cover
11266 it with hardware watchpoints. */
11267 struct type
*vtype
= check_typedef (value_type (v
));
11269 /* We only watch structs and arrays if user asked for it
11270 explicitly, never if they just happen to appear in a
11271 middle of some value chain. */
11273 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11274 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11276 CORE_ADDR vaddr
= value_address (v
);
11280 len
= (target_exact_watchpoints
11281 && is_scalar_type_recursive (vtype
))?
11282 1 : TYPE_LENGTH (value_type (v
));
11284 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11288 found_memory_cnt
+= num_regs
;
11292 else if (VALUE_LVAL (v
) != not_lval
11293 && deprecated_value_modifiable (v
) == 0)
11294 return 0; /* These are values from the history (e.g., $1). */
11295 else if (VALUE_LVAL (v
) == lval_register
)
11296 return 0; /* Cannot watch a register with a HW watchpoint. */
11299 /* The expression itself looks suitable for using a hardware
11300 watchpoint, but give the target machine a chance to reject it. */
11301 return found_memory_cnt
;
11305 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11307 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11310 /* A helper function that looks for the "-location" argument and then
11311 calls watch_command_1. */
11314 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11316 int just_location
= 0;
11319 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11320 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11322 arg
= skip_spaces (arg
);
11326 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11330 watch_command (char *arg
, int from_tty
)
11332 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11336 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11338 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11342 rwatch_command (char *arg
, int from_tty
)
11344 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11348 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11350 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11354 awatch_command (char *arg
, int from_tty
)
11356 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11360 /* Data for the FSM that manages the until(location)/advance commands
11361 in infcmd.c. Here because it uses the mechanisms of
11364 struct until_break_fsm
11366 /* The base class. */
11367 struct thread_fsm thread_fsm
;
11369 /* The thread that as current when the command was executed. */
11372 /* The breakpoint set at the destination location. */
11373 struct breakpoint
*location_breakpoint
;
11375 /* Breakpoint set at the return address in the caller frame. May be
11377 struct breakpoint
*caller_breakpoint
;
11380 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11381 struct thread_info
*thread
);
11382 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11383 struct thread_info
*thread
);
11384 static enum async_reply_reason
11385 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11387 /* until_break_fsm's vtable. */
11389 static struct thread_fsm_ops until_break_fsm_ops
=
11392 until_break_fsm_clean_up
,
11393 until_break_fsm_should_stop
,
11394 NULL
, /* return_value */
11395 until_break_fsm_async_reply_reason
,
11398 /* Allocate a new until_break_command_fsm. */
11400 static struct until_break_fsm
*
11401 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11402 struct breakpoint
*location_breakpoint
,
11403 struct breakpoint
*caller_breakpoint
)
11405 struct until_break_fsm
*sm
;
11407 sm
= XCNEW (struct until_break_fsm
);
11408 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11410 sm
->thread
= thread
;
11411 sm
->location_breakpoint
= location_breakpoint
;
11412 sm
->caller_breakpoint
= caller_breakpoint
;
11417 /* Implementation of the 'should_stop' FSM method for the
11418 until(location)/advance commands. */
11421 until_break_fsm_should_stop (struct thread_fsm
*self
,
11422 struct thread_info
*tp
)
11424 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11426 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11427 sm
->location_breakpoint
) != NULL
11428 || (sm
->caller_breakpoint
!= NULL
11429 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11430 sm
->caller_breakpoint
) != NULL
))
11431 thread_fsm_set_finished (self
);
11436 /* Implementation of the 'clean_up' FSM method for the
11437 until(location)/advance commands. */
11440 until_break_fsm_clean_up (struct thread_fsm
*self
,
11441 struct thread_info
*thread
)
11443 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11445 /* Clean up our temporary breakpoints. */
11446 if (sm
->location_breakpoint
!= NULL
)
11448 delete_breakpoint (sm
->location_breakpoint
);
11449 sm
->location_breakpoint
= NULL
;
11451 if (sm
->caller_breakpoint
!= NULL
)
11453 delete_breakpoint (sm
->caller_breakpoint
);
11454 sm
->caller_breakpoint
= NULL
;
11456 delete_longjmp_breakpoint (sm
->thread
);
11459 /* Implementation of the 'async_reply_reason' FSM method for the
11460 until(location)/advance commands. */
11462 static enum async_reply_reason
11463 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11465 return EXEC_ASYNC_LOCATION_REACHED
;
11469 until_break_command (char *arg
, int from_tty
, int anywhere
)
11471 struct frame_info
*frame
;
11472 struct gdbarch
*frame_gdbarch
;
11473 struct frame_id stack_frame_id
;
11474 struct frame_id caller_frame_id
;
11475 struct breakpoint
*location_breakpoint
;
11476 struct breakpoint
*caller_breakpoint
= NULL
;
11477 struct cleanup
*old_chain
;
11479 struct thread_info
*tp
;
11480 struct until_break_fsm
*sm
;
11482 clear_proceed_status (0);
11484 /* Set a breakpoint where the user wants it and at return from
11487 event_location_up location
= string_to_event_location (&arg
, current_language
);
11489 std::vector
<symtab_and_line
> sals
11490 = (last_displayed_sal_is_valid ()
11491 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11492 get_last_displayed_symtab (),
11493 get_last_displayed_line ())
11494 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11495 NULL
, (struct symtab
*) NULL
, 0));
11497 if (sals
.size () != 1)
11498 error (_("Couldn't get information on specified line."));
11500 symtab_and_line
&sal
= sals
[0];
11503 error (_("Junk at end of arguments."));
11505 resolve_sal_pc (&sal
);
11507 tp
= inferior_thread ();
11508 thread
= tp
->global_num
;
11510 old_chain
= make_cleanup (null_cleanup
, NULL
);
11512 /* Note linespec handling above invalidates the frame chain.
11513 Installing a breakpoint also invalidates the frame chain (as it
11514 may need to switch threads), so do any frame handling before
11517 frame
= get_selected_frame (NULL
);
11518 frame_gdbarch
= get_frame_arch (frame
);
11519 stack_frame_id
= get_stack_frame_id (frame
);
11520 caller_frame_id
= frame_unwind_caller_id (frame
);
11522 /* Keep within the current frame, or in frames called by the current
11525 if (frame_id_p (caller_frame_id
))
11527 struct symtab_and_line sal2
;
11528 struct gdbarch
*caller_gdbarch
;
11530 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11531 sal2
.pc
= frame_unwind_caller_pc (frame
);
11532 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11533 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11537 make_cleanup_delete_breakpoint (caller_breakpoint
);
11539 set_longjmp_breakpoint (tp
, caller_frame_id
);
11540 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11543 /* set_momentary_breakpoint could invalidate FRAME. */
11547 /* If the user told us to continue until a specified location,
11548 we don't specify a frame at which we need to stop. */
11549 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11550 null_frame_id
, bp_until
);
11552 /* Otherwise, specify the selected frame, because we want to stop
11553 only at the very same frame. */
11554 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11555 stack_frame_id
, bp_until
);
11556 make_cleanup_delete_breakpoint (location_breakpoint
);
11558 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11559 location_breakpoint
, caller_breakpoint
);
11560 tp
->thread_fsm
= &sm
->thread_fsm
;
11562 discard_cleanups (old_chain
);
11564 proceed (-1, GDB_SIGNAL_DEFAULT
);
11567 /* This function attempts to parse an optional "if <cond>" clause
11568 from the arg string. If one is not found, it returns NULL.
11570 Else, it returns a pointer to the condition string. (It does not
11571 attempt to evaluate the string against a particular block.) And,
11572 it updates arg to point to the first character following the parsed
11573 if clause in the arg string. */
11576 ep_parse_optional_if_clause (const char **arg
)
11578 const char *cond_string
;
11580 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11583 /* Skip the "if" keyword. */
11586 /* Skip any extra leading whitespace, and record the start of the
11587 condition string. */
11588 *arg
= skip_spaces_const (*arg
);
11589 cond_string
= *arg
;
11591 /* Assume that the condition occupies the remainder of the arg
11593 (*arg
) += strlen (cond_string
);
11595 return cond_string
;
11598 /* Commands to deal with catching events, such as signals, exceptions,
11599 process start/exit, etc. */
11603 catch_fork_temporary
, catch_vfork_temporary
,
11604 catch_fork_permanent
, catch_vfork_permanent
11609 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11610 struct cmd_list_element
*command
)
11612 const char *arg
= arg_entry
;
11613 struct gdbarch
*gdbarch
= get_current_arch ();
11614 const char *cond_string
= NULL
;
11615 catch_fork_kind fork_kind
;
11618 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11619 tempflag
= (fork_kind
== catch_fork_temporary
11620 || fork_kind
== catch_vfork_temporary
);
11624 arg
= skip_spaces_const (arg
);
11626 /* The allowed syntax is:
11628 catch [v]fork if <cond>
11630 First, check if there's an if clause. */
11631 cond_string
= ep_parse_optional_if_clause (&arg
);
11633 if ((*arg
!= '\0') && !isspace (*arg
))
11634 error (_("Junk at end of arguments."));
11636 /* If this target supports it, create a fork or vfork catchpoint
11637 and enable reporting of such events. */
11640 case catch_fork_temporary
:
11641 case catch_fork_permanent
:
11642 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11643 &catch_fork_breakpoint_ops
);
11645 case catch_vfork_temporary
:
11646 case catch_vfork_permanent
:
11647 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11648 &catch_vfork_breakpoint_ops
);
11651 error (_("unsupported or unknown fork kind; cannot catch it"));
11657 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11658 struct cmd_list_element
*command
)
11660 const char *arg
= arg_entry
;
11661 struct gdbarch
*gdbarch
= get_current_arch ();
11663 const char *cond_string
= NULL
;
11665 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11669 arg
= skip_spaces_const (arg
);
11671 /* The allowed syntax is:
11673 catch exec if <cond>
11675 First, check if there's an if clause. */
11676 cond_string
= ep_parse_optional_if_clause (&arg
);
11678 if ((*arg
!= '\0') && !isspace (*arg
))
11679 error (_("Junk at end of arguments."));
11681 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11682 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11683 &catch_exec_breakpoint_ops
);
11684 c
->exec_pathname
= NULL
;
11686 install_breakpoint (0, std::move (c
), 1);
11690 init_ada_exception_breakpoint (struct breakpoint
*b
,
11691 struct gdbarch
*gdbarch
,
11692 struct symtab_and_line sal
,
11694 const struct breakpoint_ops
*ops
,
11701 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11703 loc_gdbarch
= gdbarch
;
11705 describe_other_breakpoints (loc_gdbarch
,
11706 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11707 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11708 version for exception catchpoints, because two catchpoints
11709 used for different exception names will use the same address.
11710 In this case, a "breakpoint ... also set at..." warning is
11711 unproductive. Besides, the warning phrasing is also a bit
11712 inappropriate, we should use the word catchpoint, and tell
11713 the user what type of catchpoint it is. The above is good
11714 enough for now, though. */
11717 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11719 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11720 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11721 b
->location
= string_to_event_location (&addr_string
,
11722 language_def (language_ada
));
11723 b
->language
= language_ada
;
11727 catch_command (char *arg
, int from_tty
)
11729 error (_("Catch requires an event name."));
11734 tcatch_command (char *arg
, int from_tty
)
11736 error (_("Catch requires an event name."));
11739 /* A qsort comparison function that sorts breakpoints in order. */
11742 compare_breakpoints (const void *a
, const void *b
)
11744 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11745 uintptr_t ua
= (uintptr_t) *ba
;
11746 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11747 uintptr_t ub
= (uintptr_t) *bb
;
11749 if ((*ba
)->number
< (*bb
)->number
)
11751 else if ((*ba
)->number
> (*bb
)->number
)
11754 /* Now sort by address, in case we see, e..g, two breakpoints with
11758 return ua
> ub
? 1 : 0;
11761 /* Delete breakpoints by address or line. */
11764 clear_command (char *arg
, int from_tty
)
11766 struct breakpoint
*b
, *prev
;
11767 VEC(breakpoint_p
) *found
= 0;
11771 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11773 std::vector
<symtab_and_line
> decoded_sals
;
11774 symtab_and_line last_sal
;
11775 gdb::array_view
<symtab_and_line
> sals
;
11779 = decode_line_with_current_source (arg
,
11780 (DECODE_LINE_FUNFIRSTLINE
11781 | DECODE_LINE_LIST_MODE
));
11783 sals
= decoded_sals
;
11787 /* Set sal's line, symtab, pc, and pspace to the values
11788 corresponding to the last call to print_frame_info. If the
11789 codepoint is not valid, this will set all the fields to 0. */
11790 last_sal
= get_last_displayed_sal ();
11791 if (last_sal
.symtab
== 0)
11792 error (_("No source file specified."));
11798 /* We don't call resolve_sal_pc here. That's not as bad as it
11799 seems, because all existing breakpoints typically have both
11800 file/line and pc set. So, if clear is given file/line, we can
11801 match this to existing breakpoint without obtaining pc at all.
11803 We only support clearing given the address explicitly
11804 present in breakpoint table. Say, we've set breakpoint
11805 at file:line. There were several PC values for that file:line,
11806 due to optimization, all in one block.
11808 We've picked one PC value. If "clear" is issued with another
11809 PC corresponding to the same file:line, the breakpoint won't
11810 be cleared. We probably can still clear the breakpoint, but
11811 since the other PC value is never presented to user, user
11812 can only find it by guessing, and it does not seem important
11813 to support that. */
11815 /* For each line spec given, delete bps which correspond to it. Do
11816 it in two passes, solely to preserve the current behavior that
11817 from_tty is forced true if we delete more than one
11821 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11822 for (const auto &sal
: sals
)
11824 const char *sal_fullname
;
11826 /* If exact pc given, clear bpts at that pc.
11827 If line given (pc == 0), clear all bpts on specified line.
11828 If defaulting, clear all bpts on default line
11831 defaulting sal.pc != 0 tests to do
11836 1 0 <can't happen> */
11838 sal_fullname
= (sal
.symtab
== NULL
11839 ? NULL
: symtab_to_fullname (sal
.symtab
));
11841 /* Find all matching breakpoints and add them to 'found'. */
11842 ALL_BREAKPOINTS (b
)
11845 /* Are we going to delete b? */
11846 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11848 struct bp_location
*loc
= b
->loc
;
11849 for (; loc
; loc
= loc
->next
)
11851 /* If the user specified file:line, don't allow a PC
11852 match. This matches historical gdb behavior. */
11853 int pc_match
= (!sal
.explicit_line
11855 && (loc
->pspace
== sal
.pspace
)
11856 && (loc
->address
== sal
.pc
)
11857 && (!section_is_overlay (loc
->section
)
11858 || loc
->section
== sal
.section
));
11859 int line_match
= 0;
11861 if ((default_match
|| sal
.explicit_line
)
11862 && loc
->symtab
!= NULL
11863 && sal_fullname
!= NULL
11864 && sal
.pspace
== loc
->pspace
11865 && loc
->line_number
== sal
.line
11866 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11867 sal_fullname
) == 0)
11870 if (pc_match
|| line_match
)
11879 VEC_safe_push(breakpoint_p
, found
, b
);
11883 /* Now go thru the 'found' chain and delete them. */
11884 if (VEC_empty(breakpoint_p
, found
))
11887 error (_("No breakpoint at %s."), arg
);
11889 error (_("No breakpoint at this line."));
11892 /* Remove duplicates from the vec. */
11893 qsort (VEC_address (breakpoint_p
, found
),
11894 VEC_length (breakpoint_p
, found
),
11895 sizeof (breakpoint_p
),
11896 compare_breakpoints
);
11897 prev
= VEC_index (breakpoint_p
, found
, 0);
11898 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11902 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11907 if (VEC_length(breakpoint_p
, found
) > 1)
11908 from_tty
= 1; /* Always report if deleted more than one. */
11911 if (VEC_length(breakpoint_p
, found
) == 1)
11912 printf_unfiltered (_("Deleted breakpoint "));
11914 printf_unfiltered (_("Deleted breakpoints "));
11917 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11920 printf_unfiltered ("%d ", b
->number
);
11921 delete_breakpoint (b
);
11924 putchar_unfiltered ('\n');
11926 do_cleanups (cleanups
);
11929 /* Delete breakpoint in BS if they are `delete' breakpoints and
11930 all breakpoints that are marked for deletion, whether hit or not.
11931 This is called after any breakpoint is hit, or after errors. */
11934 breakpoint_auto_delete (bpstat bs
)
11936 struct breakpoint
*b
, *b_tmp
;
11938 for (; bs
; bs
= bs
->next
)
11939 if (bs
->breakpoint_at
11940 && bs
->breakpoint_at
->disposition
== disp_del
11942 delete_breakpoint (bs
->breakpoint_at
);
11944 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11946 if (b
->disposition
== disp_del_at_next_stop
)
11947 delete_breakpoint (b
);
11951 /* A comparison function for bp_location AP and BP being interfaced to
11952 qsort. Sort elements primarily by their ADDRESS (no matter what
11953 does breakpoint_address_is_meaningful say for its OWNER),
11954 secondarily by ordering first permanent elements and
11955 terciarily just ensuring the array is sorted stable way despite
11956 qsort being an unstable algorithm. */
11959 bp_locations_compare (const void *ap
, const void *bp
)
11961 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11962 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11964 if (a
->address
!= b
->address
)
11965 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11967 /* Sort locations at the same address by their pspace number, keeping
11968 locations of the same inferior (in a multi-inferior environment)
11971 if (a
->pspace
->num
!= b
->pspace
->num
)
11972 return ((a
->pspace
->num
> b
->pspace
->num
)
11973 - (a
->pspace
->num
< b
->pspace
->num
));
11975 /* Sort permanent breakpoints first. */
11976 if (a
->permanent
!= b
->permanent
)
11977 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11979 /* Make the internal GDB representation stable across GDB runs
11980 where A and B memory inside GDB can differ. Breakpoint locations of
11981 the same type at the same address can be sorted in arbitrary order. */
11983 if (a
->owner
->number
!= b
->owner
->number
)
11984 return ((a
->owner
->number
> b
->owner
->number
)
11985 - (a
->owner
->number
< b
->owner
->number
));
11987 return (a
> b
) - (a
< b
);
11990 /* Set bp_locations_placed_address_before_address_max and
11991 bp_locations_shadow_len_after_address_max according to the current
11992 content of the bp_locations array. */
11995 bp_locations_target_extensions_update (void)
11997 struct bp_location
*bl
, **blp_tmp
;
11999 bp_locations_placed_address_before_address_max
= 0;
12000 bp_locations_shadow_len_after_address_max
= 0;
12002 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12004 CORE_ADDR start
, end
, addr
;
12006 if (!bp_location_has_shadow (bl
))
12009 start
= bl
->target_info
.placed_address
;
12010 end
= start
+ bl
->target_info
.shadow_len
;
12012 gdb_assert (bl
->address
>= start
);
12013 addr
= bl
->address
- start
;
12014 if (addr
> bp_locations_placed_address_before_address_max
)
12015 bp_locations_placed_address_before_address_max
= addr
;
12017 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12019 gdb_assert (bl
->address
< end
);
12020 addr
= end
- bl
->address
;
12021 if (addr
> bp_locations_shadow_len_after_address_max
)
12022 bp_locations_shadow_len_after_address_max
= addr
;
12026 /* Download tracepoint locations if they haven't been. */
12029 download_tracepoint_locations (void)
12031 struct breakpoint
*b
;
12032 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12034 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12036 ALL_TRACEPOINTS (b
)
12038 struct bp_location
*bl
;
12039 struct tracepoint
*t
;
12040 int bp_location_downloaded
= 0;
12042 if ((b
->type
== bp_fast_tracepoint
12043 ? !may_insert_fast_tracepoints
12044 : !may_insert_tracepoints
))
12047 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12049 if (target_can_download_tracepoint ())
12050 can_download_tracepoint
= TRIBOOL_TRUE
;
12052 can_download_tracepoint
= TRIBOOL_FALSE
;
12055 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12058 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12060 /* In tracepoint, locations are _never_ duplicated, so
12061 should_be_inserted is equivalent to
12062 unduplicated_should_be_inserted. */
12063 if (!should_be_inserted (bl
) || bl
->inserted
)
12066 switch_to_program_space_and_thread (bl
->pspace
);
12068 target_download_tracepoint (bl
);
12071 bp_location_downloaded
= 1;
12073 t
= (struct tracepoint
*) b
;
12074 t
->number_on_target
= b
->number
;
12075 if (bp_location_downloaded
)
12076 observer_notify_breakpoint_modified (b
);
12080 /* Swap the insertion/duplication state between two locations. */
12083 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12085 const int left_inserted
= left
->inserted
;
12086 const int left_duplicate
= left
->duplicate
;
12087 const int left_needs_update
= left
->needs_update
;
12088 const struct bp_target_info left_target_info
= left
->target_info
;
12090 /* Locations of tracepoints can never be duplicated. */
12091 if (is_tracepoint (left
->owner
))
12092 gdb_assert (!left
->duplicate
);
12093 if (is_tracepoint (right
->owner
))
12094 gdb_assert (!right
->duplicate
);
12096 left
->inserted
= right
->inserted
;
12097 left
->duplicate
= right
->duplicate
;
12098 left
->needs_update
= right
->needs_update
;
12099 left
->target_info
= right
->target_info
;
12100 right
->inserted
= left_inserted
;
12101 right
->duplicate
= left_duplicate
;
12102 right
->needs_update
= left_needs_update
;
12103 right
->target_info
= left_target_info
;
12106 /* Force the re-insertion of the locations at ADDRESS. This is called
12107 once a new/deleted/modified duplicate location is found and we are evaluating
12108 conditions on the target's side. Such conditions need to be updated on
12112 force_breakpoint_reinsertion (struct bp_location
*bl
)
12114 struct bp_location
**locp
= NULL
, **loc2p
;
12115 struct bp_location
*loc
;
12116 CORE_ADDR address
= 0;
12119 address
= bl
->address
;
12120 pspace_num
= bl
->pspace
->num
;
12122 /* This is only meaningful if the target is
12123 evaluating conditions and if the user has
12124 opted for condition evaluation on the target's
12126 if (gdb_evaluates_breakpoint_condition_p ()
12127 || !target_supports_evaluation_of_breakpoint_conditions ())
12130 /* Flag all breakpoint locations with this address and
12131 the same program space as the location
12132 as "its condition has changed". We need to
12133 update the conditions on the target's side. */
12134 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12138 if (!is_breakpoint (loc
->owner
)
12139 || pspace_num
!= loc
->pspace
->num
)
12142 /* Flag the location appropriately. We use a different state to
12143 let everyone know that we already updated the set of locations
12144 with addr bl->address and program space bl->pspace. This is so
12145 we don't have to keep calling these functions just to mark locations
12146 that have already been marked. */
12147 loc
->condition_changed
= condition_updated
;
12149 /* Free the agent expression bytecode as well. We will compute
12151 loc
->cond_bytecode
.reset ();
12154 /* Called whether new breakpoints are created, or existing breakpoints
12155 deleted, to update the global location list and recompute which
12156 locations are duplicate of which.
12158 The INSERT_MODE flag determines whether locations may not, may, or
12159 shall be inserted now. See 'enum ugll_insert_mode' for more
12163 update_global_location_list (enum ugll_insert_mode insert_mode
)
12165 struct breakpoint
*b
;
12166 struct bp_location
**locp
, *loc
;
12167 struct cleanup
*cleanups
;
12168 /* Last breakpoint location address that was marked for update. */
12169 CORE_ADDR last_addr
= 0;
12170 /* Last breakpoint location program space that was marked for update. */
12171 int last_pspace_num
= -1;
12173 /* Used in the duplicates detection below. When iterating over all
12174 bp_locations, points to the first bp_location of a given address.
12175 Breakpoints and watchpoints of different types are never
12176 duplicates of each other. Keep one pointer for each type of
12177 breakpoint/watchpoint, so we only need to loop over all locations
12179 struct bp_location
*bp_loc_first
; /* breakpoint */
12180 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12181 struct bp_location
*awp_loc_first
; /* access watchpoint */
12182 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12184 /* Saved former bp_locations array which we compare against the newly
12185 built bp_locations from the current state of ALL_BREAKPOINTS. */
12186 struct bp_location
**old_locations
, **old_locp
;
12187 unsigned old_locations_count
;
12189 old_locations
= bp_locations
;
12190 old_locations_count
= bp_locations_count
;
12191 bp_locations
= NULL
;
12192 bp_locations_count
= 0;
12193 cleanups
= make_cleanup (xfree
, old_locations
);
12195 ALL_BREAKPOINTS (b
)
12196 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12197 bp_locations_count
++;
12199 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12200 locp
= bp_locations
;
12201 ALL_BREAKPOINTS (b
)
12202 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12204 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12205 bp_locations_compare
);
12207 bp_locations_target_extensions_update ();
12209 /* Identify bp_location instances that are no longer present in the
12210 new list, and therefore should be freed. Note that it's not
12211 necessary that those locations should be removed from inferior --
12212 if there's another location at the same address (previously
12213 marked as duplicate), we don't need to remove/insert the
12216 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12217 and former bp_location array state respectively. */
12219 locp
= bp_locations
;
12220 for (old_locp
= old_locations
;
12221 old_locp
< old_locations
+ old_locations_count
;
12224 struct bp_location
*old_loc
= *old_locp
;
12225 struct bp_location
**loc2p
;
12227 /* Tells if 'old_loc' is found among the new locations. If
12228 not, we have to free it. */
12229 int found_object
= 0;
12230 /* Tells if the location should remain inserted in the target. */
12231 int keep_in_target
= 0;
12234 /* Skip LOCP entries which will definitely never be needed.
12235 Stop either at or being the one matching OLD_LOC. */
12236 while (locp
< bp_locations
+ bp_locations_count
12237 && (*locp
)->address
< old_loc
->address
)
12241 (loc2p
< bp_locations
+ bp_locations_count
12242 && (*loc2p
)->address
== old_loc
->address
);
12245 /* Check if this is a new/duplicated location or a duplicated
12246 location that had its condition modified. If so, we want to send
12247 its condition to the target if evaluation of conditions is taking
12249 if ((*loc2p
)->condition_changed
== condition_modified
12250 && (last_addr
!= old_loc
->address
12251 || last_pspace_num
!= old_loc
->pspace
->num
))
12253 force_breakpoint_reinsertion (*loc2p
);
12254 last_pspace_num
= old_loc
->pspace
->num
;
12257 if (*loc2p
== old_loc
)
12261 /* We have already handled this address, update it so that we don't
12262 have to go through updates again. */
12263 last_addr
= old_loc
->address
;
12265 /* Target-side condition evaluation: Handle deleted locations. */
12267 force_breakpoint_reinsertion (old_loc
);
12269 /* If this location is no longer present, and inserted, look if
12270 there's maybe a new location at the same address. If so,
12271 mark that one inserted, and don't remove this one. This is
12272 needed so that we don't have a time window where a breakpoint
12273 at certain location is not inserted. */
12275 if (old_loc
->inserted
)
12277 /* If the location is inserted now, we might have to remove
12280 if (found_object
&& should_be_inserted (old_loc
))
12282 /* The location is still present in the location list,
12283 and still should be inserted. Don't do anything. */
12284 keep_in_target
= 1;
12288 /* This location still exists, but it won't be kept in the
12289 target since it may have been disabled. We proceed to
12290 remove its target-side condition. */
12292 /* The location is either no longer present, or got
12293 disabled. See if there's another location at the
12294 same address, in which case we don't need to remove
12295 this one from the target. */
12297 /* OLD_LOC comes from existing struct breakpoint. */
12298 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12301 (loc2p
< bp_locations
+ bp_locations_count
12302 && (*loc2p
)->address
== old_loc
->address
);
12305 struct bp_location
*loc2
= *loc2p
;
12307 if (breakpoint_locations_match (loc2
, old_loc
))
12309 /* Read watchpoint locations are switched to
12310 access watchpoints, if the former are not
12311 supported, but the latter are. */
12312 if (is_hardware_watchpoint (old_loc
->owner
))
12314 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12315 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12318 /* loc2 is a duplicated location. We need to check
12319 if it should be inserted in case it will be
12321 if (loc2
!= old_loc
12322 && unduplicated_should_be_inserted (loc2
))
12324 swap_insertion (old_loc
, loc2
);
12325 keep_in_target
= 1;
12333 if (!keep_in_target
)
12335 if (remove_breakpoint (old_loc
))
12337 /* This is just about all we can do. We could keep
12338 this location on the global list, and try to
12339 remove it next time, but there's no particular
12340 reason why we will succeed next time.
12342 Note that at this point, old_loc->owner is still
12343 valid, as delete_breakpoint frees the breakpoint
12344 only after calling us. */
12345 printf_filtered (_("warning: Error removing "
12346 "breakpoint %d\n"),
12347 old_loc
->owner
->number
);
12355 if (removed
&& target_is_non_stop_p ()
12356 && need_moribund_for_location_type (old_loc
))
12358 /* This location was removed from the target. In
12359 non-stop mode, a race condition is possible where
12360 we've removed a breakpoint, but stop events for that
12361 breakpoint are already queued and will arrive later.
12362 We apply an heuristic to be able to distinguish such
12363 SIGTRAPs from other random SIGTRAPs: we keep this
12364 breakpoint location for a bit, and will retire it
12365 after we see some number of events. The theory here
12366 is that reporting of events should, "on the average",
12367 be fair, so after a while we'll see events from all
12368 threads that have anything of interest, and no longer
12369 need to keep this breakpoint location around. We
12370 don't hold locations forever so to reduce chances of
12371 mistaking a non-breakpoint SIGTRAP for a breakpoint
12374 The heuristic failing can be disastrous on
12375 decr_pc_after_break targets.
12377 On decr_pc_after_break targets, like e.g., x86-linux,
12378 if we fail to recognize a late breakpoint SIGTRAP,
12379 because events_till_retirement has reached 0 too
12380 soon, we'll fail to do the PC adjustment, and report
12381 a random SIGTRAP to the user. When the user resumes
12382 the inferior, it will most likely immediately crash
12383 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12384 corrupted, because of being resumed e.g., in the
12385 middle of a multi-byte instruction, or skipped a
12386 one-byte instruction. This was actually seen happen
12387 on native x86-linux, and should be less rare on
12388 targets that do not support new thread events, like
12389 remote, due to the heuristic depending on
12392 Mistaking a random SIGTRAP for a breakpoint trap
12393 causes similar symptoms (PC adjustment applied when
12394 it shouldn't), but then again, playing with SIGTRAPs
12395 behind the debugger's back is asking for trouble.
12397 Since hardware watchpoint traps are always
12398 distinguishable from other traps, so we don't need to
12399 apply keep hardware watchpoint moribund locations
12400 around. We simply always ignore hardware watchpoint
12401 traps we can no longer explain. */
12403 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12404 old_loc
->owner
= NULL
;
12406 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12410 old_loc
->owner
= NULL
;
12411 decref_bp_location (&old_loc
);
12416 /* Rescan breakpoints at the same address and section, marking the
12417 first one as "first" and any others as "duplicates". This is so
12418 that the bpt instruction is only inserted once. If we have a
12419 permanent breakpoint at the same place as BPT, make that one the
12420 official one, and the rest as duplicates. Permanent breakpoints
12421 are sorted first for the same address.
12423 Do the same for hardware watchpoints, but also considering the
12424 watchpoint's type (regular/access/read) and length. */
12426 bp_loc_first
= NULL
;
12427 wp_loc_first
= NULL
;
12428 awp_loc_first
= NULL
;
12429 rwp_loc_first
= NULL
;
12430 ALL_BP_LOCATIONS (loc
, locp
)
12432 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12434 struct bp_location
**loc_first_p
;
12437 if (!unduplicated_should_be_inserted (loc
)
12438 || !breakpoint_address_is_meaningful (b
)
12439 /* Don't detect duplicate for tracepoint locations because they are
12440 never duplicated. See the comments in field `duplicate' of
12441 `struct bp_location'. */
12442 || is_tracepoint (b
))
12444 /* Clear the condition modification flag. */
12445 loc
->condition_changed
= condition_unchanged
;
12449 if (b
->type
== bp_hardware_watchpoint
)
12450 loc_first_p
= &wp_loc_first
;
12451 else if (b
->type
== bp_read_watchpoint
)
12452 loc_first_p
= &rwp_loc_first
;
12453 else if (b
->type
== bp_access_watchpoint
)
12454 loc_first_p
= &awp_loc_first
;
12456 loc_first_p
= &bp_loc_first
;
12458 if (*loc_first_p
== NULL
12459 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12460 || !breakpoint_locations_match (loc
, *loc_first_p
))
12462 *loc_first_p
= loc
;
12463 loc
->duplicate
= 0;
12465 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12467 loc
->needs_update
= 1;
12468 /* Clear the condition modification flag. */
12469 loc
->condition_changed
= condition_unchanged
;
12475 /* This and the above ensure the invariant that the first location
12476 is not duplicated, and is the inserted one.
12477 All following are marked as duplicated, and are not inserted. */
12479 swap_insertion (loc
, *loc_first_p
);
12480 loc
->duplicate
= 1;
12482 /* Clear the condition modification flag. */
12483 loc
->condition_changed
= condition_unchanged
;
12486 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12488 if (insert_mode
!= UGLL_DONT_INSERT
)
12489 insert_breakpoint_locations ();
12492 /* Even though the caller told us to not insert new
12493 locations, we may still need to update conditions on the
12494 target's side of breakpoints that were already inserted
12495 if the target is evaluating breakpoint conditions. We
12496 only update conditions for locations that are marked
12498 update_inserted_breakpoint_locations ();
12502 if (insert_mode
!= UGLL_DONT_INSERT
)
12503 download_tracepoint_locations ();
12505 do_cleanups (cleanups
);
12509 breakpoint_retire_moribund (void)
12511 struct bp_location
*loc
;
12514 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12515 if (--(loc
->events_till_retirement
) == 0)
12517 decref_bp_location (&loc
);
12518 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12524 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12529 update_global_location_list (insert_mode
);
12531 CATCH (e
, RETURN_MASK_ERROR
)
12537 /* Clear BKP from a BPS. */
12540 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12544 for (bs
= bps
; bs
; bs
= bs
->next
)
12545 if (bs
->breakpoint_at
== bpt
)
12547 bs
->breakpoint_at
= NULL
;
12548 bs
->old_val
= NULL
;
12549 /* bs->commands will be freed later. */
12553 /* Callback for iterate_over_threads. */
12555 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12557 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12559 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12563 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12567 say_where (struct breakpoint
*b
)
12569 struct value_print_options opts
;
12571 get_user_print_options (&opts
);
12573 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12575 if (b
->loc
== NULL
)
12577 /* For pending locations, the output differs slightly based
12578 on b->extra_string. If this is non-NULL, it contains either
12579 a condition or dprintf arguments. */
12580 if (b
->extra_string
== NULL
)
12582 printf_filtered (_(" (%s) pending."),
12583 event_location_to_string (b
->location
.get ()));
12585 else if (b
->type
== bp_dprintf
)
12587 printf_filtered (_(" (%s,%s) pending."),
12588 event_location_to_string (b
->location
.get ()),
12593 printf_filtered (_(" (%s %s) pending."),
12594 event_location_to_string (b
->location
.get ()),
12600 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12602 printf_filtered (" at ");
12603 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12606 if (b
->loc
->symtab
!= NULL
)
12608 /* If there is a single location, we can print the location
12610 if (b
->loc
->next
== NULL
)
12611 printf_filtered (": file %s, line %d.",
12612 symtab_to_filename_for_display (b
->loc
->symtab
),
12613 b
->loc
->line_number
);
12615 /* This is not ideal, but each location may have a
12616 different file name, and this at least reflects the
12617 real situation somewhat. */
12618 printf_filtered (": %s.",
12619 event_location_to_string (b
->location
.get ()));
12624 struct bp_location
*loc
= b
->loc
;
12626 for (; loc
; loc
= loc
->next
)
12628 printf_filtered (" (%d locations)", n
);
12633 /* Default bp_location_ops methods. */
12636 bp_location_dtor (struct bp_location
*self
)
12638 xfree (self
->function_name
);
12641 static const struct bp_location_ops bp_location_ops
=
12646 /* Destructor for the breakpoint base class. */
12648 breakpoint::~breakpoint ()
12650 decref_counted_command_line (&this->commands
);
12651 xfree (this->cond_string
);
12652 xfree (this->extra_string
);
12653 xfree (this->filter
);
12656 static struct bp_location
*
12657 base_breakpoint_allocate_location (struct breakpoint
*self
)
12659 return new bp_location (&bp_location_ops
, self
);
12663 base_breakpoint_re_set (struct breakpoint
*b
)
12665 /* Nothing to re-set. */
12668 #define internal_error_pure_virtual_called() \
12669 gdb_assert_not_reached ("pure virtual function called")
12672 base_breakpoint_insert_location (struct bp_location
*bl
)
12674 internal_error_pure_virtual_called ();
12678 base_breakpoint_remove_location (struct bp_location
*bl
,
12679 enum remove_bp_reason reason
)
12681 internal_error_pure_virtual_called ();
12685 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12686 struct address_space
*aspace
,
12688 const struct target_waitstatus
*ws
)
12690 internal_error_pure_virtual_called ();
12694 base_breakpoint_check_status (bpstat bs
)
12699 /* A "works_in_software_mode" breakpoint_ops method that just internal
12703 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12705 internal_error_pure_virtual_called ();
12708 /* A "resources_needed" breakpoint_ops method that just internal
12712 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12714 internal_error_pure_virtual_called ();
12717 static enum print_stop_action
12718 base_breakpoint_print_it (bpstat bs
)
12720 internal_error_pure_virtual_called ();
12724 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12725 struct ui_out
*uiout
)
12731 base_breakpoint_print_mention (struct breakpoint
*b
)
12733 internal_error_pure_virtual_called ();
12737 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12739 internal_error_pure_virtual_called ();
12743 base_breakpoint_create_sals_from_location
12744 (const struct event_location
*location
,
12745 struct linespec_result
*canonical
,
12746 enum bptype type_wanted
)
12748 internal_error_pure_virtual_called ();
12752 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12753 struct linespec_result
*c
,
12754 gdb::unique_xmalloc_ptr
<char> cond_string
,
12755 gdb::unique_xmalloc_ptr
<char> extra_string
,
12756 enum bptype type_wanted
,
12757 enum bpdisp disposition
,
12759 int task
, int ignore_count
,
12760 const struct breakpoint_ops
*o
,
12761 int from_tty
, int enabled
,
12762 int internal
, unsigned flags
)
12764 internal_error_pure_virtual_called ();
12767 static std::vector
<symtab_and_line
>
12768 base_breakpoint_decode_location (struct breakpoint
*b
,
12769 const struct event_location
*location
,
12770 struct program_space
*search_pspace
)
12772 internal_error_pure_virtual_called ();
12775 /* The default 'explains_signal' method. */
12778 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12783 /* The default "after_condition_true" method. */
12786 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12788 /* Nothing to do. */
12791 struct breakpoint_ops base_breakpoint_ops
=
12793 base_breakpoint_allocate_location
,
12794 base_breakpoint_re_set
,
12795 base_breakpoint_insert_location
,
12796 base_breakpoint_remove_location
,
12797 base_breakpoint_breakpoint_hit
,
12798 base_breakpoint_check_status
,
12799 base_breakpoint_resources_needed
,
12800 base_breakpoint_works_in_software_mode
,
12801 base_breakpoint_print_it
,
12803 base_breakpoint_print_one_detail
,
12804 base_breakpoint_print_mention
,
12805 base_breakpoint_print_recreate
,
12806 base_breakpoint_create_sals_from_location
,
12807 base_breakpoint_create_breakpoints_sal
,
12808 base_breakpoint_decode_location
,
12809 base_breakpoint_explains_signal
,
12810 base_breakpoint_after_condition_true
,
12813 /* Default breakpoint_ops methods. */
12816 bkpt_re_set (struct breakpoint
*b
)
12818 /* FIXME: is this still reachable? */
12819 if (breakpoint_event_location_empty_p (b
))
12821 /* Anything without a location can't be re-set. */
12822 delete_breakpoint (b
);
12826 breakpoint_re_set_default (b
);
12830 bkpt_insert_location (struct bp_location
*bl
)
12832 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12834 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12835 bl
->target_info
.placed_address
= addr
;
12837 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12838 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12840 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12844 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12846 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12847 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12849 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12853 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12854 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12855 const struct target_waitstatus
*ws
)
12857 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12858 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12861 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12865 if (overlay_debugging
/* unmapped overlay section */
12866 && section_is_overlay (bl
->section
)
12867 && !section_is_mapped (bl
->section
))
12874 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12875 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12876 const struct target_waitstatus
*ws
)
12878 if (dprintf_style
== dprintf_style_agent
12879 && target_can_run_breakpoint_commands ())
12881 /* An agent-style dprintf never causes a stop. If we see a trap
12882 for this address it must be for a breakpoint that happens to
12883 be set at the same address. */
12887 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12891 bkpt_resources_needed (const struct bp_location
*bl
)
12893 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12898 static enum print_stop_action
12899 bkpt_print_it (bpstat bs
)
12901 struct breakpoint
*b
;
12902 const struct bp_location
*bl
;
12904 struct ui_out
*uiout
= current_uiout
;
12906 gdb_assert (bs
->bp_location_at
!= NULL
);
12908 bl
= bs
->bp_location_at
;
12909 b
= bs
->breakpoint_at
;
12911 bp_temp
= b
->disposition
== disp_del
;
12912 if (bl
->address
!= bl
->requested_address
)
12913 breakpoint_adjustment_warning (bl
->requested_address
,
12916 annotate_breakpoint (b
->number
);
12917 maybe_print_thread_hit_breakpoint (uiout
);
12920 uiout
->text ("Temporary breakpoint ");
12922 uiout
->text ("Breakpoint ");
12923 if (uiout
->is_mi_like_p ())
12925 uiout
->field_string ("reason",
12926 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12927 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12929 uiout
->field_int ("bkptno", b
->number
);
12930 uiout
->text (", ");
12932 return PRINT_SRC_AND_LOC
;
12936 bkpt_print_mention (struct breakpoint
*b
)
12938 if (current_uiout
->is_mi_like_p ())
12943 case bp_breakpoint
:
12944 case bp_gnu_ifunc_resolver
:
12945 if (b
->disposition
== disp_del
)
12946 printf_filtered (_("Temporary breakpoint"));
12948 printf_filtered (_("Breakpoint"));
12949 printf_filtered (_(" %d"), b
->number
);
12950 if (b
->type
== bp_gnu_ifunc_resolver
)
12951 printf_filtered (_(" at gnu-indirect-function resolver"));
12953 case bp_hardware_breakpoint
:
12954 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12957 printf_filtered (_("Dprintf %d"), b
->number
);
12965 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12967 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12968 fprintf_unfiltered (fp
, "tbreak");
12969 else if (tp
->type
== bp_breakpoint
)
12970 fprintf_unfiltered (fp
, "break");
12971 else if (tp
->type
== bp_hardware_breakpoint
12972 && tp
->disposition
== disp_del
)
12973 fprintf_unfiltered (fp
, "thbreak");
12974 else if (tp
->type
== bp_hardware_breakpoint
)
12975 fprintf_unfiltered (fp
, "hbreak");
12977 internal_error (__FILE__
, __LINE__
,
12978 _("unhandled breakpoint type %d"), (int) tp
->type
);
12980 fprintf_unfiltered (fp
, " %s",
12981 event_location_to_string (tp
->location
.get ()));
12983 /* Print out extra_string if this breakpoint is pending. It might
12984 contain, for example, conditions that were set by the user. */
12985 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12986 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12988 print_recreate_thread (tp
, fp
);
12992 bkpt_create_sals_from_location (const struct event_location
*location
,
12993 struct linespec_result
*canonical
,
12994 enum bptype type_wanted
)
12996 create_sals_from_location_default (location
, canonical
, type_wanted
);
13000 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13001 struct linespec_result
*canonical
,
13002 gdb::unique_xmalloc_ptr
<char> cond_string
,
13003 gdb::unique_xmalloc_ptr
<char> extra_string
,
13004 enum bptype type_wanted
,
13005 enum bpdisp disposition
,
13007 int task
, int ignore_count
,
13008 const struct breakpoint_ops
*ops
,
13009 int from_tty
, int enabled
,
13010 int internal
, unsigned flags
)
13012 create_breakpoints_sal_default (gdbarch
, canonical
,
13013 std::move (cond_string
),
13014 std::move (extra_string
),
13016 disposition
, thread
, task
,
13017 ignore_count
, ops
, from_tty
,
13018 enabled
, internal
, flags
);
13021 static std::vector
<symtab_and_line
>
13022 bkpt_decode_location (struct breakpoint
*b
,
13023 const struct event_location
*location
,
13024 struct program_space
*search_pspace
)
13026 return decode_location_default (b
, location
, search_pspace
);
13029 /* Virtual table for internal breakpoints. */
13032 internal_bkpt_re_set (struct breakpoint
*b
)
13036 /* Delete overlay event and longjmp master breakpoints; they
13037 will be reset later by breakpoint_re_set. */
13038 case bp_overlay_event
:
13039 case bp_longjmp_master
:
13040 case bp_std_terminate_master
:
13041 case bp_exception_master
:
13042 delete_breakpoint (b
);
13045 /* This breakpoint is special, it's set up when the inferior
13046 starts and we really don't want to touch it. */
13047 case bp_shlib_event
:
13049 /* Like bp_shlib_event, this breakpoint type is special. Once
13050 it is set up, we do not want to touch it. */
13051 case bp_thread_event
:
13057 internal_bkpt_check_status (bpstat bs
)
13059 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13061 /* If requested, stop when the dynamic linker notifies GDB of
13062 events. This allows the user to get control and place
13063 breakpoints in initializer routines for dynamically loaded
13064 objects (among other things). */
13065 bs
->stop
= stop_on_solib_events
;
13066 bs
->print
= stop_on_solib_events
;
13072 static enum print_stop_action
13073 internal_bkpt_print_it (bpstat bs
)
13075 struct breakpoint
*b
;
13077 b
= bs
->breakpoint_at
;
13081 case bp_shlib_event
:
13082 /* Did we stop because the user set the stop_on_solib_events
13083 variable? (If so, we report this as a generic, "Stopped due
13084 to shlib event" message.) */
13085 print_solib_event (0);
13088 case bp_thread_event
:
13089 /* Not sure how we will get here.
13090 GDB should not stop for these breakpoints. */
13091 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13094 case bp_overlay_event
:
13095 /* By analogy with the thread event, GDB should not stop for these. */
13096 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13099 case bp_longjmp_master
:
13100 /* These should never be enabled. */
13101 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13104 case bp_std_terminate_master
:
13105 /* These should never be enabled. */
13106 printf_filtered (_("std::terminate Master Breakpoint: "
13107 "gdb should not stop!\n"));
13110 case bp_exception_master
:
13111 /* These should never be enabled. */
13112 printf_filtered (_("Exception Master Breakpoint: "
13113 "gdb should not stop!\n"));
13117 return PRINT_NOTHING
;
13121 internal_bkpt_print_mention (struct breakpoint
*b
)
13123 /* Nothing to mention. These breakpoints are internal. */
13126 /* Virtual table for momentary breakpoints */
13129 momentary_bkpt_re_set (struct breakpoint
*b
)
13131 /* Keep temporary breakpoints, which can be encountered when we step
13132 over a dlopen call and solib_add is resetting the breakpoints.
13133 Otherwise these should have been blown away via the cleanup chain
13134 or by breakpoint_init_inferior when we rerun the executable. */
13138 momentary_bkpt_check_status (bpstat bs
)
13140 /* Nothing. The point of these breakpoints is causing a stop. */
13143 static enum print_stop_action
13144 momentary_bkpt_print_it (bpstat bs
)
13146 return PRINT_UNKNOWN
;
13150 momentary_bkpt_print_mention (struct breakpoint
*b
)
13152 /* Nothing to mention. These breakpoints are internal. */
13155 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13157 It gets cleared already on the removal of the first one of such placed
13158 breakpoints. This is OK as they get all removed altogether. */
13160 longjmp_breakpoint::~longjmp_breakpoint ()
13162 thread_info
*tp
= find_thread_global_id (this->thread
);
13165 tp
->initiating_frame
= null_frame_id
;
13168 /* Specific methods for probe breakpoints. */
13171 bkpt_probe_insert_location (struct bp_location
*bl
)
13173 int v
= bkpt_insert_location (bl
);
13177 /* The insertion was successful, now let's set the probe's semaphore
13179 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13180 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13189 bkpt_probe_remove_location (struct bp_location
*bl
,
13190 enum remove_bp_reason reason
)
13192 /* Let's clear the semaphore before removing the location. */
13193 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13194 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13198 return bkpt_remove_location (bl
, reason
);
13202 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13203 struct linespec_result
*canonical
,
13204 enum bptype type_wanted
)
13206 struct linespec_sals lsal
;
13208 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13210 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13211 canonical
->lsals
.push_back (std::move (lsal
));
13214 static std::vector
<symtab_and_line
>
13215 bkpt_probe_decode_location (struct breakpoint
*b
,
13216 const struct event_location
*location
,
13217 struct program_space
*search_pspace
)
13219 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
13221 error (_("probe not found"));
13225 /* The breakpoint_ops structure to be used in tracepoints. */
13228 tracepoint_re_set (struct breakpoint
*b
)
13230 breakpoint_re_set_default (b
);
13234 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13235 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13236 const struct target_waitstatus
*ws
)
13238 /* By definition, the inferior does not report stops at
13244 tracepoint_print_one_detail (const struct breakpoint
*self
,
13245 struct ui_out
*uiout
)
13247 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13248 if (tp
->static_trace_marker_id
)
13250 gdb_assert (self
->type
== bp_static_tracepoint
);
13252 uiout
->text ("\tmarker id is ");
13253 uiout
->field_string ("static-tracepoint-marker-string-id",
13254 tp
->static_trace_marker_id
);
13255 uiout
->text ("\n");
13260 tracepoint_print_mention (struct breakpoint
*b
)
13262 if (current_uiout
->is_mi_like_p ())
13267 case bp_tracepoint
:
13268 printf_filtered (_("Tracepoint"));
13269 printf_filtered (_(" %d"), b
->number
);
13271 case bp_fast_tracepoint
:
13272 printf_filtered (_("Fast tracepoint"));
13273 printf_filtered (_(" %d"), b
->number
);
13275 case bp_static_tracepoint
:
13276 printf_filtered (_("Static tracepoint"));
13277 printf_filtered (_(" %d"), b
->number
);
13280 internal_error (__FILE__
, __LINE__
,
13281 _("unhandled tracepoint type %d"), (int) b
->type
);
13288 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13290 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13292 if (self
->type
== bp_fast_tracepoint
)
13293 fprintf_unfiltered (fp
, "ftrace");
13294 else if (self
->type
== bp_static_tracepoint
)
13295 fprintf_unfiltered (fp
, "strace");
13296 else if (self
->type
== bp_tracepoint
)
13297 fprintf_unfiltered (fp
, "trace");
13299 internal_error (__FILE__
, __LINE__
,
13300 _("unhandled tracepoint type %d"), (int) self
->type
);
13302 fprintf_unfiltered (fp
, " %s",
13303 event_location_to_string (self
->location
.get ()));
13304 print_recreate_thread (self
, fp
);
13306 if (tp
->pass_count
)
13307 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13311 tracepoint_create_sals_from_location (const struct event_location
*location
,
13312 struct linespec_result
*canonical
,
13313 enum bptype type_wanted
)
13315 create_sals_from_location_default (location
, canonical
, type_wanted
);
13319 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13320 struct linespec_result
*canonical
,
13321 gdb::unique_xmalloc_ptr
<char> cond_string
,
13322 gdb::unique_xmalloc_ptr
<char> extra_string
,
13323 enum bptype type_wanted
,
13324 enum bpdisp disposition
,
13326 int task
, int ignore_count
,
13327 const struct breakpoint_ops
*ops
,
13328 int from_tty
, int enabled
,
13329 int internal
, unsigned flags
)
13331 create_breakpoints_sal_default (gdbarch
, canonical
,
13332 std::move (cond_string
),
13333 std::move (extra_string
),
13335 disposition
, thread
, task
,
13336 ignore_count
, ops
, from_tty
,
13337 enabled
, internal
, flags
);
13340 static std::vector
<symtab_and_line
>
13341 tracepoint_decode_location (struct breakpoint
*b
,
13342 const struct event_location
*location
,
13343 struct program_space
*search_pspace
)
13345 return decode_location_default (b
, location
, search_pspace
);
13348 struct breakpoint_ops tracepoint_breakpoint_ops
;
13350 /* The breakpoint_ops structure to be use on tracepoints placed in a
13354 tracepoint_probe_create_sals_from_location
13355 (const struct event_location
*location
,
13356 struct linespec_result
*canonical
,
13357 enum bptype type_wanted
)
13359 /* We use the same method for breakpoint on probes. */
13360 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13363 static std::vector
<symtab_and_line
>
13364 tracepoint_probe_decode_location (struct breakpoint
*b
,
13365 const struct event_location
*location
,
13366 struct program_space
*search_pspace
)
13368 /* We use the same method for breakpoint on probes. */
13369 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13372 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13374 /* Dprintf breakpoint_ops methods. */
13377 dprintf_re_set (struct breakpoint
*b
)
13379 breakpoint_re_set_default (b
);
13381 /* extra_string should never be non-NULL for dprintf. */
13382 gdb_assert (b
->extra_string
!= NULL
);
13384 /* 1 - connect to target 1, that can run breakpoint commands.
13385 2 - create a dprintf, which resolves fine.
13386 3 - disconnect from target 1
13387 4 - connect to target 2, that can NOT run breakpoint commands.
13389 After steps #3/#4, you'll want the dprintf command list to
13390 be updated, because target 1 and 2 may well return different
13391 answers for target_can_run_breakpoint_commands().
13392 Given absence of finer grained resetting, we get to do
13393 it all the time. */
13394 if (b
->extra_string
!= NULL
)
13395 update_dprintf_command_list (b
);
13398 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13401 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13403 fprintf_unfiltered (fp
, "dprintf %s,%s",
13404 event_location_to_string (tp
->location
.get ()),
13406 print_recreate_thread (tp
, fp
);
13409 /* Implement the "after_condition_true" breakpoint_ops method for
13412 dprintf's are implemented with regular commands in their command
13413 list, but we run the commands here instead of before presenting the
13414 stop to the user, as dprintf's don't actually cause a stop. This
13415 also makes it so that the commands of multiple dprintfs at the same
13416 address are all handled. */
13419 dprintf_after_condition_true (struct bpstats
*bs
)
13421 struct cleanup
*old_chain
;
13422 struct bpstats tmp_bs
= { NULL
};
13423 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13425 /* dprintf's never cause a stop. This wasn't set in the
13426 check_status hook instead because that would make the dprintf's
13427 condition not be evaluated. */
13430 /* Run the command list here. Take ownership of it instead of
13431 copying. We never want these commands to run later in
13432 bpstat_do_actions, if a breakpoint that causes a stop happens to
13433 be set at same address as this dprintf, or even if running the
13434 commands here throws. */
13435 tmp_bs
.commands
= bs
->commands
;
13436 bs
->commands
= NULL
;
13437 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13439 bpstat_do_actions_1 (&tmp_bs_p
);
13441 /* 'tmp_bs.commands' will usually be NULL by now, but
13442 bpstat_do_actions_1 may return early without processing the whole
13444 do_cleanups (old_chain
);
13447 /* The breakpoint_ops structure to be used on static tracepoints with
13451 strace_marker_create_sals_from_location (const struct event_location
*location
,
13452 struct linespec_result
*canonical
,
13453 enum bptype type_wanted
)
13455 struct linespec_sals lsal
;
13456 const char *arg_start
, *arg
;
13458 struct cleanup
*cleanup
;
13460 arg
= arg_start
= get_linespec_location (location
);
13461 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13463 str
= savestring (arg_start
, arg
- arg_start
);
13464 cleanup
= make_cleanup (xfree
, str
);
13465 canonical
->location
= new_linespec_location (&str
);
13466 do_cleanups (cleanup
);
13469 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13470 canonical
->lsals
.push_back (std::move (lsal
));
13474 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13475 struct linespec_result
*canonical
,
13476 gdb::unique_xmalloc_ptr
<char> cond_string
,
13477 gdb::unique_xmalloc_ptr
<char> extra_string
,
13478 enum bptype type_wanted
,
13479 enum bpdisp disposition
,
13481 int task
, int ignore_count
,
13482 const struct breakpoint_ops
*ops
,
13483 int from_tty
, int enabled
,
13484 int internal
, unsigned flags
)
13486 const linespec_sals
&lsal
= canonical
->lsals
[0];
13488 /* If the user is creating a static tracepoint by marker id
13489 (strace -m MARKER_ID), then store the sals index, so that
13490 breakpoint_re_set can try to match up which of the newly
13491 found markers corresponds to this one, and, don't try to
13492 expand multiple locations for each sal, given than SALS
13493 already should contain all sals for MARKER_ID. */
13495 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13497 event_location_up location
13498 = copy_event_location (canonical
->location
.get ());
13500 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13501 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13502 std::move (location
), NULL
,
13503 std::move (cond_string
),
13504 std::move (extra_string
),
13505 type_wanted
, disposition
,
13506 thread
, task
, ignore_count
, ops
,
13507 from_tty
, enabled
, internal
, flags
,
13508 canonical
->special_display
);
13509 /* Given that its possible to have multiple markers with
13510 the same string id, if the user is creating a static
13511 tracepoint by marker id ("strace -m MARKER_ID"), then
13512 store the sals index, so that breakpoint_re_set can
13513 try to match up which of the newly found markers
13514 corresponds to this one */
13515 tp
->static_trace_marker_id_idx
= i
;
13517 install_breakpoint (internal
, std::move (tp
), 0);
13521 static std::vector
<symtab_and_line
>
13522 strace_marker_decode_location (struct breakpoint
*b
,
13523 const struct event_location
*location
,
13524 struct program_space
*search_pspace
)
13526 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13527 const char *s
= get_linespec_location (location
);
13529 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13530 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13532 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13537 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13540 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13543 strace_marker_p (struct breakpoint
*b
)
13545 return b
->ops
== &strace_marker_breakpoint_ops
;
13548 /* Delete a breakpoint and clean up all traces of it in the data
13552 delete_breakpoint (struct breakpoint
*bpt
)
13554 struct breakpoint
*b
;
13556 gdb_assert (bpt
!= NULL
);
13558 /* Has this bp already been deleted? This can happen because
13559 multiple lists can hold pointers to bp's. bpstat lists are
13562 One example of this happening is a watchpoint's scope bp. When
13563 the scope bp triggers, we notice that the watchpoint is out of
13564 scope, and delete it. We also delete its scope bp. But the
13565 scope bp is marked "auto-deleting", and is already on a bpstat.
13566 That bpstat is then checked for auto-deleting bp's, which are
13569 A real solution to this problem might involve reference counts in
13570 bp's, and/or giving them pointers back to their referencing
13571 bpstat's, and teaching delete_breakpoint to only free a bp's
13572 storage when no more references were extent. A cheaper bandaid
13574 if (bpt
->type
== bp_none
)
13577 /* At least avoid this stale reference until the reference counting
13578 of breakpoints gets resolved. */
13579 if (bpt
->related_breakpoint
!= bpt
)
13581 struct breakpoint
*related
;
13582 struct watchpoint
*w
;
13584 if (bpt
->type
== bp_watchpoint_scope
)
13585 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13586 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13587 w
= (struct watchpoint
*) bpt
;
13591 watchpoint_del_at_next_stop (w
);
13593 /* Unlink bpt from the bpt->related_breakpoint ring. */
13594 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13595 related
= related
->related_breakpoint
);
13596 related
->related_breakpoint
= bpt
->related_breakpoint
;
13597 bpt
->related_breakpoint
= bpt
;
13600 /* watch_command_1 creates a watchpoint but only sets its number if
13601 update_watchpoint succeeds in creating its bp_locations. If there's
13602 a problem in that process, we'll be asked to delete the half-created
13603 watchpoint. In that case, don't announce the deletion. */
13605 observer_notify_breakpoint_deleted (bpt
);
13607 if (breakpoint_chain
== bpt
)
13608 breakpoint_chain
= bpt
->next
;
13610 ALL_BREAKPOINTS (b
)
13611 if (b
->next
== bpt
)
13613 b
->next
= bpt
->next
;
13617 /* Be sure no bpstat's are pointing at the breakpoint after it's
13619 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13620 in all threads for now. Note that we cannot just remove bpstats
13621 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13622 commands are associated with the bpstat; if we remove it here,
13623 then the later call to bpstat_do_actions (&stop_bpstat); in
13624 event-top.c won't do anything, and temporary breakpoints with
13625 commands won't work. */
13627 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13629 /* Now that breakpoint is removed from breakpoint list, update the
13630 global location list. This will remove locations that used to
13631 belong to this breakpoint. Do this before freeing the breakpoint
13632 itself, since remove_breakpoint looks at location's owner. It
13633 might be better design to have location completely
13634 self-contained, but it's not the case now. */
13635 update_global_location_list (UGLL_DONT_INSERT
);
13637 /* On the chance that someone will soon try again to delete this
13638 same bp, we mark it as deleted before freeing its storage. */
13639 bpt
->type
= bp_none
;
13644 do_delete_breakpoint_cleanup (void *b
)
13646 delete_breakpoint ((struct breakpoint
*) b
);
13650 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13652 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13655 /* Iterator function to call a user-provided callback function once
13656 for each of B and its related breakpoints. */
13659 iterate_over_related_breakpoints (struct breakpoint
*b
,
13660 void (*function
) (struct breakpoint
*,
13664 struct breakpoint
*related
;
13669 struct breakpoint
*next
;
13671 /* FUNCTION may delete RELATED. */
13672 next
= related
->related_breakpoint
;
13674 if (next
== related
)
13676 /* RELATED is the last ring entry. */
13677 function (related
, data
);
13679 /* FUNCTION may have deleted it, so we'd never reach back to
13680 B. There's nothing left to do anyway, so just break
13685 function (related
, data
);
13689 while (related
!= b
);
13693 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13695 delete_breakpoint (b
);
13698 /* A callback for map_breakpoint_numbers that calls
13699 delete_breakpoint. */
13702 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13704 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13708 delete_command (char *arg
, int from_tty
)
13710 struct breakpoint
*b
, *b_tmp
;
13716 int breaks_to_delete
= 0;
13718 /* Delete all breakpoints if no argument. Do not delete
13719 internal breakpoints, these have to be deleted with an
13720 explicit breakpoint number argument. */
13721 ALL_BREAKPOINTS (b
)
13722 if (user_breakpoint_p (b
))
13724 breaks_to_delete
= 1;
13728 /* Ask user only if there are some breakpoints to delete. */
13730 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13732 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13733 if (user_breakpoint_p (b
))
13734 delete_breakpoint (b
);
13738 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13741 /* Return true if all locations of B bound to PSPACE are pending. If
13742 PSPACE is NULL, all locations of all program spaces are
13746 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13748 struct bp_location
*loc
;
13750 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13751 if ((pspace
== NULL
13752 || loc
->pspace
== pspace
)
13753 && !loc
->shlib_disabled
13754 && !loc
->pspace
->executing_startup
)
13759 /* Subroutine of update_breakpoint_locations to simplify it.
13760 Return non-zero if multiple fns in list LOC have the same name.
13761 Null names are ignored. */
13764 ambiguous_names_p (struct bp_location
*loc
)
13766 struct bp_location
*l
;
13767 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13768 (int (*) (const void *,
13769 const void *)) streq
,
13770 NULL
, xcalloc
, xfree
);
13772 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13775 const char *name
= l
->function_name
;
13777 /* Allow for some names to be NULL, ignore them. */
13781 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13783 /* NOTE: We can assume slot != NULL here because xcalloc never
13787 htab_delete (htab
);
13793 htab_delete (htab
);
13797 /* When symbols change, it probably means the sources changed as well,
13798 and it might mean the static tracepoint markers are no longer at
13799 the same address or line numbers they used to be at last we
13800 checked. Losing your static tracepoints whenever you rebuild is
13801 undesirable. This function tries to resync/rematch gdb static
13802 tracepoints with the markers on the target, for static tracepoints
13803 that have not been set by marker id. Static tracepoint that have
13804 been set by marker id are reset by marker id in breakpoint_re_set.
13807 1) For a tracepoint set at a specific address, look for a marker at
13808 the old PC. If one is found there, assume to be the same marker.
13809 If the name / string id of the marker found is different from the
13810 previous known name, assume that means the user renamed the marker
13811 in the sources, and output a warning.
13813 2) For a tracepoint set at a given line number, look for a marker
13814 at the new address of the old line number. If one is found there,
13815 assume to be the same marker. If the name / string id of the
13816 marker found is different from the previous known name, assume that
13817 means the user renamed the marker in the sources, and output a
13820 3) If a marker is no longer found at the same address or line, it
13821 may mean the marker no longer exists. But it may also just mean
13822 the code changed a bit. Maybe the user added a few lines of code
13823 that made the marker move up or down (in line number terms). Ask
13824 the target for info about the marker with the string id as we knew
13825 it. If found, update line number and address in the matching
13826 static tracepoint. This will get confused if there's more than one
13827 marker with the same ID (possible in UST, although unadvised
13828 precisely because it confuses tools). */
13830 static struct symtab_and_line
13831 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13833 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13834 struct static_tracepoint_marker marker
;
13839 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13841 if (target_static_tracepoint_marker_at (pc
, &marker
))
13843 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13844 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13846 tp
->static_trace_marker_id
, marker
.str_id
);
13848 xfree (tp
->static_trace_marker_id
);
13849 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13850 release_static_tracepoint_marker (&marker
);
13855 /* Old marker wasn't found on target at lineno. Try looking it up
13857 if (!sal
.explicit_pc
13859 && sal
.symtab
!= NULL
13860 && tp
->static_trace_marker_id
!= NULL
)
13862 VEC(static_tracepoint_marker_p
) *markers
;
13865 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13867 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13869 struct symbol
*sym
;
13870 struct static_tracepoint_marker
*tpmarker
;
13871 struct ui_out
*uiout
= current_uiout
;
13872 struct explicit_location explicit_loc
;
13874 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13876 xfree (tp
->static_trace_marker_id
);
13877 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13879 warning (_("marker for static tracepoint %d (%s) not "
13880 "found at previous line number"),
13881 b
->number
, tp
->static_trace_marker_id
);
13883 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13884 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13885 uiout
->text ("Now in ");
13888 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13889 uiout
->text (" at ");
13891 uiout
->field_string ("file",
13892 symtab_to_filename_for_display (sal2
.symtab
));
13895 if (uiout
->is_mi_like_p ())
13897 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13899 uiout
->field_string ("fullname", fullname
);
13902 uiout
->field_int ("line", sal2
.line
);
13903 uiout
->text ("\n");
13905 b
->loc
->line_number
= sal2
.line
;
13906 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13908 b
->location
.reset (NULL
);
13909 initialize_explicit_location (&explicit_loc
);
13910 explicit_loc
.source_filename
13911 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13912 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13913 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13914 b
->location
= new_explicit_location (&explicit_loc
);
13916 /* Might be nice to check if function changed, and warn if
13919 release_static_tracepoint_marker (tpmarker
);
13925 /* Returns 1 iff locations A and B are sufficiently same that
13926 we don't need to report breakpoint as changed. */
13929 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13933 if (a
->address
!= b
->address
)
13936 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13939 if (a
->enabled
!= b
->enabled
)
13946 if ((a
== NULL
) != (b
== NULL
))
13952 /* Split all locations of B that are bound to PSPACE out of B's
13953 location list to a separate list and return that list's head. If
13954 PSPACE is NULL, hoist out all locations of B. */
13956 static struct bp_location
*
13957 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13959 struct bp_location head
;
13960 struct bp_location
*i
= b
->loc
;
13961 struct bp_location
**i_link
= &b
->loc
;
13962 struct bp_location
*hoisted
= &head
;
13964 if (pspace
== NULL
)
13975 if (i
->pspace
== pspace
)
13990 /* Create new breakpoint locations for B (a hardware or software
13991 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13992 zero, then B is a ranged breakpoint. Only recreates locations for
13993 FILTER_PSPACE. Locations of other program spaces are left
13997 update_breakpoint_locations (struct breakpoint
*b
,
13998 struct program_space
*filter_pspace
,
13999 gdb::array_view
<const symtab_and_line
> sals
,
14000 gdb::array_view
<const symtab_and_line
> sals_end
)
14003 struct bp_location
*existing_locations
;
14005 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
14007 /* Ranged breakpoints have only one start location and one end
14009 b
->enable_state
= bp_disabled
;
14010 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14011 "multiple locations found\n"),
14016 /* If there's no new locations, and all existing locations are
14017 pending, don't do anything. This optimizes the common case where
14018 all locations are in the same shared library, that was unloaded.
14019 We'd like to retain the location, so that when the library is
14020 loaded again, we don't loose the enabled/disabled status of the
14021 individual locations. */
14022 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
14025 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14027 for (const auto &sal
: sals
)
14029 struct bp_location
*new_loc
;
14031 switch_to_program_space_and_thread (sal
.pspace
);
14033 new_loc
= add_location_to_breakpoint (b
, &sal
);
14035 /* Reparse conditions, they might contain references to the
14037 if (b
->cond_string
!= NULL
)
14041 s
= b
->cond_string
;
14044 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
14045 block_for_pc (sal
.pc
),
14048 CATCH (e
, RETURN_MASK_ERROR
)
14050 warning (_("failed to reevaluate condition "
14051 "for breakpoint %d: %s"),
14052 b
->number
, e
.message
);
14053 new_loc
->enabled
= 0;
14058 if (!sals_end
.empty ())
14060 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
14062 new_loc
->length
= end
- sals
[0].pc
+ 1;
14066 /* If possible, carry over 'disable' status from existing
14069 struct bp_location
*e
= existing_locations
;
14070 /* If there are multiple breakpoints with the same function name,
14071 e.g. for inline functions, comparing function names won't work.
14072 Instead compare pc addresses; this is just a heuristic as things
14073 may have moved, but in practice it gives the correct answer
14074 often enough until a better solution is found. */
14075 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14077 for (; e
; e
= e
->next
)
14079 if (!e
->enabled
&& e
->function_name
)
14081 struct bp_location
*l
= b
->loc
;
14082 if (have_ambiguous_names
)
14084 for (; l
; l
= l
->next
)
14085 if (breakpoint_locations_match (e
, l
))
14093 for (; l
; l
= l
->next
)
14094 if (l
->function_name
14095 && strcmp (e
->function_name
, l
->function_name
) == 0)
14105 if (!locations_are_equal (existing_locations
, b
->loc
))
14106 observer_notify_breakpoint_modified (b
);
14109 /* Find the SaL locations corresponding to the given LOCATION.
14110 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14112 static std::vector
<symtab_and_line
>
14113 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14114 struct program_space
*search_pspace
, int *found
)
14116 struct gdb_exception exception
= exception_none
;
14118 gdb_assert (b
->ops
!= NULL
);
14120 std::vector
<symtab_and_line
> sals
;
14124 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
14126 CATCH (e
, RETURN_MASK_ERROR
)
14128 int not_found_and_ok
= 0;
14132 /* For pending breakpoints, it's expected that parsing will
14133 fail until the right shared library is loaded. User has
14134 already told to create pending breakpoints and don't need
14135 extra messages. If breakpoint is in bp_shlib_disabled
14136 state, then user already saw the message about that
14137 breakpoint being disabled, and don't want to see more
14139 if (e
.error
== NOT_FOUND_ERROR
14140 && (b
->condition_not_parsed
14142 && search_pspace
!= NULL
14143 && b
->loc
->pspace
!= search_pspace
)
14144 || (b
->loc
&& b
->loc
->shlib_disabled
)
14145 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14146 || b
->enable_state
== bp_disabled
))
14147 not_found_and_ok
= 1;
14149 if (!not_found_and_ok
)
14151 /* We surely don't want to warn about the same breakpoint
14152 10 times. One solution, implemented here, is disable
14153 the breakpoint on error. Another solution would be to
14154 have separate 'warning emitted' flag. Since this
14155 happens only when a binary has changed, I don't know
14156 which approach is better. */
14157 b
->enable_state
= bp_disabled
;
14158 throw_exception (e
);
14163 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14165 for (auto &sal
: sals
)
14166 resolve_sal_pc (&sal
);
14167 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14169 char *cond_string
, *extra_string
;
14172 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
14173 &cond_string
, &thread
, &task
,
14175 gdb_assert (b
->cond_string
== NULL
);
14177 b
->cond_string
= cond_string
;
14178 b
->thread
= thread
;
14182 xfree (b
->extra_string
);
14183 b
->extra_string
= extra_string
;
14185 b
->condition_not_parsed
= 0;
14188 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14189 sals
[0] = update_static_tracepoint (b
, sals
[0]);
14199 /* The default re_set method, for typical hardware or software
14200 breakpoints. Reevaluate the breakpoint and recreate its
14204 breakpoint_re_set_default (struct breakpoint
*b
)
14206 struct program_space
*filter_pspace
= current_program_space
;
14207 std::vector
<symtab_and_line
> expanded
, expanded_end
;
14210 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
14211 filter_pspace
, &found
);
14213 expanded
= std::move (sals
);
14215 if (b
->location_range_end
!= NULL
)
14217 std::vector
<symtab_and_line
> sals_end
14218 = location_to_sals (b
, b
->location_range_end
.get (),
14219 filter_pspace
, &found
);
14221 expanded_end
= std::move (sals_end
);
14224 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14227 /* Default method for creating SALs from an address string. It basically
14228 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14231 create_sals_from_location_default (const struct event_location
*location
,
14232 struct linespec_result
*canonical
,
14233 enum bptype type_wanted
)
14235 parse_breakpoint_sals (location
, canonical
);
14238 /* Call create_breakpoints_sal for the given arguments. This is the default
14239 function for the `create_breakpoints_sal' method of
14243 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14244 struct linespec_result
*canonical
,
14245 gdb::unique_xmalloc_ptr
<char> cond_string
,
14246 gdb::unique_xmalloc_ptr
<char> extra_string
,
14247 enum bptype type_wanted
,
14248 enum bpdisp disposition
,
14250 int task
, int ignore_count
,
14251 const struct breakpoint_ops
*ops
,
14252 int from_tty
, int enabled
,
14253 int internal
, unsigned flags
)
14255 create_breakpoints_sal (gdbarch
, canonical
,
14256 std::move (cond_string
),
14257 std::move (extra_string
),
14258 type_wanted
, disposition
,
14259 thread
, task
, ignore_count
, ops
, from_tty
,
14260 enabled
, internal
, flags
);
14263 /* Decode the line represented by S by calling decode_line_full. This is the
14264 default function for the `decode_location' method of breakpoint_ops. */
14266 static std::vector
<symtab_and_line
>
14267 decode_location_default (struct breakpoint
*b
,
14268 const struct event_location
*location
,
14269 struct program_space
*search_pspace
)
14271 struct linespec_result canonical
;
14273 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14274 (struct symtab
*) NULL
, 0,
14275 &canonical
, multiple_symbols_all
,
14278 /* We should get 0 or 1 resulting SALs. */
14279 gdb_assert (canonical
.lsals
.size () < 2);
14281 if (!canonical
.lsals
.empty ())
14283 const linespec_sals
&lsal
= canonical
.lsals
[0];
14284 return std::move (lsal
.sals
);
14289 /* Prepare the global context for a re-set of breakpoint B. */
14291 static struct cleanup
*
14292 prepare_re_set_context (struct breakpoint
*b
)
14294 input_radix
= b
->input_radix
;
14295 set_language (b
->language
);
14297 return make_cleanup (null_cleanup
, NULL
);
14300 /* Reset a breakpoint given it's struct breakpoint * BINT.
14301 The value we return ends up being the return value from catch_errors.
14302 Unused in this case. */
14305 breakpoint_re_set_one (void *bint
)
14307 /* Get past catch_errs. */
14308 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14309 struct cleanup
*cleanups
;
14311 cleanups
= prepare_re_set_context (b
);
14312 b
->ops
->re_set (b
);
14313 do_cleanups (cleanups
);
14317 /* Re-set breakpoint locations for the current program space.
14318 Locations bound to other program spaces are left untouched. */
14321 breakpoint_re_set (void)
14323 struct breakpoint
*b
, *b_tmp
;
14324 enum language save_language
;
14325 int save_input_radix
;
14327 save_language
= current_language
->la_language
;
14328 save_input_radix
= input_radix
;
14331 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14333 /* Note: we must not try to insert locations until after all
14334 breakpoints have been re-set. Otherwise, e.g., when re-setting
14335 breakpoint 1, we'd insert the locations of breakpoint 2, which
14336 hadn't been re-set yet, and thus may have stale locations. */
14338 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14340 /* Format possible error msg. */
14341 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14343 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14344 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14345 do_cleanups (cleanups
);
14347 set_language (save_language
);
14348 input_radix
= save_input_radix
;
14350 jit_breakpoint_re_set ();
14353 create_overlay_event_breakpoint ();
14354 create_longjmp_master_breakpoint ();
14355 create_std_terminate_master_breakpoint ();
14356 create_exception_master_breakpoint ();
14358 /* Now we can insert. */
14359 update_global_location_list (UGLL_MAY_INSERT
);
14362 /* Reset the thread number of this breakpoint:
14364 - If the breakpoint is for all threads, leave it as-is.
14365 - Else, reset it to the current thread for inferior_ptid. */
14367 breakpoint_re_set_thread (struct breakpoint
*b
)
14369 if (b
->thread
!= -1)
14371 if (in_thread_list (inferior_ptid
))
14372 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14374 /* We're being called after following a fork. The new fork is
14375 selected as current, and unless this was a vfork will have a
14376 different program space from the original thread. Reset that
14378 b
->loc
->pspace
= current_program_space
;
14382 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14383 If from_tty is nonzero, it prints a message to that effect,
14384 which ends with a period (no newline). */
14387 set_ignore_count (int bptnum
, int count
, int from_tty
)
14389 struct breakpoint
*b
;
14394 ALL_BREAKPOINTS (b
)
14395 if (b
->number
== bptnum
)
14397 if (is_tracepoint (b
))
14399 if (from_tty
&& count
!= 0)
14400 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14405 b
->ignore_count
= count
;
14409 printf_filtered (_("Will stop next time "
14410 "breakpoint %d is reached."),
14412 else if (count
== 1)
14413 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14416 printf_filtered (_("Will ignore next %d "
14417 "crossings of breakpoint %d."),
14420 observer_notify_breakpoint_modified (b
);
14424 error (_("No breakpoint number %d."), bptnum
);
14427 /* Command to set ignore-count of breakpoint N to COUNT. */
14430 ignore_command (char *args
, int from_tty
)
14436 error_no_arg (_("a breakpoint number"));
14438 num
= get_number (&p
);
14440 error (_("bad breakpoint number: '%s'"), args
);
14442 error (_("Second argument (specified ignore-count) is missing."));
14444 set_ignore_count (num
,
14445 longest_to_int (value_as_long (parse_and_eval (p
))),
14448 printf_filtered ("\n");
14451 /* Call FUNCTION on each of the breakpoints
14452 whose numbers are given in ARGS. */
14455 map_breakpoint_numbers (const char *args
,
14456 void (*function
) (struct breakpoint
*,
14461 struct breakpoint
*b
, *tmp
;
14463 if (args
== 0 || *args
== '\0')
14464 error_no_arg (_("one or more breakpoint numbers"));
14466 number_or_range_parser
parser (args
);
14468 while (!parser
.finished ())
14470 const char *p
= parser
.cur_tok ();
14471 bool match
= false;
14473 num
= parser
.get_number ();
14476 warning (_("bad breakpoint number at or near '%s'"), p
);
14480 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14481 if (b
->number
== num
)
14484 function (b
, data
);
14488 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14493 static struct bp_location
*
14494 find_location_by_number (char *number
)
14496 char *dot
= strchr (number
, '.');
14500 struct breakpoint
*b
;
14501 struct bp_location
*loc
;
14506 bp_num
= get_number (&p1
);
14508 error (_("Bad breakpoint number '%s'"), number
);
14510 ALL_BREAKPOINTS (b
)
14511 if (b
->number
== bp_num
)
14516 if (!b
|| b
->number
!= bp_num
)
14517 error (_("Bad breakpoint number '%s'"), number
);
14520 loc_num
= get_number (&p1
);
14522 error (_("Bad breakpoint location number '%s'"), number
);
14526 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14529 error (_("Bad breakpoint location number '%s'"), dot
+1);
14535 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14536 If from_tty is nonzero, it prints a message to that effect,
14537 which ends with a period (no newline). */
14540 disable_breakpoint (struct breakpoint
*bpt
)
14542 /* Never disable a watchpoint scope breakpoint; we want to
14543 hit them when we leave scope so we can delete both the
14544 watchpoint and its scope breakpoint at that time. */
14545 if (bpt
->type
== bp_watchpoint_scope
)
14548 bpt
->enable_state
= bp_disabled
;
14550 /* Mark breakpoint locations modified. */
14551 mark_breakpoint_modified (bpt
);
14553 if (target_supports_enable_disable_tracepoint ()
14554 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14556 struct bp_location
*location
;
14558 for (location
= bpt
->loc
; location
; location
= location
->next
)
14559 target_disable_tracepoint (location
);
14562 update_global_location_list (UGLL_DONT_INSERT
);
14564 observer_notify_breakpoint_modified (bpt
);
14567 /* A callback for iterate_over_related_breakpoints. */
14570 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14572 disable_breakpoint (b
);
14575 /* A callback for map_breakpoint_numbers that calls
14576 disable_breakpoint. */
14579 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14581 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14585 disable_command (char *args
, int from_tty
)
14589 struct breakpoint
*bpt
;
14591 ALL_BREAKPOINTS (bpt
)
14592 if (user_breakpoint_p (bpt
))
14593 disable_breakpoint (bpt
);
14597 char *num
= extract_arg (&args
);
14601 if (strchr (num
, '.'))
14603 struct bp_location
*loc
= find_location_by_number (num
);
14610 mark_breakpoint_location_modified (loc
);
14612 if (target_supports_enable_disable_tracepoint ()
14613 && current_trace_status ()->running
&& loc
->owner
14614 && is_tracepoint (loc
->owner
))
14615 target_disable_tracepoint (loc
);
14617 update_global_location_list (UGLL_DONT_INSERT
);
14620 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14621 num
= extract_arg (&args
);
14627 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14630 int target_resources_ok
;
14632 if (bpt
->type
== bp_hardware_breakpoint
)
14635 i
= hw_breakpoint_used_count ();
14636 target_resources_ok
=
14637 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14639 if (target_resources_ok
== 0)
14640 error (_("No hardware breakpoint support in the target."));
14641 else if (target_resources_ok
< 0)
14642 error (_("Hardware breakpoints used exceeds limit."));
14645 if (is_watchpoint (bpt
))
14647 /* Initialize it just to avoid a GCC false warning. */
14648 enum enable_state orig_enable_state
= bp_disabled
;
14652 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14654 orig_enable_state
= bpt
->enable_state
;
14655 bpt
->enable_state
= bp_enabled
;
14656 update_watchpoint (w
, 1 /* reparse */);
14658 CATCH (e
, RETURN_MASK_ALL
)
14660 bpt
->enable_state
= orig_enable_state
;
14661 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14668 bpt
->enable_state
= bp_enabled
;
14670 /* Mark breakpoint locations modified. */
14671 mark_breakpoint_modified (bpt
);
14673 if (target_supports_enable_disable_tracepoint ()
14674 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14676 struct bp_location
*location
;
14678 for (location
= bpt
->loc
; location
; location
= location
->next
)
14679 target_enable_tracepoint (location
);
14682 bpt
->disposition
= disposition
;
14683 bpt
->enable_count
= count
;
14684 update_global_location_list (UGLL_MAY_INSERT
);
14686 observer_notify_breakpoint_modified (bpt
);
14691 enable_breakpoint (struct breakpoint
*bpt
)
14693 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14697 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14699 enable_breakpoint (bpt
);
14702 /* A callback for map_breakpoint_numbers that calls
14703 enable_breakpoint. */
14706 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14708 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14711 /* The enable command enables the specified breakpoints (or all defined
14712 breakpoints) so they once again become (or continue to be) effective
14713 in stopping the inferior. */
14716 enable_command (char *args
, int from_tty
)
14720 struct breakpoint
*bpt
;
14722 ALL_BREAKPOINTS (bpt
)
14723 if (user_breakpoint_p (bpt
))
14724 enable_breakpoint (bpt
);
14728 char *num
= extract_arg (&args
);
14732 if (strchr (num
, '.'))
14734 struct bp_location
*loc
= find_location_by_number (num
);
14741 mark_breakpoint_location_modified (loc
);
14743 if (target_supports_enable_disable_tracepoint ()
14744 && current_trace_status ()->running
&& loc
->owner
14745 && is_tracepoint (loc
->owner
))
14746 target_enable_tracepoint (loc
);
14748 update_global_location_list (UGLL_MAY_INSERT
);
14751 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14752 num
= extract_arg (&args
);
14757 /* This struct packages up disposition data for application to multiple
14767 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14769 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14771 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14775 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14777 struct disp_data disp
= { disp_disable
, 1 };
14779 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14783 enable_once_command (char *args
, int from_tty
)
14785 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14789 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14791 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14793 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14797 enable_count_command (char *args
, int from_tty
)
14802 error_no_arg (_("hit count"));
14804 count
= get_number (&args
);
14806 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14810 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14812 struct disp_data disp
= { disp_del
, 1 };
14814 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14818 enable_delete_command (char *args
, int from_tty
)
14820 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14824 set_breakpoint_cmd (char *args
, int from_tty
)
14829 show_breakpoint_cmd (char *args
, int from_tty
)
14833 /* Invalidate last known value of any hardware watchpoint if
14834 the memory which that value represents has been written to by
14838 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14839 CORE_ADDR addr
, ssize_t len
,
14840 const bfd_byte
*data
)
14842 struct breakpoint
*bp
;
14844 ALL_BREAKPOINTS (bp
)
14845 if (bp
->enable_state
== bp_enabled
14846 && bp
->type
== bp_hardware_watchpoint
)
14848 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14850 if (wp
->val_valid
&& wp
->val
)
14852 struct bp_location
*loc
;
14854 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14855 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14856 && loc
->address
+ loc
->length
> addr
14857 && addr
+ len
> loc
->address
)
14859 value_free (wp
->val
);
14867 /* Create and insert a breakpoint for software single step. */
14870 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14871 struct address_space
*aspace
,
14874 struct thread_info
*tp
= inferior_thread ();
14875 struct symtab_and_line sal
;
14876 CORE_ADDR pc
= next_pc
;
14878 if (tp
->control
.single_step_breakpoints
== NULL
)
14880 tp
->control
.single_step_breakpoints
14881 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14884 sal
= find_pc_line (pc
, 0);
14886 sal
.section
= find_pc_overlay (pc
);
14887 sal
.explicit_pc
= 1;
14888 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14890 update_global_location_list (UGLL_INSERT
);
14893 /* Insert single step breakpoints according to the current state. */
14896 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14898 struct regcache
*regcache
= get_current_regcache ();
14899 std::vector
<CORE_ADDR
> next_pcs
;
14901 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14903 if (!next_pcs
.empty ())
14905 struct frame_info
*frame
= get_current_frame ();
14906 struct address_space
*aspace
= get_frame_address_space (frame
);
14908 for (CORE_ADDR pc
: next_pcs
)
14909 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14917 /* See breakpoint.h. */
14920 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14921 struct address_space
*aspace
,
14924 struct bp_location
*loc
;
14926 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14928 && breakpoint_location_address_match (loc
, aspace
, pc
))
14934 /* Check whether a software single-step breakpoint is inserted at
14938 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14941 struct breakpoint
*bpt
;
14943 ALL_BREAKPOINTS (bpt
)
14945 if (bpt
->type
== bp_single_step
14946 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14952 /* Tracepoint-specific operations. */
14954 /* Set tracepoint count to NUM. */
14956 set_tracepoint_count (int num
)
14958 tracepoint_count
= num
;
14959 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14963 trace_command (char *arg
, int from_tty
)
14965 struct breakpoint_ops
*ops
;
14967 event_location_up location
= string_to_event_location (&arg
,
14969 if (location
!= NULL
14970 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14971 ops
= &tracepoint_probe_breakpoint_ops
;
14973 ops
= &tracepoint_breakpoint_ops
;
14975 create_breakpoint (get_current_arch (),
14977 NULL
, 0, arg
, 1 /* parse arg */,
14979 bp_tracepoint
/* type_wanted */,
14980 0 /* Ignore count */,
14981 pending_break_support
,
14985 0 /* internal */, 0);
14989 ftrace_command (char *arg
, int from_tty
)
14991 event_location_up location
= string_to_event_location (&arg
,
14993 create_breakpoint (get_current_arch (),
14995 NULL
, 0, arg
, 1 /* parse arg */,
14997 bp_fast_tracepoint
/* type_wanted */,
14998 0 /* Ignore count */,
14999 pending_break_support
,
15000 &tracepoint_breakpoint_ops
,
15003 0 /* internal */, 0);
15006 /* strace command implementation. Creates a static tracepoint. */
15009 strace_command (char *arg
, int from_tty
)
15011 struct breakpoint_ops
*ops
;
15012 event_location_up location
;
15013 struct cleanup
*back_to
;
15015 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15016 or with a normal static tracepoint. */
15017 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15019 ops
= &strace_marker_breakpoint_ops
;
15020 location
= new_linespec_location (&arg
);
15024 ops
= &tracepoint_breakpoint_ops
;
15025 location
= string_to_event_location (&arg
, current_language
);
15028 create_breakpoint (get_current_arch (),
15030 NULL
, 0, arg
, 1 /* parse arg */,
15032 bp_static_tracepoint
/* type_wanted */,
15033 0 /* Ignore count */,
15034 pending_break_support
,
15038 0 /* internal */, 0);
15041 /* Set up a fake reader function that gets command lines from a linked
15042 list that was acquired during tracepoint uploading. */
15044 static struct uploaded_tp
*this_utp
;
15045 static int next_cmd
;
15048 read_uploaded_action (void)
15052 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15059 /* Given information about a tracepoint as recorded on a target (which
15060 can be either a live system or a trace file), attempt to create an
15061 equivalent GDB tracepoint. This is not a reliable process, since
15062 the target does not necessarily have all the information used when
15063 the tracepoint was originally defined. */
15065 struct tracepoint
*
15066 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15068 char *addr_str
, small_buf
[100];
15069 struct tracepoint
*tp
;
15071 if (utp
->at_string
)
15072 addr_str
= utp
->at_string
;
15075 /* In the absence of a source location, fall back to raw
15076 address. Since there is no way to confirm that the address
15077 means the same thing as when the trace was started, warn the
15079 warning (_("Uploaded tracepoint %d has no "
15080 "source location, using raw address"),
15082 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15083 addr_str
= small_buf
;
15086 /* There's not much we can do with a sequence of bytecodes. */
15087 if (utp
->cond
&& !utp
->cond_string
)
15088 warning (_("Uploaded tracepoint %d condition "
15089 "has no source form, ignoring it"),
15092 event_location_up location
= string_to_event_location (&addr_str
,
15094 if (!create_breakpoint (get_current_arch (),
15096 utp
->cond_string
, -1, addr_str
,
15097 0 /* parse cond/thread */,
15099 utp
->type
/* type_wanted */,
15100 0 /* Ignore count */,
15101 pending_break_support
,
15102 &tracepoint_breakpoint_ops
,
15104 utp
->enabled
/* enabled */,
15106 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15109 /* Get the tracepoint we just created. */
15110 tp
= get_tracepoint (tracepoint_count
);
15111 gdb_assert (tp
!= NULL
);
15115 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15118 trace_pass_command (small_buf
, 0);
15121 /* If we have uploaded versions of the original commands, set up a
15122 special-purpose "reader" function and call the usual command line
15123 reader, then pass the result to the breakpoint command-setting
15125 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15127 command_line_up cmd_list
;
15132 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15134 breakpoint_set_commands (tp
, std::move (cmd_list
));
15136 else if (!VEC_empty (char_ptr
, utp
->actions
)
15137 || !VEC_empty (char_ptr
, utp
->step_actions
))
15138 warning (_("Uploaded tracepoint %d actions "
15139 "have no source form, ignoring them"),
15142 /* Copy any status information that might be available. */
15143 tp
->hit_count
= utp
->hit_count
;
15144 tp
->traceframe_usage
= utp
->traceframe_usage
;
15149 /* Print information on tracepoint number TPNUM_EXP, or all if
15153 info_tracepoints_command (char *args
, int from_tty
)
15155 struct ui_out
*uiout
= current_uiout
;
15158 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15160 if (num_printed
== 0)
15162 if (args
== NULL
|| *args
== '\0')
15163 uiout
->message ("No tracepoints.\n");
15165 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15168 default_collect_info ();
15171 /* The 'enable trace' command enables tracepoints.
15172 Not supported by all targets. */
15174 enable_trace_command (char *args
, int from_tty
)
15176 enable_command (args
, from_tty
);
15179 /* The 'disable trace' command disables tracepoints.
15180 Not supported by all targets. */
15182 disable_trace_command (char *args
, int from_tty
)
15184 disable_command (args
, from_tty
);
15187 /* Remove a tracepoint (or all if no argument). */
15189 delete_trace_command (char *arg
, int from_tty
)
15191 struct breakpoint
*b
, *b_tmp
;
15197 int breaks_to_delete
= 0;
15199 /* Delete all breakpoints if no argument.
15200 Do not delete internal or call-dummy breakpoints, these
15201 have to be deleted with an explicit breakpoint number
15203 ALL_TRACEPOINTS (b
)
15204 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15206 breaks_to_delete
= 1;
15210 /* Ask user only if there are some breakpoints to delete. */
15212 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15214 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15215 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15216 delete_breakpoint (b
);
15220 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15223 /* Helper function for trace_pass_command. */
15226 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15228 tp
->pass_count
= count
;
15229 observer_notify_breakpoint_modified (tp
);
15231 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15232 tp
->number
, count
);
15235 /* Set passcount for tracepoint.
15237 First command argument is passcount, second is tracepoint number.
15238 If tracepoint number omitted, apply to most recently defined.
15239 Also accepts special argument "all". */
15242 trace_pass_command (char *args
, int from_tty
)
15244 struct tracepoint
*t1
;
15245 unsigned int count
;
15247 if (args
== 0 || *args
== 0)
15248 error (_("passcount command requires an "
15249 "argument (count + optional TP num)"));
15251 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15253 args
= skip_spaces (args
);
15254 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15256 struct breakpoint
*b
;
15258 args
+= 3; /* Skip special argument "all". */
15260 error (_("Junk at end of arguments."));
15262 ALL_TRACEPOINTS (b
)
15264 t1
= (struct tracepoint
*) b
;
15265 trace_pass_set_count (t1
, count
, from_tty
);
15268 else if (*args
== '\0')
15270 t1
= get_tracepoint_by_number (&args
, NULL
);
15272 trace_pass_set_count (t1
, count
, from_tty
);
15276 number_or_range_parser
parser (args
);
15277 while (!parser
.finished ())
15279 t1
= get_tracepoint_by_number (&args
, &parser
);
15281 trace_pass_set_count (t1
, count
, from_tty
);
15286 struct tracepoint
*
15287 get_tracepoint (int num
)
15289 struct breakpoint
*t
;
15291 ALL_TRACEPOINTS (t
)
15292 if (t
->number
== num
)
15293 return (struct tracepoint
*) t
;
15298 /* Find the tracepoint with the given target-side number (which may be
15299 different from the tracepoint number after disconnecting and
15302 struct tracepoint
*
15303 get_tracepoint_by_number_on_target (int num
)
15305 struct breakpoint
*b
;
15307 ALL_TRACEPOINTS (b
)
15309 struct tracepoint
*t
= (struct tracepoint
*) b
;
15311 if (t
->number_on_target
== num
)
15318 /* Utility: parse a tracepoint number and look it up in the list.
15319 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15320 If the argument is missing, the most recent tracepoint
15321 (tracepoint_count) is returned. */
15323 struct tracepoint
*
15324 get_tracepoint_by_number (char **arg
,
15325 number_or_range_parser
*parser
)
15327 struct breakpoint
*t
;
15329 char *instring
= arg
== NULL
? NULL
: *arg
;
15331 if (parser
!= NULL
)
15333 gdb_assert (!parser
->finished ());
15334 tpnum
= parser
->get_number ();
15336 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15337 tpnum
= tracepoint_count
;
15339 tpnum
= get_number (arg
);
15343 if (instring
&& *instring
)
15344 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15347 printf_filtered (_("No previous tracepoint\n"));
15351 ALL_TRACEPOINTS (t
)
15352 if (t
->number
== tpnum
)
15354 return (struct tracepoint
*) t
;
15357 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15362 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15364 if (b
->thread
!= -1)
15365 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15368 fprintf_unfiltered (fp
, " task %d", b
->task
);
15370 fprintf_unfiltered (fp
, "\n");
15373 /* Save information on user settable breakpoints (watchpoints, etc) to
15374 a new script file named FILENAME. If FILTER is non-NULL, call it
15375 on each breakpoint and only include the ones for which it returns
15379 save_breakpoints (char *filename
, int from_tty
,
15380 int (*filter
) (const struct breakpoint
*))
15382 struct breakpoint
*tp
;
15384 int extra_trace_bits
= 0;
15386 if (filename
== 0 || *filename
== 0)
15387 error (_("Argument required (file name in which to save)"));
15389 /* See if we have anything to save. */
15390 ALL_BREAKPOINTS (tp
)
15392 /* Skip internal and momentary breakpoints. */
15393 if (!user_breakpoint_p (tp
))
15396 /* If we have a filter, only save the breakpoints it accepts. */
15397 if (filter
&& !filter (tp
))
15402 if (is_tracepoint (tp
))
15404 extra_trace_bits
= 1;
15406 /* We can stop searching. */
15413 warning (_("Nothing to save."));
15417 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15421 if (!fp
.open (expanded_filename
.get (), "w"))
15422 error (_("Unable to open file '%s' for saving (%s)"),
15423 expanded_filename
.get (), safe_strerror (errno
));
15425 if (extra_trace_bits
)
15426 save_trace_state_variables (&fp
);
15428 ALL_BREAKPOINTS (tp
)
15430 /* Skip internal and momentary breakpoints. */
15431 if (!user_breakpoint_p (tp
))
15434 /* If we have a filter, only save the breakpoints it accepts. */
15435 if (filter
&& !filter (tp
))
15438 tp
->ops
->print_recreate (tp
, &fp
);
15440 /* Note, we can't rely on tp->number for anything, as we can't
15441 assume the recreated breakpoint numbers will match. Use $bpnum
15444 if (tp
->cond_string
)
15445 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15447 if (tp
->ignore_count
)
15448 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15450 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15452 fp
.puts (" commands\n");
15454 current_uiout
->redirect (&fp
);
15457 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15459 CATCH (ex
, RETURN_MASK_ALL
)
15461 current_uiout
->redirect (NULL
);
15462 throw_exception (ex
);
15466 current_uiout
->redirect (NULL
);
15467 fp
.puts (" end\n");
15470 if (tp
->enable_state
== bp_disabled
)
15471 fp
.puts ("disable $bpnum\n");
15473 /* If this is a multi-location breakpoint, check if the locations
15474 should be individually disabled. Watchpoint locations are
15475 special, and not user visible. */
15476 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15478 struct bp_location
*loc
;
15481 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15483 fp
.printf ("disable $bpnum.%d\n", n
);
15487 if (extra_trace_bits
&& *default_collect
)
15488 fp
.printf ("set default-collect %s\n", default_collect
);
15491 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15494 /* The `save breakpoints' command. */
15497 save_breakpoints_command (char *args
, int from_tty
)
15499 save_breakpoints (args
, from_tty
, NULL
);
15502 /* The `save tracepoints' command. */
15505 save_tracepoints_command (char *args
, int from_tty
)
15507 save_breakpoints (args
, from_tty
, is_tracepoint
);
15510 /* Create a vector of all tracepoints. */
15512 VEC(breakpoint_p
) *
15513 all_tracepoints (void)
15515 VEC(breakpoint_p
) *tp_vec
= 0;
15516 struct breakpoint
*tp
;
15518 ALL_TRACEPOINTS (tp
)
15520 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15527 /* This help string is used to consolidate all the help string for specifying
15528 locations used by several commands. */
15530 #define LOCATION_HELP_STRING \
15531 "Linespecs are colon-separated lists of location parameters, such as\n\
15532 source filename, function name, label name, and line number.\n\
15533 Example: To specify the start of a label named \"the_top\" in the\n\
15534 function \"fact\" in the file \"factorial.c\", use\n\
15535 \"factorial.c:fact:the_top\".\n\
15537 Address locations begin with \"*\" and specify an exact address in the\n\
15538 program. Example: To specify the fourth byte past the start function\n\
15539 \"main\", use \"*main + 4\".\n\
15541 Explicit locations are similar to linespecs but use an option/argument\n\
15542 syntax to specify location parameters.\n\
15543 Example: To specify the start of the label named \"the_top\" in the\n\
15544 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15545 -function fact -label the_top\".\n"
15547 /* This help string is used for the break, hbreak, tbreak and thbreak
15548 commands. It is defined as a macro to prevent duplication.
15549 COMMAND should be a string constant containing the name of the
15552 #define BREAK_ARGS_HELP(command) \
15553 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15554 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15555 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15556 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15557 `-probe-dtrace' (for a DTrace probe).\n\
15558 LOCATION may be a linespec, address, or explicit location as described\n\
15561 With no LOCATION, uses current execution address of the selected\n\
15562 stack frame. This is useful for breaking on return to a stack frame.\n\
15564 THREADNUM is the number from \"info threads\".\n\
15565 CONDITION is a boolean expression.\n\
15566 \n" LOCATION_HELP_STRING "\n\
15567 Multiple breakpoints at one place are permitted, and useful if their\n\
15568 conditions are different.\n\
15570 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15572 /* List of subcommands for "catch". */
15573 static struct cmd_list_element
*catch_cmdlist
;
15575 /* List of subcommands for "tcatch". */
15576 static struct cmd_list_element
*tcatch_cmdlist
;
15579 add_catch_command (const char *name
, const char *docstring
,
15580 cmd_sfunc_ftype
*sfunc
,
15581 completer_ftype
*completer
,
15582 void *user_data_catch
,
15583 void *user_data_tcatch
)
15585 struct cmd_list_element
*command
;
15587 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15589 set_cmd_sfunc (command
, sfunc
);
15590 set_cmd_context (command
, user_data_catch
);
15591 set_cmd_completer (command
, completer
);
15593 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15595 set_cmd_sfunc (command
, sfunc
);
15596 set_cmd_context (command
, user_data_tcatch
);
15597 set_cmd_completer (command
, completer
);
15601 save_command (char *arg
, int from_tty
)
15603 printf_unfiltered (_("\"save\" must be followed by "
15604 "the name of a save subcommand.\n"));
15605 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15608 struct breakpoint
*
15609 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15612 struct breakpoint
*b
, *b_tmp
;
15614 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15616 if ((*callback
) (b
, data
))
15623 /* Zero if any of the breakpoint's locations could be a location where
15624 functions have been inlined, nonzero otherwise. */
15627 is_non_inline_function (struct breakpoint
*b
)
15629 /* The shared library event breakpoint is set on the address of a
15630 non-inline function. */
15631 if (b
->type
== bp_shlib_event
)
15637 /* Nonzero if the specified PC cannot be a location where functions
15638 have been inlined. */
15641 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15642 const struct target_waitstatus
*ws
)
15644 struct breakpoint
*b
;
15645 struct bp_location
*bl
;
15647 ALL_BREAKPOINTS (b
)
15649 if (!is_non_inline_function (b
))
15652 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15654 if (!bl
->shlib_disabled
15655 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15663 /* Remove any references to OBJFILE which is going to be freed. */
15666 breakpoint_free_objfile (struct objfile
*objfile
)
15668 struct bp_location
**locp
, *loc
;
15670 ALL_BP_LOCATIONS (loc
, locp
)
15671 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15672 loc
->symtab
= NULL
;
15676 initialize_breakpoint_ops (void)
15678 static int initialized
= 0;
15680 struct breakpoint_ops
*ops
;
15686 /* The breakpoint_ops structure to be inherit by all kinds of
15687 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15688 internal and momentary breakpoints, etc.). */
15689 ops
= &bkpt_base_breakpoint_ops
;
15690 *ops
= base_breakpoint_ops
;
15691 ops
->re_set
= bkpt_re_set
;
15692 ops
->insert_location
= bkpt_insert_location
;
15693 ops
->remove_location
= bkpt_remove_location
;
15694 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15695 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15696 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15697 ops
->decode_location
= bkpt_decode_location
;
15699 /* The breakpoint_ops structure to be used in regular breakpoints. */
15700 ops
= &bkpt_breakpoint_ops
;
15701 *ops
= bkpt_base_breakpoint_ops
;
15702 ops
->re_set
= bkpt_re_set
;
15703 ops
->resources_needed
= bkpt_resources_needed
;
15704 ops
->print_it
= bkpt_print_it
;
15705 ops
->print_mention
= bkpt_print_mention
;
15706 ops
->print_recreate
= bkpt_print_recreate
;
15708 /* Ranged breakpoints. */
15709 ops
= &ranged_breakpoint_ops
;
15710 *ops
= bkpt_breakpoint_ops
;
15711 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15712 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15713 ops
->print_it
= print_it_ranged_breakpoint
;
15714 ops
->print_one
= print_one_ranged_breakpoint
;
15715 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15716 ops
->print_mention
= print_mention_ranged_breakpoint
;
15717 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15719 /* Internal breakpoints. */
15720 ops
= &internal_breakpoint_ops
;
15721 *ops
= bkpt_base_breakpoint_ops
;
15722 ops
->re_set
= internal_bkpt_re_set
;
15723 ops
->check_status
= internal_bkpt_check_status
;
15724 ops
->print_it
= internal_bkpt_print_it
;
15725 ops
->print_mention
= internal_bkpt_print_mention
;
15727 /* Momentary breakpoints. */
15728 ops
= &momentary_breakpoint_ops
;
15729 *ops
= bkpt_base_breakpoint_ops
;
15730 ops
->re_set
= momentary_bkpt_re_set
;
15731 ops
->check_status
= momentary_bkpt_check_status
;
15732 ops
->print_it
= momentary_bkpt_print_it
;
15733 ops
->print_mention
= momentary_bkpt_print_mention
;
15735 /* Probe breakpoints. */
15736 ops
= &bkpt_probe_breakpoint_ops
;
15737 *ops
= bkpt_breakpoint_ops
;
15738 ops
->insert_location
= bkpt_probe_insert_location
;
15739 ops
->remove_location
= bkpt_probe_remove_location
;
15740 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15741 ops
->decode_location
= bkpt_probe_decode_location
;
15744 ops
= &watchpoint_breakpoint_ops
;
15745 *ops
= base_breakpoint_ops
;
15746 ops
->re_set
= re_set_watchpoint
;
15747 ops
->insert_location
= insert_watchpoint
;
15748 ops
->remove_location
= remove_watchpoint
;
15749 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15750 ops
->check_status
= check_status_watchpoint
;
15751 ops
->resources_needed
= resources_needed_watchpoint
;
15752 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15753 ops
->print_it
= print_it_watchpoint
;
15754 ops
->print_mention
= print_mention_watchpoint
;
15755 ops
->print_recreate
= print_recreate_watchpoint
;
15756 ops
->explains_signal
= explains_signal_watchpoint
;
15758 /* Masked watchpoints. */
15759 ops
= &masked_watchpoint_breakpoint_ops
;
15760 *ops
= watchpoint_breakpoint_ops
;
15761 ops
->insert_location
= insert_masked_watchpoint
;
15762 ops
->remove_location
= remove_masked_watchpoint
;
15763 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15764 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15765 ops
->print_it
= print_it_masked_watchpoint
;
15766 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15767 ops
->print_mention
= print_mention_masked_watchpoint
;
15768 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15771 ops
= &tracepoint_breakpoint_ops
;
15772 *ops
= base_breakpoint_ops
;
15773 ops
->re_set
= tracepoint_re_set
;
15774 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15775 ops
->print_one_detail
= tracepoint_print_one_detail
;
15776 ops
->print_mention
= tracepoint_print_mention
;
15777 ops
->print_recreate
= tracepoint_print_recreate
;
15778 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15779 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15780 ops
->decode_location
= tracepoint_decode_location
;
15782 /* Probe tracepoints. */
15783 ops
= &tracepoint_probe_breakpoint_ops
;
15784 *ops
= tracepoint_breakpoint_ops
;
15785 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15786 ops
->decode_location
= tracepoint_probe_decode_location
;
15788 /* Static tracepoints with marker (`-m'). */
15789 ops
= &strace_marker_breakpoint_ops
;
15790 *ops
= tracepoint_breakpoint_ops
;
15791 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15792 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15793 ops
->decode_location
= strace_marker_decode_location
;
15795 /* Fork catchpoints. */
15796 ops
= &catch_fork_breakpoint_ops
;
15797 *ops
= base_breakpoint_ops
;
15798 ops
->insert_location
= insert_catch_fork
;
15799 ops
->remove_location
= remove_catch_fork
;
15800 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15801 ops
->print_it
= print_it_catch_fork
;
15802 ops
->print_one
= print_one_catch_fork
;
15803 ops
->print_mention
= print_mention_catch_fork
;
15804 ops
->print_recreate
= print_recreate_catch_fork
;
15806 /* Vfork catchpoints. */
15807 ops
= &catch_vfork_breakpoint_ops
;
15808 *ops
= base_breakpoint_ops
;
15809 ops
->insert_location
= insert_catch_vfork
;
15810 ops
->remove_location
= remove_catch_vfork
;
15811 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15812 ops
->print_it
= print_it_catch_vfork
;
15813 ops
->print_one
= print_one_catch_vfork
;
15814 ops
->print_mention
= print_mention_catch_vfork
;
15815 ops
->print_recreate
= print_recreate_catch_vfork
;
15817 /* Exec catchpoints. */
15818 ops
= &catch_exec_breakpoint_ops
;
15819 *ops
= base_breakpoint_ops
;
15820 ops
->insert_location
= insert_catch_exec
;
15821 ops
->remove_location
= remove_catch_exec
;
15822 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15823 ops
->print_it
= print_it_catch_exec
;
15824 ops
->print_one
= print_one_catch_exec
;
15825 ops
->print_mention
= print_mention_catch_exec
;
15826 ops
->print_recreate
= print_recreate_catch_exec
;
15828 /* Solib-related catchpoints. */
15829 ops
= &catch_solib_breakpoint_ops
;
15830 *ops
= base_breakpoint_ops
;
15831 ops
->insert_location
= insert_catch_solib
;
15832 ops
->remove_location
= remove_catch_solib
;
15833 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15834 ops
->check_status
= check_status_catch_solib
;
15835 ops
->print_it
= print_it_catch_solib
;
15836 ops
->print_one
= print_one_catch_solib
;
15837 ops
->print_mention
= print_mention_catch_solib
;
15838 ops
->print_recreate
= print_recreate_catch_solib
;
15840 ops
= &dprintf_breakpoint_ops
;
15841 *ops
= bkpt_base_breakpoint_ops
;
15842 ops
->re_set
= dprintf_re_set
;
15843 ops
->resources_needed
= bkpt_resources_needed
;
15844 ops
->print_it
= bkpt_print_it
;
15845 ops
->print_mention
= bkpt_print_mention
;
15846 ops
->print_recreate
= dprintf_print_recreate
;
15847 ops
->after_condition_true
= dprintf_after_condition_true
;
15848 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15851 /* Chain containing all defined "enable breakpoint" subcommands. */
15853 static struct cmd_list_element
*enablebreaklist
= NULL
;
15856 _initialize_breakpoint (void)
15858 struct cmd_list_element
*c
;
15860 initialize_breakpoint_ops ();
15862 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15863 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15864 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15866 breakpoint_objfile_key
15867 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15869 breakpoint_chain
= 0;
15870 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15871 before a breakpoint is set. */
15872 breakpoint_count
= 0;
15874 tracepoint_count
= 0;
15876 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15877 Set ignore-count of breakpoint number N to COUNT.\n\
15878 Usage is `ignore N COUNT'."));
15880 add_com ("commands", class_breakpoint
, commands_command
, _("\
15881 Set commands to be executed when the given breakpoints are hit.\n\
15882 Give a space-separated breakpoint list as argument after \"commands\".\n\
15883 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15885 With no argument, the targeted breakpoint is the last one set.\n\
15886 The commands themselves follow starting on the next line.\n\
15887 Type a line containing \"end\" to indicate the end of them.\n\
15888 Give \"silent\" as the first line to make the breakpoint silent;\n\
15889 then no output is printed when it is hit, except what the commands print."));
15891 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15892 Specify breakpoint number N to break only if COND is true.\n\
15893 Usage is `condition N COND', where N is an integer and COND is an\n\
15894 expression to be evaluated whenever breakpoint N is reached."));
15895 set_cmd_completer (c
, condition_completer
);
15897 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15898 Set a temporary breakpoint.\n\
15899 Like \"break\" except the breakpoint is only temporary,\n\
15900 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15901 by using \"enable delete\" on the breakpoint number.\n\
15903 BREAK_ARGS_HELP ("tbreak")));
15904 set_cmd_completer (c
, location_completer
);
15906 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15907 Set a hardware assisted breakpoint.\n\
15908 Like \"break\" except the breakpoint requires hardware support,\n\
15909 some target hardware may not have this support.\n\
15911 BREAK_ARGS_HELP ("hbreak")));
15912 set_cmd_completer (c
, location_completer
);
15914 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15915 Set a temporary hardware assisted breakpoint.\n\
15916 Like \"hbreak\" except the breakpoint is only temporary,\n\
15917 so it will be deleted when hit.\n\
15919 BREAK_ARGS_HELP ("thbreak")));
15920 set_cmd_completer (c
, location_completer
);
15922 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15923 Enable some breakpoints.\n\
15924 Give breakpoint numbers (separated by spaces) as arguments.\n\
15925 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15926 This is used to cancel the effect of the \"disable\" command.\n\
15927 With a subcommand you can enable temporarily."),
15928 &enablelist
, "enable ", 1, &cmdlist
);
15930 add_com_alias ("en", "enable", class_breakpoint
, 1);
15932 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15933 Enable some breakpoints.\n\
15934 Give breakpoint numbers (separated by spaces) as arguments.\n\
15935 This is used to cancel the effect of the \"disable\" command.\n\
15936 May be abbreviated to simply \"enable\".\n"),
15937 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15939 add_cmd ("once", no_class
, enable_once_command
, _("\
15940 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15941 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15944 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15945 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15946 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15949 add_cmd ("count", no_class
, enable_count_command
, _("\
15950 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15951 If a breakpoint is hit while enabled in this fashion,\n\
15952 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15955 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15956 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15957 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15960 add_cmd ("once", no_class
, enable_once_command
, _("\
15961 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15962 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15965 add_cmd ("count", no_class
, enable_count_command
, _("\
15966 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15967 If a breakpoint is hit while enabled in this fashion,\n\
15968 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15971 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15972 Disable some breakpoints.\n\
15973 Arguments are breakpoint numbers with spaces in between.\n\
15974 To disable all breakpoints, give no argument.\n\
15975 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15976 &disablelist
, "disable ", 1, &cmdlist
);
15977 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15978 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15980 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15981 Disable some breakpoints.\n\
15982 Arguments are breakpoint numbers with spaces in between.\n\
15983 To disable all breakpoints, give no argument.\n\
15984 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15985 This command may be abbreviated \"disable\"."),
15988 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15989 Delete some breakpoints or auto-display expressions.\n\
15990 Arguments are breakpoint numbers with spaces in between.\n\
15991 To delete all breakpoints, give no argument.\n\
15993 Also a prefix command for deletion of other GDB objects.\n\
15994 The \"unset\" command is also an alias for \"delete\"."),
15995 &deletelist
, "delete ", 1, &cmdlist
);
15996 add_com_alias ("d", "delete", class_breakpoint
, 1);
15997 add_com_alias ("del", "delete", class_breakpoint
, 1);
15999 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16000 Delete some breakpoints or auto-display expressions.\n\
16001 Arguments are breakpoint numbers with spaces in between.\n\
16002 To delete all breakpoints, give no argument.\n\
16003 This command may be abbreviated \"delete\"."),
16006 add_com ("clear", class_breakpoint
, clear_command
, _("\
16007 Clear breakpoint at specified location.\n\
16008 Argument may be a linespec, explicit, or address location as described below.\n\
16010 With no argument, clears all breakpoints in the line that the selected frame\n\
16011 is executing in.\n"
16012 "\n" LOCATION_HELP_STRING
"\n\
16013 See also the \"delete\" command which clears breakpoints by number."));
16014 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16016 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16017 Set breakpoint at specified location.\n"
16018 BREAK_ARGS_HELP ("break")));
16019 set_cmd_completer (c
, location_completer
);
16021 add_com_alias ("b", "break", class_run
, 1);
16022 add_com_alias ("br", "break", class_run
, 1);
16023 add_com_alias ("bre", "break", class_run
, 1);
16024 add_com_alias ("brea", "break", class_run
, 1);
16028 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16029 Break in function/address or break at a line in the current file."),
16030 &stoplist
, "stop ", 1, &cmdlist
);
16031 add_cmd ("in", class_breakpoint
, stopin_command
,
16032 _("Break in function or address."), &stoplist
);
16033 add_cmd ("at", class_breakpoint
, stopat_command
,
16034 _("Break at a line in the current file."), &stoplist
);
16035 add_com ("status", class_info
, info_breakpoints_command
, _("\
16036 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16037 The \"Type\" column indicates one of:\n\
16038 \tbreakpoint - normal breakpoint\n\
16039 \twatchpoint - watchpoint\n\
16040 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16041 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16042 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16043 address and file/line number respectively.\n\
16045 Convenience variable \"$_\" and default examine address for \"x\"\n\
16046 are set to the address of the last breakpoint listed unless the command\n\
16047 is prefixed with \"server \".\n\n\
16048 Convenience variable \"$bpnum\" contains the number of the last\n\
16049 breakpoint set."));
16052 add_info ("breakpoints", info_breakpoints_command
, _("\
16053 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16054 The \"Type\" column indicates one of:\n\
16055 \tbreakpoint - normal breakpoint\n\
16056 \twatchpoint - watchpoint\n\
16057 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16058 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16059 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16060 address and file/line number respectively.\n\
16062 Convenience variable \"$_\" and default examine address for \"x\"\n\
16063 are set to the address of the last breakpoint listed unless the command\n\
16064 is prefixed with \"server \".\n\n\
16065 Convenience variable \"$bpnum\" contains the number of the last\n\
16066 breakpoint set."));
16068 add_info_alias ("b", "breakpoints", 1);
16070 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16071 Status of all breakpoints, or breakpoint number NUMBER.\n\
16072 The \"Type\" column indicates one of:\n\
16073 \tbreakpoint - normal breakpoint\n\
16074 \twatchpoint - watchpoint\n\
16075 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16076 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16077 \tuntil - internal breakpoint used by the \"until\" command\n\
16078 \tfinish - internal breakpoint used by the \"finish\" command\n\
16079 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16080 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16081 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16082 address and file/line number respectively.\n\
16084 Convenience variable \"$_\" and default examine address for \"x\"\n\
16085 are set to the address of the last breakpoint listed unless the command\n\
16086 is prefixed with \"server \".\n\n\
16087 Convenience variable \"$bpnum\" contains the number of the last\n\
16089 &maintenanceinfolist
);
16091 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16092 Set catchpoints to catch events."),
16093 &catch_cmdlist
, "catch ",
16094 0/*allow-unknown*/, &cmdlist
);
16096 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16097 Set temporary catchpoints to catch events."),
16098 &tcatch_cmdlist
, "tcatch ",
16099 0/*allow-unknown*/, &cmdlist
);
16101 add_catch_command ("fork", _("Catch calls to fork."),
16102 catch_fork_command_1
,
16104 (void *) (uintptr_t) catch_fork_permanent
,
16105 (void *) (uintptr_t) catch_fork_temporary
);
16106 add_catch_command ("vfork", _("Catch calls to vfork."),
16107 catch_fork_command_1
,
16109 (void *) (uintptr_t) catch_vfork_permanent
,
16110 (void *) (uintptr_t) catch_vfork_temporary
);
16111 add_catch_command ("exec", _("Catch calls to exec."),
16112 catch_exec_command_1
,
16116 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16117 Usage: catch load [REGEX]\n\
16118 If REGEX is given, only stop for libraries matching the regular expression."),
16119 catch_load_command_1
,
16123 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16124 Usage: catch unload [REGEX]\n\
16125 If REGEX is given, only stop for libraries matching the regular expression."),
16126 catch_unload_command_1
,
16131 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16132 Set a watchpoint for an expression.\n\
16133 Usage: watch [-l|-location] EXPRESSION\n\
16134 A watchpoint stops execution of your program whenever the value of\n\
16135 an expression changes.\n\
16136 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16137 the memory to which it refers."));
16138 set_cmd_completer (c
, expression_completer
);
16140 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16141 Set a read watchpoint for an expression.\n\
16142 Usage: rwatch [-l|-location] EXPRESSION\n\
16143 A watchpoint stops execution of your program whenever the value of\n\
16144 an expression is read.\n\
16145 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16146 the memory to which it refers."));
16147 set_cmd_completer (c
, expression_completer
);
16149 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16150 Set a watchpoint for an expression.\n\
16151 Usage: awatch [-l|-location] EXPRESSION\n\
16152 A watchpoint stops execution of your program whenever the value of\n\
16153 an expression is either read or written.\n\
16154 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16155 the memory to which it refers."));
16156 set_cmd_completer (c
, expression_completer
);
16158 add_info ("watchpoints", info_watchpoints_command
, _("\
16159 Status of specified watchpoints (all watchpoints if no argument)."));
16161 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16162 respond to changes - contrary to the description. */
16163 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16164 &can_use_hw_watchpoints
, _("\
16165 Set debugger's willingness to use watchpoint hardware."), _("\
16166 Show debugger's willingness to use watchpoint hardware."), _("\
16167 If zero, gdb will not use hardware for new watchpoints, even if\n\
16168 such is available. (However, any hardware watchpoints that were\n\
16169 created before setting this to nonzero, will continue to use watchpoint\n\
16172 show_can_use_hw_watchpoints
,
16173 &setlist
, &showlist
);
16175 can_use_hw_watchpoints
= 1;
16177 /* Tracepoint manipulation commands. */
16179 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16180 Set a tracepoint at specified location.\n\
16182 BREAK_ARGS_HELP ("trace") "\n\
16183 Do \"help tracepoints\" for info on other tracepoint commands."));
16184 set_cmd_completer (c
, location_completer
);
16186 add_com_alias ("tp", "trace", class_alias
, 0);
16187 add_com_alias ("tr", "trace", class_alias
, 1);
16188 add_com_alias ("tra", "trace", class_alias
, 1);
16189 add_com_alias ("trac", "trace", class_alias
, 1);
16191 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16192 Set a fast tracepoint at specified location.\n\
16194 BREAK_ARGS_HELP ("ftrace") "\n\
16195 Do \"help tracepoints\" for info on other tracepoint commands."));
16196 set_cmd_completer (c
, location_completer
);
16198 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16199 Set a static tracepoint at location or marker.\n\
16201 strace [LOCATION] [if CONDITION]\n\
16202 LOCATION may be a linespec, explicit, or address location (described below) \n\
16203 or -m MARKER_ID.\n\n\
16204 If a marker id is specified, probe the marker with that name. With\n\
16205 no LOCATION, uses current execution address of the selected stack frame.\n\
16206 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16207 This collects arbitrary user data passed in the probe point call to the\n\
16208 tracing library. You can inspect it when analyzing the trace buffer,\n\
16209 by printing the $_sdata variable like any other convenience variable.\n\
16211 CONDITION is a boolean expression.\n\
16212 \n" LOCATION_HELP_STRING
"\n\
16213 Multiple tracepoints at one place are permitted, and useful if their\n\
16214 conditions are different.\n\
16216 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16217 Do \"help tracepoints\" for info on other tracepoint commands."));
16218 set_cmd_completer (c
, location_completer
);
16220 add_info ("tracepoints", info_tracepoints_command
, _("\
16221 Status of specified tracepoints (all tracepoints if no argument).\n\
16222 Convenience variable \"$tpnum\" contains the number of the\n\
16223 last tracepoint set."));
16225 add_info_alias ("tp", "tracepoints", 1);
16227 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16228 Delete specified tracepoints.\n\
16229 Arguments are tracepoint numbers, separated by spaces.\n\
16230 No argument means delete all tracepoints."),
16232 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16234 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16235 Disable specified tracepoints.\n\
16236 Arguments are tracepoint numbers, separated by spaces.\n\
16237 No argument means disable all tracepoints."),
16239 deprecate_cmd (c
, "disable");
16241 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16242 Enable specified tracepoints.\n\
16243 Arguments are tracepoint numbers, separated by spaces.\n\
16244 No argument means enable all tracepoints."),
16246 deprecate_cmd (c
, "enable");
16248 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16249 Set the passcount for a tracepoint.\n\
16250 The trace will end when the tracepoint has been passed 'count' times.\n\
16251 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16252 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16254 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16255 _("Save breakpoint definitions as a script."),
16256 &save_cmdlist
, "save ",
16257 0/*allow-unknown*/, &cmdlist
);
16259 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16260 Save current breakpoint definitions as a script.\n\
16261 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16262 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16263 session to restore them."),
16265 set_cmd_completer (c
, filename_completer
);
16267 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16268 Save current tracepoint definitions as a script.\n\
16269 Use the 'source' command in another debug session to restore them."),
16271 set_cmd_completer (c
, filename_completer
);
16273 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16274 deprecate_cmd (c
, "save tracepoints");
16276 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16277 Breakpoint specific settings\n\
16278 Configure various breakpoint-specific variables such as\n\
16279 pending breakpoint behavior"),
16280 &breakpoint_set_cmdlist
, "set breakpoint ",
16281 0/*allow-unknown*/, &setlist
);
16282 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16283 Breakpoint specific settings\n\
16284 Configure various breakpoint-specific variables such as\n\
16285 pending breakpoint behavior"),
16286 &breakpoint_show_cmdlist
, "show breakpoint ",
16287 0/*allow-unknown*/, &showlist
);
16289 add_setshow_auto_boolean_cmd ("pending", no_class
,
16290 &pending_break_support
, _("\
16291 Set debugger's behavior regarding pending breakpoints."), _("\
16292 Show debugger's behavior regarding pending breakpoints."), _("\
16293 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16294 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16295 an error. If auto, an unrecognized breakpoint location results in a\n\
16296 user-query to see if a pending breakpoint should be created."),
16298 show_pending_break_support
,
16299 &breakpoint_set_cmdlist
,
16300 &breakpoint_show_cmdlist
);
16302 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16304 add_setshow_boolean_cmd ("auto-hw", no_class
,
16305 &automatic_hardware_breakpoints
, _("\
16306 Set automatic usage of hardware breakpoints."), _("\
16307 Show automatic usage of hardware breakpoints."), _("\
16308 If set, the debugger will automatically use hardware breakpoints for\n\
16309 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16310 a warning will be emitted for such breakpoints."),
16312 show_automatic_hardware_breakpoints
,
16313 &breakpoint_set_cmdlist
,
16314 &breakpoint_show_cmdlist
);
16316 add_setshow_boolean_cmd ("always-inserted", class_support
,
16317 &always_inserted_mode
, _("\
16318 Set mode for inserting breakpoints."), _("\
16319 Show mode for inserting breakpoints."), _("\
16320 When this mode is on, breakpoints are inserted immediately as soon as\n\
16321 they're created, kept inserted even when execution stops, and removed\n\
16322 only when the user deletes them. When this mode is off (the default),\n\
16323 breakpoints are inserted only when execution continues, and removed\n\
16324 when execution stops."),
16326 &show_always_inserted_mode
,
16327 &breakpoint_set_cmdlist
,
16328 &breakpoint_show_cmdlist
);
16330 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16331 condition_evaluation_enums
,
16332 &condition_evaluation_mode_1
, _("\
16333 Set mode of breakpoint condition evaluation."), _("\
16334 Show mode of breakpoint condition evaluation."), _("\
16335 When this is set to \"host\", breakpoint conditions will be\n\
16336 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16337 breakpoint conditions will be downloaded to the target (if the target\n\
16338 supports such feature) and conditions will be evaluated on the target's side.\n\
16339 If this is set to \"auto\" (default), this will be automatically set to\n\
16340 \"target\" if it supports condition evaluation, otherwise it will\n\
16341 be set to \"gdb\""),
16342 &set_condition_evaluation_mode
,
16343 &show_condition_evaluation_mode
,
16344 &breakpoint_set_cmdlist
,
16345 &breakpoint_show_cmdlist
);
16347 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16348 Set a breakpoint for an address range.\n\
16349 break-range START-LOCATION, END-LOCATION\n\
16350 where START-LOCATION and END-LOCATION can be one of the following:\n\
16351 LINENUM, for that line in the current file,\n\
16352 FILE:LINENUM, for that line in that file,\n\
16353 +OFFSET, for that number of lines after the current line\n\
16354 or the start of the range\n\
16355 FUNCTION, for the first line in that function,\n\
16356 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16357 *ADDRESS, for the instruction at that address.\n\
16359 The breakpoint will stop execution of the inferior whenever it executes\n\
16360 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16361 range (including START-LOCATION and END-LOCATION)."));
16363 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16364 Set a dynamic printf at specified location.\n\
16365 dprintf location,format string,arg1,arg2,...\n\
16366 location may be a linespec, explicit, or address location.\n"
16367 "\n" LOCATION_HELP_STRING
));
16368 set_cmd_completer (c
, location_completer
);
16370 add_setshow_enum_cmd ("dprintf-style", class_support
,
16371 dprintf_style_enums
, &dprintf_style
, _("\
16372 Set the style of usage for dynamic printf."), _("\
16373 Show the style of usage for dynamic printf."), _("\
16374 This setting chooses how GDB will do a dynamic printf.\n\
16375 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16376 console, as with the \"printf\" command.\n\
16377 If the value is \"call\", the print is done by calling a function in your\n\
16378 program; by default printf(), but you can choose a different function or\n\
16379 output stream by setting dprintf-function and dprintf-channel."),
16380 update_dprintf_commands
, NULL
,
16381 &setlist
, &showlist
);
16383 dprintf_function
= xstrdup ("printf");
16384 add_setshow_string_cmd ("dprintf-function", class_support
,
16385 &dprintf_function
, _("\
16386 Set the function to use for dynamic printf"), _("\
16387 Show the function to use for dynamic printf"), NULL
,
16388 update_dprintf_commands
, NULL
,
16389 &setlist
, &showlist
);
16391 dprintf_channel
= xstrdup ("");
16392 add_setshow_string_cmd ("dprintf-channel", class_support
,
16393 &dprintf_channel
, _("\
16394 Set the channel to use for dynamic printf"), _("\
16395 Show the channel to use for dynamic printf"), NULL
,
16396 update_dprintf_commands
, NULL
,
16397 &setlist
, &showlist
);
16399 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16400 &disconnected_dprintf
, _("\
16401 Set whether dprintf continues after GDB disconnects."), _("\
16402 Show whether dprintf continues after GDB disconnects."), _("\
16403 Use this to let dprintf commands continue to hit and produce output\n\
16404 even if GDB disconnects or detaches from the target."),
16407 &setlist
, &showlist
);
16409 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16410 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16411 (target agent only) This is useful for formatted output in user-defined commands."));
16413 automatic_hardware_breakpoints
= 1;
16415 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16416 observer_attach_thread_exit (remove_threaded_breakpoints
);