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 void _initialize_breakpoint (void);
556 /* Are we executing breakpoint commands? */
557 static int executing_breakpoint_commands
;
559 /* Are overlay event breakpoints enabled? */
560 static int overlay_events_enabled
;
562 /* See description in breakpoint.h. */
563 int target_exact_watchpoints
= 0;
565 /* Walk the following statement or block through all breakpoints.
566 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
567 current breakpoint. */
569 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
571 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
572 for (B = breakpoint_chain; \
573 B ? (TMP=B->next, 1): 0; \
576 /* Similar iterator for the low-level breakpoints. SAFE variant is
577 not provided so update_global_location_list must not be called
578 while executing the block of ALL_BP_LOCATIONS. */
580 #define ALL_BP_LOCATIONS(B,BP_TMP) \
581 for (BP_TMP = bp_locations; \
582 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
585 /* Iterates through locations with address ADDRESS for the currently selected
586 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
587 to where the loop should start from.
588 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
589 appropriate location to start with. */
591 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
592 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
593 BP_LOCP_TMP = BP_LOCP_START; \
595 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
596 && (*BP_LOCP_TMP)->address == ADDRESS); \
599 /* Iterator for tracepoints only. */
601 #define ALL_TRACEPOINTS(B) \
602 for (B = breakpoint_chain; B; B = B->next) \
603 if (is_tracepoint (B))
605 /* Chains of all breakpoints defined. */
607 struct breakpoint
*breakpoint_chain
;
609 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
611 static struct bp_location
**bp_locations
;
613 /* Number of elements of BP_LOCATIONS. */
615 static unsigned bp_locations_count
;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATIONS which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_locations_placed_address_before_address_max
;
625 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
626 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
627 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATIONS to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from the bp_locations array, but for which a hit may still be
635 reported by a target. */
636 VEC(bp_location_p
) *moribund_locations
= NULL
;
638 /* Number of last breakpoint made. */
640 static int breakpoint_count
;
642 /* The value of `breakpoint_count' before the last command that
643 created breakpoints. If the last (break-like) command created more
644 than one breakpoint, then the difference between BREAKPOINT_COUNT
645 and PREV_BREAKPOINT_COUNT is more than one. */
646 static int prev_breakpoint_count
;
648 /* Number of last tracepoint made. */
650 static int tracepoint_count
;
652 static struct cmd_list_element
*breakpoint_set_cmdlist
;
653 static struct cmd_list_element
*breakpoint_show_cmdlist
;
654 struct cmd_list_element
*save_cmdlist
;
656 /* See declaration at breakpoint.h. */
659 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
662 struct breakpoint
*b
= NULL
;
666 if (func (b
, user_data
) != 0)
673 /* Return whether a breakpoint is an active enabled breakpoint. */
675 breakpoint_enabled (struct breakpoint
*b
)
677 return (b
->enable_state
== bp_enabled
);
680 /* Set breakpoint count to NUM. */
683 set_breakpoint_count (int num
)
685 prev_breakpoint_count
= breakpoint_count
;
686 breakpoint_count
= num
;
687 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
690 /* Used by `start_rbreak_breakpoints' below, to record the current
691 breakpoint count before "rbreak" creates any breakpoint. */
692 static int rbreak_start_breakpoint_count
;
694 /* Called at the start an "rbreak" command to record the first
698 start_rbreak_breakpoints (void)
700 rbreak_start_breakpoint_count
= breakpoint_count
;
703 /* Called at the end of an "rbreak" command to record the last
707 end_rbreak_breakpoints (void)
709 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
712 /* Used in run_command to zero the hit count when a new run starts. */
715 clear_breakpoint_hit_counts (void)
717 struct breakpoint
*b
;
723 /* Allocate a new counted_command_line with reference count of 1.
724 The new structure owns COMMANDS. */
726 static struct counted_command_line
*
727 alloc_counted_command_line (struct command_line
*commands
)
729 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
732 result
->commands
= commands
;
737 /* Increment reference count. This does nothing if CMD is NULL. */
740 incref_counted_command_line (struct counted_command_line
*cmd
)
746 /* Decrement reference count. If the reference count reaches 0,
747 destroy the counted_command_line. Sets *CMDP to NULL. This does
748 nothing if *CMDP is NULL. */
751 decref_counted_command_line (struct counted_command_line
**cmdp
)
755 if (--(*cmdp
)->refc
== 0)
757 free_command_lines (&(*cmdp
)->commands
);
764 /* A cleanup function that calls decref_counted_command_line. */
767 do_cleanup_counted_command_line (void *arg
)
769 decref_counted_command_line ((struct counted_command_line
**) arg
);
772 /* Create a cleanup that calls decref_counted_command_line on the
775 static struct cleanup
*
776 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
778 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
782 /* Return the breakpoint with the specified number, or NULL
783 if the number does not refer to an existing breakpoint. */
786 get_breakpoint (int num
)
788 struct breakpoint
*b
;
791 if (b
->number
== num
)
799 /* Mark locations as "conditions have changed" in case the target supports
800 evaluating conditions on its side. */
803 mark_breakpoint_modified (struct breakpoint
*b
)
805 struct bp_location
*loc
;
807 /* This is only meaningful if the target is
808 evaluating conditions and if the user has
809 opted for condition evaluation on the target's
811 if (gdb_evaluates_breakpoint_condition_p ()
812 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (b
))
818 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
819 loc
->condition_changed
= condition_modified
;
822 /* Mark location as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_location_modified (struct bp_location
*loc
)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
837 if (!is_breakpoint (loc
->owner
))
840 loc
->condition_changed
= condition_modified
;
843 /* Sets the condition-evaluation mode using the static global
844 condition_evaluation_mode. */
847 set_condition_evaluation_mode (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 const char *old_mode
, *new_mode
;
852 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
853 && !target_supports_evaluation_of_breakpoint_conditions ())
855 condition_evaluation_mode_1
= condition_evaluation_mode
;
856 warning (_("Target does not support breakpoint condition evaluation.\n"
857 "Using host evaluation mode instead."));
861 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
862 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
864 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
865 settings was "auto". */
866 condition_evaluation_mode
= condition_evaluation_mode_1
;
868 /* Only update the mode if the user picked a different one. */
869 if (new_mode
!= old_mode
)
871 struct bp_location
*loc
, **loc_tmp
;
872 /* If the user switched to a different evaluation mode, we
873 need to synch the changes with the target as follows:
875 "host" -> "target": Send all (valid) conditions to the target.
876 "target" -> "host": Remove all the conditions from the target.
879 if (new_mode
== condition_evaluation_target
)
881 /* Mark everything modified and synch conditions with the
883 ALL_BP_LOCATIONS (loc
, loc_tmp
)
884 mark_breakpoint_location_modified (loc
);
888 /* Manually mark non-duplicate locations to synch conditions
889 with the target. We do this to remove all the conditions the
890 target knows about. */
891 ALL_BP_LOCATIONS (loc
, loc_tmp
)
892 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
893 loc
->needs_update
= 1;
897 update_global_location_list (UGLL_MAY_INSERT
);
903 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
904 what "auto" is translating to. */
907 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
908 struct cmd_list_element
*c
, const char *value
)
910 if (condition_evaluation_mode
== condition_evaluation_auto
)
911 fprintf_filtered (file
,
912 _("Breakpoint condition evaluation "
913 "mode is %s (currently %s).\n"),
915 breakpoint_condition_evaluation_mode ());
917 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
921 /* A comparison function for bp_location AP and BP that is used by
922 bsearch. This comparison function only cares about addresses, unlike
923 the more general bp_locations_compare function. */
926 bp_locations_compare_addrs (const void *ap
, const void *bp
)
928 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
929 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
931 if (a
->address
== b
->address
)
934 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
937 /* Helper function to skip all bp_locations with addresses
938 less than ADDRESS. It returns the first bp_location that
939 is greater than or equal to ADDRESS. If none is found, just
942 static struct bp_location
**
943 get_first_locp_gte_addr (CORE_ADDR address
)
945 struct bp_location dummy_loc
;
946 struct bp_location
*dummy_locp
= &dummy_loc
;
947 struct bp_location
**locp_found
= NULL
;
949 /* Initialize the dummy location's address field. */
950 dummy_loc
.address
= address
;
952 /* Find a close match to the first location at ADDRESS. */
953 locp_found
= ((struct bp_location
**)
954 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
955 sizeof (struct bp_location
**),
956 bp_locations_compare_addrs
));
958 /* Nothing was found, nothing left to do. */
959 if (locp_found
== NULL
)
962 /* We may have found a location that is at ADDRESS but is not the first in the
963 location's list. Go backwards (if possible) and locate the first one. */
964 while ((locp_found
- 1) >= bp_locations
965 && (*(locp_found
- 1))->address
== address
)
972 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
975 xfree (b
->cond_string
);
976 b
->cond_string
= NULL
;
978 if (is_watchpoint (b
))
980 struct watchpoint
*w
= (struct watchpoint
*) b
;
982 w
->cond_exp
.reset ();
986 struct bp_location
*loc
;
988 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
992 /* No need to free the condition agent expression
993 bytecode (if we have one). We will handle this
994 when we go through update_global_location_list. */
1001 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1005 const char *arg
= exp
;
1007 /* I don't know if it matters whether this is the string the user
1008 typed in or the decompiled expression. */
1009 b
->cond_string
= xstrdup (arg
);
1010 b
->condition_not_parsed
= 0;
1012 if (is_watchpoint (b
))
1014 struct watchpoint
*w
= (struct watchpoint
*) b
;
1016 innermost_block
= NULL
;
1018 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1020 error (_("Junk at end of expression"));
1021 w
->cond_exp_valid_block
= innermost_block
;
1025 struct bp_location
*loc
;
1027 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1031 parse_exp_1 (&arg
, loc
->address
,
1032 block_for_pc (loc
->address
), 0);
1034 error (_("Junk at end of expression"));
1038 mark_breakpoint_modified (b
);
1040 observer_notify_breakpoint_modified (b
);
1043 /* Completion for the "condition" command. */
1046 condition_completer (struct cmd_list_element
*cmd
,
1047 completion_tracker
&tracker
,
1048 const char *text
, const char *word
)
1052 text
= skip_spaces_const (text
);
1053 space
= skip_to_space_const (text
);
1057 struct breakpoint
*b
;
1058 VEC (char_ptr
) *result
= NULL
;
1062 /* We don't support completion of history indices. */
1063 if (!isdigit (text
[1]))
1064 complete_internalvar (tracker
, &text
[1]);
1068 /* We're completing the breakpoint number. */
1069 len
= strlen (text
);
1075 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1077 if (strncmp (number
, text
, len
) == 0)
1079 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
1080 tracker
.add_completion (std::move (copy
));
1087 /* We're completing the expression part. */
1088 text
= skip_spaces_const (space
);
1089 expression_completer (cmd
, tracker
, text
, word
);
1092 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1095 condition_command (char *arg
, int from_tty
)
1097 struct breakpoint
*b
;
1102 error_no_arg (_("breakpoint number"));
1105 bnum
= get_number (&p
);
1107 error (_("Bad breakpoint argument: '%s'"), arg
);
1110 if (b
->number
== bnum
)
1112 /* Check if this breakpoint has a "stop" method implemented in an
1113 extension language. This method and conditions entered into GDB
1114 from the CLI are mutually exclusive. */
1115 const struct extension_language_defn
*extlang
1116 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1118 if (extlang
!= NULL
)
1120 error (_("Only one stop condition allowed. There is currently"
1121 " a %s stop condition defined for this breakpoint."),
1122 ext_lang_capitalized_name (extlang
));
1124 set_breakpoint_condition (b
, p
, from_tty
);
1126 if (is_breakpoint (b
))
1127 update_global_location_list (UGLL_MAY_INSERT
);
1132 error (_("No breakpoint number %d."), bnum
);
1135 /* Check that COMMAND do not contain commands that are suitable
1136 only for tracepoints and not suitable for ordinary breakpoints.
1137 Throw if any such commands is found. */
1140 check_no_tracepoint_commands (struct command_line
*commands
)
1142 struct command_line
*c
;
1144 for (c
= commands
; c
; c
= c
->next
)
1148 if (c
->control_type
== while_stepping_control
)
1149 error (_("The 'while-stepping' command can "
1150 "only be used for tracepoints"));
1152 for (i
= 0; i
< c
->body_count
; ++i
)
1153 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1155 /* Not that command parsing removes leading whitespace and comment
1156 lines and also empty lines. So, we only need to check for
1157 command directly. */
1158 if (strstr (c
->line
, "collect ") == c
->line
)
1159 error (_("The 'collect' command can only be used for tracepoints"));
1161 if (strstr (c
->line
, "teval ") == c
->line
)
1162 error (_("The 'teval' command can only be used for tracepoints"));
1166 struct longjmp_breakpoint
: public breakpoint
1168 ~longjmp_breakpoint () override
;
1171 /* Encapsulate tests for different types of tracepoints. */
1174 is_tracepoint_type (bptype type
)
1176 return (type
== bp_tracepoint
1177 || type
== bp_fast_tracepoint
1178 || type
== bp_static_tracepoint
);
1182 is_longjmp_type (bptype type
)
1184 return type
== bp_longjmp
|| type
== bp_exception
;
1188 is_tracepoint (const struct breakpoint
*b
)
1190 return is_tracepoint_type (b
->type
);
1193 /* Factory function to create an appropriate instance of breakpoint given
1196 static std::unique_ptr
<breakpoint
>
1197 new_breakpoint_from_type (bptype type
)
1201 if (is_tracepoint_type (type
))
1202 b
= new tracepoint ();
1203 else if (is_longjmp_type (type
))
1204 b
= new longjmp_breakpoint ();
1206 b
= new breakpoint ();
1208 return std::unique_ptr
<breakpoint
> (b
);
1211 /* A helper function that validates that COMMANDS are valid for a
1212 breakpoint. This function will throw an exception if a problem is
1216 validate_commands_for_breakpoint (struct breakpoint
*b
,
1217 struct command_line
*commands
)
1219 if (is_tracepoint (b
))
1221 struct tracepoint
*t
= (struct tracepoint
*) b
;
1222 struct command_line
*c
;
1223 struct command_line
*while_stepping
= 0;
1225 /* Reset the while-stepping step count. The previous commands
1226 might have included a while-stepping action, while the new
1230 /* We need to verify that each top-level element of commands is
1231 valid for tracepoints, that there's at most one
1232 while-stepping element, and that the while-stepping's body
1233 has valid tracing commands excluding nested while-stepping.
1234 We also need to validate the tracepoint action line in the
1235 context of the tracepoint --- validate_actionline actually
1236 has side effects, like setting the tracepoint's
1237 while-stepping STEP_COUNT, in addition to checking if the
1238 collect/teval actions parse and make sense in the
1239 tracepoint's context. */
1240 for (c
= commands
; c
; c
= c
->next
)
1242 if (c
->control_type
== while_stepping_control
)
1244 if (b
->type
== bp_fast_tracepoint
)
1245 error (_("The 'while-stepping' command "
1246 "cannot be used for fast tracepoint"));
1247 else if (b
->type
== bp_static_tracepoint
)
1248 error (_("The 'while-stepping' command "
1249 "cannot be used for static tracepoint"));
1252 error (_("The 'while-stepping' command "
1253 "can be used only once"));
1258 validate_actionline (c
->line
, b
);
1262 struct command_line
*c2
;
1264 gdb_assert (while_stepping
->body_count
== 1);
1265 c2
= while_stepping
->body_list
[0];
1266 for (; c2
; c2
= c2
->next
)
1268 if (c2
->control_type
== while_stepping_control
)
1269 error (_("The 'while-stepping' command cannot be nested"));
1275 check_no_tracepoint_commands (commands
);
1279 /* Return a vector of all the static tracepoints set at ADDR. The
1280 caller is responsible for releasing the vector. */
1283 static_tracepoints_here (CORE_ADDR addr
)
1285 struct breakpoint
*b
;
1286 VEC(breakpoint_p
) *found
= 0;
1287 struct bp_location
*loc
;
1290 if (b
->type
== bp_static_tracepoint
)
1292 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1293 if (loc
->address
== addr
)
1294 VEC_safe_push(breakpoint_p
, found
, b
);
1300 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1301 validate that only allowed commands are included. */
1304 breakpoint_set_commands (struct breakpoint
*b
,
1305 command_line_up
&&commands
)
1307 validate_commands_for_breakpoint (b
, commands
.get ());
1309 decref_counted_command_line (&b
->commands
);
1310 b
->commands
= alloc_counted_command_line (commands
.release ());
1311 observer_notify_breakpoint_modified (b
);
1314 /* Set the internal `silent' flag on the breakpoint. Note that this
1315 is not the same as the "silent" that may appear in the breakpoint's
1319 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1321 int old_silent
= b
->silent
;
1324 if (old_silent
!= silent
)
1325 observer_notify_breakpoint_modified (b
);
1328 /* Set the thread for this breakpoint. If THREAD is -1, make the
1329 breakpoint work for any thread. */
1332 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1334 int old_thread
= b
->thread
;
1337 if (old_thread
!= thread
)
1338 observer_notify_breakpoint_modified (b
);
1341 /* Set the task for this breakpoint. If TASK is 0, make the
1342 breakpoint work for any task. */
1345 breakpoint_set_task (struct breakpoint
*b
, int task
)
1347 int old_task
= b
->task
;
1350 if (old_task
!= task
)
1351 observer_notify_breakpoint_modified (b
);
1355 check_tracepoint_command (char *line
, void *closure
)
1357 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1359 validate_actionline (line
, b
);
1362 /* A structure used to pass information through
1363 map_breakpoint_numbers. */
1365 struct commands_info
1367 /* True if the command was typed at a tty. */
1370 /* The breakpoint range spec. */
1373 /* Non-NULL if the body of the commands are being read from this
1374 already-parsed command. */
1375 struct command_line
*control
;
1377 /* The command lines read from the user, or NULL if they have not
1379 struct counted_command_line
*cmd
;
1382 /* A callback for map_breakpoint_numbers that sets the commands for
1383 commands_command. */
1386 do_map_commands_command (struct breakpoint
*b
, void *data
)
1388 struct commands_info
*info
= (struct commands_info
*) data
;
1390 if (info
->cmd
== NULL
)
1394 if (info
->control
!= NULL
)
1395 l
= copy_command_lines (info
->control
->body_list
[0]);
1398 struct cleanup
*old_chain
;
1401 str
= xstrprintf (_("Type commands for breakpoint(s) "
1402 "%s, one per line."),
1405 old_chain
= make_cleanup (xfree
, str
);
1407 l
= read_command_lines (str
,
1410 ? check_tracepoint_command
: 0),
1413 do_cleanups (old_chain
);
1416 info
->cmd
= alloc_counted_command_line (l
.release ());
1419 /* If a breakpoint was on the list more than once, we don't need to
1421 if (b
->commands
!= info
->cmd
)
1423 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1424 incref_counted_command_line (info
->cmd
);
1425 decref_counted_command_line (&b
->commands
);
1426 b
->commands
= info
->cmd
;
1427 observer_notify_breakpoint_modified (b
);
1432 commands_command_1 (const char *arg
, int from_tty
,
1433 struct command_line
*control
)
1435 struct cleanup
*cleanups
;
1436 struct commands_info info
;
1438 info
.from_tty
= from_tty
;
1439 info
.control
= control
;
1441 /* If we read command lines from the user, then `info' will hold an
1442 extra reference to the commands that we must clean up. */
1443 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1445 std::string new_arg
;
1447 if (arg
== NULL
|| !*arg
)
1449 if (breakpoint_count
- prev_breakpoint_count
> 1)
1450 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1452 else if (breakpoint_count
> 0)
1453 new_arg
= string_printf ("%d", breakpoint_count
);
1458 info
.arg
= new_arg
.c_str ();
1460 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1462 if (info
.cmd
== NULL
)
1463 error (_("No breakpoints specified."));
1465 do_cleanups (cleanups
);
1469 commands_command (char *arg
, int from_tty
)
1471 commands_command_1 (arg
, from_tty
, NULL
);
1474 /* Like commands_command, but instead of reading the commands from
1475 input stream, takes them from an already parsed command structure.
1477 This is used by cli-script.c to DTRT with breakpoint commands
1478 that are part of if and while bodies. */
1479 enum command_control_type
1480 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1482 commands_command_1 (arg
, 0, cmd
);
1483 return simple_control
;
1486 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1489 bp_location_has_shadow (struct bp_location
*bl
)
1491 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1495 if (bl
->target_info
.shadow_len
== 0)
1496 /* BL isn't valid, or doesn't shadow memory. */
1501 /* Update BUF, which is LEN bytes read from the target address
1502 MEMADDR, by replacing a memory breakpoint with its shadowed
1505 If READBUF is not NULL, this buffer must not overlap with the of
1506 the breakpoint location's shadow_contents buffer. Otherwise, a
1507 failed assertion internal error will be raised. */
1510 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1511 const gdb_byte
*writebuf_org
,
1512 ULONGEST memaddr
, LONGEST len
,
1513 struct bp_target_info
*target_info
,
1514 struct gdbarch
*gdbarch
)
1516 /* Now do full processing of the found relevant range of elements. */
1517 CORE_ADDR bp_addr
= 0;
1521 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1522 current_program_space
->aspace
, 0))
1524 /* The breakpoint is inserted in a different address space. */
1528 /* Addresses and length of the part of the breakpoint that
1530 bp_addr
= target_info
->placed_address
;
1531 bp_size
= target_info
->shadow_len
;
1533 if (bp_addr
+ bp_size
<= memaddr
)
1535 /* The breakpoint is entirely before the chunk of memory we are
1540 if (bp_addr
>= memaddr
+ len
)
1542 /* The breakpoint is entirely after the chunk of memory we are
1547 /* Offset within shadow_contents. */
1548 if (bp_addr
< memaddr
)
1550 /* Only copy the second part of the breakpoint. */
1551 bp_size
-= memaddr
- bp_addr
;
1552 bptoffset
= memaddr
- bp_addr
;
1556 if (bp_addr
+ bp_size
> memaddr
+ len
)
1558 /* Only copy the first part of the breakpoint. */
1559 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1562 if (readbuf
!= NULL
)
1564 /* Verify that the readbuf buffer does not overlap with the
1565 shadow_contents buffer. */
1566 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1567 || readbuf
>= (target_info
->shadow_contents
1568 + target_info
->shadow_len
));
1570 /* Update the read buffer with this inserted breakpoint's
1572 memcpy (readbuf
+ bp_addr
- memaddr
,
1573 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1577 const unsigned char *bp
;
1578 CORE_ADDR addr
= target_info
->reqstd_address
;
1581 /* Update the shadow with what we want to write to memory. */
1582 memcpy (target_info
->shadow_contents
+ bptoffset
,
1583 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1585 /* Determine appropriate breakpoint contents and size for this
1587 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1589 /* Update the final write buffer with this inserted
1590 breakpoint's INSN. */
1591 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1595 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1596 by replacing any memory breakpoints with their shadowed contents.
1598 If READBUF is not NULL, this buffer must not overlap with any of
1599 the breakpoint location's shadow_contents buffers. Otherwise,
1600 a failed assertion internal error will be raised.
1602 The range of shadowed area by each bp_location is:
1603 bl->address - bp_locations_placed_address_before_address_max
1604 up to bl->address + bp_locations_shadow_len_after_address_max
1605 The range we were requested to resolve shadows for is:
1606 memaddr ... memaddr + len
1607 Thus the safe cutoff boundaries for performance optimization are
1608 memaddr + len <= (bl->address
1609 - bp_locations_placed_address_before_address_max)
1611 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1614 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1615 const gdb_byte
*writebuf_org
,
1616 ULONGEST memaddr
, LONGEST len
)
1618 /* Left boundary, right boundary and median element of our binary
1620 unsigned bc_l
, bc_r
, bc
;
1622 /* Find BC_L which is a leftmost element which may affect BUF
1623 content. It is safe to report lower value but a failure to
1624 report higher one. */
1627 bc_r
= bp_locations_count
;
1628 while (bc_l
+ 1 < bc_r
)
1630 struct bp_location
*bl
;
1632 bc
= (bc_l
+ bc_r
) / 2;
1633 bl
= bp_locations
[bc
];
1635 /* Check first BL->ADDRESS will not overflow due to the added
1636 constant. Then advance the left boundary only if we are sure
1637 the BC element can in no way affect the BUF content (MEMADDR
1638 to MEMADDR + LEN range).
1640 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1641 offset so that we cannot miss a breakpoint with its shadow
1642 range tail still reaching MEMADDR. */
1644 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1646 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1653 /* Due to the binary search above, we need to make sure we pick the
1654 first location that's at BC_L's address. E.g., if there are
1655 multiple locations at the same address, BC_L may end up pointing
1656 at a duplicate location, and miss the "master"/"inserted"
1657 location. Say, given locations L1, L2 and L3 at addresses A and
1660 L1@A, L2@A, L3@B, ...
1662 BC_L could end up pointing at location L2, while the "master"
1663 location could be L1. Since the `loc->inserted' flag is only set
1664 on "master" locations, we'd forget to restore the shadow of L1
1667 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1670 /* Now do full processing of the found relevant range of elements. */
1672 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1674 struct bp_location
*bl
= bp_locations
[bc
];
1676 /* bp_location array has BL->OWNER always non-NULL. */
1677 if (bl
->owner
->type
== bp_none
)
1678 warning (_("reading through apparently deleted breakpoint #%d?"),
1681 /* Performance optimization: any further element can no longer affect BUF
1684 if (bl
->address
>= bp_locations_placed_address_before_address_max
1685 && memaddr
+ len
<= (bl
->address
1686 - bp_locations_placed_address_before_address_max
))
1689 if (!bp_location_has_shadow (bl
))
1692 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1693 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1699 /* Return true if BPT is either a software breakpoint or a hardware
1703 is_breakpoint (const struct breakpoint
*bpt
)
1705 return (bpt
->type
== bp_breakpoint
1706 || bpt
->type
== bp_hardware_breakpoint
1707 || bpt
->type
== bp_dprintf
);
1710 /* Return true if BPT is of any hardware watchpoint kind. */
1713 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1715 return (bpt
->type
== bp_hardware_watchpoint
1716 || bpt
->type
== bp_read_watchpoint
1717 || bpt
->type
== bp_access_watchpoint
);
1720 /* Return true if BPT is of any watchpoint kind, hardware or
1724 is_watchpoint (const struct breakpoint
*bpt
)
1726 return (is_hardware_watchpoint (bpt
)
1727 || bpt
->type
== bp_watchpoint
);
1730 /* Returns true if the current thread and its running state are safe
1731 to evaluate or update watchpoint B. Watchpoints on local
1732 expressions need to be evaluated in the context of the thread that
1733 was current when the watchpoint was created, and, that thread needs
1734 to be stopped to be able to select the correct frame context.
1735 Watchpoints on global expressions can be evaluated on any thread,
1736 and in any state. It is presently left to the target allowing
1737 memory accesses when threads are running. */
1740 watchpoint_in_thread_scope (struct watchpoint
*b
)
1742 return (b
->pspace
== current_program_space
1743 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1744 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1745 && !is_executing (inferior_ptid
))));
1748 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1749 associated bp_watchpoint_scope breakpoint. */
1752 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1754 if (w
->related_breakpoint
!= w
)
1756 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1757 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1758 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1759 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1760 w
->related_breakpoint
= w
;
1762 w
->disposition
= disp_del_at_next_stop
;
1765 /* Extract a bitfield value from value VAL using the bit parameters contained in
1768 static struct value
*
1769 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1771 struct value
*bit_val
;
1776 bit_val
= allocate_value (value_type (val
));
1778 unpack_value_bitfield (bit_val
,
1781 value_contents_for_printing (val
),
1788 /* Allocate a dummy location and add it to B, which must be a software
1789 watchpoint. This is required because even if a software watchpoint
1790 is not watching any memory, bpstat_stop_status requires a location
1791 to be able to report stops. */
1794 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1795 struct program_space
*pspace
)
1797 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1799 b
->loc
= allocate_bp_location (b
);
1800 b
->loc
->pspace
= pspace
;
1801 b
->loc
->address
= -1;
1802 b
->loc
->length
= -1;
1805 /* Returns true if B is a software watchpoint that is not watching any
1806 memory (e.g., "watch $pc"). */
1809 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1811 return (b
->type
== bp_watchpoint
1813 && b
->loc
->next
== NULL
1814 && b
->loc
->address
== -1
1815 && b
->loc
->length
== -1);
1818 /* Assuming that B is a watchpoint:
1819 - Reparse watchpoint expression, if REPARSE is non-zero
1820 - Evaluate expression and store the result in B->val
1821 - Evaluate the condition if there is one, and store the result
1823 - Update the list of values that must be watched in B->loc.
1825 If the watchpoint disposition is disp_del_at_next_stop, then do
1826 nothing. If this is local watchpoint that is out of scope, delete
1829 Even with `set breakpoint always-inserted on' the watchpoints are
1830 removed + inserted on each stop here. Normal breakpoints must
1831 never be removed because they might be missed by a running thread
1832 when debugging in non-stop mode. On the other hand, hardware
1833 watchpoints (is_hardware_watchpoint; processed here) are specific
1834 to each LWP since they are stored in each LWP's hardware debug
1835 registers. Therefore, such LWP must be stopped first in order to
1836 be able to modify its hardware watchpoints.
1838 Hardware watchpoints must be reset exactly once after being
1839 presented to the user. It cannot be done sooner, because it would
1840 reset the data used to present the watchpoint hit to the user. And
1841 it must not be done later because it could display the same single
1842 watchpoint hit during multiple GDB stops. Note that the latter is
1843 relevant only to the hardware watchpoint types bp_read_watchpoint
1844 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1845 not user-visible - its hit is suppressed if the memory content has
1848 The following constraints influence the location where we can reset
1849 hardware watchpoints:
1851 * target_stopped_by_watchpoint and target_stopped_data_address are
1852 called several times when GDB stops.
1855 * Multiple hardware watchpoints can be hit at the same time,
1856 causing GDB to stop. GDB only presents one hardware watchpoint
1857 hit at a time as the reason for stopping, and all the other hits
1858 are presented later, one after the other, each time the user
1859 requests the execution to be resumed. Execution is not resumed
1860 for the threads still having pending hit event stored in
1861 LWP_INFO->STATUS. While the watchpoint is already removed from
1862 the inferior on the first stop the thread hit event is kept being
1863 reported from its cached value by linux_nat_stopped_data_address
1864 until the real thread resume happens after the watchpoint gets
1865 presented and thus its LWP_INFO->STATUS gets reset.
1867 Therefore the hardware watchpoint hit can get safely reset on the
1868 watchpoint removal from inferior. */
1871 update_watchpoint (struct watchpoint
*b
, int reparse
)
1873 int within_current_scope
;
1874 struct frame_id saved_frame_id
;
1877 /* If this is a local watchpoint, we only want to check if the
1878 watchpoint frame is in scope if the current thread is the thread
1879 that was used to create the watchpoint. */
1880 if (!watchpoint_in_thread_scope (b
))
1883 if (b
->disposition
== disp_del_at_next_stop
)
1888 /* Determine if the watchpoint is within scope. */
1889 if (b
->exp_valid_block
== NULL
)
1890 within_current_scope
= 1;
1893 struct frame_info
*fi
= get_current_frame ();
1894 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1895 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1897 /* If we're at a point where the stack has been destroyed
1898 (e.g. in a function epilogue), unwinding may not work
1899 properly. Do not attempt to recreate locations at this
1900 point. See similar comments in watchpoint_check. */
1901 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1904 /* Save the current frame's ID so we can restore it after
1905 evaluating the watchpoint expression on its own frame. */
1906 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1907 took a frame parameter, so that we didn't have to change the
1910 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1912 fi
= frame_find_by_id (b
->watchpoint_frame
);
1913 within_current_scope
= (fi
!= NULL
);
1914 if (within_current_scope
)
1918 /* We don't free locations. They are stored in the bp_location array
1919 and update_global_location_list will eventually delete them and
1920 remove breakpoints if needed. */
1923 if (within_current_scope
&& reparse
)
1928 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1929 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1930 /* If the meaning of expression itself changed, the old value is
1931 no longer relevant. We don't want to report a watchpoint hit
1932 to the user when the old value and the new value may actually
1933 be completely different objects. */
1934 value_free (b
->val
);
1938 /* Note that unlike with breakpoints, the watchpoint's condition
1939 expression is stored in the breakpoint object, not in the
1940 locations (re)created below. */
1941 if (b
->cond_string
!= NULL
)
1943 b
->cond_exp
.reset ();
1946 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1950 /* If we failed to parse the expression, for example because
1951 it refers to a global variable in a not-yet-loaded shared library,
1952 don't try to insert watchpoint. We don't automatically delete
1953 such watchpoint, though, since failure to parse expression
1954 is different from out-of-scope watchpoint. */
1955 if (!target_has_execution
)
1957 /* Without execution, memory can't change. No use to try and
1958 set watchpoint locations. The watchpoint will be reset when
1959 the target gains execution, through breakpoint_re_set. */
1960 if (!can_use_hw_watchpoints
)
1962 if (b
->ops
->works_in_software_mode (b
))
1963 b
->type
= bp_watchpoint
;
1965 error (_("Can't set read/access watchpoint when "
1966 "hardware watchpoints are disabled."));
1969 else if (within_current_scope
&& b
->exp
)
1972 struct value
*val_chain
, *v
, *result
, *next
;
1973 struct program_space
*frame_pspace
;
1975 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1977 /* Avoid setting b->val if it's already set. The meaning of
1978 b->val is 'the last value' user saw, and we should update
1979 it only if we reported that last value to user. As it
1980 happens, the code that reports it updates b->val directly.
1981 We don't keep track of the memory value for masked
1983 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1985 if (b
->val_bitsize
!= 0)
1987 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1995 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1997 /* Look at each value on the value chain. */
1998 for (v
= val_chain
; v
; v
= value_next (v
))
2000 /* If it's a memory location, and GDB actually needed
2001 its contents to evaluate the expression, then we
2002 must watch it. If the first value returned is
2003 still lazy, that means an error occurred reading it;
2004 watch it anyway in case it becomes readable. */
2005 if (VALUE_LVAL (v
) == lval_memory
2006 && (v
== val_chain
|| ! value_lazy (v
)))
2008 struct type
*vtype
= check_typedef (value_type (v
));
2010 /* We only watch structs and arrays if user asked
2011 for it explicitly, never if they just happen to
2012 appear in the middle of some value chain. */
2014 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2015 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2018 enum target_hw_bp_type type
;
2019 struct bp_location
*loc
, **tmp
;
2020 int bitpos
= 0, bitsize
= 0;
2022 if (value_bitsize (v
) != 0)
2024 /* Extract the bit parameters out from the bitfield
2026 bitpos
= value_bitpos (v
);
2027 bitsize
= value_bitsize (v
);
2029 else if (v
== result
&& b
->val_bitsize
!= 0)
2031 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2032 lvalue whose bit parameters are saved in the fields
2033 VAL_BITPOS and VAL_BITSIZE. */
2034 bitpos
= b
->val_bitpos
;
2035 bitsize
= b
->val_bitsize
;
2038 addr
= value_address (v
);
2041 /* Skip the bytes that don't contain the bitfield. */
2046 if (b
->type
== bp_read_watchpoint
)
2048 else if (b
->type
== bp_access_watchpoint
)
2051 loc
= allocate_bp_location (b
);
2052 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2055 loc
->gdbarch
= get_type_arch (value_type (v
));
2057 loc
->pspace
= frame_pspace
;
2058 loc
->address
= addr
;
2062 /* Just cover the bytes that make up the bitfield. */
2063 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2066 loc
->length
= TYPE_LENGTH (value_type (v
));
2068 loc
->watchpoint_type
= type
;
2073 /* Change the type of breakpoint between hardware assisted or
2074 an ordinary watchpoint depending on the hardware support
2075 and free hardware slots. REPARSE is set when the inferior
2080 enum bp_loc_type loc_type
;
2081 struct bp_location
*bl
;
2083 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2087 int i
, target_resources_ok
, other_type_used
;
2090 /* Use an exact watchpoint when there's only one memory region to be
2091 watched, and only one debug register is needed to watch it. */
2092 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2094 /* We need to determine how many resources are already
2095 used for all other hardware watchpoints plus this one
2096 to see if we still have enough resources to also fit
2097 this watchpoint in as well. */
2099 /* If this is a software watchpoint, we try to turn it
2100 to a hardware one -- count resources as if B was of
2101 hardware watchpoint type. */
2103 if (type
== bp_watchpoint
)
2104 type
= bp_hardware_watchpoint
;
2106 /* This watchpoint may or may not have been placed on
2107 the list yet at this point (it won't be in the list
2108 if we're trying to create it for the first time,
2109 through watch_command), so always account for it
2112 /* Count resources used by all watchpoints except B. */
2113 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2115 /* Add in the resources needed for B. */
2116 i
+= hw_watchpoint_use_count (b
);
2119 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2120 if (target_resources_ok
<= 0)
2122 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2124 if (target_resources_ok
== 0 && !sw_mode
)
2125 error (_("Target does not support this type of "
2126 "hardware watchpoint."));
2127 else if (target_resources_ok
< 0 && !sw_mode
)
2128 error (_("There are not enough available hardware "
2129 "resources for this watchpoint."));
2131 /* Downgrade to software watchpoint. */
2132 b
->type
= bp_watchpoint
;
2136 /* If this was a software watchpoint, we've just
2137 found we have enough resources to turn it to a
2138 hardware watchpoint. Otherwise, this is a
2143 else if (!b
->ops
->works_in_software_mode (b
))
2145 if (!can_use_hw_watchpoints
)
2146 error (_("Can't set read/access watchpoint when "
2147 "hardware watchpoints are disabled."));
2149 error (_("Expression cannot be implemented with "
2150 "read/access watchpoint."));
2153 b
->type
= bp_watchpoint
;
2155 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2156 : bp_loc_hardware_watchpoint
);
2157 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2158 bl
->loc_type
= loc_type
;
2161 for (v
= val_chain
; v
; v
= next
)
2163 next
= value_next (v
);
2168 /* If a software watchpoint is not watching any memory, then the
2169 above left it without any location set up. But,
2170 bpstat_stop_status requires a location to be able to report
2171 stops, so make sure there's at least a dummy one. */
2172 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2173 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2175 else if (!within_current_scope
)
2177 printf_filtered (_("\
2178 Watchpoint %d deleted because the program has left the block\n\
2179 in which its expression is valid.\n"),
2181 watchpoint_del_at_next_stop (b
);
2184 /* Restore the selected frame. */
2186 select_frame (frame_find_by_id (saved_frame_id
));
2190 /* Returns 1 iff breakpoint location should be
2191 inserted in the inferior. We don't differentiate the type of BL's owner
2192 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2193 breakpoint_ops is not defined, because in insert_bp_location,
2194 tracepoint's insert_location will not be called. */
2196 should_be_inserted (struct bp_location
*bl
)
2198 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2201 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2204 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2207 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2210 /* This is set for example, when we're attached to the parent of a
2211 vfork, and have detached from the child. The child is running
2212 free, and we expect it to do an exec or exit, at which point the
2213 OS makes the parent schedulable again (and the target reports
2214 that the vfork is done). Until the child is done with the shared
2215 memory region, do not insert breakpoints in the parent, otherwise
2216 the child could still trip on the parent's breakpoints. Since
2217 the parent is blocked anyway, it won't miss any breakpoint. */
2218 if (bl
->pspace
->breakpoints_not_allowed
)
2221 /* Don't insert a breakpoint if we're trying to step past its
2222 location, except if the breakpoint is a single-step breakpoint,
2223 and the breakpoint's thread is the thread which is stepping past
2225 if ((bl
->loc_type
== bp_loc_software_breakpoint
2226 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2227 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2229 /* The single-step breakpoint may be inserted at the location
2230 we're trying to step if the instruction branches to itself.
2231 However, the instruction won't be executed at all and it may
2232 break the semantics of the instruction, for example, the
2233 instruction is a conditional branch or updates some flags.
2234 We can't fix it unless GDB is able to emulate the instruction
2235 or switch to displaced stepping. */
2236 && !(bl
->owner
->type
== bp_single_step
2237 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2241 fprintf_unfiltered (gdb_stdlog
,
2242 "infrun: skipping breakpoint: "
2243 "stepping past insn at: %s\n",
2244 paddress (bl
->gdbarch
, bl
->address
));
2249 /* Don't insert watchpoints if we're trying to step past the
2250 instruction that triggered one. */
2251 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2252 && stepping_past_nonsteppable_watchpoint ())
2256 fprintf_unfiltered (gdb_stdlog
,
2257 "infrun: stepping past non-steppable watchpoint. "
2258 "skipping watchpoint at %s:%d\n",
2259 paddress (bl
->gdbarch
, bl
->address
),
2268 /* Same as should_be_inserted but does the check assuming
2269 that the location is not duplicated. */
2272 unduplicated_should_be_inserted (struct bp_location
*bl
)
2275 const int save_duplicate
= bl
->duplicate
;
2278 result
= should_be_inserted (bl
);
2279 bl
->duplicate
= save_duplicate
;
2283 /* Parses a conditional described by an expression COND into an
2284 agent expression bytecode suitable for evaluation
2285 by the bytecode interpreter. Return NULL if there was
2286 any error during parsing. */
2288 static agent_expr_up
2289 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2294 agent_expr_up aexpr
;
2296 /* We don't want to stop processing, so catch any errors
2297 that may show up. */
2300 aexpr
= gen_eval_for_expr (scope
, cond
);
2303 CATCH (ex
, RETURN_MASK_ERROR
)
2305 /* If we got here, it means the condition could not be parsed to a valid
2306 bytecode expression and thus can't be evaluated on the target's side.
2307 It's no use iterating through the conditions. */
2311 /* We have a valid agent expression. */
2315 /* Based on location BL, create a list of breakpoint conditions to be
2316 passed on to the target. If we have duplicated locations with different
2317 conditions, we will add such conditions to the list. The idea is that the
2318 target will evaluate the list of conditions and will only notify GDB when
2319 one of them is true. */
2322 build_target_condition_list (struct bp_location
*bl
)
2324 struct bp_location
**locp
= NULL
, **loc2p
;
2325 int null_condition_or_parse_error
= 0;
2326 int modified
= bl
->needs_update
;
2327 struct bp_location
*loc
;
2329 /* Release conditions left over from a previous insert. */
2330 bl
->target_info
.conditions
.clear ();
2332 /* This is only meaningful if the target is
2333 evaluating conditions and if the user has
2334 opted for condition evaluation on the target's
2336 if (gdb_evaluates_breakpoint_condition_p ()
2337 || !target_supports_evaluation_of_breakpoint_conditions ())
2340 /* Do a first pass to check for locations with no assigned
2341 conditions or conditions that fail to parse to a valid agent expression
2342 bytecode. If any of these happen, then it's no use to send conditions
2343 to the target since this location will always trigger and generate a
2344 response back to GDB. */
2345 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2348 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2352 /* Re-parse the conditions since something changed. In that
2353 case we already freed the condition bytecodes (see
2354 force_breakpoint_reinsertion). We just
2355 need to parse the condition to bytecodes again. */
2356 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2360 /* If we have a NULL bytecode expression, it means something
2361 went wrong or we have a null condition expression. */
2362 if (!loc
->cond_bytecode
)
2364 null_condition_or_parse_error
= 1;
2370 /* If any of these happened, it means we will have to evaluate the conditions
2371 for the location's address on gdb's side. It is no use keeping bytecodes
2372 for all the other duplicate locations, thus we free all of them here.
2374 This is so we have a finer control over which locations' conditions are
2375 being evaluated by GDB or the remote stub. */
2376 if (null_condition_or_parse_error
)
2378 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2381 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2383 /* Only go as far as the first NULL bytecode is
2385 if (!loc
->cond_bytecode
)
2388 loc
->cond_bytecode
.reset ();
2393 /* No NULL conditions or failed bytecode generation. Build a condition list
2394 for this location's address. */
2395 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2399 && is_breakpoint (loc
->owner
)
2400 && loc
->pspace
->num
== bl
->pspace
->num
2401 && loc
->owner
->enable_state
== bp_enabled
2404 /* Add the condition to the vector. This will be used later
2405 to send the conditions to the target. */
2406 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2413 /* Parses a command described by string CMD into an agent expression
2414 bytecode suitable for evaluation by the bytecode interpreter.
2415 Return NULL if there was any error during parsing. */
2417 static agent_expr_up
2418 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2420 struct cleanup
*old_cleanups
= 0;
2421 struct expression
**argvec
;
2422 const char *cmdrest
;
2423 const char *format_start
, *format_end
;
2424 struct format_piece
*fpieces
;
2426 struct gdbarch
*gdbarch
= get_current_arch ();
2433 if (*cmdrest
== ',')
2435 cmdrest
= skip_spaces_const (cmdrest
);
2437 if (*cmdrest
++ != '"')
2438 error (_("No format string following the location"));
2440 format_start
= cmdrest
;
2442 fpieces
= parse_format_string (&cmdrest
);
2444 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2446 format_end
= cmdrest
;
2448 if (*cmdrest
++ != '"')
2449 error (_("Bad format string, non-terminated '\"'."));
2451 cmdrest
= skip_spaces_const (cmdrest
);
2453 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2454 error (_("Invalid argument syntax"));
2456 if (*cmdrest
== ',')
2458 cmdrest
= skip_spaces_const (cmdrest
);
2460 /* For each argument, make an expression. */
2462 argvec
= (struct expression
**) alloca (strlen (cmd
)
2463 * sizeof (struct expression
*));
2466 while (*cmdrest
!= '\0')
2471 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2472 argvec
[nargs
++] = expr
.release ();
2474 if (*cmdrest
== ',')
2478 agent_expr_up aexpr
;
2480 /* We don't want to stop processing, so catch any errors
2481 that may show up. */
2484 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2485 format_start
, format_end
- format_start
,
2486 fpieces
, nargs
, argvec
);
2488 CATCH (ex
, RETURN_MASK_ERROR
)
2490 /* If we got here, it means the command could not be parsed to a valid
2491 bytecode expression and thus can't be evaluated on the target's side.
2492 It's no use iterating through the other commands. */
2496 do_cleanups (old_cleanups
);
2498 /* We have a valid agent expression, return it. */
2502 /* Based on location BL, create a list of breakpoint commands to be
2503 passed on to the target. If we have duplicated locations with
2504 different commands, we will add any such to the list. */
2507 build_target_command_list (struct bp_location
*bl
)
2509 struct bp_location
**locp
= NULL
, **loc2p
;
2510 int null_command_or_parse_error
= 0;
2511 int modified
= bl
->needs_update
;
2512 struct bp_location
*loc
;
2514 /* Clear commands left over from a previous insert. */
2515 bl
->target_info
.tcommands
.clear ();
2517 if (!target_can_run_breakpoint_commands ())
2520 /* For now, limit to agent-style dprintf breakpoints. */
2521 if (dprintf_style
!= dprintf_style_agent
)
2524 /* For now, if we have any duplicate location that isn't a dprintf,
2525 don't install the target-side commands, as that would make the
2526 breakpoint not be reported to the core, and we'd lose
2528 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2531 if (is_breakpoint (loc
->owner
)
2532 && loc
->pspace
->num
== bl
->pspace
->num
2533 && loc
->owner
->type
!= bp_dprintf
)
2537 /* Do a first pass to check for locations with no assigned
2538 conditions or conditions that fail to parse to a valid agent expression
2539 bytecode. If any of these happen, then it's no use to send conditions
2540 to the target since this location will always trigger and generate a
2541 response back to GDB. */
2542 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2545 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2549 /* Re-parse the commands since something changed. In that
2550 case we already freed the command bytecodes (see
2551 force_breakpoint_reinsertion). We just
2552 need to parse the command to bytecodes again. */
2554 = parse_cmd_to_aexpr (bl
->address
,
2555 loc
->owner
->extra_string
);
2558 /* If we have a NULL bytecode expression, it means something
2559 went wrong or we have a null command expression. */
2560 if (!loc
->cmd_bytecode
)
2562 null_command_or_parse_error
= 1;
2568 /* If anything failed, then we're not doing target-side commands,
2570 if (null_command_or_parse_error
)
2572 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2575 if (is_breakpoint (loc
->owner
)
2576 && loc
->pspace
->num
== bl
->pspace
->num
)
2578 /* Only go as far as the first NULL bytecode is
2580 if (loc
->cmd_bytecode
== NULL
)
2583 loc
->cmd_bytecode
.reset ();
2588 /* No NULL commands or failed bytecode generation. Build a command list
2589 for this location's address. */
2590 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2593 if (loc
->owner
->extra_string
2594 && is_breakpoint (loc
->owner
)
2595 && loc
->pspace
->num
== bl
->pspace
->num
2596 && loc
->owner
->enable_state
== bp_enabled
2599 /* Add the command to the vector. This will be used later
2600 to send the commands to the target. */
2601 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2605 bl
->target_info
.persist
= 0;
2606 /* Maybe flag this location as persistent. */
2607 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2608 bl
->target_info
.persist
= 1;
2611 /* Return the kind of breakpoint on address *ADDR. Get the kind
2612 of breakpoint according to ADDR except single-step breakpoint.
2613 Get the kind of single-step breakpoint according to the current
2617 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2619 if (bl
->owner
->type
== bp_single_step
)
2621 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2622 struct regcache
*regcache
;
2624 regcache
= get_thread_regcache (thr
->ptid
);
2626 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2630 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2633 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2634 location. Any error messages are printed to TMP_ERROR_STREAM; and
2635 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2636 Returns 0 for success, 1 if the bp_location type is not supported or
2639 NOTE drow/2003-09-09: This routine could be broken down to an
2640 object-style method for each breakpoint or catchpoint type. */
2642 insert_bp_location (struct bp_location
*bl
,
2643 struct ui_file
*tmp_error_stream
,
2644 int *disabled_breaks
,
2645 int *hw_breakpoint_error
,
2646 int *hw_bp_error_explained_already
)
2648 enum errors bp_err
= GDB_NO_ERROR
;
2649 const char *bp_err_message
= NULL
;
2651 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2654 /* Note we don't initialize bl->target_info, as that wipes out
2655 the breakpoint location's shadow_contents if the breakpoint
2656 is still inserted at that location. This in turn breaks
2657 target_read_memory which depends on these buffers when
2658 a memory read is requested at the breakpoint location:
2659 Once the target_info has been wiped, we fail to see that
2660 we have a breakpoint inserted at that address and thus
2661 read the breakpoint instead of returning the data saved in
2662 the breakpoint location's shadow contents. */
2663 bl
->target_info
.reqstd_address
= bl
->address
;
2664 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2665 bl
->target_info
.length
= bl
->length
;
2667 /* When working with target-side conditions, we must pass all the conditions
2668 for the same breakpoint address down to the target since GDB will not
2669 insert those locations. With a list of breakpoint conditions, the target
2670 can decide when to stop and notify GDB. */
2672 if (is_breakpoint (bl
->owner
))
2674 build_target_condition_list (bl
);
2675 build_target_command_list (bl
);
2676 /* Reset the modification marker. */
2677 bl
->needs_update
= 0;
2680 if (bl
->loc_type
== bp_loc_software_breakpoint
2681 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2683 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2685 /* If the explicitly specified breakpoint type
2686 is not hardware breakpoint, check the memory map to see
2687 if the breakpoint address is in read only memory or not.
2689 Two important cases are:
2690 - location type is not hardware breakpoint, memory
2691 is readonly. We change the type of the location to
2692 hardware breakpoint.
2693 - location type is hardware breakpoint, memory is
2694 read-write. This means we've previously made the
2695 location hardware one, but then the memory map changed,
2698 When breakpoints are removed, remove_breakpoints will use
2699 location types we've just set here, the only possible
2700 problem is that memory map has changed during running
2701 program, but it's not going to work anyway with current
2703 struct mem_region
*mr
2704 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2708 if (automatic_hardware_breakpoints
)
2710 enum bp_loc_type new_type
;
2712 if (mr
->attrib
.mode
!= MEM_RW
)
2713 new_type
= bp_loc_hardware_breakpoint
;
2715 new_type
= bp_loc_software_breakpoint
;
2717 if (new_type
!= bl
->loc_type
)
2719 static int said
= 0;
2721 bl
->loc_type
= new_type
;
2724 fprintf_filtered (gdb_stdout
,
2725 _("Note: automatically using "
2726 "hardware breakpoints for "
2727 "read-only addresses.\n"));
2732 else if (bl
->loc_type
== bp_loc_software_breakpoint
2733 && mr
->attrib
.mode
!= MEM_RW
)
2735 fprintf_unfiltered (tmp_error_stream
,
2736 _("Cannot insert breakpoint %d.\n"
2737 "Cannot set software breakpoint "
2738 "at read-only address %s\n"),
2740 paddress (bl
->gdbarch
, bl
->address
));
2746 /* First check to see if we have to handle an overlay. */
2747 if (overlay_debugging
== ovly_off
2748 || bl
->section
== NULL
2749 || !(section_is_overlay (bl
->section
)))
2751 /* No overlay handling: just set the breakpoint. */
2756 val
= bl
->owner
->ops
->insert_location (bl
);
2758 bp_err
= GENERIC_ERROR
;
2760 CATCH (e
, RETURN_MASK_ALL
)
2763 bp_err_message
= e
.message
;
2769 /* This breakpoint is in an overlay section.
2770 Shall we set a breakpoint at the LMA? */
2771 if (!overlay_events_enabled
)
2773 /* Yes -- overlay event support is not active,
2774 so we must try to set a breakpoint at the LMA.
2775 This will not work for a hardware breakpoint. */
2776 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2777 warning (_("hardware breakpoint %d not supported in overlay!"),
2781 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2783 /* Set a software (trap) breakpoint at the LMA. */
2784 bl
->overlay_target_info
= bl
->target_info
;
2785 bl
->overlay_target_info
.reqstd_address
= addr
;
2787 /* No overlay handling: just set the breakpoint. */
2792 bl
->overlay_target_info
.kind
2793 = breakpoint_kind (bl
, &addr
);
2794 bl
->overlay_target_info
.placed_address
= addr
;
2795 val
= target_insert_breakpoint (bl
->gdbarch
,
2796 &bl
->overlay_target_info
);
2798 bp_err
= GENERIC_ERROR
;
2800 CATCH (e
, RETURN_MASK_ALL
)
2803 bp_err_message
= e
.message
;
2807 if (bp_err
!= GDB_NO_ERROR
)
2808 fprintf_unfiltered (tmp_error_stream
,
2809 "Overlay breakpoint %d "
2810 "failed: in ROM?\n",
2814 /* Shall we set a breakpoint at the VMA? */
2815 if (section_is_mapped (bl
->section
))
2817 /* Yes. This overlay section is mapped into memory. */
2822 val
= bl
->owner
->ops
->insert_location (bl
);
2824 bp_err
= GENERIC_ERROR
;
2826 CATCH (e
, RETURN_MASK_ALL
)
2829 bp_err_message
= e
.message
;
2835 /* No. This breakpoint will not be inserted.
2836 No error, but do not mark the bp as 'inserted'. */
2841 if (bp_err
!= GDB_NO_ERROR
)
2843 /* Can't set the breakpoint. */
2845 /* In some cases, we might not be able to insert a
2846 breakpoint in a shared library that has already been
2847 removed, but we have not yet processed the shlib unload
2848 event. Unfortunately, some targets that implement
2849 breakpoint insertion themselves can't tell why the
2850 breakpoint insertion failed (e.g., the remote target
2851 doesn't define error codes), so we must treat generic
2852 errors as memory errors. */
2853 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2854 && bl
->loc_type
== bp_loc_software_breakpoint
2855 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2856 || shared_objfile_contains_address_p (bl
->pspace
,
2859 /* See also: disable_breakpoints_in_shlibs. */
2860 bl
->shlib_disabled
= 1;
2861 observer_notify_breakpoint_modified (bl
->owner
);
2862 if (!*disabled_breaks
)
2864 fprintf_unfiltered (tmp_error_stream
,
2865 "Cannot insert breakpoint %d.\n",
2867 fprintf_unfiltered (tmp_error_stream
,
2868 "Temporarily disabling shared "
2869 "library breakpoints:\n");
2871 *disabled_breaks
= 1;
2872 fprintf_unfiltered (tmp_error_stream
,
2873 "breakpoint #%d\n", bl
->owner
->number
);
2878 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2880 *hw_breakpoint_error
= 1;
2881 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2882 fprintf_unfiltered (tmp_error_stream
,
2883 "Cannot insert hardware breakpoint %d%s",
2884 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2885 if (bp_err_message
!= NULL
)
2886 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2890 if (bp_err_message
== NULL
)
2893 = memory_error_message (TARGET_XFER_E_IO
,
2894 bl
->gdbarch
, bl
->address
);
2896 fprintf_unfiltered (tmp_error_stream
,
2897 "Cannot insert breakpoint %d.\n"
2899 bl
->owner
->number
, message
.c_str ());
2903 fprintf_unfiltered (tmp_error_stream
,
2904 "Cannot insert breakpoint %d: %s\n",
2919 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2920 /* NOTE drow/2003-09-08: This state only exists for removing
2921 watchpoints. It's not clear that it's necessary... */
2922 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2926 gdb_assert (bl
->owner
->ops
!= NULL
2927 && bl
->owner
->ops
->insert_location
!= NULL
);
2929 val
= bl
->owner
->ops
->insert_location (bl
);
2931 /* If trying to set a read-watchpoint, and it turns out it's not
2932 supported, try emulating one with an access watchpoint. */
2933 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2935 struct bp_location
*loc
, **loc_temp
;
2937 /* But don't try to insert it, if there's already another
2938 hw_access location that would be considered a duplicate
2940 ALL_BP_LOCATIONS (loc
, loc_temp
)
2942 && loc
->watchpoint_type
== hw_access
2943 && watchpoint_locations_match (bl
, loc
))
2947 bl
->target_info
= loc
->target_info
;
2948 bl
->watchpoint_type
= hw_access
;
2955 bl
->watchpoint_type
= hw_access
;
2956 val
= bl
->owner
->ops
->insert_location (bl
);
2959 /* Back to the original value. */
2960 bl
->watchpoint_type
= hw_read
;
2964 bl
->inserted
= (val
== 0);
2967 else if (bl
->owner
->type
== bp_catchpoint
)
2971 gdb_assert (bl
->owner
->ops
!= NULL
2972 && bl
->owner
->ops
->insert_location
!= NULL
);
2974 val
= bl
->owner
->ops
->insert_location (bl
);
2977 bl
->owner
->enable_state
= bp_disabled
;
2981 Error inserting catchpoint %d: Your system does not support this type\n\
2982 of catchpoint."), bl
->owner
->number
);
2984 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2987 bl
->inserted
= (val
== 0);
2989 /* We've already printed an error message if there was a problem
2990 inserting this catchpoint, and we've disabled the catchpoint,
2991 so just return success. */
2998 /* This function is called when program space PSPACE is about to be
2999 deleted. It takes care of updating breakpoints to not reference
3003 breakpoint_program_space_exit (struct program_space
*pspace
)
3005 struct breakpoint
*b
, *b_temp
;
3006 struct bp_location
*loc
, **loc_temp
;
3008 /* Remove any breakpoint that was set through this program space. */
3009 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
3011 if (b
->pspace
== pspace
)
3012 delete_breakpoint (b
);
3015 /* Breakpoints set through other program spaces could have locations
3016 bound to PSPACE as well. Remove those. */
3017 ALL_BP_LOCATIONS (loc
, loc_temp
)
3019 struct bp_location
*tmp
;
3021 if (loc
->pspace
== pspace
)
3023 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3024 if (loc
->owner
->loc
== loc
)
3025 loc
->owner
->loc
= loc
->next
;
3027 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3028 if (tmp
->next
== loc
)
3030 tmp
->next
= loc
->next
;
3036 /* Now update the global location list to permanently delete the
3037 removed locations above. */
3038 update_global_location_list (UGLL_DONT_INSERT
);
3041 /* Make sure all breakpoints are inserted in inferior.
3042 Throws exception on any error.
3043 A breakpoint that is already inserted won't be inserted
3044 again, so calling this function twice is safe. */
3046 insert_breakpoints (void)
3048 struct breakpoint
*bpt
;
3050 ALL_BREAKPOINTS (bpt
)
3051 if (is_hardware_watchpoint (bpt
))
3053 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3055 update_watchpoint (w
, 0 /* don't reparse. */);
3058 /* Updating watchpoints creates new locations, so update the global
3059 location list. Explicitly tell ugll to insert locations and
3060 ignore breakpoints_always_inserted_mode. */
3061 update_global_location_list (UGLL_INSERT
);
3064 /* Invoke CALLBACK for each of bp_location. */
3067 iterate_over_bp_locations (walk_bp_location_callback callback
)
3069 struct bp_location
*loc
, **loc_tmp
;
3071 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3073 callback (loc
, NULL
);
3077 /* This is used when we need to synch breakpoint conditions between GDB and the
3078 target. It is the case with deleting and disabling of breakpoints when using
3079 always-inserted mode. */
3082 update_inserted_breakpoint_locations (void)
3084 struct bp_location
*bl
, **blp_tmp
;
3087 int disabled_breaks
= 0;
3088 int hw_breakpoint_error
= 0;
3089 int hw_bp_details_reported
= 0;
3091 string_file tmp_error_stream
;
3093 /* Explicitly mark the warning -- this will only be printed if
3094 there was an error. */
3095 tmp_error_stream
.puts ("Warning:\n");
3097 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3099 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3101 /* We only want to update software breakpoints and hardware
3103 if (!is_breakpoint (bl
->owner
))
3106 /* We only want to update locations that are already inserted
3107 and need updating. This is to avoid unwanted insertion during
3108 deletion of breakpoints. */
3109 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3112 switch_to_program_space_and_thread (bl
->pspace
);
3114 /* For targets that support global breakpoints, there's no need
3115 to select an inferior to insert breakpoint to. In fact, even
3116 if we aren't attached to any process yet, we should still
3117 insert breakpoints. */
3118 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3119 && ptid_equal (inferior_ptid
, null_ptid
))
3122 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3123 &hw_breakpoint_error
, &hw_bp_details_reported
);
3130 target_terminal_ours_for_output ();
3131 error_stream (tmp_error_stream
);
3135 /* Used when starting or continuing the program. */
3138 insert_breakpoint_locations (void)
3140 struct breakpoint
*bpt
;
3141 struct bp_location
*bl
, **blp_tmp
;
3144 int disabled_breaks
= 0;
3145 int hw_breakpoint_error
= 0;
3146 int hw_bp_error_explained_already
= 0;
3148 string_file tmp_error_stream
;
3150 /* Explicitly mark the warning -- this will only be printed if
3151 there was an error. */
3152 tmp_error_stream
.puts ("Warning:\n");
3154 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3156 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3158 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3161 /* There is no point inserting thread-specific breakpoints if
3162 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3163 has BL->OWNER always non-NULL. */
3164 if (bl
->owner
->thread
!= -1
3165 && !valid_global_thread_id (bl
->owner
->thread
))
3168 switch_to_program_space_and_thread (bl
->pspace
);
3170 /* For targets that support global breakpoints, there's no need
3171 to select an inferior to insert breakpoint to. In fact, even
3172 if we aren't attached to any process yet, we should still
3173 insert breakpoints. */
3174 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3175 && ptid_equal (inferior_ptid
, null_ptid
))
3178 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3179 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3184 /* If we failed to insert all locations of a watchpoint, remove
3185 them, as half-inserted watchpoint is of limited use. */
3186 ALL_BREAKPOINTS (bpt
)
3188 int some_failed
= 0;
3189 struct bp_location
*loc
;
3191 if (!is_hardware_watchpoint (bpt
))
3194 if (!breakpoint_enabled (bpt
))
3197 if (bpt
->disposition
== disp_del_at_next_stop
)
3200 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3201 if (!loc
->inserted
&& should_be_inserted (loc
))
3208 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3210 remove_breakpoint (loc
);
3212 hw_breakpoint_error
= 1;
3213 tmp_error_stream
.printf ("Could not insert "
3214 "hardware watchpoint %d.\n",
3222 /* If a hardware breakpoint or watchpoint was inserted, add a
3223 message about possibly exhausted resources. */
3224 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3226 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3227 You may have requested too many hardware breakpoints/watchpoints.\n");
3229 target_terminal_ours_for_output ();
3230 error_stream (tmp_error_stream
);
3234 /* Used when the program stops.
3235 Returns zero if successful, or non-zero if there was a problem
3236 removing a breakpoint location. */
3239 remove_breakpoints (void)
3241 struct bp_location
*bl
, **blp_tmp
;
3244 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3246 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3247 val
|= remove_breakpoint (bl
);
3252 /* When a thread exits, remove breakpoints that are related to
3256 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3258 struct breakpoint
*b
, *b_tmp
;
3260 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3262 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3264 b
->disposition
= disp_del_at_next_stop
;
3266 printf_filtered (_("\
3267 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3268 b
->number
, print_thread_id (tp
));
3270 /* Hide it from the user. */
3276 /* Remove breakpoints of process PID. */
3279 remove_breakpoints_pid (int pid
)
3281 struct bp_location
*bl
, **blp_tmp
;
3283 struct inferior
*inf
= find_inferior_pid (pid
);
3285 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3287 if (bl
->pspace
!= inf
->pspace
)
3290 if (bl
->inserted
&& !bl
->target_info
.persist
)
3292 val
= remove_breakpoint (bl
);
3301 reattach_breakpoints (int pid
)
3303 struct bp_location
*bl
, **blp_tmp
;
3305 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3306 struct inferior
*inf
;
3307 struct thread_info
*tp
;
3309 tp
= any_live_thread_of_process (pid
);
3313 inf
= find_inferior_pid (pid
);
3315 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3316 inferior_ptid
= tp
->ptid
;
3318 string_file tmp_error_stream
;
3320 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3322 if (bl
->pspace
!= inf
->pspace
)
3328 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3336 static int internal_breakpoint_number
= -1;
3338 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3339 If INTERNAL is non-zero, the breakpoint number will be populated
3340 from internal_breakpoint_number and that variable decremented.
3341 Otherwise the breakpoint number will be populated from
3342 breakpoint_count and that value incremented. Internal breakpoints
3343 do not set the internal var bpnum. */
3345 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3348 b
->number
= internal_breakpoint_number
--;
3351 set_breakpoint_count (breakpoint_count
+ 1);
3352 b
->number
= breakpoint_count
;
3356 static struct breakpoint
*
3357 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3358 CORE_ADDR address
, enum bptype type
,
3359 const struct breakpoint_ops
*ops
)
3361 struct symtab_and_line sal
;
3362 struct breakpoint
*b
;
3364 init_sal (&sal
); /* Initialize to zeroes. */
3367 sal
.section
= find_pc_overlay (sal
.pc
);
3368 sal
.pspace
= current_program_space
;
3370 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3371 b
->number
= internal_breakpoint_number
--;
3372 b
->disposition
= disp_donttouch
;
3377 static const char *const longjmp_names
[] =
3379 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3381 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3383 /* Per-objfile data private to breakpoint.c. */
3384 struct breakpoint_objfile_data
3386 /* Minimal symbol for "_ovly_debug_event" (if any). */
3387 struct bound_minimal_symbol overlay_msym
;
3389 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3390 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3392 /* True if we have looked for longjmp probes. */
3393 int longjmp_searched
;
3395 /* SystemTap probe points for longjmp (if any). */
3396 VEC (probe_p
) *longjmp_probes
;
3398 /* Minimal symbol for "std::terminate()" (if any). */
3399 struct bound_minimal_symbol terminate_msym
;
3401 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3402 struct bound_minimal_symbol exception_msym
;
3404 /* True if we have looked for exception probes. */
3405 int exception_searched
;
3407 /* SystemTap probe points for unwinding (if any). */
3408 VEC (probe_p
) *exception_probes
;
3411 static const struct objfile_data
*breakpoint_objfile_key
;
3413 /* Minimal symbol not found sentinel. */
3414 static struct minimal_symbol msym_not_found
;
3416 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3419 msym_not_found_p (const struct minimal_symbol
*msym
)
3421 return msym
== &msym_not_found
;
3424 /* Return per-objfile data needed by breakpoint.c.
3425 Allocate the data if necessary. */
3427 static struct breakpoint_objfile_data
*
3428 get_breakpoint_objfile_data (struct objfile
*objfile
)
3430 struct breakpoint_objfile_data
*bp_objfile_data
;
3432 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3433 objfile_data (objfile
, breakpoint_objfile_key
));
3434 if (bp_objfile_data
== NULL
)
3437 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3439 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3440 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3442 return bp_objfile_data
;
3446 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3448 struct breakpoint_objfile_data
*bp_objfile_data
3449 = (struct breakpoint_objfile_data
*) data
;
3451 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3452 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3456 create_overlay_event_breakpoint (void)
3458 struct objfile
*objfile
;
3459 const char *const func_name
= "_ovly_debug_event";
3461 ALL_OBJFILES (objfile
)
3463 struct breakpoint
*b
;
3464 struct breakpoint_objfile_data
*bp_objfile_data
;
3466 struct explicit_location explicit_loc
;
3468 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3470 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3473 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3475 struct bound_minimal_symbol m
;
3477 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3478 if (m
.minsym
== NULL
)
3480 /* Avoid future lookups in this objfile. */
3481 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3484 bp_objfile_data
->overlay_msym
= m
;
3487 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3488 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3490 &internal_breakpoint_ops
);
3491 initialize_explicit_location (&explicit_loc
);
3492 explicit_loc
.function_name
= ASTRDUP (func_name
);
3493 b
->location
= new_explicit_location (&explicit_loc
);
3495 if (overlay_debugging
== ovly_auto
)
3497 b
->enable_state
= bp_enabled
;
3498 overlay_events_enabled
= 1;
3502 b
->enable_state
= bp_disabled
;
3503 overlay_events_enabled
= 0;
3509 create_longjmp_master_breakpoint (void)
3511 struct program_space
*pspace
;
3513 scoped_restore_current_program_space restore_pspace
;
3515 ALL_PSPACES (pspace
)
3517 struct objfile
*objfile
;
3519 set_current_program_space (pspace
);
3521 ALL_OBJFILES (objfile
)
3524 struct gdbarch
*gdbarch
;
3525 struct breakpoint_objfile_data
*bp_objfile_data
;
3527 gdbarch
= get_objfile_arch (objfile
);
3529 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3531 if (!bp_objfile_data
->longjmp_searched
)
3535 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3538 /* We are only interested in checking one element. */
3539 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3541 if (!can_evaluate_probe_arguments (p
))
3543 /* We cannot use the probe interface here, because it does
3544 not know how to evaluate arguments. */
3545 VEC_free (probe_p
, ret
);
3549 bp_objfile_data
->longjmp_probes
= ret
;
3550 bp_objfile_data
->longjmp_searched
= 1;
3553 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3556 struct probe
*probe
;
3557 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3560 VEC_iterate (probe_p
,
3561 bp_objfile_data
->longjmp_probes
,
3565 struct breakpoint
*b
;
3567 b
= create_internal_breakpoint (gdbarch
,
3568 get_probe_address (probe
,
3571 &internal_breakpoint_ops
);
3572 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3573 b
->enable_state
= bp_disabled
;
3579 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3582 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3584 struct breakpoint
*b
;
3585 const char *func_name
;
3587 struct explicit_location explicit_loc
;
3589 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3592 func_name
= longjmp_names
[i
];
3593 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3595 struct bound_minimal_symbol m
;
3597 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3598 if (m
.minsym
== NULL
)
3600 /* Prevent future lookups in this objfile. */
3601 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3604 bp_objfile_data
->longjmp_msym
[i
] = m
;
3607 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3608 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3609 &internal_breakpoint_ops
);
3610 initialize_explicit_location (&explicit_loc
);
3611 explicit_loc
.function_name
= ASTRDUP (func_name
);
3612 b
->location
= new_explicit_location (&explicit_loc
);
3613 b
->enable_state
= bp_disabled
;
3619 /* Create a master std::terminate breakpoint. */
3621 create_std_terminate_master_breakpoint (void)
3623 struct program_space
*pspace
;
3624 const char *const func_name
= "std::terminate()";
3626 scoped_restore_current_program_space restore_pspace
;
3628 ALL_PSPACES (pspace
)
3630 struct objfile
*objfile
;
3633 set_current_program_space (pspace
);
3635 ALL_OBJFILES (objfile
)
3637 struct breakpoint
*b
;
3638 struct breakpoint_objfile_data
*bp_objfile_data
;
3639 struct explicit_location explicit_loc
;
3641 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3643 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3646 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3648 struct bound_minimal_symbol m
;
3650 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3651 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3652 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3654 /* Prevent future lookups in this objfile. */
3655 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3658 bp_objfile_data
->terminate_msym
= m
;
3661 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3662 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3663 bp_std_terminate_master
,
3664 &internal_breakpoint_ops
);
3665 initialize_explicit_location (&explicit_loc
);
3666 explicit_loc
.function_name
= ASTRDUP (func_name
);
3667 b
->location
= new_explicit_location (&explicit_loc
);
3668 b
->enable_state
= bp_disabled
;
3673 /* Install a master breakpoint on the unwinder's debug hook. */
3676 create_exception_master_breakpoint (void)
3678 struct objfile
*objfile
;
3679 const char *const func_name
= "_Unwind_DebugHook";
3681 ALL_OBJFILES (objfile
)
3683 struct breakpoint
*b
;
3684 struct gdbarch
*gdbarch
;
3685 struct breakpoint_objfile_data
*bp_objfile_data
;
3687 struct explicit_location explicit_loc
;
3689 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3691 /* We prefer the SystemTap probe point if it exists. */
3692 if (!bp_objfile_data
->exception_searched
)
3696 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3700 /* We are only interested in checking one element. */
3701 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3703 if (!can_evaluate_probe_arguments (p
))
3705 /* We cannot use the probe interface here, because it does
3706 not know how to evaluate arguments. */
3707 VEC_free (probe_p
, ret
);
3711 bp_objfile_data
->exception_probes
= ret
;
3712 bp_objfile_data
->exception_searched
= 1;
3715 if (bp_objfile_data
->exception_probes
!= NULL
)
3717 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3719 struct probe
*probe
;
3722 VEC_iterate (probe_p
,
3723 bp_objfile_data
->exception_probes
,
3727 struct breakpoint
*b
;
3729 b
= create_internal_breakpoint (gdbarch
,
3730 get_probe_address (probe
,
3732 bp_exception_master
,
3733 &internal_breakpoint_ops
);
3734 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3735 b
->enable_state
= bp_disabled
;
3741 /* Otherwise, try the hook function. */
3743 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3746 gdbarch
= get_objfile_arch (objfile
);
3748 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3750 struct bound_minimal_symbol debug_hook
;
3752 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3753 if (debug_hook
.minsym
== NULL
)
3755 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3759 bp_objfile_data
->exception_msym
= debug_hook
;
3762 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3763 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3765 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3766 &internal_breakpoint_ops
);
3767 initialize_explicit_location (&explicit_loc
);
3768 explicit_loc
.function_name
= ASTRDUP (func_name
);
3769 b
->location
= new_explicit_location (&explicit_loc
);
3770 b
->enable_state
= bp_disabled
;
3774 /* Does B have a location spec? */
3777 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3779 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3783 update_breakpoints_after_exec (void)
3785 struct breakpoint
*b
, *b_tmp
;
3786 struct bp_location
*bploc
, **bplocp_tmp
;
3788 /* We're about to delete breakpoints from GDB's lists. If the
3789 INSERTED flag is true, GDB will try to lift the breakpoints by
3790 writing the breakpoints' "shadow contents" back into memory. The
3791 "shadow contents" are NOT valid after an exec, so GDB should not
3792 do that. Instead, the target is responsible from marking
3793 breakpoints out as soon as it detects an exec. We don't do that
3794 here instead, because there may be other attempts to delete
3795 breakpoints after detecting an exec and before reaching here. */
3796 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3797 if (bploc
->pspace
== current_program_space
)
3798 gdb_assert (!bploc
->inserted
);
3800 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3802 if (b
->pspace
!= current_program_space
)
3805 /* Solib breakpoints must be explicitly reset after an exec(). */
3806 if (b
->type
== bp_shlib_event
)
3808 delete_breakpoint (b
);
3812 /* JIT breakpoints must be explicitly reset after an exec(). */
3813 if (b
->type
== bp_jit_event
)
3815 delete_breakpoint (b
);
3819 /* Thread event breakpoints must be set anew after an exec(),
3820 as must overlay event and longjmp master breakpoints. */
3821 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3822 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3823 || b
->type
== bp_exception_master
)
3825 delete_breakpoint (b
);
3829 /* Step-resume breakpoints are meaningless after an exec(). */
3830 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3832 delete_breakpoint (b
);
3836 /* Just like single-step breakpoints. */
3837 if (b
->type
== bp_single_step
)
3839 delete_breakpoint (b
);
3843 /* Longjmp and longjmp-resume breakpoints are also meaningless
3845 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3846 || b
->type
== bp_longjmp_call_dummy
3847 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3849 delete_breakpoint (b
);
3853 if (b
->type
== bp_catchpoint
)
3855 /* For now, none of the bp_catchpoint breakpoints need to
3856 do anything at this point. In the future, if some of
3857 the catchpoints need to something, we will need to add
3858 a new method, and call this method from here. */
3862 /* bp_finish is a special case. The only way we ought to be able
3863 to see one of these when an exec() has happened, is if the user
3864 caught a vfork, and then said "finish". Ordinarily a finish just
3865 carries them to the call-site of the current callee, by setting
3866 a temporary bp there and resuming. But in this case, the finish
3867 will carry them entirely through the vfork & exec.
3869 We don't want to allow a bp_finish to remain inserted now. But
3870 we can't safely delete it, 'cause finish_command has a handle to
3871 the bp on a bpstat, and will later want to delete it. There's a
3872 chance (and I've seen it happen) that if we delete the bp_finish
3873 here, that its storage will get reused by the time finish_command
3874 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3875 We really must allow finish_command to delete a bp_finish.
3877 In the absence of a general solution for the "how do we know
3878 it's safe to delete something others may have handles to?"
3879 problem, what we'll do here is just uninsert the bp_finish, and
3880 let finish_command delete it.
3882 (We know the bp_finish is "doomed" in the sense that it's
3883 momentary, and will be deleted as soon as finish_command sees
3884 the inferior stopped. So it doesn't matter that the bp's
3885 address is probably bogus in the new a.out, unlike e.g., the
3886 solib breakpoints.) */
3888 if (b
->type
== bp_finish
)
3893 /* Without a symbolic address, we have little hope of the
3894 pre-exec() address meaning the same thing in the post-exec()
3896 if (breakpoint_event_location_empty_p (b
))
3898 delete_breakpoint (b
);
3905 detach_breakpoints (ptid_t ptid
)
3907 struct bp_location
*bl
, **blp_tmp
;
3909 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3910 struct inferior
*inf
= current_inferior ();
3912 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3913 error (_("Cannot detach breakpoints of inferior_ptid"));
3915 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3916 inferior_ptid
= ptid
;
3917 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3919 if (bl
->pspace
!= inf
->pspace
)
3922 /* This function must physically remove breakpoints locations
3923 from the specified ptid, without modifying the breakpoint
3924 package's state. Locations of type bp_loc_other are only
3925 maintained at GDB side. So, there is no need to remove
3926 these bp_loc_other locations. Moreover, removing these
3927 would modify the breakpoint package's state. */
3928 if (bl
->loc_type
== bp_loc_other
)
3932 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3938 /* Remove the breakpoint location BL from the current address space.
3939 Note that this is used to detach breakpoints from a child fork.
3940 When we get here, the child isn't in the inferior list, and neither
3941 do we have objects to represent its address space --- we should
3942 *not* look at bl->pspace->aspace here. */
3945 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3949 /* BL is never in moribund_locations by our callers. */
3950 gdb_assert (bl
->owner
!= NULL
);
3952 /* The type of none suggests that owner is actually deleted.
3953 This should not ever happen. */
3954 gdb_assert (bl
->owner
->type
!= bp_none
);
3956 if (bl
->loc_type
== bp_loc_software_breakpoint
3957 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3959 /* "Normal" instruction breakpoint: either the standard
3960 trap-instruction bp (bp_breakpoint), or a
3961 bp_hardware_breakpoint. */
3963 /* First check to see if we have to handle an overlay. */
3964 if (overlay_debugging
== ovly_off
3965 || bl
->section
== NULL
3966 || !(section_is_overlay (bl
->section
)))
3968 /* No overlay handling: just remove the breakpoint. */
3970 /* If we're trying to uninsert a memory breakpoint that we
3971 know is set in a dynamic object that is marked
3972 shlib_disabled, then either the dynamic object was
3973 removed with "remove-symbol-file" or with
3974 "nosharedlibrary". In the former case, we don't know
3975 whether another dynamic object might have loaded over the
3976 breakpoint's address -- the user might well let us know
3977 about it next with add-symbol-file (the whole point of
3978 add-symbol-file is letting the user manually maintain a
3979 list of dynamically loaded objects). If we have the
3980 breakpoint's shadow memory, that is, this is a software
3981 breakpoint managed by GDB, check whether the breakpoint
3982 is still inserted in memory, to avoid overwriting wrong
3983 code with stale saved shadow contents. Note that HW
3984 breakpoints don't have shadow memory, as they're
3985 implemented using a mechanism that is not dependent on
3986 being able to modify the target's memory, and as such
3987 they should always be removed. */
3988 if (bl
->shlib_disabled
3989 && bl
->target_info
.shadow_len
!= 0
3990 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3993 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3997 /* This breakpoint is in an overlay section.
3998 Did we set a breakpoint at the LMA? */
3999 if (!overlay_events_enabled
)
4001 /* Yes -- overlay event support is not active, so we
4002 should have set a breakpoint at the LMA. Remove it.
4004 /* Ignore any failures: if the LMA is in ROM, we will
4005 have already warned when we failed to insert it. */
4006 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4007 target_remove_hw_breakpoint (bl
->gdbarch
,
4008 &bl
->overlay_target_info
);
4010 target_remove_breakpoint (bl
->gdbarch
,
4011 &bl
->overlay_target_info
,
4014 /* Did we set a breakpoint at the VMA?
4015 If so, we will have marked the breakpoint 'inserted'. */
4018 /* Yes -- remove it. Previously we did not bother to
4019 remove the breakpoint if the section had been
4020 unmapped, but let's not rely on that being safe. We
4021 don't know what the overlay manager might do. */
4023 /* However, we should remove *software* breakpoints only
4024 if the section is still mapped, or else we overwrite
4025 wrong code with the saved shadow contents. */
4026 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4027 || section_is_mapped (bl
->section
))
4028 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4034 /* No -- not inserted, so no need to remove. No error. */
4039 /* In some cases, we might not be able to remove a breakpoint in
4040 a shared library that has already been removed, but we have
4041 not yet processed the shlib unload event. Similarly for an
4042 unloaded add-symbol-file object - the user might not yet have
4043 had the chance to remove-symbol-file it. shlib_disabled will
4044 be set if the library/object has already been removed, but
4045 the breakpoint hasn't been uninserted yet, e.g., after
4046 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4047 always-inserted mode. */
4049 && (bl
->loc_type
== bp_loc_software_breakpoint
4050 && (bl
->shlib_disabled
4051 || solib_name_from_address (bl
->pspace
, bl
->address
)
4052 || shared_objfile_contains_address_p (bl
->pspace
,
4058 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4060 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4062 gdb_assert (bl
->owner
->ops
!= NULL
4063 && bl
->owner
->ops
->remove_location
!= NULL
);
4065 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4066 bl
->owner
->ops
->remove_location (bl
, reason
);
4068 /* Failure to remove any of the hardware watchpoints comes here. */
4069 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4070 warning (_("Could not remove hardware watchpoint %d."),
4073 else if (bl
->owner
->type
== bp_catchpoint
4074 && breakpoint_enabled (bl
->owner
)
4077 gdb_assert (bl
->owner
->ops
!= NULL
4078 && bl
->owner
->ops
->remove_location
!= NULL
);
4080 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4084 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4091 remove_breakpoint (struct bp_location
*bl
)
4093 /* BL is never in moribund_locations by our callers. */
4094 gdb_assert (bl
->owner
!= NULL
);
4096 /* The type of none suggests that owner is actually deleted.
4097 This should not ever happen. */
4098 gdb_assert (bl
->owner
->type
!= bp_none
);
4100 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4102 switch_to_program_space_and_thread (bl
->pspace
);
4104 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4107 /* Clear the "inserted" flag in all breakpoints. */
4110 mark_breakpoints_out (void)
4112 struct bp_location
*bl
, **blp_tmp
;
4114 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4115 if (bl
->pspace
== current_program_space
)
4119 /* Clear the "inserted" flag in all breakpoints and delete any
4120 breakpoints which should go away between runs of the program.
4122 Plus other such housekeeping that has to be done for breakpoints
4125 Note: this function gets called at the end of a run (by
4126 generic_mourn_inferior) and when a run begins (by
4127 init_wait_for_inferior). */
4132 breakpoint_init_inferior (enum inf_context context
)
4134 struct breakpoint
*b
, *b_tmp
;
4135 struct bp_location
*bl
;
4137 struct program_space
*pspace
= current_program_space
;
4139 /* If breakpoint locations are shared across processes, then there's
4141 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4144 mark_breakpoints_out ();
4146 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4148 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4154 case bp_longjmp_call_dummy
:
4156 /* If the call dummy breakpoint is at the entry point it will
4157 cause problems when the inferior is rerun, so we better get
4160 case bp_watchpoint_scope
:
4162 /* Also get rid of scope breakpoints. */
4164 case bp_shlib_event
:
4166 /* Also remove solib event breakpoints. Their addresses may
4167 have changed since the last time we ran the program.
4168 Actually we may now be debugging against different target;
4169 and so the solib backend that installed this breakpoint may
4170 not be used in by the target. E.g.,
4172 (gdb) file prog-linux
4173 (gdb) run # native linux target
4176 (gdb) file prog-win.exe
4177 (gdb) tar rem :9999 # remote Windows gdbserver.
4180 case bp_step_resume
:
4182 /* Also remove step-resume breakpoints. */
4184 case bp_single_step
:
4186 /* Also remove single-step breakpoints. */
4188 delete_breakpoint (b
);
4192 case bp_hardware_watchpoint
:
4193 case bp_read_watchpoint
:
4194 case bp_access_watchpoint
:
4196 struct watchpoint
*w
= (struct watchpoint
*) b
;
4198 /* Likewise for watchpoints on local expressions. */
4199 if (w
->exp_valid_block
!= NULL
)
4200 delete_breakpoint (b
);
4203 /* Get rid of existing locations, which are no longer
4204 valid. New ones will be created in
4205 update_watchpoint, when the inferior is restarted.
4206 The next update_global_location_list call will
4207 garbage collect them. */
4210 if (context
== inf_starting
)
4212 /* Reset val field to force reread of starting value in
4213 insert_breakpoints. */
4215 value_free (w
->val
);
4227 /* Get rid of the moribund locations. */
4228 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4229 decref_bp_location (&bl
);
4230 VEC_free (bp_location_p
, moribund_locations
);
4233 /* These functions concern about actual breakpoints inserted in the
4234 target --- to e.g. check if we need to do decr_pc adjustment or if
4235 we need to hop over the bkpt --- so we check for address space
4236 match, not program space. */
4238 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4239 exists at PC. It returns ordinary_breakpoint_here if it's an
4240 ordinary breakpoint, or permanent_breakpoint_here if it's a
4241 permanent breakpoint.
4242 - When continuing from a location with an ordinary breakpoint, we
4243 actually single step once before calling insert_breakpoints.
4244 - When continuing from a location with a permanent breakpoint, we
4245 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4246 the target, to advance the PC past the breakpoint. */
4248 enum breakpoint_here
4249 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4251 struct bp_location
*bl
, **blp_tmp
;
4252 int any_breakpoint_here
= 0;
4254 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4256 if (bl
->loc_type
!= bp_loc_software_breakpoint
4257 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4260 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4261 if ((breakpoint_enabled (bl
->owner
)
4263 && breakpoint_location_address_match (bl
, aspace
, pc
))
4265 if (overlay_debugging
4266 && section_is_overlay (bl
->section
)
4267 && !section_is_mapped (bl
->section
))
4268 continue; /* unmapped overlay -- can't be a match */
4269 else if (bl
->permanent
)
4270 return permanent_breakpoint_here
;
4272 any_breakpoint_here
= 1;
4276 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4279 /* See breakpoint.h. */
4282 breakpoint_in_range_p (struct address_space
*aspace
,
4283 CORE_ADDR addr
, ULONGEST len
)
4285 struct bp_location
*bl
, **blp_tmp
;
4287 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4289 if (bl
->loc_type
!= bp_loc_software_breakpoint
4290 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4293 if ((breakpoint_enabled (bl
->owner
)
4295 && breakpoint_location_address_range_overlap (bl
, aspace
,
4298 if (overlay_debugging
4299 && section_is_overlay (bl
->section
)
4300 && !section_is_mapped (bl
->section
))
4302 /* Unmapped overlay -- can't be a match. */
4313 /* Return true if there's a moribund breakpoint at PC. */
4316 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4318 struct bp_location
*loc
;
4321 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4322 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4328 /* Returns non-zero iff BL is inserted at PC, in address space
4332 bp_location_inserted_here_p (struct bp_location
*bl
,
4333 struct address_space
*aspace
, CORE_ADDR pc
)
4336 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4339 if (overlay_debugging
4340 && section_is_overlay (bl
->section
)
4341 && !section_is_mapped (bl
->section
))
4342 return 0; /* unmapped overlay -- can't be a match */
4349 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4352 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4354 struct bp_location
**blp
, **blp_tmp
= NULL
;
4356 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4358 struct bp_location
*bl
= *blp
;
4360 if (bl
->loc_type
!= bp_loc_software_breakpoint
4361 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4364 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4370 /* This function returns non-zero iff there is a software breakpoint
4374 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4377 struct bp_location
**blp
, **blp_tmp
= NULL
;
4379 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4381 struct bp_location
*bl
= *blp
;
4383 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4386 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4393 /* See breakpoint.h. */
4396 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4399 struct bp_location
**blp
, **blp_tmp
= NULL
;
4401 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4403 struct bp_location
*bl
= *blp
;
4405 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4408 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4416 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4417 CORE_ADDR addr
, ULONGEST len
)
4419 struct breakpoint
*bpt
;
4421 ALL_BREAKPOINTS (bpt
)
4423 struct bp_location
*loc
;
4425 if (bpt
->type
!= bp_hardware_watchpoint
4426 && bpt
->type
!= bp_access_watchpoint
)
4429 if (!breakpoint_enabled (bpt
))
4432 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4433 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4437 /* Check for intersection. */
4438 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4439 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4448 /* bpstat stuff. External routines' interfaces are documented
4452 is_catchpoint (struct breakpoint
*ep
)
4454 return (ep
->type
== bp_catchpoint
);
4457 /* Frees any storage that is part of a bpstat. Does not walk the
4461 bpstat_free (bpstat bs
)
4463 if (bs
->old_val
!= NULL
)
4464 value_free (bs
->old_val
);
4465 decref_counted_command_line (&bs
->commands
);
4466 decref_bp_location (&bs
->bp_location_at
);
4470 /* Clear a bpstat so that it says we are not at any breakpoint.
4471 Also free any storage that is part of a bpstat. */
4474 bpstat_clear (bpstat
*bsp
)
4491 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4492 is part of the bpstat is copied as well. */
4495 bpstat_copy (bpstat bs
)
4499 bpstat retval
= NULL
;
4504 for (; bs
!= NULL
; bs
= bs
->next
)
4506 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4507 memcpy (tmp
, bs
, sizeof (*tmp
));
4508 incref_counted_command_line (tmp
->commands
);
4509 incref_bp_location (tmp
->bp_location_at
);
4510 if (bs
->old_val
!= NULL
)
4512 tmp
->old_val
= value_copy (bs
->old_val
);
4513 release_value (tmp
->old_val
);
4517 /* This is the first thing in the chain. */
4527 /* Find the bpstat associated with this breakpoint. */
4530 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4535 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4537 if (bsp
->breakpoint_at
== breakpoint
)
4543 /* See breakpoint.h. */
4546 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4548 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4550 if (bsp
->breakpoint_at
== NULL
)
4552 /* A moribund location can never explain a signal other than
4554 if (sig
== GDB_SIGNAL_TRAP
)
4559 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4568 /* Put in *NUM the breakpoint number of the first breakpoint we are
4569 stopped at. *BSP upon return is a bpstat which points to the
4570 remaining breakpoints stopped at (but which is not guaranteed to be
4571 good for anything but further calls to bpstat_num).
4573 Return 0 if passed a bpstat which does not indicate any breakpoints.
4574 Return -1 if stopped at a breakpoint that has been deleted since
4576 Return 1 otherwise. */
4579 bpstat_num (bpstat
*bsp
, int *num
)
4581 struct breakpoint
*b
;
4584 return 0; /* No more breakpoint values */
4586 /* We assume we'll never have several bpstats that correspond to a
4587 single breakpoint -- otherwise, this function might return the
4588 same number more than once and this will look ugly. */
4589 b
= (*bsp
)->breakpoint_at
;
4590 *bsp
= (*bsp
)->next
;
4592 return -1; /* breakpoint that's been deleted since */
4594 *num
= b
->number
; /* We have its number */
4598 /* See breakpoint.h. */
4601 bpstat_clear_actions (void)
4603 struct thread_info
*tp
;
4606 if (ptid_equal (inferior_ptid
, null_ptid
))
4609 tp
= find_thread_ptid (inferior_ptid
);
4613 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4615 decref_counted_command_line (&bs
->commands
);
4617 if (bs
->old_val
!= NULL
)
4619 value_free (bs
->old_val
);
4625 /* Called when a command is about to proceed the inferior. */
4628 breakpoint_about_to_proceed (void)
4630 if (!ptid_equal (inferior_ptid
, null_ptid
))
4632 struct thread_info
*tp
= inferior_thread ();
4634 /* Allow inferior function calls in breakpoint commands to not
4635 interrupt the command list. When the call finishes
4636 successfully, the inferior will be standing at the same
4637 breakpoint as if nothing happened. */
4638 if (tp
->control
.in_infcall
)
4642 breakpoint_proceeded
= 1;
4645 /* Stub for cleaning up our state if we error-out of a breakpoint
4648 cleanup_executing_breakpoints (void *ignore
)
4650 executing_breakpoint_commands
= 0;
4653 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4654 or its equivalent. */
4657 command_line_is_silent (struct command_line
*cmd
)
4659 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4662 /* Execute all the commands associated with all the breakpoints at
4663 this location. Any of these commands could cause the process to
4664 proceed beyond this point, etc. We look out for such changes by
4665 checking the global "breakpoint_proceeded" after each command.
4667 Returns true if a breakpoint command resumed the inferior. In that
4668 case, it is the caller's responsibility to recall it again with the
4669 bpstat of the current thread. */
4672 bpstat_do_actions_1 (bpstat
*bsp
)
4675 struct cleanup
*old_chain
;
4678 /* Avoid endless recursion if a `source' command is contained
4680 if (executing_breakpoint_commands
)
4683 executing_breakpoint_commands
= 1;
4684 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4686 scoped_restore preventer
= prevent_dont_repeat ();
4688 /* This pointer will iterate over the list of bpstat's. */
4691 breakpoint_proceeded
= 0;
4692 for (; bs
!= NULL
; bs
= bs
->next
)
4694 struct counted_command_line
*ccmd
;
4695 struct command_line
*cmd
;
4696 struct cleanup
*this_cmd_tree_chain
;
4698 /* Take ownership of the BSP's command tree, if it has one.
4700 The command tree could legitimately contain commands like
4701 'step' and 'next', which call clear_proceed_status, which
4702 frees stop_bpstat's command tree. To make sure this doesn't
4703 free the tree we're executing out from under us, we need to
4704 take ownership of the tree ourselves. Since a given bpstat's
4705 commands are only executed once, we don't need to copy it; we
4706 can clear the pointer in the bpstat, and make sure we free
4707 the tree when we're done. */
4708 ccmd
= bs
->commands
;
4709 bs
->commands
= NULL
;
4710 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4711 cmd
= ccmd
? ccmd
->commands
: NULL
;
4712 if (command_line_is_silent (cmd
))
4714 /* The action has been already done by bpstat_stop_status. */
4720 execute_control_command (cmd
);
4722 if (breakpoint_proceeded
)
4728 /* We can free this command tree now. */
4729 do_cleanups (this_cmd_tree_chain
);
4731 if (breakpoint_proceeded
)
4733 if (current_ui
->async
)
4734 /* If we are in async mode, then the target might be still
4735 running, not stopped at any breakpoint, so nothing for
4736 us to do here -- just return to the event loop. */
4739 /* In sync mode, when execute_control_command returns
4740 we're already standing on the next breakpoint.
4741 Breakpoint commands for that stop were not run, since
4742 execute_command does not run breakpoint commands --
4743 only command_line_handler does, but that one is not
4744 involved in execution of breakpoint commands. So, we
4745 can now execute breakpoint commands. It should be
4746 noted that making execute_command do bpstat actions is
4747 not an option -- in this case we'll have recursive
4748 invocation of bpstat for each breakpoint with a
4749 command, and can easily blow up GDB stack. Instead, we
4750 return true, which will trigger the caller to recall us
4751 with the new stop_bpstat. */
4756 do_cleanups (old_chain
);
4761 bpstat_do_actions (void)
4763 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4765 /* Do any commands attached to breakpoint we are stopped at. */
4766 while (!ptid_equal (inferior_ptid
, null_ptid
)
4767 && target_has_execution
4768 && !is_exited (inferior_ptid
)
4769 && !is_executing (inferior_ptid
))
4770 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4771 and only return when it is stopped at the next breakpoint, we
4772 keep doing breakpoint actions until it returns false to
4773 indicate the inferior was not resumed. */
4774 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4777 discard_cleanups (cleanup_if_error
);
4780 /* Print out the (old or new) value associated with a watchpoint. */
4783 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4786 fprintf_unfiltered (stream
, _("<unreadable>"));
4789 struct value_print_options opts
;
4790 get_user_print_options (&opts
);
4791 value_print (val
, stream
, &opts
);
4795 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4796 debugging multiple threads. */
4799 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4801 if (uiout
->is_mi_like_p ())
4806 if (show_thread_that_caused_stop ())
4809 struct thread_info
*thr
= inferior_thread ();
4811 uiout
->text ("Thread ");
4812 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4814 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4817 uiout
->text (" \"");
4818 uiout
->field_fmt ("name", "%s", name
);
4822 uiout
->text (" hit ");
4826 /* Generic routine for printing messages indicating why we
4827 stopped. The behavior of this function depends on the value
4828 'print_it' in the bpstat structure. Under some circumstances we
4829 may decide not to print anything here and delegate the task to
4832 static enum print_stop_action
4833 print_bp_stop_message (bpstat bs
)
4835 switch (bs
->print_it
)
4838 /* Nothing should be printed for this bpstat entry. */
4839 return PRINT_UNKNOWN
;
4843 /* We still want to print the frame, but we already printed the
4844 relevant messages. */
4845 return PRINT_SRC_AND_LOC
;
4848 case print_it_normal
:
4850 struct breakpoint
*b
= bs
->breakpoint_at
;
4852 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4853 which has since been deleted. */
4855 return PRINT_UNKNOWN
;
4857 /* Normal case. Call the breakpoint's print_it method. */
4858 return b
->ops
->print_it (bs
);
4863 internal_error (__FILE__
, __LINE__
,
4864 _("print_bp_stop_message: unrecognized enum value"));
4869 /* A helper function that prints a shared library stopped event. */
4872 print_solib_event (int is_catchpoint
)
4875 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4877 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4881 if (any_added
|| any_deleted
)
4882 current_uiout
->text (_("Stopped due to shared library event:\n"));
4884 current_uiout
->text (_("Stopped due to shared library event (no "
4885 "libraries added or removed)\n"));
4888 if (current_uiout
->is_mi_like_p ())
4889 current_uiout
->field_string ("reason",
4890 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4897 current_uiout
->text (_(" Inferior unloaded "));
4898 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4900 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4905 current_uiout
->text (" ");
4906 current_uiout
->field_string ("library", name
);
4907 current_uiout
->text ("\n");
4913 struct so_list
*iter
;
4916 current_uiout
->text (_(" Inferior loaded "));
4917 ui_out_emit_list
list_emitter (current_uiout
, "added");
4919 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4924 current_uiout
->text (" ");
4925 current_uiout
->field_string ("library", iter
->so_name
);
4926 current_uiout
->text ("\n");
4931 /* Print a message indicating what happened. This is called from
4932 normal_stop(). The input to this routine is the head of the bpstat
4933 list - a list of the eventpoints that caused this stop. KIND is
4934 the target_waitkind for the stopping event. This
4935 routine calls the generic print routine for printing a message
4936 about reasons for stopping. This will print (for example) the
4937 "Breakpoint n," part of the output. The return value of this
4940 PRINT_UNKNOWN: Means we printed nothing.
4941 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4942 code to print the location. An example is
4943 "Breakpoint 1, " which should be followed by
4945 PRINT_SRC_ONLY: Means we printed something, but there is no need
4946 to also print the location part of the message.
4947 An example is the catch/throw messages, which
4948 don't require a location appended to the end.
4949 PRINT_NOTHING: We have done some printing and we don't need any
4950 further info to be printed. */
4952 enum print_stop_action
4953 bpstat_print (bpstat bs
, int kind
)
4955 enum print_stop_action val
;
4957 /* Maybe another breakpoint in the chain caused us to stop.
4958 (Currently all watchpoints go on the bpstat whether hit or not.
4959 That probably could (should) be changed, provided care is taken
4960 with respect to bpstat_explains_signal). */
4961 for (; bs
; bs
= bs
->next
)
4963 val
= print_bp_stop_message (bs
);
4964 if (val
== PRINT_SRC_ONLY
4965 || val
== PRINT_SRC_AND_LOC
4966 || val
== PRINT_NOTHING
)
4970 /* If we had hit a shared library event breakpoint,
4971 print_bp_stop_message would print out this message. If we hit an
4972 OS-level shared library event, do the same thing. */
4973 if (kind
== TARGET_WAITKIND_LOADED
)
4975 print_solib_event (0);
4976 return PRINT_NOTHING
;
4979 /* We reached the end of the chain, or we got a null BS to start
4980 with and nothing was printed. */
4981 return PRINT_UNKNOWN
;
4984 /* Evaluate the expression EXP and return 1 if value is zero.
4985 This returns the inverse of the condition because it is called
4986 from catch_errors which returns 0 if an exception happened, and if an
4987 exception happens we want execution to stop.
4988 The argument is a "struct expression *" that has been cast to a
4989 "void *" to make it pass through catch_errors. */
4992 breakpoint_cond_eval (void *exp
)
4994 struct value
*mark
= value_mark ();
4995 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4997 value_free_to_mark (mark
);
5001 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5004 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5008 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5010 **bs_link_pointer
= bs
;
5011 *bs_link_pointer
= &bs
->next
;
5012 bs
->breakpoint_at
= bl
->owner
;
5013 bs
->bp_location_at
= bl
;
5014 incref_bp_location (bl
);
5015 /* If the condition is false, etc., don't do the commands. */
5016 bs
->commands
= NULL
;
5018 bs
->print_it
= print_it_normal
;
5022 /* The target has stopped with waitstatus WS. Check if any hardware
5023 watchpoints have triggered, according to the target. */
5026 watchpoints_triggered (struct target_waitstatus
*ws
)
5028 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5030 struct breakpoint
*b
;
5032 if (!stopped_by_watchpoint
)
5034 /* We were not stopped by a watchpoint. Mark all watchpoints
5035 as not triggered. */
5037 if (is_hardware_watchpoint (b
))
5039 struct watchpoint
*w
= (struct watchpoint
*) b
;
5041 w
->watchpoint_triggered
= watch_triggered_no
;
5047 if (!target_stopped_data_address (¤t_target
, &addr
))
5049 /* We were stopped by a watchpoint, but we don't know where.
5050 Mark all watchpoints as unknown. */
5052 if (is_hardware_watchpoint (b
))
5054 struct watchpoint
*w
= (struct watchpoint
*) b
;
5056 w
->watchpoint_triggered
= watch_triggered_unknown
;
5062 /* The target could report the data address. Mark watchpoints
5063 affected by this data address as triggered, and all others as not
5067 if (is_hardware_watchpoint (b
))
5069 struct watchpoint
*w
= (struct watchpoint
*) b
;
5070 struct bp_location
*loc
;
5072 w
->watchpoint_triggered
= watch_triggered_no
;
5073 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5075 if (is_masked_watchpoint (b
))
5077 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5078 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5080 if (newaddr
== start
)
5082 w
->watchpoint_triggered
= watch_triggered_yes
;
5086 /* Exact match not required. Within range is sufficient. */
5087 else if (target_watchpoint_addr_within_range (¤t_target
,
5091 w
->watchpoint_triggered
= watch_triggered_yes
;
5100 /* Possible return values for watchpoint_check (this can't be an enum
5101 because of check_errors). */
5102 /* The watchpoint has been deleted. */
5103 #define WP_DELETED 1
5104 /* The value has changed. */
5105 #define WP_VALUE_CHANGED 2
5106 /* The value has not changed. */
5107 #define WP_VALUE_NOT_CHANGED 3
5108 /* Ignore this watchpoint, no matter if the value changed or not. */
5111 #define BP_TEMPFLAG 1
5112 #define BP_HARDWAREFLAG 2
5114 /* Evaluate watchpoint condition expression and check if its value
5117 P should be a pointer to struct bpstat, but is defined as a void *
5118 in order for this function to be usable with catch_errors. */
5121 watchpoint_check (void *p
)
5123 bpstat bs
= (bpstat
) p
;
5124 struct watchpoint
*b
;
5125 struct frame_info
*fr
;
5126 int within_current_scope
;
5128 /* BS is built from an existing struct breakpoint. */
5129 gdb_assert (bs
->breakpoint_at
!= NULL
);
5130 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5132 /* If this is a local watchpoint, we only want to check if the
5133 watchpoint frame is in scope if the current thread is the thread
5134 that was used to create the watchpoint. */
5135 if (!watchpoint_in_thread_scope (b
))
5138 if (b
->exp_valid_block
== NULL
)
5139 within_current_scope
= 1;
5142 struct frame_info
*frame
= get_current_frame ();
5143 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5144 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5146 /* stack_frame_destroyed_p() returns a non-zero value if we're
5147 still in the function but the stack frame has already been
5148 invalidated. Since we can't rely on the values of local
5149 variables after the stack has been destroyed, we are treating
5150 the watchpoint in that state as `not changed' without further
5151 checking. Don't mark watchpoints as changed if the current
5152 frame is in an epilogue - even if they are in some other
5153 frame, our view of the stack is likely to be wrong and
5154 frame_find_by_id could error out. */
5155 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5158 fr
= frame_find_by_id (b
->watchpoint_frame
);
5159 within_current_scope
= (fr
!= NULL
);
5161 /* If we've gotten confused in the unwinder, we might have
5162 returned a frame that can't describe this variable. */
5163 if (within_current_scope
)
5165 struct symbol
*function
;
5167 function
= get_frame_function (fr
);
5168 if (function
== NULL
5169 || !contained_in (b
->exp_valid_block
,
5170 SYMBOL_BLOCK_VALUE (function
)))
5171 within_current_scope
= 0;
5174 if (within_current_scope
)
5175 /* If we end up stopping, the current frame will get selected
5176 in normal_stop. So this call to select_frame won't affect
5181 if (within_current_scope
)
5183 /* We use value_{,free_to_}mark because it could be a *long*
5184 time before we return to the command level and call
5185 free_all_values. We can't call free_all_values because we
5186 might be in the middle of evaluating a function call. */
5190 struct value
*new_val
;
5192 if (is_masked_watchpoint (b
))
5193 /* Since we don't know the exact trigger address (from
5194 stopped_data_address), just tell the user we've triggered
5195 a mask watchpoint. */
5196 return WP_VALUE_CHANGED
;
5198 mark
= value_mark ();
5199 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5201 if (b
->val_bitsize
!= 0)
5202 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5204 /* We use value_equal_contents instead of value_equal because
5205 the latter coerces an array to a pointer, thus comparing just
5206 the address of the array instead of its contents. This is
5207 not what we want. */
5208 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5209 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5211 if (new_val
!= NULL
)
5213 release_value (new_val
);
5214 value_free_to_mark (mark
);
5216 bs
->old_val
= b
->val
;
5219 return WP_VALUE_CHANGED
;
5223 /* Nothing changed. */
5224 value_free_to_mark (mark
);
5225 return WP_VALUE_NOT_CHANGED
;
5230 /* This seems like the only logical thing to do because
5231 if we temporarily ignored the watchpoint, then when
5232 we reenter the block in which it is valid it contains
5233 garbage (in the case of a function, it may have two
5234 garbage values, one before and one after the prologue).
5235 So we can't even detect the first assignment to it and
5236 watch after that (since the garbage may or may not equal
5237 the first value assigned). */
5238 /* We print all the stop information in
5239 breakpoint_ops->print_it, but in this case, by the time we
5240 call breakpoint_ops->print_it this bp will be deleted
5241 already. So we have no choice but print the information
5244 SWITCH_THRU_ALL_UIS ()
5246 struct ui_out
*uiout
= current_uiout
;
5248 if (uiout
->is_mi_like_p ())
5250 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5251 uiout
->text ("\nWatchpoint ");
5252 uiout
->field_int ("wpnum", b
->number
);
5253 uiout
->text (" deleted because the program has left the block in\n"
5254 "which its expression is valid.\n");
5257 /* Make sure the watchpoint's commands aren't executed. */
5258 decref_counted_command_line (&b
->commands
);
5259 watchpoint_del_at_next_stop (b
);
5265 /* Return true if it looks like target has stopped due to hitting
5266 breakpoint location BL. This function does not check if we should
5267 stop, only if BL explains the stop. */
5270 bpstat_check_location (const struct bp_location
*bl
,
5271 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5272 const struct target_waitstatus
*ws
)
5274 struct breakpoint
*b
= bl
->owner
;
5276 /* BL is from an existing breakpoint. */
5277 gdb_assert (b
!= NULL
);
5279 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5282 /* Determine if the watched values have actually changed, and we
5283 should stop. If not, set BS->stop to 0. */
5286 bpstat_check_watchpoint (bpstat bs
)
5288 const struct bp_location
*bl
;
5289 struct watchpoint
*b
;
5291 /* BS is built for existing struct breakpoint. */
5292 bl
= bs
->bp_location_at
;
5293 gdb_assert (bl
!= NULL
);
5294 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5295 gdb_assert (b
!= NULL
);
5298 int must_check_value
= 0;
5300 if (b
->type
== bp_watchpoint
)
5301 /* For a software watchpoint, we must always check the
5303 must_check_value
= 1;
5304 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5305 /* We have a hardware watchpoint (read, write, or access)
5306 and the target earlier reported an address watched by
5308 must_check_value
= 1;
5309 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5310 && b
->type
== bp_hardware_watchpoint
)
5311 /* We were stopped by a hardware watchpoint, but the target could
5312 not report the data address. We must check the watchpoint's
5313 value. Access and read watchpoints are out of luck; without
5314 a data address, we can't figure it out. */
5315 must_check_value
= 1;
5317 if (must_check_value
)
5320 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5322 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5323 int e
= catch_errors (watchpoint_check
, bs
, message
,
5325 do_cleanups (cleanups
);
5329 /* We've already printed what needs to be printed. */
5330 bs
->print_it
= print_it_done
;
5334 bs
->print_it
= print_it_noop
;
5337 case WP_VALUE_CHANGED
:
5338 if (b
->type
== bp_read_watchpoint
)
5340 /* There are two cases to consider here:
5342 1. We're watching the triggered memory for reads.
5343 In that case, trust the target, and always report
5344 the watchpoint hit to the user. Even though
5345 reads don't cause value changes, the value may
5346 have changed since the last time it was read, and
5347 since we're not trapping writes, we will not see
5348 those, and as such we should ignore our notion of
5351 2. We're watching the triggered memory for both
5352 reads and writes. There are two ways this may
5355 2.1. This is a target that can't break on data
5356 reads only, but can break on accesses (reads or
5357 writes), such as e.g., x86. We detect this case
5358 at the time we try to insert read watchpoints.
5360 2.2. Otherwise, the target supports read
5361 watchpoints, but, the user set an access or write
5362 watchpoint watching the same memory as this read
5365 If we're watching memory writes as well as reads,
5366 ignore watchpoint hits when we find that the
5367 value hasn't changed, as reads don't cause
5368 changes. This still gives false positives when
5369 the program writes the same value to memory as
5370 what there was already in memory (we will confuse
5371 it for a read), but it's much better than
5374 int other_write_watchpoint
= 0;
5376 if (bl
->watchpoint_type
== hw_read
)
5378 struct breakpoint
*other_b
;
5380 ALL_BREAKPOINTS (other_b
)
5381 if (other_b
->type
== bp_hardware_watchpoint
5382 || other_b
->type
== bp_access_watchpoint
)
5384 struct watchpoint
*other_w
=
5385 (struct watchpoint
*) other_b
;
5387 if (other_w
->watchpoint_triggered
5388 == watch_triggered_yes
)
5390 other_write_watchpoint
= 1;
5396 if (other_write_watchpoint
5397 || bl
->watchpoint_type
== hw_access
)
5399 /* We're watching the same memory for writes,
5400 and the value changed since the last time we
5401 updated it, so this trap must be for a write.
5403 bs
->print_it
= print_it_noop
;
5408 case WP_VALUE_NOT_CHANGED
:
5409 if (b
->type
== bp_hardware_watchpoint
5410 || b
->type
== bp_watchpoint
)
5412 /* Don't stop: write watchpoints shouldn't fire if
5413 the value hasn't changed. */
5414 bs
->print_it
= print_it_noop
;
5422 /* Error from catch_errors. */
5424 SWITCH_THRU_ALL_UIS ()
5426 printf_filtered (_("Watchpoint %d deleted.\n"),
5429 watchpoint_del_at_next_stop (b
);
5430 /* We've already printed what needs to be printed. */
5431 bs
->print_it
= print_it_done
;
5436 else /* must_check_value == 0 */
5438 /* This is a case where some watchpoint(s) triggered, but
5439 not at the address of this watchpoint, or else no
5440 watchpoint triggered after all. So don't print
5441 anything for this watchpoint. */
5442 bs
->print_it
= print_it_noop
;
5448 /* For breakpoints that are currently marked as telling gdb to stop,
5449 check conditions (condition proper, frame, thread and ignore count)
5450 of breakpoint referred to by BS. If we should not stop for this
5451 breakpoint, set BS->stop to 0. */
5454 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5456 const struct bp_location
*bl
;
5457 struct breakpoint
*b
;
5458 int value_is_zero
= 0;
5459 struct expression
*cond
;
5461 gdb_assert (bs
->stop
);
5463 /* BS is built for existing struct breakpoint. */
5464 bl
= bs
->bp_location_at
;
5465 gdb_assert (bl
!= NULL
);
5466 b
= bs
->breakpoint_at
;
5467 gdb_assert (b
!= NULL
);
5469 /* Even if the target evaluated the condition on its end and notified GDB, we
5470 need to do so again since GDB does not know if we stopped due to a
5471 breakpoint or a single step breakpoint. */
5473 if (frame_id_p (b
->frame_id
)
5474 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5480 /* If this is a thread/task-specific breakpoint, don't waste cpu
5481 evaluating the condition if this isn't the specified
5483 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5484 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5491 /* Evaluate extension language breakpoints that have a "stop" method
5493 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5495 if (is_watchpoint (b
))
5497 struct watchpoint
*w
= (struct watchpoint
*) b
;
5499 cond
= w
->cond_exp
.get ();
5502 cond
= bl
->cond
.get ();
5504 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5506 int within_current_scope
= 1;
5507 struct watchpoint
* w
;
5509 /* We use value_mark and value_free_to_mark because it could
5510 be a long time before we return to the command level and
5511 call free_all_values. We can't call free_all_values
5512 because we might be in the middle of evaluating a
5514 struct value
*mark
= value_mark ();
5516 if (is_watchpoint (b
))
5517 w
= (struct watchpoint
*) b
;
5521 /* Need to select the frame, with all that implies so that
5522 the conditions will have the right context. Because we
5523 use the frame, we will not see an inlined function's
5524 variables when we arrive at a breakpoint at the start
5525 of the inlined function; the current frame will be the
5527 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5528 select_frame (get_current_frame ());
5531 struct frame_info
*frame
;
5533 /* For local watchpoint expressions, which particular
5534 instance of a local is being watched matters, so we
5535 keep track of the frame to evaluate the expression
5536 in. To evaluate the condition however, it doesn't
5537 really matter which instantiation of the function
5538 where the condition makes sense triggers the
5539 watchpoint. This allows an expression like "watch
5540 global if q > 10" set in `func', catch writes to
5541 global on all threads that call `func', or catch
5542 writes on all recursive calls of `func' by a single
5543 thread. We simply always evaluate the condition in
5544 the innermost frame that's executing where it makes
5545 sense to evaluate the condition. It seems
5547 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5549 select_frame (frame
);
5551 within_current_scope
= 0;
5553 if (within_current_scope
)
5555 = catch_errors (breakpoint_cond_eval
, cond
,
5556 "Error in testing breakpoint condition:\n",
5560 warning (_("Watchpoint condition cannot be tested "
5561 "in the current scope"));
5562 /* If we failed to set the right context for this
5563 watchpoint, unconditionally report it. */
5566 /* FIXME-someday, should give breakpoint #. */
5567 value_free_to_mark (mark
);
5570 if (cond
&& value_is_zero
)
5574 else if (b
->ignore_count
> 0)
5578 /* Increase the hit count even though we don't stop. */
5580 observer_notify_breakpoint_modified (b
);
5584 /* Returns true if we need to track moribund locations of LOC's type
5585 on the current target. */
5588 need_moribund_for_location_type (struct bp_location
*loc
)
5590 return ((loc
->loc_type
== bp_loc_software_breakpoint
5591 && !target_supports_stopped_by_sw_breakpoint ())
5592 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5593 && !target_supports_stopped_by_hw_breakpoint ()));
5597 /* Get a bpstat associated with having just stopped at address
5598 BP_ADDR in thread PTID.
5600 Determine whether we stopped at a breakpoint, etc, or whether we
5601 don't understand this stop. Result is a chain of bpstat's such
5604 if we don't understand the stop, the result is a null pointer.
5606 if we understand why we stopped, the result is not null.
5608 Each element of the chain refers to a particular breakpoint or
5609 watchpoint at which we have stopped. (We may have stopped for
5610 several reasons concurrently.)
5612 Each element of the chain has valid next, breakpoint_at,
5613 commands, FIXME??? fields. */
5616 bpstat_stop_status (struct address_space
*aspace
,
5617 CORE_ADDR bp_addr
, ptid_t ptid
,
5618 const struct target_waitstatus
*ws
)
5620 struct breakpoint
*b
= NULL
;
5621 struct bp_location
*bl
;
5622 struct bp_location
*loc
;
5623 /* First item of allocated bpstat's. */
5624 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5625 /* Pointer to the last thing in the chain currently. */
5628 int need_remove_insert
;
5631 /* First, build the bpstat chain with locations that explain a
5632 target stop, while being careful to not set the target running,
5633 as that may invalidate locations (in particular watchpoint
5634 locations are recreated). Resuming will happen here with
5635 breakpoint conditions or watchpoint expressions that include
5636 inferior function calls. */
5640 if (!breakpoint_enabled (b
))
5643 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5645 /* For hardware watchpoints, we look only at the first
5646 location. The watchpoint_check function will work on the
5647 entire expression, not the individual locations. For
5648 read watchpoints, the watchpoints_triggered function has
5649 checked all locations already. */
5650 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5653 if (!bl
->enabled
|| bl
->shlib_disabled
)
5656 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5659 /* Come here if it's a watchpoint, or if the break address
5662 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5665 /* Assume we stop. Should we find a watchpoint that is not
5666 actually triggered, or if the condition of the breakpoint
5667 evaluates as false, we'll reset 'stop' to 0. */
5671 /* If this is a scope breakpoint, mark the associated
5672 watchpoint as triggered so that we will handle the
5673 out-of-scope event. We'll get to the watchpoint next
5675 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5677 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5679 w
->watchpoint_triggered
= watch_triggered_yes
;
5684 /* Check if a moribund breakpoint explains the stop. */
5685 if (!target_supports_stopped_by_sw_breakpoint ()
5686 || !target_supports_stopped_by_hw_breakpoint ())
5688 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5690 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5691 && need_moribund_for_location_type (loc
))
5693 bs
= bpstat_alloc (loc
, &bs_link
);
5694 /* For hits of moribund locations, we should just proceed. */
5697 bs
->print_it
= print_it_noop
;
5702 /* A bit of special processing for shlib breakpoints. We need to
5703 process solib loading here, so that the lists of loaded and
5704 unloaded libraries are correct before we handle "catch load" and
5706 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5708 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5710 handle_solib_event ();
5715 /* Now go through the locations that caused the target to stop, and
5716 check whether we're interested in reporting this stop to higher
5717 layers, or whether we should resume the target transparently. */
5721 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5726 b
= bs
->breakpoint_at
;
5727 b
->ops
->check_status (bs
);
5730 bpstat_check_breakpoint_conditions (bs
, ptid
);
5735 observer_notify_breakpoint_modified (b
);
5737 /* We will stop here. */
5738 if (b
->disposition
== disp_disable
)
5740 --(b
->enable_count
);
5741 if (b
->enable_count
<= 0)
5742 b
->enable_state
= bp_disabled
;
5747 bs
->commands
= b
->commands
;
5748 incref_counted_command_line (bs
->commands
);
5749 if (command_line_is_silent (bs
->commands
5750 ? bs
->commands
->commands
: NULL
))
5753 b
->ops
->after_condition_true (bs
);
5758 /* Print nothing for this entry if we don't stop or don't
5760 if (!bs
->stop
|| !bs
->print
)
5761 bs
->print_it
= print_it_noop
;
5764 /* If we aren't stopping, the value of some hardware watchpoint may
5765 not have changed, but the intermediate memory locations we are
5766 watching may have. Don't bother if we're stopping; this will get
5768 need_remove_insert
= 0;
5769 if (! bpstat_causes_stop (bs_head
))
5770 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5772 && bs
->breakpoint_at
5773 && is_hardware_watchpoint (bs
->breakpoint_at
))
5775 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5777 update_watchpoint (w
, 0 /* don't reparse. */);
5778 need_remove_insert
= 1;
5781 if (need_remove_insert
)
5782 update_global_location_list (UGLL_MAY_INSERT
);
5783 else if (removed_any
)
5784 update_global_location_list (UGLL_DONT_INSERT
);
5790 handle_jit_event (void)
5792 struct frame_info
*frame
;
5793 struct gdbarch
*gdbarch
;
5796 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5798 /* Switch terminal for any messages produced by
5799 breakpoint_re_set. */
5800 target_terminal_ours_for_output ();
5802 frame
= get_current_frame ();
5803 gdbarch
= get_frame_arch (frame
);
5805 jit_event_handler (gdbarch
);
5807 target_terminal_inferior ();
5810 /* Prepare WHAT final decision for infrun. */
5812 /* Decide what infrun needs to do with this bpstat. */
5815 bpstat_what (bpstat bs_head
)
5817 struct bpstat_what retval
;
5820 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5821 retval
.call_dummy
= STOP_NONE
;
5822 retval
.is_longjmp
= 0;
5824 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5826 /* Extract this BS's action. After processing each BS, we check
5827 if its action overrides all we've seem so far. */
5828 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5831 if (bs
->breakpoint_at
== NULL
)
5833 /* I suspect this can happen if it was a momentary
5834 breakpoint which has since been deleted. */
5838 bptype
= bs
->breakpoint_at
->type
;
5845 case bp_hardware_breakpoint
:
5846 case bp_single_step
:
5849 case bp_shlib_event
:
5853 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5855 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5858 this_action
= BPSTAT_WHAT_SINGLE
;
5861 case bp_hardware_watchpoint
:
5862 case bp_read_watchpoint
:
5863 case bp_access_watchpoint
:
5867 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5869 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5873 /* There was a watchpoint, but we're not stopping.
5874 This requires no further action. */
5878 case bp_longjmp_call_dummy
:
5882 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5883 retval
.is_longjmp
= bptype
!= bp_exception
;
5886 this_action
= BPSTAT_WHAT_SINGLE
;
5888 case bp_longjmp_resume
:
5889 case bp_exception_resume
:
5892 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5893 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5896 this_action
= BPSTAT_WHAT_SINGLE
;
5898 case bp_step_resume
:
5900 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5903 /* It is for the wrong frame. */
5904 this_action
= BPSTAT_WHAT_SINGLE
;
5907 case bp_hp_step_resume
:
5909 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5912 /* It is for the wrong frame. */
5913 this_action
= BPSTAT_WHAT_SINGLE
;
5916 case bp_watchpoint_scope
:
5917 case bp_thread_event
:
5918 case bp_overlay_event
:
5919 case bp_longjmp_master
:
5920 case bp_std_terminate_master
:
5921 case bp_exception_master
:
5922 this_action
= BPSTAT_WHAT_SINGLE
;
5928 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5930 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5934 /* There was a catchpoint, but we're not stopping.
5935 This requires no further action. */
5939 this_action
= BPSTAT_WHAT_SINGLE
;
5942 /* Make sure the action is stop (silent or noisy),
5943 so infrun.c pops the dummy frame. */
5944 retval
.call_dummy
= STOP_STACK_DUMMY
;
5945 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5947 case bp_std_terminate
:
5948 /* Make sure the action is stop (silent or noisy),
5949 so infrun.c pops the dummy frame. */
5950 retval
.call_dummy
= STOP_STD_TERMINATE
;
5951 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5954 case bp_fast_tracepoint
:
5955 case bp_static_tracepoint
:
5956 /* Tracepoint hits should not be reported back to GDB, and
5957 if one got through somehow, it should have been filtered
5959 internal_error (__FILE__
, __LINE__
,
5960 _("bpstat_what: tracepoint encountered"));
5962 case bp_gnu_ifunc_resolver
:
5963 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5964 this_action
= BPSTAT_WHAT_SINGLE
;
5966 case bp_gnu_ifunc_resolver_return
:
5967 /* The breakpoint will be removed, execution will restart from the
5968 PC of the former breakpoint. */
5969 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5974 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5976 this_action
= BPSTAT_WHAT_SINGLE
;
5980 internal_error (__FILE__
, __LINE__
,
5981 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5984 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5991 bpstat_run_callbacks (bpstat bs_head
)
5995 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5997 struct breakpoint
*b
= bs
->breakpoint_at
;
6004 handle_jit_event ();
6006 case bp_gnu_ifunc_resolver
:
6007 gnu_ifunc_resolver_stop (b
);
6009 case bp_gnu_ifunc_resolver_return
:
6010 gnu_ifunc_resolver_return_stop (b
);
6016 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6017 without hardware support). This isn't related to a specific bpstat,
6018 just to things like whether watchpoints are set. */
6021 bpstat_should_step (void)
6023 struct breakpoint
*b
;
6026 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6032 bpstat_causes_stop (bpstat bs
)
6034 for (; bs
!= NULL
; bs
= bs
->next
)
6043 /* Compute a string of spaces suitable to indent the next line
6044 so it starts at the position corresponding to the table column
6045 named COL_NAME in the currently active table of UIOUT. */
6048 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6050 static char wrap_indent
[80];
6051 int i
, total_width
, width
, align
;
6055 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6057 if (strcmp (text
, col_name
) == 0)
6059 gdb_assert (total_width
< sizeof wrap_indent
);
6060 memset (wrap_indent
, ' ', total_width
);
6061 wrap_indent
[total_width
] = 0;
6066 total_width
+= width
+ 1;
6072 /* Determine if the locations of this breakpoint will have their conditions
6073 evaluated by the target, host or a mix of both. Returns the following:
6075 "host": Host evals condition.
6076 "host or target": Host or Target evals condition.
6077 "target": Target evals condition.
6081 bp_condition_evaluator (struct breakpoint
*b
)
6083 struct bp_location
*bl
;
6084 char host_evals
= 0;
6085 char target_evals
= 0;
6090 if (!is_breakpoint (b
))
6093 if (gdb_evaluates_breakpoint_condition_p ()
6094 || !target_supports_evaluation_of_breakpoint_conditions ())
6095 return condition_evaluation_host
;
6097 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6099 if (bl
->cond_bytecode
)
6105 if (host_evals
&& target_evals
)
6106 return condition_evaluation_both
;
6107 else if (target_evals
)
6108 return condition_evaluation_target
;
6110 return condition_evaluation_host
;
6113 /* Determine the breakpoint location's condition evaluator. This is
6114 similar to bp_condition_evaluator, but for locations. */
6117 bp_location_condition_evaluator (struct bp_location
*bl
)
6119 if (bl
&& !is_breakpoint (bl
->owner
))
6122 if (gdb_evaluates_breakpoint_condition_p ()
6123 || !target_supports_evaluation_of_breakpoint_conditions ())
6124 return condition_evaluation_host
;
6126 if (bl
&& bl
->cond_bytecode
)
6127 return condition_evaluation_target
;
6129 return condition_evaluation_host
;
6132 /* Print the LOC location out of the list of B->LOC locations. */
6135 print_breakpoint_location (struct breakpoint
*b
,
6136 struct bp_location
*loc
)
6138 struct ui_out
*uiout
= current_uiout
;
6140 scoped_restore_current_program_space restore_pspace
;
6142 if (loc
!= NULL
&& loc
->shlib_disabled
)
6146 set_current_program_space (loc
->pspace
);
6148 if (b
->display_canonical
)
6149 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6150 else if (loc
&& loc
->symtab
)
6153 = find_pc_sect_function (loc
->address
, loc
->section
);
6156 uiout
->text ("in ");
6157 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6159 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6160 uiout
->text ("at ");
6162 uiout
->field_string ("file",
6163 symtab_to_filename_for_display (loc
->symtab
));
6166 if (uiout
->is_mi_like_p ())
6167 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6169 uiout
->field_int ("line", loc
->line_number
);
6175 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6177 uiout
->field_stream ("at", stb
);
6181 uiout
->field_string ("pending",
6182 event_location_to_string (b
->location
.get ()));
6183 /* If extra_string is available, it could be holding a condition
6184 or dprintf arguments. In either case, make sure it is printed,
6185 too, but only for non-MI streams. */
6186 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6188 if (b
->type
== bp_dprintf
)
6192 uiout
->text (b
->extra_string
);
6196 if (loc
&& is_breakpoint (b
)
6197 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6198 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6201 uiout
->field_string ("evaluated-by",
6202 bp_location_condition_evaluator (loc
));
6208 bptype_string (enum bptype type
)
6210 struct ep_type_description
6213 const char *description
;
6215 static struct ep_type_description bptypes
[] =
6217 {bp_none
, "?deleted?"},
6218 {bp_breakpoint
, "breakpoint"},
6219 {bp_hardware_breakpoint
, "hw breakpoint"},
6220 {bp_single_step
, "sw single-step"},
6221 {bp_until
, "until"},
6222 {bp_finish
, "finish"},
6223 {bp_watchpoint
, "watchpoint"},
6224 {bp_hardware_watchpoint
, "hw watchpoint"},
6225 {bp_read_watchpoint
, "read watchpoint"},
6226 {bp_access_watchpoint
, "acc watchpoint"},
6227 {bp_longjmp
, "longjmp"},
6228 {bp_longjmp_resume
, "longjmp resume"},
6229 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6230 {bp_exception
, "exception"},
6231 {bp_exception_resume
, "exception resume"},
6232 {bp_step_resume
, "step resume"},
6233 {bp_hp_step_resume
, "high-priority step resume"},
6234 {bp_watchpoint_scope
, "watchpoint scope"},
6235 {bp_call_dummy
, "call dummy"},
6236 {bp_std_terminate
, "std::terminate"},
6237 {bp_shlib_event
, "shlib events"},
6238 {bp_thread_event
, "thread events"},
6239 {bp_overlay_event
, "overlay events"},
6240 {bp_longjmp_master
, "longjmp master"},
6241 {bp_std_terminate_master
, "std::terminate master"},
6242 {bp_exception_master
, "exception master"},
6243 {bp_catchpoint
, "catchpoint"},
6244 {bp_tracepoint
, "tracepoint"},
6245 {bp_fast_tracepoint
, "fast tracepoint"},
6246 {bp_static_tracepoint
, "static tracepoint"},
6247 {bp_dprintf
, "dprintf"},
6248 {bp_jit_event
, "jit events"},
6249 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6250 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6253 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6254 || ((int) type
!= bptypes
[(int) type
].type
))
6255 internal_error (__FILE__
, __LINE__
,
6256 _("bptypes table does not describe type #%d."),
6259 return bptypes
[(int) type
].description
;
6262 /* For MI, output a field named 'thread-groups' with a list as the value.
6263 For CLI, prefix the list with the string 'inf'. */
6266 output_thread_groups (struct ui_out
*uiout
,
6267 const char *field_name
,
6271 int is_mi
= uiout
->is_mi_like_p ();
6275 /* For backward compatibility, don't display inferiors in CLI unless
6276 there are several. Always display them for MI. */
6277 if (!is_mi
&& mi_only
)
6280 ui_out_emit_list
list_emitter (uiout
, field_name
);
6282 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6288 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6289 uiout
->field_string (NULL
, mi_group
);
6294 uiout
->text (" inf ");
6298 uiout
->text (plongest (inf
));
6303 /* Print B to gdb_stdout. */
6306 print_one_breakpoint_location (struct breakpoint
*b
,
6307 struct bp_location
*loc
,
6309 struct bp_location
**last_loc
,
6312 struct command_line
*l
;
6313 static char bpenables
[] = "nynny";
6315 struct ui_out
*uiout
= current_uiout
;
6316 int header_of_multiple
= 0;
6317 int part_of_multiple
= (loc
!= NULL
);
6318 struct value_print_options opts
;
6320 get_user_print_options (&opts
);
6322 gdb_assert (!loc
|| loc_number
!= 0);
6323 /* See comment in print_one_breakpoint concerning treatment of
6324 breakpoints with single disabled location. */
6327 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6328 header_of_multiple
= 1;
6336 if (part_of_multiple
)
6339 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6340 uiout
->field_string ("number", formatted
);
6345 uiout
->field_int ("number", b
->number
);
6350 if (part_of_multiple
)
6351 uiout
->field_skip ("type");
6353 uiout
->field_string ("type", bptype_string (b
->type
));
6357 if (part_of_multiple
)
6358 uiout
->field_skip ("disp");
6360 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6365 if (part_of_multiple
)
6366 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6368 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6373 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6375 /* Although the print_one can possibly print all locations,
6376 calling it here is not likely to get any nice result. So,
6377 make sure there's just one location. */
6378 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6379 b
->ops
->print_one (b
, last_loc
);
6385 internal_error (__FILE__
, __LINE__
,
6386 _("print_one_breakpoint: bp_none encountered\n"));
6390 case bp_hardware_watchpoint
:
6391 case bp_read_watchpoint
:
6392 case bp_access_watchpoint
:
6394 struct watchpoint
*w
= (struct watchpoint
*) b
;
6396 /* Field 4, the address, is omitted (which makes the columns
6397 not line up too nicely with the headers, but the effect
6398 is relatively readable). */
6399 if (opts
.addressprint
)
6400 uiout
->field_skip ("addr");
6402 uiout
->field_string ("what", w
->exp_string
);
6407 case bp_hardware_breakpoint
:
6408 case bp_single_step
:
6412 case bp_longjmp_resume
:
6413 case bp_longjmp_call_dummy
:
6415 case bp_exception_resume
:
6416 case bp_step_resume
:
6417 case bp_hp_step_resume
:
6418 case bp_watchpoint_scope
:
6420 case bp_std_terminate
:
6421 case bp_shlib_event
:
6422 case bp_thread_event
:
6423 case bp_overlay_event
:
6424 case bp_longjmp_master
:
6425 case bp_std_terminate_master
:
6426 case bp_exception_master
:
6428 case bp_fast_tracepoint
:
6429 case bp_static_tracepoint
:
6432 case bp_gnu_ifunc_resolver
:
6433 case bp_gnu_ifunc_resolver_return
:
6434 if (opts
.addressprint
)
6437 if (header_of_multiple
)
6438 uiout
->field_string ("addr", "<MULTIPLE>");
6439 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6440 uiout
->field_string ("addr", "<PENDING>");
6442 uiout
->field_core_addr ("addr",
6443 loc
->gdbarch
, loc
->address
);
6446 if (!header_of_multiple
)
6447 print_breakpoint_location (b
, loc
);
6454 if (loc
!= NULL
&& !header_of_multiple
)
6456 struct inferior
*inf
;
6457 VEC(int) *inf_num
= NULL
;
6462 if (inf
->pspace
== loc
->pspace
)
6463 VEC_safe_push (int, inf_num
, inf
->num
);
6466 /* For backward compatibility, don't display inferiors in CLI unless
6467 there are several. Always display for MI. */
6469 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6470 && (number_of_program_spaces () > 1
6471 || number_of_inferiors () > 1)
6472 /* LOC is for existing B, it cannot be in
6473 moribund_locations and thus having NULL OWNER. */
6474 && loc
->owner
->type
!= bp_catchpoint
))
6476 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6477 VEC_free (int, inf_num
);
6480 if (!part_of_multiple
)
6482 if (b
->thread
!= -1)
6484 /* FIXME: This seems to be redundant and lost here; see the
6485 "stop only in" line a little further down. */
6486 uiout
->text (" thread ");
6487 uiout
->field_int ("thread", b
->thread
);
6489 else if (b
->task
!= 0)
6491 uiout
->text (" task ");
6492 uiout
->field_int ("task", b
->task
);
6498 if (!part_of_multiple
)
6499 b
->ops
->print_one_detail (b
, uiout
);
6501 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6504 uiout
->text ("\tstop only in stack frame at ");
6505 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6507 uiout
->field_core_addr ("frame",
6508 b
->gdbarch
, b
->frame_id
.stack_addr
);
6512 if (!part_of_multiple
&& b
->cond_string
)
6515 if (is_tracepoint (b
))
6516 uiout
->text ("\ttrace only if ");
6518 uiout
->text ("\tstop only if ");
6519 uiout
->field_string ("cond", b
->cond_string
);
6521 /* Print whether the target is doing the breakpoint's condition
6522 evaluation. If GDB is doing the evaluation, don't print anything. */
6523 if (is_breakpoint (b
)
6524 && breakpoint_condition_evaluation_mode ()
6525 == condition_evaluation_target
)
6528 uiout
->field_string ("evaluated-by",
6529 bp_condition_evaluator (b
));
6530 uiout
->text (" evals)");
6535 if (!part_of_multiple
&& b
->thread
!= -1)
6537 /* FIXME should make an annotation for this. */
6538 uiout
->text ("\tstop only in thread ");
6539 if (uiout
->is_mi_like_p ())
6540 uiout
->field_int ("thread", b
->thread
);
6543 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6545 uiout
->field_string ("thread", print_thread_id (thr
));
6550 if (!part_of_multiple
)
6554 /* FIXME should make an annotation for this. */
6555 if (is_catchpoint (b
))
6556 uiout
->text ("\tcatchpoint");
6557 else if (is_tracepoint (b
))
6558 uiout
->text ("\ttracepoint");
6560 uiout
->text ("\tbreakpoint");
6561 uiout
->text (" already hit ");
6562 uiout
->field_int ("times", b
->hit_count
);
6563 if (b
->hit_count
== 1)
6564 uiout
->text (" time\n");
6566 uiout
->text (" times\n");
6570 /* Output the count also if it is zero, but only if this is mi. */
6571 if (uiout
->is_mi_like_p ())
6572 uiout
->field_int ("times", b
->hit_count
);
6576 if (!part_of_multiple
&& b
->ignore_count
)
6579 uiout
->text ("\tignore next ");
6580 uiout
->field_int ("ignore", b
->ignore_count
);
6581 uiout
->text (" hits\n");
6584 /* Note that an enable count of 1 corresponds to "enable once"
6585 behavior, which is reported by the combination of enablement and
6586 disposition, so we don't need to mention it here. */
6587 if (!part_of_multiple
&& b
->enable_count
> 1)
6590 uiout
->text ("\tdisable after ");
6591 /* Tweak the wording to clarify that ignore and enable counts
6592 are distinct, and have additive effect. */
6593 if (b
->ignore_count
)
6594 uiout
->text ("additional ");
6596 uiout
->text ("next ");
6597 uiout
->field_int ("enable", b
->enable_count
);
6598 uiout
->text (" hits\n");
6601 if (!part_of_multiple
&& is_tracepoint (b
))
6603 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6605 if (tp
->traceframe_usage
)
6607 uiout
->text ("\ttrace buffer usage ");
6608 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6609 uiout
->text (" bytes\n");
6613 l
= b
->commands
? b
->commands
->commands
: NULL
;
6614 if (!part_of_multiple
&& l
)
6617 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6618 print_command_lines (uiout
, l
, 4);
6621 if (is_tracepoint (b
))
6623 struct tracepoint
*t
= (struct tracepoint
*) b
;
6625 if (!part_of_multiple
&& t
->pass_count
)
6627 annotate_field (10);
6628 uiout
->text ("\tpass count ");
6629 uiout
->field_int ("pass", t
->pass_count
);
6630 uiout
->text (" \n");
6633 /* Don't display it when tracepoint or tracepoint location is
6635 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6637 annotate_field (11);
6639 if (uiout
->is_mi_like_p ())
6640 uiout
->field_string ("installed",
6641 loc
->inserted
? "y" : "n");
6647 uiout
->text ("\tnot ");
6648 uiout
->text ("installed on target\n");
6653 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6655 if (is_watchpoint (b
))
6657 struct watchpoint
*w
= (struct watchpoint
*) b
;
6659 uiout
->field_string ("original-location", w
->exp_string
);
6661 else if (b
->location
!= NULL
6662 && event_location_to_string (b
->location
.get ()) != NULL
)
6663 uiout
->field_string ("original-location",
6664 event_location_to_string (b
->location
.get ()));
6669 print_one_breakpoint (struct breakpoint
*b
,
6670 struct bp_location
**last_loc
,
6673 struct ui_out
*uiout
= current_uiout
;
6676 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6678 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6681 /* If this breakpoint has custom print function,
6682 it's already printed. Otherwise, print individual
6683 locations, if any. */
6684 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6686 /* If breakpoint has a single location that is disabled, we
6687 print it as if it had several locations, since otherwise it's
6688 hard to represent "breakpoint enabled, location disabled"
6691 Note that while hardware watchpoints have several locations
6692 internally, that's not a property exposed to user. */
6694 && !is_hardware_watchpoint (b
)
6695 && (b
->loc
->next
|| !b
->loc
->enabled
))
6697 struct bp_location
*loc
;
6700 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6702 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6703 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6710 breakpoint_address_bits (struct breakpoint
*b
)
6712 int print_address_bits
= 0;
6713 struct bp_location
*loc
;
6715 /* Software watchpoints that aren't watching memory don't have an
6716 address to print. */
6717 if (is_no_memory_software_watchpoint (b
))
6720 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6724 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6725 if (addr_bit
> print_address_bits
)
6726 print_address_bits
= addr_bit
;
6729 return print_address_bits
;
6732 struct captured_breakpoint_query_args
6738 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6740 struct captured_breakpoint_query_args
*args
6741 = (struct captured_breakpoint_query_args
*) data
;
6742 struct breakpoint
*b
;
6743 struct bp_location
*dummy_loc
= NULL
;
6747 if (args
->bnum
== b
->number
)
6749 print_one_breakpoint (b
, &dummy_loc
, 0);
6757 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6758 char **error_message
)
6760 struct captured_breakpoint_query_args args
;
6763 /* For the moment we don't trust print_one_breakpoint() to not throw
6765 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6766 error_message
, RETURN_MASK_ALL
) < 0)
6772 /* Return true if this breakpoint was set by the user, false if it is
6773 internal or momentary. */
6776 user_breakpoint_p (struct breakpoint
*b
)
6778 return b
->number
> 0;
6781 /* See breakpoint.h. */
6784 pending_breakpoint_p (struct breakpoint
*b
)
6786 return b
->loc
== NULL
;
6789 /* Print information on user settable breakpoint (watchpoint, etc)
6790 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6791 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6792 FILTER is non-NULL, call it on each breakpoint and only include the
6793 ones for which it returns non-zero. Return the total number of
6794 breakpoints listed. */
6797 breakpoint_1 (char *args
, int allflag
,
6798 int (*filter
) (const struct breakpoint
*))
6800 struct breakpoint
*b
;
6801 struct bp_location
*last_loc
= NULL
;
6802 int nr_printable_breakpoints
;
6803 struct value_print_options opts
;
6804 int print_address_bits
= 0;
6805 int print_type_col_width
= 14;
6806 struct ui_out
*uiout
= current_uiout
;
6808 get_user_print_options (&opts
);
6810 /* Compute the number of rows in the table, as well as the size
6811 required for address fields. */
6812 nr_printable_breakpoints
= 0;
6815 /* If we have a filter, only list the breakpoints it accepts. */
6816 if (filter
&& !filter (b
))
6819 /* If we have an "args" string, it is a list of breakpoints to
6820 accept. Skip the others. */
6821 if (args
!= NULL
&& *args
!= '\0')
6823 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6825 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6829 if (allflag
|| user_breakpoint_p (b
))
6831 int addr_bit
, type_len
;
6833 addr_bit
= breakpoint_address_bits (b
);
6834 if (addr_bit
> print_address_bits
)
6835 print_address_bits
= addr_bit
;
6837 type_len
= strlen (bptype_string (b
->type
));
6838 if (type_len
> print_type_col_width
)
6839 print_type_col_width
= type_len
;
6841 nr_printable_breakpoints
++;
6846 ui_out_emit_table
table_emitter (uiout
,
6847 opts
.addressprint
? 6 : 5,
6848 nr_printable_breakpoints
,
6851 if (nr_printable_breakpoints
> 0)
6852 annotate_breakpoints_headers ();
6853 if (nr_printable_breakpoints
> 0)
6855 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6856 if (nr_printable_breakpoints
> 0)
6858 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6859 if (nr_printable_breakpoints
> 0)
6861 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6862 if (nr_printable_breakpoints
> 0)
6864 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6865 if (opts
.addressprint
)
6867 if (nr_printable_breakpoints
> 0)
6869 if (print_address_bits
<= 32)
6870 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6872 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6874 if (nr_printable_breakpoints
> 0)
6876 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6877 uiout
->table_body ();
6878 if (nr_printable_breakpoints
> 0)
6879 annotate_breakpoints_table ();
6884 /* If we have a filter, only list the breakpoints it accepts. */
6885 if (filter
&& !filter (b
))
6888 /* If we have an "args" string, it is a list of breakpoints to
6889 accept. Skip the others. */
6891 if (args
!= NULL
&& *args
!= '\0')
6893 if (allflag
) /* maintenance info breakpoint */
6895 if (parse_and_eval_long (args
) != b
->number
)
6898 else /* all others */
6900 if (!number_is_in_list (args
, b
->number
))
6904 /* We only print out user settable breakpoints unless the
6906 if (allflag
|| user_breakpoint_p (b
))
6907 print_one_breakpoint (b
, &last_loc
, allflag
);
6911 if (nr_printable_breakpoints
== 0)
6913 /* If there's a filter, let the caller decide how to report
6917 if (args
== NULL
|| *args
== '\0')
6918 uiout
->message ("No breakpoints or watchpoints.\n");
6920 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6926 if (last_loc
&& !server_command
)
6927 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6930 /* FIXME? Should this be moved up so that it is only called when
6931 there have been breakpoints? */
6932 annotate_breakpoints_table_end ();
6934 return nr_printable_breakpoints
;
6937 /* Display the value of default-collect in a way that is generally
6938 compatible with the breakpoint list. */
6941 default_collect_info (void)
6943 struct ui_out
*uiout
= current_uiout
;
6945 /* If it has no value (which is frequently the case), say nothing; a
6946 message like "No default-collect." gets in user's face when it's
6948 if (!*default_collect
)
6951 /* The following phrase lines up nicely with per-tracepoint collect
6953 uiout
->text ("default collect ");
6954 uiout
->field_string ("default-collect", default_collect
);
6955 uiout
->text (" \n");
6959 info_breakpoints_command (char *args
, int from_tty
)
6961 breakpoint_1 (args
, 0, NULL
);
6963 default_collect_info ();
6967 info_watchpoints_command (char *args
, int from_tty
)
6969 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6970 struct ui_out
*uiout
= current_uiout
;
6972 if (num_printed
== 0)
6974 if (args
== NULL
|| *args
== '\0')
6975 uiout
->message ("No watchpoints.\n");
6977 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6982 maintenance_info_breakpoints (char *args
, int from_tty
)
6984 breakpoint_1 (args
, 1, NULL
);
6986 default_collect_info ();
6990 breakpoint_has_pc (struct breakpoint
*b
,
6991 struct program_space
*pspace
,
6992 CORE_ADDR pc
, struct obj_section
*section
)
6994 struct bp_location
*bl
= b
->loc
;
6996 for (; bl
; bl
= bl
->next
)
6998 if (bl
->pspace
== pspace
6999 && bl
->address
== pc
7000 && (!overlay_debugging
|| bl
->section
== section
))
7006 /* Print a message describing any user-breakpoints set at PC. This
7007 concerns with logical breakpoints, so we match program spaces, not
7011 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7012 struct program_space
*pspace
, CORE_ADDR pc
,
7013 struct obj_section
*section
, int thread
)
7016 struct breakpoint
*b
;
7019 others
+= (user_breakpoint_p (b
)
7020 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7024 printf_filtered (_("Note: breakpoint "));
7025 else /* if (others == ???) */
7026 printf_filtered (_("Note: breakpoints "));
7028 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7031 printf_filtered ("%d", b
->number
);
7032 if (b
->thread
== -1 && thread
!= -1)
7033 printf_filtered (" (all threads)");
7034 else if (b
->thread
!= -1)
7035 printf_filtered (" (thread %d)", b
->thread
);
7036 printf_filtered ("%s%s ",
7037 ((b
->enable_state
== bp_disabled
7038 || b
->enable_state
== bp_call_disabled
)
7042 : ((others
== 1) ? " and" : ""));
7044 printf_filtered (_("also set at pc "));
7045 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7046 printf_filtered (".\n");
7051 /* Return true iff it is meaningful to use the address member of
7052 BPT locations. For some breakpoint types, the locations' address members
7053 are irrelevant and it makes no sense to attempt to compare them to other
7054 addresses (or use them for any other purpose either).
7056 More specifically, each of the following breakpoint types will
7057 always have a zero valued location address and we don't want to mark
7058 breakpoints of any of these types to be a duplicate of an actual
7059 breakpoint location at address zero:
7067 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7069 enum bptype type
= bpt
->type
;
7071 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7074 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7075 true if LOC1 and LOC2 represent the same watchpoint location. */
7078 watchpoint_locations_match (struct bp_location
*loc1
,
7079 struct bp_location
*loc2
)
7081 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7082 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7084 /* Both of them must exist. */
7085 gdb_assert (w1
!= NULL
);
7086 gdb_assert (w2
!= NULL
);
7088 /* If the target can evaluate the condition expression in hardware,
7089 then we we need to insert both watchpoints even if they are at
7090 the same place. Otherwise the watchpoint will only trigger when
7091 the condition of whichever watchpoint was inserted evaluates to
7092 true, not giving a chance for GDB to check the condition of the
7093 other watchpoint. */
7095 && target_can_accel_watchpoint_condition (loc1
->address
,
7097 loc1
->watchpoint_type
,
7098 w1
->cond_exp
.get ()))
7100 && target_can_accel_watchpoint_condition (loc2
->address
,
7102 loc2
->watchpoint_type
,
7103 w2
->cond_exp
.get ())))
7106 /* Note that this checks the owner's type, not the location's. In
7107 case the target does not support read watchpoints, but does
7108 support access watchpoints, we'll have bp_read_watchpoint
7109 watchpoints with hw_access locations. Those should be considered
7110 duplicates of hw_read locations. The hw_read locations will
7111 become hw_access locations later. */
7112 return (loc1
->owner
->type
== loc2
->owner
->type
7113 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7114 && loc1
->address
== loc2
->address
7115 && loc1
->length
== loc2
->length
);
7118 /* See breakpoint.h. */
7121 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7122 struct address_space
*aspace2
, CORE_ADDR addr2
)
7124 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7125 || aspace1
== aspace2
)
7129 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7130 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7131 matches ASPACE2. On targets that have global breakpoints, the address
7132 space doesn't really matter. */
7135 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7136 int len1
, struct address_space
*aspace2
,
7139 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7140 || aspace1
== aspace2
)
7141 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7144 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7145 a ranged breakpoint. In most targets, a match happens only if ASPACE
7146 matches the breakpoint's address space. On targets that have global
7147 breakpoints, the address space doesn't really matter. */
7150 breakpoint_location_address_match (struct bp_location
*bl
,
7151 struct address_space
*aspace
,
7154 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7157 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7158 bl
->address
, bl
->length
,
7162 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7163 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7164 match happens only if ASPACE matches the breakpoint's address
7165 space. On targets that have global breakpoints, the address space
7166 doesn't really matter. */
7169 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7170 struct address_space
*aspace
,
7171 CORE_ADDR addr
, int len
)
7173 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7174 || bl
->pspace
->aspace
== aspace
)
7176 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7178 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7184 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7185 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7186 true, otherwise returns false. */
7189 tracepoint_locations_match (struct bp_location
*loc1
,
7190 struct bp_location
*loc2
)
7192 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7193 /* Since tracepoint locations are never duplicated with others', tracepoint
7194 locations at the same address of different tracepoints are regarded as
7195 different locations. */
7196 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7201 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7202 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7203 represent the same location. */
7206 breakpoint_locations_match (struct bp_location
*loc1
,
7207 struct bp_location
*loc2
)
7209 int hw_point1
, hw_point2
;
7211 /* Both of them must not be in moribund_locations. */
7212 gdb_assert (loc1
->owner
!= NULL
);
7213 gdb_assert (loc2
->owner
!= NULL
);
7215 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7216 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7218 if (hw_point1
!= hw_point2
)
7221 return watchpoint_locations_match (loc1
, loc2
);
7222 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7223 return tracepoint_locations_match (loc1
, loc2
);
7225 /* We compare bp_location.length in order to cover ranged breakpoints. */
7226 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7227 loc2
->pspace
->aspace
, loc2
->address
)
7228 && loc1
->length
== loc2
->length
);
7232 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7233 int bnum
, int have_bnum
)
7235 /* The longest string possibly returned by hex_string_custom
7236 is 50 chars. These must be at least that big for safety. */
7240 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7241 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7243 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7244 bnum
, astr1
, astr2
);
7246 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7249 /* Adjust a breakpoint's address to account for architectural
7250 constraints on breakpoint placement. Return the adjusted address.
7251 Note: Very few targets require this kind of adjustment. For most
7252 targets, this function is simply the identity function. */
7255 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7256 CORE_ADDR bpaddr
, enum bptype bptype
)
7258 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7260 /* Very few targets need any kind of breakpoint adjustment. */
7263 else if (bptype
== bp_watchpoint
7264 || bptype
== bp_hardware_watchpoint
7265 || bptype
== bp_read_watchpoint
7266 || bptype
== bp_access_watchpoint
7267 || bptype
== bp_catchpoint
)
7269 /* Watchpoints and the various bp_catch_* eventpoints should not
7270 have their addresses modified. */
7273 else if (bptype
== bp_single_step
)
7275 /* Single-step breakpoints should not have their addresses
7276 modified. If there's any architectural constrain that
7277 applies to this address, then it should have already been
7278 taken into account when the breakpoint was created in the
7279 first place. If we didn't do this, stepping through e.g.,
7280 Thumb-2 IT blocks would break. */
7285 CORE_ADDR adjusted_bpaddr
;
7287 /* Some targets have architectural constraints on the placement
7288 of breakpoint instructions. Obtain the adjusted address. */
7289 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7291 /* An adjusted breakpoint address can significantly alter
7292 a user's expectations. Print a warning if an adjustment
7294 if (adjusted_bpaddr
!= bpaddr
)
7295 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7297 return adjusted_bpaddr
;
7301 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7303 bp_location
*loc
= this;
7305 gdb_assert (ops
!= NULL
);
7309 loc
->cond_bytecode
= NULL
;
7310 loc
->shlib_disabled
= 0;
7313 switch (owner
->type
)
7316 case bp_single_step
:
7320 case bp_longjmp_resume
:
7321 case bp_longjmp_call_dummy
:
7323 case bp_exception_resume
:
7324 case bp_step_resume
:
7325 case bp_hp_step_resume
:
7326 case bp_watchpoint_scope
:
7328 case bp_std_terminate
:
7329 case bp_shlib_event
:
7330 case bp_thread_event
:
7331 case bp_overlay_event
:
7333 case bp_longjmp_master
:
7334 case bp_std_terminate_master
:
7335 case bp_exception_master
:
7336 case bp_gnu_ifunc_resolver
:
7337 case bp_gnu_ifunc_resolver_return
:
7339 loc
->loc_type
= bp_loc_software_breakpoint
;
7340 mark_breakpoint_location_modified (loc
);
7342 case bp_hardware_breakpoint
:
7343 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7344 mark_breakpoint_location_modified (loc
);
7346 case bp_hardware_watchpoint
:
7347 case bp_read_watchpoint
:
7348 case bp_access_watchpoint
:
7349 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7354 case bp_fast_tracepoint
:
7355 case bp_static_tracepoint
:
7356 loc
->loc_type
= bp_loc_other
;
7359 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7365 /* Allocate a struct bp_location. */
7367 static struct bp_location
*
7368 allocate_bp_location (struct breakpoint
*bpt
)
7370 return bpt
->ops
->allocate_location (bpt
);
7374 free_bp_location (struct bp_location
*loc
)
7376 loc
->ops
->dtor (loc
);
7380 /* Increment reference count. */
7383 incref_bp_location (struct bp_location
*bl
)
7388 /* Decrement reference count. If the reference count reaches 0,
7389 destroy the bp_location. Sets *BLP to NULL. */
7392 decref_bp_location (struct bp_location
**blp
)
7394 gdb_assert ((*blp
)->refc
> 0);
7396 if (--(*blp
)->refc
== 0)
7397 free_bp_location (*blp
);
7401 /* Add breakpoint B at the end of the global breakpoint chain. */
7404 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7406 struct breakpoint
*b1
;
7407 struct breakpoint
*result
= b
.get ();
7409 /* Add this breakpoint to the end of the chain so that a list of
7410 breakpoints will come out in order of increasing numbers. */
7412 b1
= breakpoint_chain
;
7414 breakpoint_chain
= b
.release ();
7419 b1
->next
= b
.release ();
7425 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7428 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7429 struct gdbarch
*gdbarch
,
7431 const struct breakpoint_ops
*ops
)
7433 gdb_assert (ops
!= NULL
);
7437 b
->gdbarch
= gdbarch
;
7438 b
->language
= current_language
->la_language
;
7439 b
->input_radix
= input_radix
;
7440 b
->related_breakpoint
= b
;
7443 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7444 that has type BPTYPE and has no locations as yet. */
7446 static struct breakpoint
*
7447 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7449 const struct breakpoint_ops
*ops
)
7451 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7453 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7454 return add_to_breakpoint_chain (std::move (b
));
7457 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7458 resolutions should be made as the user specified the location explicitly
7462 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7464 gdb_assert (loc
->owner
!= NULL
);
7466 if (loc
->owner
->type
== bp_breakpoint
7467 || loc
->owner
->type
== bp_hardware_breakpoint
7468 || is_tracepoint (loc
->owner
))
7471 const char *function_name
;
7472 CORE_ADDR func_addr
;
7474 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7475 &func_addr
, NULL
, &is_gnu_ifunc
);
7477 if (is_gnu_ifunc
&& !explicit_loc
)
7479 struct breakpoint
*b
= loc
->owner
;
7481 gdb_assert (loc
->pspace
== current_program_space
);
7482 if (gnu_ifunc_resolve_name (function_name
,
7483 &loc
->requested_address
))
7485 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7486 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7487 loc
->requested_address
,
7490 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7491 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7493 /* Create only the whole new breakpoint of this type but do not
7494 mess more complicated breakpoints with multiple locations. */
7495 b
->type
= bp_gnu_ifunc_resolver
;
7496 /* Remember the resolver's address for use by the return
7498 loc
->related_address
= func_addr
;
7503 loc
->function_name
= xstrdup (function_name
);
7507 /* Attempt to determine architecture of location identified by SAL. */
7509 get_sal_arch (struct symtab_and_line sal
)
7512 return get_objfile_arch (sal
.section
->objfile
);
7514 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7519 /* Low level routine for partially initializing a breakpoint of type
7520 BPTYPE. The newly created breakpoint's address, section, source
7521 file name, and line number are provided by SAL.
7523 It is expected that the caller will complete the initialization of
7524 the newly created breakpoint struct as well as output any status
7525 information regarding the creation of a new breakpoint. */
7528 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7529 struct symtab_and_line sal
, enum bptype bptype
,
7530 const struct breakpoint_ops
*ops
)
7532 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7534 add_location_to_breakpoint (b
, &sal
);
7536 if (bptype
!= bp_catchpoint
)
7537 gdb_assert (sal
.pspace
!= NULL
);
7539 /* Store the program space that was used to set the breakpoint,
7540 except for ordinary breakpoints, which are independent of the
7542 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7543 b
->pspace
= sal
.pspace
;
7546 /* set_raw_breakpoint is a low level routine for allocating and
7547 partially initializing a breakpoint of type BPTYPE. The newly
7548 created breakpoint's address, section, source file name, and line
7549 number are provided by SAL. The newly created and partially
7550 initialized breakpoint is added to the breakpoint chain and
7551 is also returned as the value of this function.
7553 It is expected that the caller will complete the initialization of
7554 the newly created breakpoint struct as well as output any status
7555 information regarding the creation of a new breakpoint. In
7556 particular, set_raw_breakpoint does NOT set the breakpoint
7557 number! Care should be taken to not allow an error to occur
7558 prior to completing the initialization of the breakpoint. If this
7559 should happen, a bogus breakpoint will be left on the chain. */
7562 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7563 struct symtab_and_line sal
, enum bptype bptype
,
7564 const struct breakpoint_ops
*ops
)
7566 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7568 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7569 return add_to_breakpoint_chain (std::move (b
));
7572 /* Call this routine when stepping and nexting to enable a breakpoint
7573 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7574 initiated the operation. */
7577 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7579 struct breakpoint
*b
, *b_tmp
;
7580 int thread
= tp
->global_num
;
7582 /* To avoid having to rescan all objfile symbols at every step,
7583 we maintain a list of continually-inserted but always disabled
7584 longjmp "master" breakpoints. Here, we simply create momentary
7585 clones of those and enable them for the requested thread. */
7586 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7587 if (b
->pspace
== current_program_space
7588 && (b
->type
== bp_longjmp_master
7589 || b
->type
== bp_exception_master
))
7591 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7592 struct breakpoint
*clone
;
7594 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7595 after their removal. */
7596 clone
= momentary_breakpoint_from_master (b
, type
,
7597 &momentary_breakpoint_ops
, 1);
7598 clone
->thread
= thread
;
7601 tp
->initiating_frame
= frame
;
7604 /* Delete all longjmp breakpoints from THREAD. */
7606 delete_longjmp_breakpoint (int thread
)
7608 struct breakpoint
*b
, *b_tmp
;
7610 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7611 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7613 if (b
->thread
== thread
)
7614 delete_breakpoint (b
);
7619 delete_longjmp_breakpoint_at_next_stop (int thread
)
7621 struct breakpoint
*b
, *b_tmp
;
7623 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7624 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7626 if (b
->thread
== thread
)
7627 b
->disposition
= disp_del_at_next_stop
;
7631 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7632 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7633 pointer to any of them. Return NULL if this system cannot place longjmp
7637 set_longjmp_breakpoint_for_call_dummy (void)
7639 struct breakpoint
*b
, *retval
= NULL
;
7642 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7644 struct breakpoint
*new_b
;
7646 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7647 &momentary_breakpoint_ops
,
7649 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7651 /* Link NEW_B into the chain of RETVAL breakpoints. */
7653 gdb_assert (new_b
->related_breakpoint
== new_b
);
7656 new_b
->related_breakpoint
= retval
;
7657 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7658 retval
= retval
->related_breakpoint
;
7659 retval
->related_breakpoint
= new_b
;
7665 /* Verify all existing dummy frames and their associated breakpoints for
7666 TP. Remove those which can no longer be found in the current frame
7669 You should call this function only at places where it is safe to currently
7670 unwind the whole stack. Failed stack unwind would discard live dummy
7674 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7676 struct breakpoint
*b
, *b_tmp
;
7678 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7679 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7681 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7683 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7684 dummy_b
= dummy_b
->related_breakpoint
;
7685 if (dummy_b
->type
!= bp_call_dummy
7686 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7689 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7691 while (b
->related_breakpoint
!= b
)
7693 if (b_tmp
== b
->related_breakpoint
)
7694 b_tmp
= b
->related_breakpoint
->next
;
7695 delete_breakpoint (b
->related_breakpoint
);
7697 delete_breakpoint (b
);
7702 enable_overlay_breakpoints (void)
7704 struct breakpoint
*b
;
7707 if (b
->type
== bp_overlay_event
)
7709 b
->enable_state
= bp_enabled
;
7710 update_global_location_list (UGLL_MAY_INSERT
);
7711 overlay_events_enabled
= 1;
7716 disable_overlay_breakpoints (void)
7718 struct breakpoint
*b
;
7721 if (b
->type
== bp_overlay_event
)
7723 b
->enable_state
= bp_disabled
;
7724 update_global_location_list (UGLL_DONT_INSERT
);
7725 overlay_events_enabled
= 0;
7729 /* Set an active std::terminate breakpoint for each std::terminate
7730 master breakpoint. */
7732 set_std_terminate_breakpoint (void)
7734 struct breakpoint
*b
, *b_tmp
;
7736 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7737 if (b
->pspace
== current_program_space
7738 && b
->type
== bp_std_terminate_master
)
7740 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7741 &momentary_breakpoint_ops
, 1);
7745 /* Delete all the std::terminate breakpoints. */
7747 delete_std_terminate_breakpoint (void)
7749 struct breakpoint
*b
, *b_tmp
;
7751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7752 if (b
->type
== bp_std_terminate
)
7753 delete_breakpoint (b
);
7757 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7759 struct breakpoint
*b
;
7761 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7762 &internal_breakpoint_ops
);
7764 b
->enable_state
= bp_enabled
;
7765 /* location has to be used or breakpoint_re_set will delete me. */
7766 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7768 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7773 struct lang_and_radix
7779 /* Create a breakpoint for JIT code registration and unregistration. */
7782 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7784 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7785 &internal_breakpoint_ops
);
7788 /* Remove JIT code registration and unregistration breakpoint(s). */
7791 remove_jit_event_breakpoints (void)
7793 struct breakpoint
*b
, *b_tmp
;
7795 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7796 if (b
->type
== bp_jit_event
7797 && b
->loc
->pspace
== current_program_space
)
7798 delete_breakpoint (b
);
7802 remove_solib_event_breakpoints (void)
7804 struct breakpoint
*b
, *b_tmp
;
7806 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7807 if (b
->type
== bp_shlib_event
7808 && b
->loc
->pspace
== current_program_space
)
7809 delete_breakpoint (b
);
7812 /* See breakpoint.h. */
7815 remove_solib_event_breakpoints_at_next_stop (void)
7817 struct breakpoint
*b
, *b_tmp
;
7819 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7820 if (b
->type
== bp_shlib_event
7821 && b
->loc
->pspace
== current_program_space
)
7822 b
->disposition
= disp_del_at_next_stop
;
7825 /* Helper for create_solib_event_breakpoint /
7826 create_and_insert_solib_event_breakpoint. Allows specifying which
7827 INSERT_MODE to pass through to update_global_location_list. */
7829 static struct breakpoint
*
7830 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7831 enum ugll_insert_mode insert_mode
)
7833 struct breakpoint
*b
;
7835 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7836 &internal_breakpoint_ops
);
7837 update_global_location_list_nothrow (insert_mode
);
7842 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7844 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7847 /* See breakpoint.h. */
7850 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7852 struct breakpoint
*b
;
7854 /* Explicitly tell update_global_location_list to insert
7856 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7857 if (!b
->loc
->inserted
)
7859 delete_breakpoint (b
);
7865 /* Disable any breakpoints that are on code in shared libraries. Only
7866 apply to enabled breakpoints, disabled ones can just stay disabled. */
7869 disable_breakpoints_in_shlibs (void)
7871 struct bp_location
*loc
, **locp_tmp
;
7873 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7875 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7876 struct breakpoint
*b
= loc
->owner
;
7878 /* We apply the check to all breakpoints, including disabled for
7879 those with loc->duplicate set. This is so that when breakpoint
7880 becomes enabled, or the duplicate is removed, gdb will try to
7881 insert all breakpoints. If we don't set shlib_disabled here,
7882 we'll try to insert those breakpoints and fail. */
7883 if (((b
->type
== bp_breakpoint
)
7884 || (b
->type
== bp_jit_event
)
7885 || (b
->type
== bp_hardware_breakpoint
)
7886 || (is_tracepoint (b
)))
7887 && loc
->pspace
== current_program_space
7888 && !loc
->shlib_disabled
7889 && solib_name_from_address (loc
->pspace
, loc
->address
)
7892 loc
->shlib_disabled
= 1;
7897 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7898 notification of unloaded_shlib. Only apply to enabled breakpoints,
7899 disabled ones can just stay disabled. */
7902 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7904 struct bp_location
*loc
, **locp_tmp
;
7905 int disabled_shlib_breaks
= 0;
7907 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7909 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7910 struct breakpoint
*b
= loc
->owner
;
7912 if (solib
->pspace
== loc
->pspace
7913 && !loc
->shlib_disabled
7914 && (((b
->type
== bp_breakpoint
7915 || b
->type
== bp_jit_event
7916 || b
->type
== bp_hardware_breakpoint
)
7917 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7918 || loc
->loc_type
== bp_loc_software_breakpoint
))
7919 || is_tracepoint (b
))
7920 && solib_contains_address_p (solib
, loc
->address
))
7922 loc
->shlib_disabled
= 1;
7923 /* At this point, we cannot rely on remove_breakpoint
7924 succeeding so we must mark the breakpoint as not inserted
7925 to prevent future errors occurring in remove_breakpoints. */
7928 /* This may cause duplicate notifications for the same breakpoint. */
7929 observer_notify_breakpoint_modified (b
);
7931 if (!disabled_shlib_breaks
)
7933 target_terminal_ours_for_output ();
7934 warning (_("Temporarily disabling breakpoints "
7935 "for unloaded shared library \"%s\""),
7938 disabled_shlib_breaks
= 1;
7943 /* Disable any breakpoints and tracepoints in OBJFILE upon
7944 notification of free_objfile. Only apply to enabled breakpoints,
7945 disabled ones can just stay disabled. */
7948 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7950 struct breakpoint
*b
;
7952 if (objfile
== NULL
)
7955 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7956 managed by the user with add-symbol-file/remove-symbol-file.
7957 Similarly to how breakpoints in shared libraries are handled in
7958 response to "nosharedlibrary", mark breakpoints in such modules
7959 shlib_disabled so they end up uninserted on the next global
7960 location list update. Shared libraries not loaded by the user
7961 aren't handled here -- they're already handled in
7962 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7963 solib_unloaded observer. We skip objfiles that are not
7964 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7966 if ((objfile
->flags
& OBJF_SHARED
) == 0
7967 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7972 struct bp_location
*loc
;
7973 int bp_modified
= 0;
7975 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7978 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7980 CORE_ADDR loc_addr
= loc
->address
;
7982 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7983 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7986 if (loc
->shlib_disabled
!= 0)
7989 if (objfile
->pspace
!= loc
->pspace
)
7992 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7993 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7996 if (is_addr_in_objfile (loc_addr
, objfile
))
7998 loc
->shlib_disabled
= 1;
7999 /* At this point, we don't know whether the object was
8000 unmapped from the inferior or not, so leave the
8001 inserted flag alone. We'll handle failure to
8002 uninsert quietly, in case the object was indeed
8005 mark_breakpoint_location_modified (loc
);
8012 observer_notify_breakpoint_modified (b
);
8016 /* FORK & VFORK catchpoints. */
8018 /* An instance of this type is used to represent a fork or vfork
8019 catchpoint. A breakpoint is really of this type iff its ops pointer points
8020 to CATCH_FORK_BREAKPOINT_OPS. */
8022 struct fork_catchpoint
: public breakpoint
8024 /* Process id of a child process whose forking triggered this
8025 catchpoint. This field is only valid immediately after this
8026 catchpoint has triggered. */
8027 ptid_t forked_inferior_pid
;
8030 /* Implement the "insert" breakpoint_ops method for fork
8034 insert_catch_fork (struct bp_location
*bl
)
8036 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8039 /* Implement the "remove" breakpoint_ops method for fork
8043 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8045 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8048 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8052 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8053 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8054 const struct target_waitstatus
*ws
)
8056 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8058 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8061 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8065 /* Implement the "print_it" breakpoint_ops method for fork
8068 static enum print_stop_action
8069 print_it_catch_fork (bpstat bs
)
8071 struct ui_out
*uiout
= current_uiout
;
8072 struct breakpoint
*b
= bs
->breakpoint_at
;
8073 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8075 annotate_catchpoint (b
->number
);
8076 maybe_print_thread_hit_breakpoint (uiout
);
8077 if (b
->disposition
== disp_del
)
8078 uiout
->text ("Temporary catchpoint ");
8080 uiout
->text ("Catchpoint ");
8081 if (uiout
->is_mi_like_p ())
8083 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8084 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8086 uiout
->field_int ("bkptno", b
->number
);
8087 uiout
->text (" (forked process ");
8088 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8089 uiout
->text ("), ");
8090 return PRINT_SRC_AND_LOC
;
8093 /* Implement the "print_one" breakpoint_ops method for fork
8097 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8099 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8100 struct value_print_options opts
;
8101 struct ui_out
*uiout
= current_uiout
;
8103 get_user_print_options (&opts
);
8105 /* Field 4, the address, is omitted (which makes the columns not
8106 line up too nicely with the headers, but the effect is relatively
8108 if (opts
.addressprint
)
8109 uiout
->field_skip ("addr");
8111 uiout
->text ("fork");
8112 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8114 uiout
->text (", process ");
8115 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8119 if (uiout
->is_mi_like_p ())
8120 uiout
->field_string ("catch-type", "fork");
8123 /* Implement the "print_mention" breakpoint_ops method for fork
8127 print_mention_catch_fork (struct breakpoint
*b
)
8129 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8132 /* Implement the "print_recreate" breakpoint_ops method for fork
8136 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8138 fprintf_unfiltered (fp
, "catch fork");
8139 print_recreate_thread (b
, fp
);
8142 /* The breakpoint_ops structure to be used in fork catchpoints. */
8144 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8146 /* Implement the "insert" breakpoint_ops method for vfork
8150 insert_catch_vfork (struct bp_location
*bl
)
8152 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8155 /* Implement the "remove" breakpoint_ops method for vfork
8159 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8161 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8164 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8168 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8169 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8170 const struct target_waitstatus
*ws
)
8172 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8174 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8177 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8181 /* Implement the "print_it" breakpoint_ops method for vfork
8184 static enum print_stop_action
8185 print_it_catch_vfork (bpstat bs
)
8187 struct ui_out
*uiout
= current_uiout
;
8188 struct breakpoint
*b
= bs
->breakpoint_at
;
8189 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8191 annotate_catchpoint (b
->number
);
8192 maybe_print_thread_hit_breakpoint (uiout
);
8193 if (b
->disposition
== disp_del
)
8194 uiout
->text ("Temporary catchpoint ");
8196 uiout
->text ("Catchpoint ");
8197 if (uiout
->is_mi_like_p ())
8199 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8200 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8202 uiout
->field_int ("bkptno", b
->number
);
8203 uiout
->text (" (vforked process ");
8204 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8205 uiout
->text ("), ");
8206 return PRINT_SRC_AND_LOC
;
8209 /* Implement the "print_one" breakpoint_ops method for vfork
8213 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8215 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8216 struct value_print_options opts
;
8217 struct ui_out
*uiout
= current_uiout
;
8219 get_user_print_options (&opts
);
8220 /* Field 4, the address, is omitted (which makes the columns not
8221 line up too nicely with the headers, but the effect is relatively
8223 if (opts
.addressprint
)
8224 uiout
->field_skip ("addr");
8226 uiout
->text ("vfork");
8227 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8229 uiout
->text (", process ");
8230 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8234 if (uiout
->is_mi_like_p ())
8235 uiout
->field_string ("catch-type", "vfork");
8238 /* Implement the "print_mention" breakpoint_ops method for vfork
8242 print_mention_catch_vfork (struct breakpoint
*b
)
8244 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8247 /* Implement the "print_recreate" breakpoint_ops method for vfork
8251 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8253 fprintf_unfiltered (fp
, "catch vfork");
8254 print_recreate_thread (b
, fp
);
8257 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8259 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8261 /* An instance of this type is used to represent an solib catchpoint.
8262 A breakpoint is really of this type iff its ops pointer points to
8263 CATCH_SOLIB_BREAKPOINT_OPS. */
8265 struct solib_catchpoint
: public breakpoint
8267 ~solib_catchpoint () override
;
8269 /* True for "catch load", false for "catch unload". */
8270 unsigned char is_load
;
8272 /* Regular expression to match, if any. COMPILED is only valid when
8273 REGEX is non-NULL. */
8275 std::unique_ptr
<compiled_regex
> compiled
;
8278 solib_catchpoint::~solib_catchpoint ()
8280 xfree (this->regex
);
8284 insert_catch_solib (struct bp_location
*ignore
)
8290 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8296 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8297 struct address_space
*aspace
,
8299 const struct target_waitstatus
*ws
)
8301 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8302 struct breakpoint
*other
;
8304 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8307 ALL_BREAKPOINTS (other
)
8309 struct bp_location
*other_bl
;
8311 if (other
== bl
->owner
)
8314 if (other
->type
!= bp_shlib_event
)
8317 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8320 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8322 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8331 check_status_catch_solib (struct bpstats
*bs
)
8333 struct solib_catchpoint
*self
8334 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8339 struct so_list
*iter
;
8342 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8347 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8356 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8361 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8367 bs
->print_it
= print_it_noop
;
8370 static enum print_stop_action
8371 print_it_catch_solib (bpstat bs
)
8373 struct breakpoint
*b
= bs
->breakpoint_at
;
8374 struct ui_out
*uiout
= current_uiout
;
8376 annotate_catchpoint (b
->number
);
8377 maybe_print_thread_hit_breakpoint (uiout
);
8378 if (b
->disposition
== disp_del
)
8379 uiout
->text ("Temporary catchpoint ");
8381 uiout
->text ("Catchpoint ");
8382 uiout
->field_int ("bkptno", b
->number
);
8384 if (uiout
->is_mi_like_p ())
8385 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8386 print_solib_event (1);
8387 return PRINT_SRC_AND_LOC
;
8391 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8393 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8394 struct value_print_options opts
;
8395 struct ui_out
*uiout
= current_uiout
;
8398 get_user_print_options (&opts
);
8399 /* Field 4, the address, is omitted (which makes the columns not
8400 line up too nicely with the headers, but the effect is relatively
8402 if (opts
.addressprint
)
8405 uiout
->field_skip ("addr");
8412 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8414 msg
= xstrdup (_("load of library"));
8419 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8421 msg
= xstrdup (_("unload of library"));
8423 uiout
->field_string ("what", msg
);
8426 if (uiout
->is_mi_like_p ())
8427 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8431 print_mention_catch_solib (struct breakpoint
*b
)
8433 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8435 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8436 self
->is_load
? "load" : "unload");
8440 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8442 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8444 fprintf_unfiltered (fp
, "%s %s",
8445 b
->disposition
== disp_del
? "tcatch" : "catch",
8446 self
->is_load
? "load" : "unload");
8448 fprintf_unfiltered (fp
, " %s", self
->regex
);
8449 fprintf_unfiltered (fp
, "\n");
8452 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8454 /* Shared helper function (MI and CLI) for creating and installing
8455 a shared object event catchpoint. If IS_LOAD is non-zero then
8456 the events to be caught are load events, otherwise they are
8457 unload events. If IS_TEMP is non-zero the catchpoint is a
8458 temporary one. If ENABLED is non-zero the catchpoint is
8459 created in an enabled state. */
8462 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8464 struct gdbarch
*gdbarch
= get_current_arch ();
8468 arg
= skip_spaces_const (arg
);
8470 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8474 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8475 _("Invalid regexp")));
8476 c
->regex
= xstrdup (arg
);
8479 c
->is_load
= is_load
;
8480 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8481 &catch_solib_breakpoint_ops
);
8483 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8485 install_breakpoint (0, std::move (c
), 1);
8488 /* A helper function that does all the work for "catch load" and
8492 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8493 struct cmd_list_element
*command
)
8496 const int enabled
= 1;
8498 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8500 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8504 catch_load_command_1 (char *arg
, int from_tty
,
8505 struct cmd_list_element
*command
)
8507 catch_load_or_unload (arg
, from_tty
, 1, command
);
8511 catch_unload_command_1 (char *arg
, int from_tty
,
8512 struct cmd_list_element
*command
)
8514 catch_load_or_unload (arg
, from_tty
, 0, command
);
8517 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8518 is non-zero, then make the breakpoint temporary. If COND_STRING is
8519 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8520 the breakpoint_ops structure associated to the catchpoint. */
8523 init_catchpoint (struct breakpoint
*b
,
8524 struct gdbarch
*gdbarch
, int tempflag
,
8525 const char *cond_string
,
8526 const struct breakpoint_ops
*ops
)
8528 struct symtab_and_line sal
;
8531 sal
.pspace
= current_program_space
;
8533 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8535 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8536 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8540 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8542 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8543 set_breakpoint_number (internal
, b
);
8544 if (is_tracepoint (b
))
8545 set_tracepoint_count (breakpoint_count
);
8548 observer_notify_breakpoint_created (b
);
8551 update_global_location_list (UGLL_MAY_INSERT
);
8555 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8556 int tempflag
, const char *cond_string
,
8557 const struct breakpoint_ops
*ops
)
8559 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8561 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8563 c
->forked_inferior_pid
= null_ptid
;
8565 install_breakpoint (0, std::move (c
), 1);
8568 /* Exec catchpoints. */
8570 /* An instance of this type is used to represent an exec catchpoint.
8571 A breakpoint is really of this type iff its ops pointer points to
8572 CATCH_EXEC_BREAKPOINT_OPS. */
8574 struct exec_catchpoint
: public breakpoint
8576 ~exec_catchpoint () override
;
8578 /* Filename of a program whose exec triggered this catchpoint.
8579 This field is only valid immediately after this catchpoint has
8581 char *exec_pathname
;
8584 /* Exec catchpoint destructor. */
8586 exec_catchpoint::~exec_catchpoint ()
8588 xfree (this->exec_pathname
);
8592 insert_catch_exec (struct bp_location
*bl
)
8594 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8598 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8600 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8604 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8605 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8606 const struct target_waitstatus
*ws
)
8608 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8610 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8613 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8617 static enum print_stop_action
8618 print_it_catch_exec (bpstat bs
)
8620 struct ui_out
*uiout
= current_uiout
;
8621 struct breakpoint
*b
= bs
->breakpoint_at
;
8622 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8624 annotate_catchpoint (b
->number
);
8625 maybe_print_thread_hit_breakpoint (uiout
);
8626 if (b
->disposition
== disp_del
)
8627 uiout
->text ("Temporary catchpoint ");
8629 uiout
->text ("Catchpoint ");
8630 if (uiout
->is_mi_like_p ())
8632 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8633 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8635 uiout
->field_int ("bkptno", b
->number
);
8636 uiout
->text (" (exec'd ");
8637 uiout
->field_string ("new-exec", c
->exec_pathname
);
8638 uiout
->text ("), ");
8640 return PRINT_SRC_AND_LOC
;
8644 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8646 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8647 struct value_print_options opts
;
8648 struct ui_out
*uiout
= current_uiout
;
8650 get_user_print_options (&opts
);
8652 /* Field 4, the address, is omitted (which makes the columns
8653 not line up too nicely with the headers, but the effect
8654 is relatively readable). */
8655 if (opts
.addressprint
)
8656 uiout
->field_skip ("addr");
8658 uiout
->text ("exec");
8659 if (c
->exec_pathname
!= NULL
)
8661 uiout
->text (", program \"");
8662 uiout
->field_string ("what", c
->exec_pathname
);
8663 uiout
->text ("\" ");
8666 if (uiout
->is_mi_like_p ())
8667 uiout
->field_string ("catch-type", "exec");
8671 print_mention_catch_exec (struct breakpoint
*b
)
8673 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8676 /* Implement the "print_recreate" breakpoint_ops method for exec
8680 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8682 fprintf_unfiltered (fp
, "catch exec");
8683 print_recreate_thread (b
, fp
);
8686 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8689 hw_breakpoint_used_count (void)
8692 struct breakpoint
*b
;
8693 struct bp_location
*bl
;
8697 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8698 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8700 /* Special types of hardware breakpoints may use more than
8702 i
+= b
->ops
->resources_needed (bl
);
8709 /* Returns the resources B would use if it were a hardware
8713 hw_watchpoint_use_count (struct breakpoint
*b
)
8716 struct bp_location
*bl
;
8718 if (!breakpoint_enabled (b
))
8721 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8723 /* Special types of hardware watchpoints may use more than
8725 i
+= b
->ops
->resources_needed (bl
);
8731 /* Returns the sum the used resources of all hardware watchpoints of
8732 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8733 the sum of the used resources of all hardware watchpoints of other
8734 types _not_ TYPE. */
8737 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8738 enum bptype type
, int *other_type_used
)
8741 struct breakpoint
*b
;
8743 *other_type_used
= 0;
8748 if (!breakpoint_enabled (b
))
8751 if (b
->type
== type
)
8752 i
+= hw_watchpoint_use_count (b
);
8753 else if (is_hardware_watchpoint (b
))
8754 *other_type_used
= 1;
8761 disable_watchpoints_before_interactive_call_start (void)
8763 struct breakpoint
*b
;
8767 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8769 b
->enable_state
= bp_call_disabled
;
8770 update_global_location_list (UGLL_DONT_INSERT
);
8776 enable_watchpoints_after_interactive_call_stop (void)
8778 struct breakpoint
*b
;
8782 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8784 b
->enable_state
= bp_enabled
;
8785 update_global_location_list (UGLL_MAY_INSERT
);
8791 disable_breakpoints_before_startup (void)
8793 current_program_space
->executing_startup
= 1;
8794 update_global_location_list (UGLL_DONT_INSERT
);
8798 enable_breakpoints_after_startup (void)
8800 current_program_space
->executing_startup
= 0;
8801 breakpoint_re_set ();
8804 /* Create a new single-step breakpoint for thread THREAD, with no
8807 static struct breakpoint
*
8808 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8810 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8812 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8813 &momentary_breakpoint_ops
);
8815 b
->disposition
= disp_donttouch
;
8816 b
->frame_id
= null_frame_id
;
8819 gdb_assert (b
->thread
!= 0);
8821 return add_to_breakpoint_chain (std::move (b
));
8824 /* Set a momentary breakpoint of type TYPE at address specified by
8825 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8829 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8830 struct frame_id frame_id
, enum bptype type
)
8832 struct breakpoint
*b
;
8834 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8836 gdb_assert (!frame_id_artificial_p (frame_id
));
8838 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8839 b
->enable_state
= bp_enabled
;
8840 b
->disposition
= disp_donttouch
;
8841 b
->frame_id
= frame_id
;
8843 /* If we're debugging a multi-threaded program, then we want
8844 momentary breakpoints to be active in only a single thread of
8846 if (in_thread_list (inferior_ptid
))
8847 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8849 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8854 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8855 The new breakpoint will have type TYPE, use OPS as its
8856 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8858 static struct breakpoint
*
8859 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8861 const struct breakpoint_ops
*ops
,
8864 struct breakpoint
*copy
;
8866 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8867 copy
->loc
= allocate_bp_location (copy
);
8868 set_breakpoint_location_function (copy
->loc
, 1);
8870 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8871 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8872 copy
->loc
->address
= orig
->loc
->address
;
8873 copy
->loc
->section
= orig
->loc
->section
;
8874 copy
->loc
->pspace
= orig
->loc
->pspace
;
8875 copy
->loc
->probe
= orig
->loc
->probe
;
8876 copy
->loc
->line_number
= orig
->loc
->line_number
;
8877 copy
->loc
->symtab
= orig
->loc
->symtab
;
8878 copy
->loc
->enabled
= loc_enabled
;
8879 copy
->frame_id
= orig
->frame_id
;
8880 copy
->thread
= orig
->thread
;
8881 copy
->pspace
= orig
->pspace
;
8883 copy
->enable_state
= bp_enabled
;
8884 copy
->disposition
= disp_donttouch
;
8885 copy
->number
= internal_breakpoint_number
--;
8887 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8891 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8895 clone_momentary_breakpoint (struct breakpoint
*orig
)
8897 /* If there's nothing to clone, then return nothing. */
8901 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8905 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8908 struct symtab_and_line sal
;
8910 sal
= find_pc_line (pc
, 0);
8912 sal
.section
= find_pc_overlay (pc
);
8913 sal
.explicit_pc
= 1;
8915 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8919 /* Tell the user we have just set a breakpoint B. */
8922 mention (struct breakpoint
*b
)
8924 b
->ops
->print_mention (b
);
8925 if (current_uiout
->is_mi_like_p ())
8927 printf_filtered ("\n");
8931 static int bp_loc_is_permanent (struct bp_location
*loc
);
8933 static struct bp_location
*
8934 add_location_to_breakpoint (struct breakpoint
*b
,
8935 const struct symtab_and_line
*sal
)
8937 struct bp_location
*loc
, **tmp
;
8938 CORE_ADDR adjusted_address
;
8939 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8941 if (loc_gdbarch
== NULL
)
8942 loc_gdbarch
= b
->gdbarch
;
8944 /* Adjust the breakpoint's address prior to allocating a location.
8945 Once we call allocate_bp_location(), that mostly uninitialized
8946 location will be placed on the location chain. Adjustment of the
8947 breakpoint may cause target_read_memory() to be called and we do
8948 not want its scan of the location chain to find a breakpoint and
8949 location that's only been partially initialized. */
8950 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8953 /* Sort the locations by their ADDRESS. */
8954 loc
= allocate_bp_location (b
);
8955 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8956 tmp
= &((*tmp
)->next
))
8961 loc
->requested_address
= sal
->pc
;
8962 loc
->address
= adjusted_address
;
8963 loc
->pspace
= sal
->pspace
;
8964 loc
->probe
.probe
= sal
->probe
;
8965 loc
->probe
.objfile
= sal
->objfile
;
8966 gdb_assert (loc
->pspace
!= NULL
);
8967 loc
->section
= sal
->section
;
8968 loc
->gdbarch
= loc_gdbarch
;
8969 loc
->line_number
= sal
->line
;
8970 loc
->symtab
= sal
->symtab
;
8972 set_breakpoint_location_function (loc
,
8973 sal
->explicit_pc
|| sal
->explicit_line
);
8975 /* While by definition, permanent breakpoints are already present in the
8976 code, we don't mark the location as inserted. Normally one would expect
8977 that GDB could rely on that breakpoint instruction to stop the program,
8978 thus removing the need to insert its own breakpoint, except that executing
8979 the breakpoint instruction can kill the target instead of reporting a
8980 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8981 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8982 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8983 breakpoint be inserted normally results in QEMU knowing about the GDB
8984 breakpoint, and thus trap before the breakpoint instruction is executed.
8985 (If GDB later needs to continue execution past the permanent breakpoint,
8986 it manually increments the PC, thus avoiding executing the breakpoint
8988 if (bp_loc_is_permanent (loc
))
8995 /* See breakpoint.h. */
8998 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9002 const gdb_byte
*bpoint
;
9003 gdb_byte
*target_mem
;
9004 struct cleanup
*cleanup
;
9008 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9010 /* Software breakpoints unsupported? */
9014 target_mem
= (gdb_byte
*) alloca (len
);
9016 /* Enable the automatic memory restoration from breakpoints while
9017 we read the memory. Otherwise we could say about our temporary
9018 breakpoints they are permanent. */
9019 cleanup
= make_show_memory_breakpoints_cleanup (0);
9021 if (target_read_memory (address
, target_mem
, len
) == 0
9022 && memcmp (target_mem
, bpoint
, len
) == 0)
9025 do_cleanups (cleanup
);
9030 /* Return 1 if LOC is pointing to a permanent breakpoint,
9031 return 0 otherwise. */
9034 bp_loc_is_permanent (struct bp_location
*loc
)
9036 gdb_assert (loc
!= NULL
);
9038 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9039 attempt to read from the addresses the locations of these breakpoint types
9040 point to. program_breakpoint_here_p, below, will attempt to read
9042 if (!breakpoint_address_is_meaningful (loc
->owner
))
9045 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9046 switch_to_program_space_and_thread (loc
->pspace
);
9047 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9050 /* Build a command list for the dprintf corresponding to the current
9051 settings of the dprintf style options. */
9054 update_dprintf_command_list (struct breakpoint
*b
)
9056 char *dprintf_args
= b
->extra_string
;
9057 char *printf_line
= NULL
;
9062 dprintf_args
= skip_spaces (dprintf_args
);
9064 /* Allow a comma, as it may have terminated a location, but don't
9066 if (*dprintf_args
== ',')
9068 dprintf_args
= skip_spaces (dprintf_args
);
9070 if (*dprintf_args
!= '"')
9071 error (_("Bad format string, missing '\"'."));
9073 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9074 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9075 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9077 if (!dprintf_function
)
9078 error (_("No function supplied for dprintf call"));
9080 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9081 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9086 printf_line
= xstrprintf ("call (void) %s (%s)",
9090 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9092 if (target_can_run_breakpoint_commands ())
9093 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9096 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9097 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9101 internal_error (__FILE__
, __LINE__
,
9102 _("Invalid dprintf style."));
9104 gdb_assert (printf_line
!= NULL
);
9105 /* Manufacture a printf sequence. */
9107 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9109 printf_cmd_line
->control_type
= simple_control
;
9110 printf_cmd_line
->body_count
= 0;
9111 printf_cmd_line
->body_list
= NULL
;
9112 printf_cmd_line
->next
= NULL
;
9113 printf_cmd_line
->line
= printf_line
;
9115 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9119 /* Update all dprintf commands, making their command lists reflect
9120 current style settings. */
9123 update_dprintf_commands (char *args
, int from_tty
,
9124 struct cmd_list_element
*c
)
9126 struct breakpoint
*b
;
9130 if (b
->type
== bp_dprintf
)
9131 update_dprintf_command_list (b
);
9135 /* Create a breakpoint with SAL as location. Use LOCATION
9136 as a description of the location, and COND_STRING
9137 as condition expression. If LOCATION is NULL then create an
9138 "address location" from the address in the SAL. */
9141 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9142 gdb::array_view
<const symtab_and_line
> sals
,
9143 event_location_up
&&location
,
9144 gdb::unique_xmalloc_ptr
<char> filter
,
9145 gdb::unique_xmalloc_ptr
<char> cond_string
,
9146 gdb::unique_xmalloc_ptr
<char> extra_string
,
9147 enum bptype type
, enum bpdisp disposition
,
9148 int thread
, int task
, int ignore_count
,
9149 const struct breakpoint_ops
*ops
, int from_tty
,
9150 int enabled
, int internal
, unsigned flags
,
9151 int display_canonical
)
9155 if (type
== bp_hardware_breakpoint
)
9157 int target_resources_ok
;
9159 i
= hw_breakpoint_used_count ();
9160 target_resources_ok
=
9161 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9163 if (target_resources_ok
== 0)
9164 error (_("No hardware breakpoint support in the target."));
9165 else if (target_resources_ok
< 0)
9166 error (_("Hardware breakpoints used exceeds limit."));
9169 gdb_assert (!sals
.empty ());
9171 for (const auto &sal
: sals
)
9173 struct bp_location
*loc
;
9177 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9179 loc_gdbarch
= gdbarch
;
9181 describe_other_breakpoints (loc_gdbarch
,
9182 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9185 if (&sal
== &sals
[0])
9187 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9191 b
->cond_string
= cond_string
.release ();
9192 b
->extra_string
= extra_string
.release ();
9193 b
->ignore_count
= ignore_count
;
9194 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9195 b
->disposition
= disposition
;
9197 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9198 b
->loc
->inserted
= 1;
9200 if (type
== bp_static_tracepoint
)
9202 struct tracepoint
*t
= (struct tracepoint
*) b
;
9203 struct static_tracepoint_marker marker
;
9205 if (strace_marker_p (b
))
9207 /* We already know the marker exists, otherwise, we
9208 wouldn't see a sal for it. */
9210 = &event_location_to_string (b
->location
.get ())[3];
9214 p
= skip_spaces_const (p
);
9216 endp
= skip_to_space_const (p
);
9218 marker_str
= savestring (p
, endp
- p
);
9219 t
->static_trace_marker_id
= marker_str
;
9221 printf_filtered (_("Probed static tracepoint "
9223 t
->static_trace_marker_id
);
9225 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9227 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9228 release_static_tracepoint_marker (&marker
);
9230 printf_filtered (_("Probed static tracepoint "
9232 t
->static_trace_marker_id
);
9235 warning (_("Couldn't determine the static "
9236 "tracepoint marker to probe"));
9243 loc
= add_location_to_breakpoint (b
, &sal
);
9244 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9250 const char *arg
= b
->cond_string
;
9252 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9253 block_for_pc (loc
->address
), 0);
9255 error (_("Garbage '%s' follows condition"), arg
);
9258 /* Dynamic printf requires and uses additional arguments on the
9259 command line, otherwise it's an error. */
9260 if (type
== bp_dprintf
)
9262 if (b
->extra_string
)
9263 update_dprintf_command_list (b
);
9265 error (_("Format string required"));
9267 else if (b
->extra_string
)
9268 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9271 b
->display_canonical
= display_canonical
;
9272 if (location
!= NULL
)
9273 b
->location
= std::move (location
);
9275 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9276 b
->filter
= filter
.release ();
9280 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9281 gdb::array_view
<const symtab_and_line
> sals
,
9282 event_location_up
&&location
,
9283 gdb::unique_xmalloc_ptr
<char> filter
,
9284 gdb::unique_xmalloc_ptr
<char> cond_string
,
9285 gdb::unique_xmalloc_ptr
<char> extra_string
,
9286 enum bptype type
, enum bpdisp disposition
,
9287 int thread
, int task
, int ignore_count
,
9288 const struct breakpoint_ops
*ops
, int from_tty
,
9289 int enabled
, int internal
, unsigned flags
,
9290 int display_canonical
)
9292 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9294 init_breakpoint_sal (b
.get (), gdbarch
,
9295 sals
, std::move (location
),
9297 std::move (cond_string
),
9298 std::move (extra_string
),
9300 thread
, task
, ignore_count
,
9302 enabled
, internal
, flags
,
9305 install_breakpoint (internal
, std::move (b
), 0);
9308 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9309 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9310 value. COND_STRING, if not NULL, specified the condition to be
9311 used for all breakpoints. Essentially the only case where
9312 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9313 function. In that case, it's still not possible to specify
9314 separate conditions for different overloaded functions, so
9315 we take just a single condition string.
9317 NOTE: If the function succeeds, the caller is expected to cleanup
9318 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9319 array contents). If the function fails (error() is called), the
9320 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9321 COND and SALS arrays and each of those arrays contents. */
9324 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9325 struct linespec_result
*canonical
,
9326 gdb::unique_xmalloc_ptr
<char> cond_string
,
9327 gdb::unique_xmalloc_ptr
<char> extra_string
,
9328 enum bptype type
, enum bpdisp disposition
,
9329 int thread
, int task
, int ignore_count
,
9330 const struct breakpoint_ops
*ops
, int from_tty
,
9331 int enabled
, int internal
, unsigned flags
)
9333 if (canonical
->pre_expanded
)
9334 gdb_assert (canonical
->lsals
.size () == 1);
9336 for (const auto &lsal
: canonical
->lsals
)
9338 /* Note that 'location' can be NULL in the case of a plain
9339 'break', without arguments. */
9340 event_location_up location
9341 = (canonical
->location
!= NULL
9342 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9343 gdb::unique_xmalloc_ptr
<char> filter_string
9344 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9346 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9347 std::move (location
),
9348 std::move (filter_string
),
9349 std::move (cond_string
),
9350 std::move (extra_string
),
9352 thread
, task
, ignore_count
, ops
,
9353 from_tty
, enabled
, internal
, flags
,
9354 canonical
->special_display
);
9358 /* Parse LOCATION which is assumed to be a SAL specification possibly
9359 followed by conditionals. On return, SALS contains an array of SAL
9360 addresses found. LOCATION points to the end of the SAL (for
9361 linespec locations).
9363 The array and the line spec strings are allocated on the heap, it is
9364 the caller's responsibility to free them. */
9367 parse_breakpoint_sals (const struct event_location
*location
,
9368 struct linespec_result
*canonical
)
9370 struct symtab_and_line cursal
;
9372 if (event_location_type (location
) == LINESPEC_LOCATION
)
9374 const char *address
= get_linespec_location (location
);
9376 if (address
== NULL
)
9378 /* The last displayed codepoint, if it's valid, is our default
9379 breakpoint address. */
9380 if (last_displayed_sal_is_valid ())
9382 struct symtab_and_line sal
;
9385 init_sal (&sal
); /* Initialize to zeroes. */
9387 /* Set sal's pspace, pc, symtab, and line to the values
9388 corresponding to the last call to print_frame_info.
9389 Be sure to reinitialize LINE with NOTCURRENT == 0
9390 as the breakpoint line number is inappropriate otherwise.
9391 find_pc_line would adjust PC, re-set it back. */
9392 get_last_displayed_sal (&sal
);
9394 sal
= find_pc_line (pc
, 0);
9396 /* "break" without arguments is equivalent to "break *PC"
9397 where PC is the last displayed codepoint's address. So
9398 make sure to set sal.explicit_pc to prevent GDB from
9399 trying to expand the list of sals to include all other
9400 instances with the same symtab and line. */
9402 sal
.explicit_pc
= 1;
9404 struct linespec_sals lsal
;
9406 lsal
.canonical
= NULL
;
9408 canonical
->lsals
.push_back (std::move (lsal
));
9412 error (_("No default breakpoint address now."));
9416 /* Force almost all breakpoints to be in terms of the
9417 current_source_symtab (which is decode_line_1's default).
9418 This should produce the results we want almost all of the
9419 time while leaving default_breakpoint_* alone.
9421 ObjC: However, don't match an Objective-C method name which
9422 may have a '+' or '-' succeeded by a '['. */
9423 cursal
= get_current_source_symtab_and_line ();
9424 if (last_displayed_sal_is_valid ())
9426 const char *address
= NULL
;
9428 if (event_location_type (location
) == LINESPEC_LOCATION
)
9429 address
= get_linespec_location (location
);
9433 && strchr ("+-", address
[0]) != NULL
9434 && address
[1] != '['))
9436 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9437 get_last_displayed_symtab (),
9438 get_last_displayed_line (),
9439 canonical
, NULL
, NULL
);
9444 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9445 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9449 /* Convert each SAL into a real PC. Verify that the PC can be
9450 inserted as a breakpoint. If it can't throw an error. */
9453 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9455 for (auto &sal
: sals
)
9456 resolve_sal_pc (&sal
);
9459 /* Fast tracepoints may have restrictions on valid locations. For
9460 instance, a fast tracepoint using a jump instead of a trap will
9461 likely have to overwrite more bytes than a trap would, and so can
9462 only be placed where the instruction is longer than the jump, or a
9463 multi-instruction sequence does not have a jump into the middle of
9467 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9468 gdb::array_view
<const symtab_and_line
> sals
)
9472 struct cleanup
*old_chain
;
9474 for (const auto &sal
: sals
)
9476 struct gdbarch
*sarch
;
9478 sarch
= get_sal_arch (sal
);
9479 /* We fall back to GDBARCH if there is no architecture
9480 associated with SAL. */
9483 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9484 old_chain
= make_cleanup (xfree
, msg
);
9487 error (_("May not have a fast tracepoint at %s%s"),
9488 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9490 do_cleanups (old_chain
);
9494 /* Given TOK, a string specification of condition and thread, as
9495 accepted by the 'break' command, extract the condition
9496 string and thread number and set *COND_STRING and *THREAD.
9497 PC identifies the context at which the condition should be parsed.
9498 If no condition is found, *COND_STRING is set to NULL.
9499 If no thread is found, *THREAD is set to -1. */
9502 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9503 char **cond_string
, int *thread
, int *task
,
9506 *cond_string
= NULL
;
9513 const char *end_tok
;
9515 const char *cond_start
= NULL
;
9516 const char *cond_end
= NULL
;
9518 tok
= skip_spaces_const (tok
);
9520 if ((*tok
== '"' || *tok
== ',') && rest
)
9522 *rest
= savestring (tok
, strlen (tok
));
9526 end_tok
= skip_to_space_const (tok
);
9528 toklen
= end_tok
- tok
;
9530 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9532 tok
= cond_start
= end_tok
+ 1;
9533 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9535 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9537 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9540 struct thread_info
*thr
;
9543 thr
= parse_thread_id (tok
, &tmptok
);
9545 error (_("Junk after thread keyword."));
9546 *thread
= thr
->global_num
;
9549 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9554 *task
= strtol (tok
, &tmptok
, 0);
9556 error (_("Junk after task keyword."));
9557 if (!valid_task_id (*task
))
9558 error (_("Unknown task %d."), *task
);
9563 *rest
= savestring (tok
, strlen (tok
));
9567 error (_("Junk at end of arguments."));
9571 /* Decode a static tracepoint marker spec. */
9573 static std::vector
<symtab_and_line
>
9574 decode_static_tracepoint_spec (const char **arg_p
)
9576 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9577 struct cleanup
*old_chain
;
9578 const char *p
= &(*arg_p
)[3];
9583 p
= skip_spaces_const (p
);
9585 endp
= skip_to_space_const (p
);
9587 marker_str
= savestring (p
, endp
- p
);
9588 old_chain
= make_cleanup (xfree
, marker_str
);
9590 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9591 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9592 error (_("No known static tracepoint marker named %s"), marker_str
);
9594 std::vector
<symtab_and_line
> sals
;
9595 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9597 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9599 struct static_tracepoint_marker
*marker
;
9601 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9603 symtab_and_line sal
;
9606 sal
= find_pc_line (marker
->address
, 0);
9607 sal
.pc
= marker
->address
;
9608 sals
.push_back (sal
);
9610 release_static_tracepoint_marker (marker
);
9613 do_cleanups (old_chain
);
9619 /* See breakpoint.h. */
9622 create_breakpoint (struct gdbarch
*gdbarch
,
9623 const struct event_location
*location
,
9624 const char *cond_string
,
9625 int thread
, const char *extra_string
,
9627 int tempflag
, enum bptype type_wanted
,
9629 enum auto_boolean pending_break_support
,
9630 const struct breakpoint_ops
*ops
,
9631 int from_tty
, int enabled
, int internal
,
9634 struct linespec_result canonical
;
9635 struct cleanup
*bkpt_chain
= NULL
;
9638 int prev_bkpt_count
= breakpoint_count
;
9640 gdb_assert (ops
!= NULL
);
9642 /* If extra_string isn't useful, set it to NULL. */
9643 if (extra_string
!= NULL
&& *extra_string
== '\0')
9644 extra_string
= NULL
;
9648 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9650 CATCH (e
, RETURN_MASK_ERROR
)
9652 /* If caller is interested in rc value from parse, set
9654 if (e
.error
== NOT_FOUND_ERROR
)
9656 /* If pending breakpoint support is turned off, throw
9659 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9660 throw_exception (e
);
9662 exception_print (gdb_stderr
, e
);
9664 /* If pending breakpoint support is auto query and the user
9665 selects no, then simply return the error code. */
9666 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9667 && !nquery (_("Make %s pending on future shared library load? "),
9668 bptype_string (type_wanted
)))
9671 /* At this point, either the user was queried about setting
9672 a pending breakpoint and selected yes, or pending
9673 breakpoint behavior is on and thus a pending breakpoint
9674 is defaulted on behalf of the user. */
9678 throw_exception (e
);
9682 if (!pending
&& canonical
.lsals
.empty ())
9685 /* ----------------------------- SNIP -----------------------------
9686 Anything added to the cleanup chain beyond this point is assumed
9687 to be part of a breakpoint. If the breakpoint create succeeds
9688 then the memory is not reclaimed. */
9689 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9691 /* Resolve all line numbers to PC's and verify that the addresses
9692 are ok for the target. */
9695 for (auto &lsal
: canonical
.lsals
)
9696 breakpoint_sals_to_pc (lsal
.sals
);
9699 /* Fast tracepoints may have additional restrictions on location. */
9700 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9702 for (const auto &lsal
: canonical
.lsals
)
9703 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9706 /* Verify that condition can be parsed, before setting any
9707 breakpoints. Allocate a separate condition expression for each
9711 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9712 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9719 const linespec_sals
&lsal
= canonical
.lsals
[0];
9721 /* Here we only parse 'arg' to separate condition
9722 from thread number, so parsing in context of first
9723 sal is OK. When setting the breakpoint we'll
9724 re-parse it in context of each sal. */
9726 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9727 &cond
, &thread
, &task
, &rest
);
9728 cond_string_copy
.reset (cond
);
9729 extra_string_copy
.reset (rest
);
9733 if (type_wanted
!= bp_dprintf
9734 && extra_string
!= NULL
&& *extra_string
!= '\0')
9735 error (_("Garbage '%s' at end of location"), extra_string
);
9737 /* Create a private copy of condition string. */
9739 cond_string_copy
.reset (xstrdup (cond_string
));
9740 /* Create a private copy of any extra string. */
9742 extra_string_copy
.reset (xstrdup (extra_string
));
9745 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9746 std::move (cond_string_copy
),
9747 std::move (extra_string_copy
),
9749 tempflag
? disp_del
: disp_donttouch
,
9750 thread
, task
, ignore_count
, ops
,
9751 from_tty
, enabled
, internal
, flags
);
9755 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9757 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9758 b
->location
= copy_event_location (location
);
9761 b
->cond_string
= NULL
;
9764 /* Create a private copy of condition string. */
9765 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9769 /* Create a private copy of any extra string. */
9770 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9771 b
->ignore_count
= ignore_count
;
9772 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9773 b
->condition_not_parsed
= 1;
9774 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9775 if ((type_wanted
!= bp_breakpoint
9776 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9777 b
->pspace
= current_program_space
;
9779 install_breakpoint (internal
, std::move (b
), 0);
9782 if (canonical
.lsals
.size () > 1)
9784 warning (_("Multiple breakpoints were set.\nUse the "
9785 "\"delete\" command to delete unwanted breakpoints."));
9786 prev_breakpoint_count
= prev_bkpt_count
;
9789 /* That's it. Discard the cleanups for data inserted into the
9791 discard_cleanups (bkpt_chain
);
9793 /* error call may happen here - have BKPT_CHAIN already discarded. */
9794 update_global_location_list (UGLL_MAY_INSERT
);
9799 /* Set a breakpoint.
9800 ARG is a string describing breakpoint address,
9801 condition, and thread.
9802 FLAG specifies if a breakpoint is hardware on,
9803 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9807 break_command_1 (char *arg
, int flag
, int from_tty
)
9809 int tempflag
= flag
& BP_TEMPFLAG
;
9810 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9811 ? bp_hardware_breakpoint
9813 struct breakpoint_ops
*ops
;
9815 event_location_up location
= string_to_event_location (&arg
, current_language
);
9817 /* Matching breakpoints on probes. */
9818 if (location
!= NULL
9819 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9820 ops
= &bkpt_probe_breakpoint_ops
;
9822 ops
= &bkpt_breakpoint_ops
;
9824 create_breakpoint (get_current_arch (),
9826 NULL
, 0, arg
, 1 /* parse arg */,
9827 tempflag
, type_wanted
,
9828 0 /* Ignore count */,
9829 pending_break_support
,
9837 /* Helper function for break_command_1 and disassemble_command. */
9840 resolve_sal_pc (struct symtab_and_line
*sal
)
9844 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9846 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9847 error (_("No line %d in file \"%s\"."),
9848 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9851 /* If this SAL corresponds to a breakpoint inserted using a line
9852 number, then skip the function prologue if necessary. */
9853 if (sal
->explicit_line
)
9854 skip_prologue_sal (sal
);
9857 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9859 const struct blockvector
*bv
;
9860 const struct block
*b
;
9863 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9864 SYMTAB_COMPUNIT (sal
->symtab
));
9867 sym
= block_linkage_function (b
);
9870 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9871 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9876 /* It really is worthwhile to have the section, so we'll
9877 just have to look harder. This case can be executed
9878 if we have line numbers but no functions (as can
9879 happen in assembly source). */
9881 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9882 switch_to_program_space_and_thread (sal
->pspace
);
9884 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9886 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9893 break_command (char *arg
, int from_tty
)
9895 break_command_1 (arg
, 0, from_tty
);
9899 tbreak_command (char *arg
, int from_tty
)
9901 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9905 hbreak_command (char *arg
, int from_tty
)
9907 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9911 thbreak_command (char *arg
, int from_tty
)
9913 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9917 stop_command (char *arg
, int from_tty
)
9919 printf_filtered (_("Specify the type of breakpoint to set.\n\
9920 Usage: stop in <function | address>\n\
9921 stop at <line>\n"));
9925 stopin_command (char *arg
, int from_tty
)
9929 if (arg
== (char *) NULL
)
9931 else if (*arg
!= '*')
9936 /* Look for a ':'. If this is a line number specification, then
9937 say it is bad, otherwise, it should be an address or
9938 function/method name. */
9939 while (*argptr
&& !hasColon
)
9941 hasColon
= (*argptr
== ':');
9946 badInput
= (*argptr
!= ':'); /* Not a class::method */
9948 badInput
= isdigit (*arg
); /* a simple line number */
9952 printf_filtered (_("Usage: stop in <function | address>\n"));
9954 break_command_1 (arg
, 0, from_tty
);
9958 stopat_command (char *arg
, int from_tty
)
9962 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9969 /* Look for a ':'. If there is a '::' then get out, otherwise
9970 it is probably a line number. */
9971 while (*argptr
&& !hasColon
)
9973 hasColon
= (*argptr
== ':');
9978 badInput
= (*argptr
== ':'); /* we have class::method */
9980 badInput
= !isdigit (*arg
); /* not a line number */
9984 printf_filtered (_("Usage: stop at <line>\n"));
9986 break_command_1 (arg
, 0, from_tty
);
9989 /* The dynamic printf command is mostly like a regular breakpoint, but
9990 with a prewired command list consisting of a single output command,
9991 built from extra arguments supplied on the dprintf command
9995 dprintf_command (char *arg
, int from_tty
)
9997 event_location_up location
= string_to_event_location (&arg
, current_language
);
9999 /* If non-NULL, ARG should have been advanced past the location;
10000 the next character must be ','. */
10003 if (arg
[0] != ',' || arg
[1] == '\0')
10004 error (_("Format string required"));
10007 /* Skip the comma. */
10012 create_breakpoint (get_current_arch (),
10014 NULL
, 0, arg
, 1 /* parse arg */,
10016 0 /* Ignore count */,
10017 pending_break_support
,
10018 &dprintf_breakpoint_ops
,
10026 agent_printf_command (char *arg
, int from_tty
)
10028 error (_("May only run agent-printf on the target"));
10031 /* Implement the "breakpoint_hit" breakpoint_ops method for
10032 ranged breakpoints. */
10035 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10036 struct address_space
*aspace
,
10038 const struct target_waitstatus
*ws
)
10040 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10041 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10044 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10045 bl
->length
, aspace
, bp_addr
);
10048 /* Implement the "resources_needed" breakpoint_ops method for
10049 ranged breakpoints. */
10052 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10054 return target_ranged_break_num_registers ();
10057 /* Implement the "print_it" breakpoint_ops method for
10058 ranged breakpoints. */
10060 static enum print_stop_action
10061 print_it_ranged_breakpoint (bpstat bs
)
10063 struct breakpoint
*b
= bs
->breakpoint_at
;
10064 struct bp_location
*bl
= b
->loc
;
10065 struct ui_out
*uiout
= current_uiout
;
10067 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10069 /* Ranged breakpoints have only one location. */
10070 gdb_assert (bl
&& bl
->next
== NULL
);
10072 annotate_breakpoint (b
->number
);
10074 maybe_print_thread_hit_breakpoint (uiout
);
10076 if (b
->disposition
== disp_del
)
10077 uiout
->text ("Temporary ranged breakpoint ");
10079 uiout
->text ("Ranged breakpoint ");
10080 if (uiout
->is_mi_like_p ())
10082 uiout
->field_string ("reason",
10083 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10084 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10086 uiout
->field_int ("bkptno", b
->number
);
10087 uiout
->text (", ");
10089 return PRINT_SRC_AND_LOC
;
10092 /* Implement the "print_one" breakpoint_ops method for
10093 ranged breakpoints. */
10096 print_one_ranged_breakpoint (struct breakpoint
*b
,
10097 struct bp_location
**last_loc
)
10099 struct bp_location
*bl
= b
->loc
;
10100 struct value_print_options opts
;
10101 struct ui_out
*uiout
= current_uiout
;
10103 /* Ranged breakpoints have only one location. */
10104 gdb_assert (bl
&& bl
->next
== NULL
);
10106 get_user_print_options (&opts
);
10108 if (opts
.addressprint
)
10109 /* We don't print the address range here, it will be printed later
10110 by print_one_detail_ranged_breakpoint. */
10111 uiout
->field_skip ("addr");
10112 annotate_field (5);
10113 print_breakpoint_location (b
, bl
);
10117 /* Implement the "print_one_detail" breakpoint_ops method for
10118 ranged breakpoints. */
10121 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10122 struct ui_out
*uiout
)
10124 CORE_ADDR address_start
, address_end
;
10125 struct bp_location
*bl
= b
->loc
;
10130 address_start
= bl
->address
;
10131 address_end
= address_start
+ bl
->length
- 1;
10133 uiout
->text ("\taddress range: ");
10134 stb
.printf ("[%s, %s]",
10135 print_core_address (bl
->gdbarch
, address_start
),
10136 print_core_address (bl
->gdbarch
, address_end
));
10137 uiout
->field_stream ("addr", stb
);
10138 uiout
->text ("\n");
10141 /* Implement the "print_mention" breakpoint_ops method for
10142 ranged breakpoints. */
10145 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10147 struct bp_location
*bl
= b
->loc
;
10148 struct ui_out
*uiout
= current_uiout
;
10151 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10153 if (uiout
->is_mi_like_p ())
10156 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10157 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10158 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10161 /* Implement the "print_recreate" breakpoint_ops method for
10162 ranged breakpoints. */
10165 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10167 fprintf_unfiltered (fp
, "break-range %s, %s",
10168 event_location_to_string (b
->location
.get ()),
10169 event_location_to_string (b
->location_range_end
.get ()));
10170 print_recreate_thread (b
, fp
);
10173 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10175 static struct breakpoint_ops ranged_breakpoint_ops
;
10177 /* Find the address where the end of the breakpoint range should be
10178 placed, given the SAL of the end of the range. This is so that if
10179 the user provides a line number, the end of the range is set to the
10180 last instruction of the given line. */
10183 find_breakpoint_range_end (struct symtab_and_line sal
)
10187 /* If the user provided a PC value, use it. Otherwise,
10188 find the address of the end of the given location. */
10189 if (sal
.explicit_pc
)
10196 ret
= find_line_pc_range (sal
, &start
, &end
);
10198 error (_("Could not find location of the end of the range."));
10200 /* find_line_pc_range returns the start of the next line. */
10207 /* Implement the "break-range" CLI command. */
10210 break_range_command (char *arg
, int from_tty
)
10212 char *arg_start
, *addr_string_start
;
10213 struct linespec_result canonical_start
, canonical_end
;
10214 int bp_count
, can_use_bp
, length
;
10216 struct breakpoint
*b
;
10217 struct cleanup
*cleanup_bkpt
;
10219 /* We don't support software ranged breakpoints. */
10220 if (target_ranged_break_num_registers () < 0)
10221 error (_("This target does not support hardware ranged breakpoints."));
10223 bp_count
= hw_breakpoint_used_count ();
10224 bp_count
+= target_ranged_break_num_registers ();
10225 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10227 if (can_use_bp
< 0)
10228 error (_("Hardware breakpoints used exceeds limit."));
10230 arg
= skip_spaces (arg
);
10231 if (arg
== NULL
|| arg
[0] == '\0')
10232 error(_("No address range specified."));
10235 event_location_up start_location
= string_to_event_location (&arg
,
10237 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10240 error (_("Too few arguments."));
10241 else if (canonical_start
.lsals
.empty ())
10242 error (_("Could not find location of the beginning of the range."));
10244 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10246 if (canonical_start
.lsals
.size () > 1
10247 || lsal_start
.sals
.size () != 1)
10248 error (_("Cannot create a ranged breakpoint with multiple locations."));
10250 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10251 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10252 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10254 arg
++; /* Skip the comma. */
10255 arg
= skip_spaces (arg
);
10257 /* Parse the end location. */
10261 /* We call decode_line_full directly here instead of using
10262 parse_breakpoint_sals because we need to specify the start location's
10263 symtab and line as the default symtab and line for the end of the
10264 range. This makes it possible to have ranges like "foo.c:27, +14",
10265 where +14 means 14 lines from the start location. */
10266 event_location_up end_location
= string_to_event_location (&arg
,
10268 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10269 sal_start
.symtab
, sal_start
.line
,
10270 &canonical_end
, NULL
, NULL
);
10272 if (canonical_end
.lsals
.empty ())
10273 error (_("Could not find location of the end of the range."));
10275 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10276 if (canonical_end
.lsals
.size () > 1
10277 || lsal_end
.sals
.size () != 1)
10278 error (_("Cannot create a ranged breakpoint with multiple locations."));
10280 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10282 end
= find_breakpoint_range_end (sal_end
);
10283 if (sal_start
.pc
> end
)
10284 error (_("Invalid address range, end precedes start."));
10286 length
= end
- sal_start
.pc
+ 1;
10288 /* Length overflowed. */
10289 error (_("Address range too large."));
10290 else if (length
== 1)
10292 /* This range is simple enough to be handled by
10293 the `hbreak' command. */
10294 hbreak_command (addr_string_start
, 1);
10296 do_cleanups (cleanup_bkpt
);
10301 /* Now set up the breakpoint. */
10302 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10303 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10304 set_breakpoint_count (breakpoint_count
+ 1);
10305 b
->number
= breakpoint_count
;
10306 b
->disposition
= disp_donttouch
;
10307 b
->location
= std::move (start_location
);
10308 b
->location_range_end
= std::move (end_location
);
10309 b
->loc
->length
= length
;
10311 do_cleanups (cleanup_bkpt
);
10314 observer_notify_breakpoint_created (b
);
10315 update_global_location_list (UGLL_MAY_INSERT
);
10318 /* Return non-zero if EXP is verified as constant. Returned zero
10319 means EXP is variable. Also the constant detection may fail for
10320 some constant expressions and in such case still falsely return
10324 watchpoint_exp_is_const (const struct expression
*exp
)
10326 int i
= exp
->nelts
;
10332 /* We are only interested in the descriptor of each element. */
10333 operator_length (exp
, i
, &oplenp
, &argsp
);
10336 switch (exp
->elts
[i
].opcode
)
10346 case BINOP_LOGICAL_AND
:
10347 case BINOP_LOGICAL_OR
:
10348 case BINOP_BITWISE_AND
:
10349 case BINOP_BITWISE_IOR
:
10350 case BINOP_BITWISE_XOR
:
10352 case BINOP_NOTEQUAL
:
10379 case OP_OBJC_NSSTRING
:
10382 case UNOP_LOGICAL_NOT
:
10383 case UNOP_COMPLEMENT
:
10388 case UNOP_CAST_TYPE
:
10389 case UNOP_REINTERPRET_CAST
:
10390 case UNOP_DYNAMIC_CAST
:
10391 /* Unary, binary and ternary operators: We have to check
10392 their operands. If they are constant, then so is the
10393 result of that operation. For instance, if A and B are
10394 determined to be constants, then so is "A + B".
10396 UNOP_IND is one exception to the rule above, because the
10397 value of *ADDR is not necessarily a constant, even when
10402 /* Check whether the associated symbol is a constant.
10404 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10405 possible that a buggy compiler could mark a variable as
10406 constant even when it is not, and TYPE_CONST would return
10407 true in this case, while SYMBOL_CLASS wouldn't.
10409 We also have to check for function symbols because they
10410 are always constant. */
10412 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10414 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10415 && SYMBOL_CLASS (s
) != LOC_CONST
10416 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10421 /* The default action is to return 0 because we are using
10422 the optimistic approach here: If we don't know something,
10423 then it is not a constant. */
10432 /* Watchpoint destructor. */
10434 watchpoint::~watchpoint ()
10436 xfree (this->exp_string
);
10437 xfree (this->exp_string_reparse
);
10438 value_free (this->val
);
10441 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10444 re_set_watchpoint (struct breakpoint
*b
)
10446 struct watchpoint
*w
= (struct watchpoint
*) b
;
10448 /* Watchpoint can be either on expression using entirely global
10449 variables, or it can be on local variables.
10451 Watchpoints of the first kind are never auto-deleted, and even
10452 persist across program restarts. Since they can use variables
10453 from shared libraries, we need to reparse expression as libraries
10454 are loaded and unloaded.
10456 Watchpoints on local variables can also change meaning as result
10457 of solib event. For example, if a watchpoint uses both a local
10458 and a global variables in expression, it's a local watchpoint,
10459 but unloading of a shared library will make the expression
10460 invalid. This is not a very common use case, but we still
10461 re-evaluate expression, to avoid surprises to the user.
10463 Note that for local watchpoints, we re-evaluate it only if
10464 watchpoints frame id is still valid. If it's not, it means the
10465 watchpoint is out of scope and will be deleted soon. In fact,
10466 I'm not sure we'll ever be called in this case.
10468 If a local watchpoint's frame id is still valid, then
10469 w->exp_valid_block is likewise valid, and we can safely use it.
10471 Don't do anything about disabled watchpoints, since they will be
10472 reevaluated again when enabled. */
10473 update_watchpoint (w
, 1 /* reparse */);
10476 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10479 insert_watchpoint (struct bp_location
*bl
)
10481 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10482 int length
= w
->exact
? 1 : bl
->length
;
10484 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10485 w
->cond_exp
.get ());
10488 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10491 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10493 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10494 int length
= w
->exact
? 1 : bl
->length
;
10496 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10497 w
->cond_exp
.get ());
10501 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10502 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10503 const struct target_waitstatus
*ws
)
10505 struct breakpoint
*b
= bl
->owner
;
10506 struct watchpoint
*w
= (struct watchpoint
*) b
;
10508 /* Continuable hardware watchpoints are treated as non-existent if the
10509 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10510 some data address). Otherwise gdb won't stop on a break instruction
10511 in the code (not from a breakpoint) when a hardware watchpoint has
10512 been defined. Also skip watchpoints which we know did not trigger
10513 (did not match the data address). */
10514 if (is_hardware_watchpoint (b
)
10515 && w
->watchpoint_triggered
== watch_triggered_no
)
10522 check_status_watchpoint (bpstat bs
)
10524 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10526 bpstat_check_watchpoint (bs
);
10529 /* Implement the "resources_needed" breakpoint_ops method for
10530 hardware watchpoints. */
10533 resources_needed_watchpoint (const struct bp_location
*bl
)
10535 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10536 int length
= w
->exact
? 1 : bl
->length
;
10538 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10541 /* Implement the "works_in_software_mode" breakpoint_ops method for
10542 hardware watchpoints. */
10545 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10547 /* Read and access watchpoints only work with hardware support. */
10548 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10551 static enum print_stop_action
10552 print_it_watchpoint (bpstat bs
)
10554 struct cleanup
*old_chain
;
10555 struct breakpoint
*b
;
10556 enum print_stop_action result
;
10557 struct watchpoint
*w
;
10558 struct ui_out
*uiout
= current_uiout
;
10560 gdb_assert (bs
->bp_location_at
!= NULL
);
10562 b
= bs
->breakpoint_at
;
10563 w
= (struct watchpoint
*) b
;
10565 old_chain
= make_cleanup (null_cleanup
, NULL
);
10567 annotate_watchpoint (b
->number
);
10568 maybe_print_thread_hit_breakpoint (uiout
);
10574 case bp_watchpoint
:
10575 case bp_hardware_watchpoint
:
10576 if (uiout
->is_mi_like_p ())
10577 uiout
->field_string
10578 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10580 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10581 uiout
->text ("\nOld value = ");
10582 watchpoint_value_print (bs
->old_val
, &stb
);
10583 uiout
->field_stream ("old", stb
);
10584 uiout
->text ("\nNew value = ");
10585 watchpoint_value_print (w
->val
, &stb
);
10586 uiout
->field_stream ("new", stb
);
10587 uiout
->text ("\n");
10588 /* More than one watchpoint may have been triggered. */
10589 result
= PRINT_UNKNOWN
;
10592 case bp_read_watchpoint
:
10593 if (uiout
->is_mi_like_p ())
10594 uiout
->field_string
10595 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10597 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10598 uiout
->text ("\nValue = ");
10599 watchpoint_value_print (w
->val
, &stb
);
10600 uiout
->field_stream ("value", stb
);
10601 uiout
->text ("\n");
10602 result
= PRINT_UNKNOWN
;
10605 case bp_access_watchpoint
:
10606 if (bs
->old_val
!= NULL
)
10608 if (uiout
->is_mi_like_p ())
10609 uiout
->field_string
10611 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10613 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10614 uiout
->text ("\nOld value = ");
10615 watchpoint_value_print (bs
->old_val
, &stb
);
10616 uiout
->field_stream ("old", stb
);
10617 uiout
->text ("\nNew value = ");
10622 if (uiout
->is_mi_like_p ())
10623 uiout
->field_string
10625 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10626 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10627 uiout
->text ("\nValue = ");
10629 watchpoint_value_print (w
->val
, &stb
);
10630 uiout
->field_stream ("new", stb
);
10631 uiout
->text ("\n");
10632 result
= PRINT_UNKNOWN
;
10635 result
= PRINT_UNKNOWN
;
10638 do_cleanups (old_chain
);
10642 /* Implement the "print_mention" breakpoint_ops method for hardware
10646 print_mention_watchpoint (struct breakpoint
*b
)
10648 struct watchpoint
*w
= (struct watchpoint
*) b
;
10649 struct ui_out
*uiout
= current_uiout
;
10650 const char *tuple_name
;
10654 case bp_watchpoint
:
10655 uiout
->text ("Watchpoint ");
10656 tuple_name
= "wpt";
10658 case bp_hardware_watchpoint
:
10659 uiout
->text ("Hardware watchpoint ");
10660 tuple_name
= "wpt";
10662 case bp_read_watchpoint
:
10663 uiout
->text ("Hardware read watchpoint ");
10664 tuple_name
= "hw-rwpt";
10666 case bp_access_watchpoint
:
10667 uiout
->text ("Hardware access (read/write) watchpoint ");
10668 tuple_name
= "hw-awpt";
10671 internal_error (__FILE__
, __LINE__
,
10672 _("Invalid hardware watchpoint type."));
10675 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10676 uiout
->field_int ("number", b
->number
);
10677 uiout
->text (": ");
10678 uiout
->field_string ("exp", w
->exp_string
);
10681 /* Implement the "print_recreate" breakpoint_ops method for
10685 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10687 struct watchpoint
*w
= (struct watchpoint
*) b
;
10691 case bp_watchpoint
:
10692 case bp_hardware_watchpoint
:
10693 fprintf_unfiltered (fp
, "watch");
10695 case bp_read_watchpoint
:
10696 fprintf_unfiltered (fp
, "rwatch");
10698 case bp_access_watchpoint
:
10699 fprintf_unfiltered (fp
, "awatch");
10702 internal_error (__FILE__
, __LINE__
,
10703 _("Invalid watchpoint type."));
10706 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10707 print_recreate_thread (b
, fp
);
10710 /* Implement the "explains_signal" breakpoint_ops method for
10714 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10716 /* A software watchpoint cannot cause a signal other than
10717 GDB_SIGNAL_TRAP. */
10718 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10724 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10726 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10728 /* Implement the "insert" breakpoint_ops method for
10729 masked hardware watchpoints. */
10732 insert_masked_watchpoint (struct bp_location
*bl
)
10734 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10736 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10737 bl
->watchpoint_type
);
10740 /* Implement the "remove" breakpoint_ops method for
10741 masked hardware watchpoints. */
10744 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10746 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10748 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10749 bl
->watchpoint_type
);
10752 /* Implement the "resources_needed" breakpoint_ops method for
10753 masked hardware watchpoints. */
10756 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10758 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10760 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10763 /* Implement the "works_in_software_mode" breakpoint_ops method for
10764 masked hardware watchpoints. */
10767 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10772 /* Implement the "print_it" breakpoint_ops method for
10773 masked hardware watchpoints. */
10775 static enum print_stop_action
10776 print_it_masked_watchpoint (bpstat bs
)
10778 struct breakpoint
*b
= bs
->breakpoint_at
;
10779 struct ui_out
*uiout
= current_uiout
;
10781 /* Masked watchpoints have only one location. */
10782 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10784 annotate_watchpoint (b
->number
);
10785 maybe_print_thread_hit_breakpoint (uiout
);
10789 case bp_hardware_watchpoint
:
10790 if (uiout
->is_mi_like_p ())
10791 uiout
->field_string
10792 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10795 case bp_read_watchpoint
:
10796 if (uiout
->is_mi_like_p ())
10797 uiout
->field_string
10798 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10801 case bp_access_watchpoint
:
10802 if (uiout
->is_mi_like_p ())
10803 uiout
->field_string
10805 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10808 internal_error (__FILE__
, __LINE__
,
10809 _("Invalid hardware watchpoint type."));
10813 uiout
->text (_("\n\
10814 Check the underlying instruction at PC for the memory\n\
10815 address and value which triggered this watchpoint.\n"));
10816 uiout
->text ("\n");
10818 /* More than one watchpoint may have been triggered. */
10819 return PRINT_UNKNOWN
;
10822 /* Implement the "print_one_detail" breakpoint_ops method for
10823 masked hardware watchpoints. */
10826 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10827 struct ui_out
*uiout
)
10829 struct watchpoint
*w
= (struct watchpoint
*) b
;
10831 /* Masked watchpoints have only one location. */
10832 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10834 uiout
->text ("\tmask ");
10835 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10836 uiout
->text ("\n");
10839 /* Implement the "print_mention" breakpoint_ops method for
10840 masked hardware watchpoints. */
10843 print_mention_masked_watchpoint (struct breakpoint
*b
)
10845 struct watchpoint
*w
= (struct watchpoint
*) b
;
10846 struct ui_out
*uiout
= current_uiout
;
10847 const char *tuple_name
;
10851 case bp_hardware_watchpoint
:
10852 uiout
->text ("Masked hardware watchpoint ");
10853 tuple_name
= "wpt";
10855 case bp_read_watchpoint
:
10856 uiout
->text ("Masked hardware read watchpoint ");
10857 tuple_name
= "hw-rwpt";
10859 case bp_access_watchpoint
:
10860 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10861 tuple_name
= "hw-awpt";
10864 internal_error (__FILE__
, __LINE__
,
10865 _("Invalid hardware watchpoint type."));
10868 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10869 uiout
->field_int ("number", b
->number
);
10870 uiout
->text (": ");
10871 uiout
->field_string ("exp", w
->exp_string
);
10874 /* Implement the "print_recreate" breakpoint_ops method for
10875 masked hardware watchpoints. */
10878 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10880 struct watchpoint
*w
= (struct watchpoint
*) b
;
10885 case bp_hardware_watchpoint
:
10886 fprintf_unfiltered (fp
, "watch");
10888 case bp_read_watchpoint
:
10889 fprintf_unfiltered (fp
, "rwatch");
10891 case bp_access_watchpoint
:
10892 fprintf_unfiltered (fp
, "awatch");
10895 internal_error (__FILE__
, __LINE__
,
10896 _("Invalid hardware watchpoint type."));
10899 sprintf_vma (tmp
, w
->hw_wp_mask
);
10900 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10901 print_recreate_thread (b
, fp
);
10904 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10906 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10908 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10911 is_masked_watchpoint (const struct breakpoint
*b
)
10913 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10916 /* accessflag: hw_write: watch write,
10917 hw_read: watch read,
10918 hw_access: watch access (read or write) */
10920 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10921 int just_location
, int internal
)
10923 struct breakpoint
*scope_breakpoint
= NULL
;
10924 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10925 struct value
*val
, *mark
, *result
;
10926 int saved_bitpos
= 0, saved_bitsize
= 0;
10927 const char *exp_start
= NULL
;
10928 const char *exp_end
= NULL
;
10929 const char *tok
, *end_tok
;
10931 const char *cond_start
= NULL
;
10932 const char *cond_end
= NULL
;
10933 enum bptype bp_type
;
10936 /* Flag to indicate whether we are going to use masks for
10937 the hardware watchpoint. */
10939 CORE_ADDR mask
= 0;
10941 struct cleanup
*back_to
;
10943 /* Make sure that we actually have parameters to parse. */
10944 if (arg
!= NULL
&& arg
[0] != '\0')
10946 const char *value_start
;
10948 exp_end
= arg
+ strlen (arg
);
10950 /* Look for "parameter value" pairs at the end
10951 of the arguments string. */
10952 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10954 /* Skip whitespace at the end of the argument list. */
10955 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10958 /* Find the beginning of the last token.
10959 This is the value of the parameter. */
10960 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10962 value_start
= tok
+ 1;
10964 /* Skip whitespace. */
10965 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10970 /* Find the beginning of the second to last token.
10971 This is the parameter itself. */
10972 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10975 toklen
= end_tok
- tok
+ 1;
10977 if (toklen
== 6 && startswith (tok
, "thread"))
10979 struct thread_info
*thr
;
10980 /* At this point we've found a "thread" token, which means
10981 the user is trying to set a watchpoint that triggers
10982 only in a specific thread. */
10986 error(_("You can specify only one thread."));
10988 /* Extract the thread ID from the next token. */
10989 thr
= parse_thread_id (value_start
, &endp
);
10991 /* Check if the user provided a valid thread ID. */
10992 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10993 invalid_thread_id_error (value_start
);
10995 thread
= thr
->global_num
;
10997 else if (toklen
== 4 && startswith (tok
, "mask"))
10999 /* We've found a "mask" token, which means the user wants to
11000 create a hardware watchpoint that is going to have the mask
11002 struct value
*mask_value
, *mark
;
11005 error(_("You can specify only one mask."));
11007 use_mask
= just_location
= 1;
11009 mark
= value_mark ();
11010 mask_value
= parse_to_comma_and_eval (&value_start
);
11011 mask
= value_as_address (mask_value
);
11012 value_free_to_mark (mark
);
11015 /* We didn't recognize what we found. We should stop here. */
11018 /* Truncate the string and get rid of the "parameter value" pair before
11019 the arguments string is parsed by the parse_exp_1 function. */
11026 /* Parse the rest of the arguments. From here on out, everything
11027 is in terms of a newly allocated string instead of the original
11029 innermost_block
= NULL
;
11030 expression
= savestring (arg
, exp_end
- arg
);
11031 back_to
= make_cleanup (xfree
, expression
);
11032 exp_start
= arg
= expression
;
11033 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11035 /* Remove trailing whitespace from the expression before saving it.
11036 This makes the eventual display of the expression string a bit
11038 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11041 /* Checking if the expression is not constant. */
11042 if (watchpoint_exp_is_const (exp
.get ()))
11046 len
= exp_end
- exp_start
;
11047 while (len
> 0 && isspace (exp_start
[len
- 1]))
11049 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11052 exp_valid_block
= innermost_block
;
11053 mark
= value_mark ();
11054 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11056 if (val
!= NULL
&& just_location
)
11058 saved_bitpos
= value_bitpos (val
);
11059 saved_bitsize
= value_bitsize (val
);
11066 exp_valid_block
= NULL
;
11067 val
= value_addr (result
);
11068 release_value (val
);
11069 value_free_to_mark (mark
);
11073 ret
= target_masked_watch_num_registers (value_as_address (val
),
11076 error (_("This target does not support masked watchpoints."));
11077 else if (ret
== -2)
11078 error (_("Invalid mask or memory region."));
11081 else if (val
!= NULL
)
11082 release_value (val
);
11084 tok
= skip_spaces_const (arg
);
11085 end_tok
= skip_to_space_const (tok
);
11087 toklen
= end_tok
- tok
;
11088 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11090 innermost_block
= NULL
;
11091 tok
= cond_start
= end_tok
+ 1;
11092 parse_exp_1 (&tok
, 0, 0, 0);
11094 /* The watchpoint expression may not be local, but the condition
11095 may still be. E.g.: `watch global if local > 0'. */
11096 cond_exp_valid_block
= innermost_block
;
11101 error (_("Junk at end of command."));
11103 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11105 /* Save this because create_internal_breakpoint below invalidates
11107 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11109 /* If the expression is "local", then set up a "watchpoint scope"
11110 breakpoint at the point where we've left the scope of the watchpoint
11111 expression. Create the scope breakpoint before the watchpoint, so
11112 that we will encounter it first in bpstat_stop_status. */
11113 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11115 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11117 if (frame_id_p (caller_frame_id
))
11119 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11120 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11123 = create_internal_breakpoint (caller_arch
, caller_pc
,
11124 bp_watchpoint_scope
,
11125 &momentary_breakpoint_ops
);
11127 /* create_internal_breakpoint could invalidate WP_FRAME. */
11130 scope_breakpoint
->enable_state
= bp_enabled
;
11132 /* Automatically delete the breakpoint when it hits. */
11133 scope_breakpoint
->disposition
= disp_del
;
11135 /* Only break in the proper frame (help with recursion). */
11136 scope_breakpoint
->frame_id
= caller_frame_id
;
11138 /* Set the address at which we will stop. */
11139 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11140 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11141 scope_breakpoint
->loc
->address
11142 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11143 scope_breakpoint
->loc
->requested_address
,
11144 scope_breakpoint
->type
);
11148 /* Now set up the breakpoint. We create all watchpoints as hardware
11149 watchpoints here even if hardware watchpoints are turned off, a call
11150 to update_watchpoint later in this function will cause the type to
11151 drop back to bp_watchpoint (software watchpoint) if required. */
11153 if (accessflag
== hw_read
)
11154 bp_type
= bp_read_watchpoint
;
11155 else if (accessflag
== hw_access
)
11156 bp_type
= bp_access_watchpoint
;
11158 bp_type
= bp_hardware_watchpoint
;
11160 std::unique_ptr
<watchpoint
> w (new watchpoint ());
11163 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11164 &masked_watchpoint_breakpoint_ops
);
11166 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11167 &watchpoint_breakpoint_ops
);
11168 w
->thread
= thread
;
11169 w
->disposition
= disp_donttouch
;
11170 w
->pspace
= current_program_space
;
11171 w
->exp
= std::move (exp
);
11172 w
->exp_valid_block
= exp_valid_block
;
11173 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11176 struct type
*t
= value_type (val
);
11177 CORE_ADDR addr
= value_as_address (val
);
11179 w
->exp_string_reparse
11180 = current_language
->la_watch_location_expression (t
, addr
).release ();
11182 w
->exp_string
= xstrprintf ("-location %.*s",
11183 (int) (exp_end
- exp_start
), exp_start
);
11186 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11190 w
->hw_wp_mask
= mask
;
11195 w
->val_bitpos
= saved_bitpos
;
11196 w
->val_bitsize
= saved_bitsize
;
11201 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11203 w
->cond_string
= 0;
11205 if (frame_id_p (watchpoint_frame
))
11207 w
->watchpoint_frame
= watchpoint_frame
;
11208 w
->watchpoint_thread
= inferior_ptid
;
11212 w
->watchpoint_frame
= null_frame_id
;
11213 w
->watchpoint_thread
= null_ptid
;
11216 if (scope_breakpoint
!= NULL
)
11218 /* The scope breakpoint is related to the watchpoint. We will
11219 need to act on them together. */
11220 w
->related_breakpoint
= scope_breakpoint
;
11221 scope_breakpoint
->related_breakpoint
= w
.get ();
11224 if (!just_location
)
11225 value_free_to_mark (mark
);
11227 /* Finally update the new watchpoint. This creates the locations
11228 that should be inserted. */
11229 update_watchpoint (w
.get (), 1);
11231 install_breakpoint (internal
, std::move (w
), 1);
11232 do_cleanups (back_to
);
11235 /* Return count of debug registers needed to watch the given expression.
11236 If the watchpoint cannot be handled in hardware return zero. */
11239 can_use_hardware_watchpoint (struct value
*v
)
11241 int found_memory_cnt
= 0;
11242 struct value
*head
= v
;
11244 /* Did the user specifically forbid us to use hardware watchpoints? */
11245 if (!can_use_hw_watchpoints
)
11248 /* Make sure that the value of the expression depends only upon
11249 memory contents, and values computed from them within GDB. If we
11250 find any register references or function calls, we can't use a
11251 hardware watchpoint.
11253 The idea here is that evaluating an expression generates a series
11254 of values, one holding the value of every subexpression. (The
11255 expression a*b+c has five subexpressions: a, b, a*b, c, and
11256 a*b+c.) GDB's values hold almost enough information to establish
11257 the criteria given above --- they identify memory lvalues,
11258 register lvalues, computed values, etcetera. So we can evaluate
11259 the expression, and then scan the chain of values that leaves
11260 behind to decide whether we can detect any possible change to the
11261 expression's final value using only hardware watchpoints.
11263 However, I don't think that the values returned by inferior
11264 function calls are special in any way. So this function may not
11265 notice that an expression involving an inferior function call
11266 can't be watched with hardware watchpoints. FIXME. */
11267 for (; v
; v
= value_next (v
))
11269 if (VALUE_LVAL (v
) == lval_memory
)
11271 if (v
!= head
&& value_lazy (v
))
11272 /* A lazy memory lvalue in the chain is one that GDB never
11273 needed to fetch; we either just used its address (e.g.,
11274 `a' in `a.b') or we never needed it at all (e.g., `a'
11275 in `a,b'). This doesn't apply to HEAD; if that is
11276 lazy then it was not readable, but watch it anyway. */
11280 /* Ahh, memory we actually used! Check if we can cover
11281 it with hardware watchpoints. */
11282 struct type
*vtype
= check_typedef (value_type (v
));
11284 /* We only watch structs and arrays if user asked for it
11285 explicitly, never if they just happen to appear in a
11286 middle of some value chain. */
11288 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11289 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11291 CORE_ADDR vaddr
= value_address (v
);
11295 len
= (target_exact_watchpoints
11296 && is_scalar_type_recursive (vtype
))?
11297 1 : TYPE_LENGTH (value_type (v
));
11299 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11303 found_memory_cnt
+= num_regs
;
11307 else if (VALUE_LVAL (v
) != not_lval
11308 && deprecated_value_modifiable (v
) == 0)
11309 return 0; /* These are values from the history (e.g., $1). */
11310 else if (VALUE_LVAL (v
) == lval_register
)
11311 return 0; /* Cannot watch a register with a HW watchpoint. */
11314 /* The expression itself looks suitable for using a hardware
11315 watchpoint, but give the target machine a chance to reject it. */
11316 return found_memory_cnt
;
11320 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11322 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11325 /* A helper function that looks for the "-location" argument and then
11326 calls watch_command_1. */
11329 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11331 int just_location
= 0;
11334 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11335 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11337 arg
= skip_spaces (arg
);
11341 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11345 watch_command (char *arg
, int from_tty
)
11347 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11351 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11353 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11357 rwatch_command (char *arg
, int from_tty
)
11359 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11363 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11365 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11369 awatch_command (char *arg
, int from_tty
)
11371 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11375 /* Data for the FSM that manages the until(location)/advance commands
11376 in infcmd.c. Here because it uses the mechanisms of
11379 struct until_break_fsm
11381 /* The base class. */
11382 struct thread_fsm thread_fsm
;
11384 /* The thread that as current when the command was executed. */
11387 /* The breakpoint set at the destination location. */
11388 struct breakpoint
*location_breakpoint
;
11390 /* Breakpoint set at the return address in the caller frame. May be
11392 struct breakpoint
*caller_breakpoint
;
11395 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11396 struct thread_info
*thread
);
11397 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11398 struct thread_info
*thread
);
11399 static enum async_reply_reason
11400 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11402 /* until_break_fsm's vtable. */
11404 static struct thread_fsm_ops until_break_fsm_ops
=
11407 until_break_fsm_clean_up
,
11408 until_break_fsm_should_stop
,
11409 NULL
, /* return_value */
11410 until_break_fsm_async_reply_reason
,
11413 /* Allocate a new until_break_command_fsm. */
11415 static struct until_break_fsm
*
11416 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11417 struct breakpoint
*location_breakpoint
,
11418 struct breakpoint
*caller_breakpoint
)
11420 struct until_break_fsm
*sm
;
11422 sm
= XCNEW (struct until_break_fsm
);
11423 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11425 sm
->thread
= thread
;
11426 sm
->location_breakpoint
= location_breakpoint
;
11427 sm
->caller_breakpoint
= caller_breakpoint
;
11432 /* Implementation of the 'should_stop' FSM method for the
11433 until(location)/advance commands. */
11436 until_break_fsm_should_stop (struct thread_fsm
*self
,
11437 struct thread_info
*tp
)
11439 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11441 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11442 sm
->location_breakpoint
) != NULL
11443 || (sm
->caller_breakpoint
!= NULL
11444 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11445 sm
->caller_breakpoint
) != NULL
))
11446 thread_fsm_set_finished (self
);
11451 /* Implementation of the 'clean_up' FSM method for the
11452 until(location)/advance commands. */
11455 until_break_fsm_clean_up (struct thread_fsm
*self
,
11456 struct thread_info
*thread
)
11458 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11460 /* Clean up our temporary breakpoints. */
11461 if (sm
->location_breakpoint
!= NULL
)
11463 delete_breakpoint (sm
->location_breakpoint
);
11464 sm
->location_breakpoint
= NULL
;
11466 if (sm
->caller_breakpoint
!= NULL
)
11468 delete_breakpoint (sm
->caller_breakpoint
);
11469 sm
->caller_breakpoint
= NULL
;
11471 delete_longjmp_breakpoint (sm
->thread
);
11474 /* Implementation of the 'async_reply_reason' FSM method for the
11475 until(location)/advance commands. */
11477 static enum async_reply_reason
11478 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11480 return EXEC_ASYNC_LOCATION_REACHED
;
11484 until_break_command (char *arg
, int from_tty
, int anywhere
)
11486 struct frame_info
*frame
;
11487 struct gdbarch
*frame_gdbarch
;
11488 struct frame_id stack_frame_id
;
11489 struct frame_id caller_frame_id
;
11490 struct breakpoint
*location_breakpoint
;
11491 struct breakpoint
*caller_breakpoint
= NULL
;
11492 struct cleanup
*old_chain
;
11494 struct thread_info
*tp
;
11495 struct until_break_fsm
*sm
;
11497 clear_proceed_status (0);
11499 /* Set a breakpoint where the user wants it and at return from
11502 event_location_up location
= string_to_event_location (&arg
, current_language
);
11504 std::vector
<symtab_and_line
> sals
11505 = (last_displayed_sal_is_valid ()
11506 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11507 get_last_displayed_symtab (),
11508 get_last_displayed_line ())
11509 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11510 NULL
, (struct symtab
*) NULL
, 0));
11512 if (sals
.size () != 1)
11513 error (_("Couldn't get information on specified line."));
11515 symtab_and_line
&sal
= sals
[0];
11518 error (_("Junk at end of arguments."));
11520 resolve_sal_pc (&sal
);
11522 tp
= inferior_thread ();
11523 thread
= tp
->global_num
;
11525 old_chain
= make_cleanup (null_cleanup
, NULL
);
11527 /* Note linespec handling above invalidates the frame chain.
11528 Installing a breakpoint also invalidates the frame chain (as it
11529 may need to switch threads), so do any frame handling before
11532 frame
= get_selected_frame (NULL
);
11533 frame_gdbarch
= get_frame_arch (frame
);
11534 stack_frame_id
= get_stack_frame_id (frame
);
11535 caller_frame_id
= frame_unwind_caller_id (frame
);
11537 /* Keep within the current frame, or in frames called by the current
11540 if (frame_id_p (caller_frame_id
))
11542 struct symtab_and_line sal2
;
11543 struct gdbarch
*caller_gdbarch
;
11545 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11546 sal2
.pc
= frame_unwind_caller_pc (frame
);
11547 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11548 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11552 make_cleanup_delete_breakpoint (caller_breakpoint
);
11554 set_longjmp_breakpoint (tp
, caller_frame_id
);
11555 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11558 /* set_momentary_breakpoint could invalidate FRAME. */
11562 /* If the user told us to continue until a specified location,
11563 we don't specify a frame at which we need to stop. */
11564 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11565 null_frame_id
, bp_until
);
11567 /* Otherwise, specify the selected frame, because we want to stop
11568 only at the very same frame. */
11569 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11570 stack_frame_id
, bp_until
);
11571 make_cleanup_delete_breakpoint (location_breakpoint
);
11573 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11574 location_breakpoint
, caller_breakpoint
);
11575 tp
->thread_fsm
= &sm
->thread_fsm
;
11577 discard_cleanups (old_chain
);
11579 proceed (-1, GDB_SIGNAL_DEFAULT
);
11582 /* This function attempts to parse an optional "if <cond>" clause
11583 from the arg string. If one is not found, it returns NULL.
11585 Else, it returns a pointer to the condition string. (It does not
11586 attempt to evaluate the string against a particular block.) And,
11587 it updates arg to point to the first character following the parsed
11588 if clause in the arg string. */
11591 ep_parse_optional_if_clause (const char **arg
)
11593 const char *cond_string
;
11595 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11598 /* Skip the "if" keyword. */
11601 /* Skip any extra leading whitespace, and record the start of the
11602 condition string. */
11603 *arg
= skip_spaces_const (*arg
);
11604 cond_string
= *arg
;
11606 /* Assume that the condition occupies the remainder of the arg
11608 (*arg
) += strlen (cond_string
);
11610 return cond_string
;
11613 /* Commands to deal with catching events, such as signals, exceptions,
11614 process start/exit, etc. */
11618 catch_fork_temporary
, catch_vfork_temporary
,
11619 catch_fork_permanent
, catch_vfork_permanent
11624 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11625 struct cmd_list_element
*command
)
11627 const char *arg
= arg_entry
;
11628 struct gdbarch
*gdbarch
= get_current_arch ();
11629 const char *cond_string
= NULL
;
11630 catch_fork_kind fork_kind
;
11633 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11634 tempflag
= (fork_kind
== catch_fork_temporary
11635 || fork_kind
== catch_vfork_temporary
);
11639 arg
= skip_spaces_const (arg
);
11641 /* The allowed syntax is:
11643 catch [v]fork if <cond>
11645 First, check if there's an if clause. */
11646 cond_string
= ep_parse_optional_if_clause (&arg
);
11648 if ((*arg
!= '\0') && !isspace (*arg
))
11649 error (_("Junk at end of arguments."));
11651 /* If this target supports it, create a fork or vfork catchpoint
11652 and enable reporting of such events. */
11655 case catch_fork_temporary
:
11656 case catch_fork_permanent
:
11657 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11658 &catch_fork_breakpoint_ops
);
11660 case catch_vfork_temporary
:
11661 case catch_vfork_permanent
:
11662 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11663 &catch_vfork_breakpoint_ops
);
11666 error (_("unsupported or unknown fork kind; cannot catch it"));
11672 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11673 struct cmd_list_element
*command
)
11675 const char *arg
= arg_entry
;
11676 struct gdbarch
*gdbarch
= get_current_arch ();
11678 const char *cond_string
= NULL
;
11680 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11684 arg
= skip_spaces_const (arg
);
11686 /* The allowed syntax is:
11688 catch exec if <cond>
11690 First, check if there's an if clause. */
11691 cond_string
= ep_parse_optional_if_clause (&arg
);
11693 if ((*arg
!= '\0') && !isspace (*arg
))
11694 error (_("Junk at end of arguments."));
11696 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11697 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11698 &catch_exec_breakpoint_ops
);
11699 c
->exec_pathname
= NULL
;
11701 install_breakpoint (0, std::move (c
), 1);
11705 init_ada_exception_breakpoint (struct breakpoint
*b
,
11706 struct gdbarch
*gdbarch
,
11707 struct symtab_and_line sal
,
11709 const struct breakpoint_ops
*ops
,
11716 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11718 loc_gdbarch
= gdbarch
;
11720 describe_other_breakpoints (loc_gdbarch
,
11721 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11722 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11723 version for exception catchpoints, because two catchpoints
11724 used for different exception names will use the same address.
11725 In this case, a "breakpoint ... also set at..." warning is
11726 unproductive. Besides, the warning phrasing is also a bit
11727 inappropriate, we should use the word catchpoint, and tell
11728 the user what type of catchpoint it is. The above is good
11729 enough for now, though. */
11732 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11734 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11735 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11736 b
->location
= string_to_event_location (&addr_string
,
11737 language_def (language_ada
));
11738 b
->language
= language_ada
;
11742 catch_command (char *arg
, int from_tty
)
11744 error (_("Catch requires an event name."));
11749 tcatch_command (char *arg
, int from_tty
)
11751 error (_("Catch requires an event name."));
11754 /* A qsort comparison function that sorts breakpoints in order. */
11757 compare_breakpoints (const void *a
, const void *b
)
11759 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11760 uintptr_t ua
= (uintptr_t) *ba
;
11761 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11762 uintptr_t ub
= (uintptr_t) *bb
;
11764 if ((*ba
)->number
< (*bb
)->number
)
11766 else if ((*ba
)->number
> (*bb
)->number
)
11769 /* Now sort by address, in case we see, e..g, two breakpoints with
11773 return ua
> ub
? 1 : 0;
11776 /* Delete breakpoints by address or line. */
11779 clear_command (char *arg
, int from_tty
)
11781 struct breakpoint
*b
, *prev
;
11782 VEC(breakpoint_p
) *found
= 0;
11786 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11788 std::vector
<symtab_and_line
> decoded_sals
;
11789 symtab_and_line last_sal
;
11790 gdb::array_view
<symtab_and_line
> sals
;
11794 = decode_line_with_current_source (arg
,
11795 (DECODE_LINE_FUNFIRSTLINE
11796 | DECODE_LINE_LIST_MODE
));
11798 sals
= decoded_sals
;
11802 init_sal (&last_sal
); /* Initialize to zeroes. */
11804 /* Set sal's line, symtab, pc, and pspace to the values
11805 corresponding to the last call to print_frame_info. If the
11806 codepoint is not valid, this will set all the fields to 0. */
11807 get_last_displayed_sal (&last_sal
);
11808 if (last_sal
.symtab
== 0)
11809 error (_("No source file specified."));
11815 /* We don't call resolve_sal_pc here. That's not as bad as it
11816 seems, because all existing breakpoints typically have both
11817 file/line and pc set. So, if clear is given file/line, we can
11818 match this to existing breakpoint without obtaining pc at all.
11820 We only support clearing given the address explicitly
11821 present in breakpoint table. Say, we've set breakpoint
11822 at file:line. There were several PC values for that file:line,
11823 due to optimization, all in one block.
11825 We've picked one PC value. If "clear" is issued with another
11826 PC corresponding to the same file:line, the breakpoint won't
11827 be cleared. We probably can still clear the breakpoint, but
11828 since the other PC value is never presented to user, user
11829 can only find it by guessing, and it does not seem important
11830 to support that. */
11832 /* For each line spec given, delete bps which correspond to it. Do
11833 it in two passes, solely to preserve the current behavior that
11834 from_tty is forced true if we delete more than one
11838 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11839 for (const auto &sal
: sals
)
11841 const char *sal_fullname
;
11843 /* If exact pc given, clear bpts at that pc.
11844 If line given (pc == 0), clear all bpts on specified line.
11845 If defaulting, clear all bpts on default line
11848 defaulting sal.pc != 0 tests to do
11853 1 0 <can't happen> */
11855 sal_fullname
= (sal
.symtab
== NULL
11856 ? NULL
: symtab_to_fullname (sal
.symtab
));
11858 /* Find all matching breakpoints and add them to 'found'. */
11859 ALL_BREAKPOINTS (b
)
11862 /* Are we going to delete b? */
11863 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11865 struct bp_location
*loc
= b
->loc
;
11866 for (; loc
; loc
= loc
->next
)
11868 /* If the user specified file:line, don't allow a PC
11869 match. This matches historical gdb behavior. */
11870 int pc_match
= (!sal
.explicit_line
11872 && (loc
->pspace
== sal
.pspace
)
11873 && (loc
->address
== sal
.pc
)
11874 && (!section_is_overlay (loc
->section
)
11875 || loc
->section
== sal
.section
));
11876 int line_match
= 0;
11878 if ((default_match
|| sal
.explicit_line
)
11879 && loc
->symtab
!= NULL
11880 && sal_fullname
!= NULL
11881 && sal
.pspace
== loc
->pspace
11882 && loc
->line_number
== sal
.line
11883 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11884 sal_fullname
) == 0)
11887 if (pc_match
|| line_match
)
11896 VEC_safe_push(breakpoint_p
, found
, b
);
11900 /* Now go thru the 'found' chain and delete them. */
11901 if (VEC_empty(breakpoint_p
, found
))
11904 error (_("No breakpoint at %s."), arg
);
11906 error (_("No breakpoint at this line."));
11909 /* Remove duplicates from the vec. */
11910 qsort (VEC_address (breakpoint_p
, found
),
11911 VEC_length (breakpoint_p
, found
),
11912 sizeof (breakpoint_p
),
11913 compare_breakpoints
);
11914 prev
= VEC_index (breakpoint_p
, found
, 0);
11915 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11919 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11924 if (VEC_length(breakpoint_p
, found
) > 1)
11925 from_tty
= 1; /* Always report if deleted more than one. */
11928 if (VEC_length(breakpoint_p
, found
) == 1)
11929 printf_unfiltered (_("Deleted breakpoint "));
11931 printf_unfiltered (_("Deleted breakpoints "));
11934 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11937 printf_unfiltered ("%d ", b
->number
);
11938 delete_breakpoint (b
);
11941 putchar_unfiltered ('\n');
11943 do_cleanups (cleanups
);
11946 /* Delete breakpoint in BS if they are `delete' breakpoints and
11947 all breakpoints that are marked for deletion, whether hit or not.
11948 This is called after any breakpoint is hit, or after errors. */
11951 breakpoint_auto_delete (bpstat bs
)
11953 struct breakpoint
*b
, *b_tmp
;
11955 for (; bs
; bs
= bs
->next
)
11956 if (bs
->breakpoint_at
11957 && bs
->breakpoint_at
->disposition
== disp_del
11959 delete_breakpoint (bs
->breakpoint_at
);
11961 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11963 if (b
->disposition
== disp_del_at_next_stop
)
11964 delete_breakpoint (b
);
11968 /* A comparison function for bp_location AP and BP being interfaced to
11969 qsort. Sort elements primarily by their ADDRESS (no matter what
11970 does breakpoint_address_is_meaningful say for its OWNER),
11971 secondarily by ordering first permanent elements and
11972 terciarily just ensuring the array is sorted stable way despite
11973 qsort being an unstable algorithm. */
11976 bp_locations_compare (const void *ap
, const void *bp
)
11978 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11979 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11981 if (a
->address
!= b
->address
)
11982 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11984 /* Sort locations at the same address by their pspace number, keeping
11985 locations of the same inferior (in a multi-inferior environment)
11988 if (a
->pspace
->num
!= b
->pspace
->num
)
11989 return ((a
->pspace
->num
> b
->pspace
->num
)
11990 - (a
->pspace
->num
< b
->pspace
->num
));
11992 /* Sort permanent breakpoints first. */
11993 if (a
->permanent
!= b
->permanent
)
11994 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11996 /* Make the internal GDB representation stable across GDB runs
11997 where A and B memory inside GDB can differ. Breakpoint locations of
11998 the same type at the same address can be sorted in arbitrary order. */
12000 if (a
->owner
->number
!= b
->owner
->number
)
12001 return ((a
->owner
->number
> b
->owner
->number
)
12002 - (a
->owner
->number
< b
->owner
->number
));
12004 return (a
> b
) - (a
< b
);
12007 /* Set bp_locations_placed_address_before_address_max and
12008 bp_locations_shadow_len_after_address_max according to the current
12009 content of the bp_locations array. */
12012 bp_locations_target_extensions_update (void)
12014 struct bp_location
*bl
, **blp_tmp
;
12016 bp_locations_placed_address_before_address_max
= 0;
12017 bp_locations_shadow_len_after_address_max
= 0;
12019 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12021 CORE_ADDR start
, end
, addr
;
12023 if (!bp_location_has_shadow (bl
))
12026 start
= bl
->target_info
.placed_address
;
12027 end
= start
+ bl
->target_info
.shadow_len
;
12029 gdb_assert (bl
->address
>= start
);
12030 addr
= bl
->address
- start
;
12031 if (addr
> bp_locations_placed_address_before_address_max
)
12032 bp_locations_placed_address_before_address_max
= addr
;
12034 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12036 gdb_assert (bl
->address
< end
);
12037 addr
= end
- bl
->address
;
12038 if (addr
> bp_locations_shadow_len_after_address_max
)
12039 bp_locations_shadow_len_after_address_max
= addr
;
12043 /* Download tracepoint locations if they haven't been. */
12046 download_tracepoint_locations (void)
12048 struct breakpoint
*b
;
12049 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12051 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12053 ALL_TRACEPOINTS (b
)
12055 struct bp_location
*bl
;
12056 struct tracepoint
*t
;
12057 int bp_location_downloaded
= 0;
12059 if ((b
->type
== bp_fast_tracepoint
12060 ? !may_insert_fast_tracepoints
12061 : !may_insert_tracepoints
))
12064 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12066 if (target_can_download_tracepoint ())
12067 can_download_tracepoint
= TRIBOOL_TRUE
;
12069 can_download_tracepoint
= TRIBOOL_FALSE
;
12072 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12075 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12077 /* In tracepoint, locations are _never_ duplicated, so
12078 should_be_inserted is equivalent to
12079 unduplicated_should_be_inserted. */
12080 if (!should_be_inserted (bl
) || bl
->inserted
)
12083 switch_to_program_space_and_thread (bl
->pspace
);
12085 target_download_tracepoint (bl
);
12088 bp_location_downloaded
= 1;
12090 t
= (struct tracepoint
*) b
;
12091 t
->number_on_target
= b
->number
;
12092 if (bp_location_downloaded
)
12093 observer_notify_breakpoint_modified (b
);
12097 /* Swap the insertion/duplication state between two locations. */
12100 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12102 const int left_inserted
= left
->inserted
;
12103 const int left_duplicate
= left
->duplicate
;
12104 const int left_needs_update
= left
->needs_update
;
12105 const struct bp_target_info left_target_info
= left
->target_info
;
12107 /* Locations of tracepoints can never be duplicated. */
12108 if (is_tracepoint (left
->owner
))
12109 gdb_assert (!left
->duplicate
);
12110 if (is_tracepoint (right
->owner
))
12111 gdb_assert (!right
->duplicate
);
12113 left
->inserted
= right
->inserted
;
12114 left
->duplicate
= right
->duplicate
;
12115 left
->needs_update
= right
->needs_update
;
12116 left
->target_info
= right
->target_info
;
12117 right
->inserted
= left_inserted
;
12118 right
->duplicate
= left_duplicate
;
12119 right
->needs_update
= left_needs_update
;
12120 right
->target_info
= left_target_info
;
12123 /* Force the re-insertion of the locations at ADDRESS. This is called
12124 once a new/deleted/modified duplicate location is found and we are evaluating
12125 conditions on the target's side. Such conditions need to be updated on
12129 force_breakpoint_reinsertion (struct bp_location
*bl
)
12131 struct bp_location
**locp
= NULL
, **loc2p
;
12132 struct bp_location
*loc
;
12133 CORE_ADDR address
= 0;
12136 address
= bl
->address
;
12137 pspace_num
= bl
->pspace
->num
;
12139 /* This is only meaningful if the target is
12140 evaluating conditions and if the user has
12141 opted for condition evaluation on the target's
12143 if (gdb_evaluates_breakpoint_condition_p ()
12144 || !target_supports_evaluation_of_breakpoint_conditions ())
12147 /* Flag all breakpoint locations with this address and
12148 the same program space as the location
12149 as "its condition has changed". We need to
12150 update the conditions on the target's side. */
12151 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12155 if (!is_breakpoint (loc
->owner
)
12156 || pspace_num
!= loc
->pspace
->num
)
12159 /* Flag the location appropriately. We use a different state to
12160 let everyone know that we already updated the set of locations
12161 with addr bl->address and program space bl->pspace. This is so
12162 we don't have to keep calling these functions just to mark locations
12163 that have already been marked. */
12164 loc
->condition_changed
= condition_updated
;
12166 /* Free the agent expression bytecode as well. We will compute
12168 loc
->cond_bytecode
.reset ();
12171 /* Called whether new breakpoints are created, or existing breakpoints
12172 deleted, to update the global location list and recompute which
12173 locations are duplicate of which.
12175 The INSERT_MODE flag determines whether locations may not, may, or
12176 shall be inserted now. See 'enum ugll_insert_mode' for more
12180 update_global_location_list (enum ugll_insert_mode insert_mode
)
12182 struct breakpoint
*b
;
12183 struct bp_location
**locp
, *loc
;
12184 struct cleanup
*cleanups
;
12185 /* Last breakpoint location address that was marked for update. */
12186 CORE_ADDR last_addr
= 0;
12187 /* Last breakpoint location program space that was marked for update. */
12188 int last_pspace_num
= -1;
12190 /* Used in the duplicates detection below. When iterating over all
12191 bp_locations, points to the first bp_location of a given address.
12192 Breakpoints and watchpoints of different types are never
12193 duplicates of each other. Keep one pointer for each type of
12194 breakpoint/watchpoint, so we only need to loop over all locations
12196 struct bp_location
*bp_loc_first
; /* breakpoint */
12197 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12198 struct bp_location
*awp_loc_first
; /* access watchpoint */
12199 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12201 /* Saved former bp_locations array which we compare against the newly
12202 built bp_locations from the current state of ALL_BREAKPOINTS. */
12203 struct bp_location
**old_locations
, **old_locp
;
12204 unsigned old_locations_count
;
12206 old_locations
= bp_locations
;
12207 old_locations_count
= bp_locations_count
;
12208 bp_locations
= NULL
;
12209 bp_locations_count
= 0;
12210 cleanups
= make_cleanup (xfree
, old_locations
);
12212 ALL_BREAKPOINTS (b
)
12213 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12214 bp_locations_count
++;
12216 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12217 locp
= bp_locations
;
12218 ALL_BREAKPOINTS (b
)
12219 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12221 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12222 bp_locations_compare
);
12224 bp_locations_target_extensions_update ();
12226 /* Identify bp_location instances that are no longer present in the
12227 new list, and therefore should be freed. Note that it's not
12228 necessary that those locations should be removed from inferior --
12229 if there's another location at the same address (previously
12230 marked as duplicate), we don't need to remove/insert the
12233 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12234 and former bp_location array state respectively. */
12236 locp
= bp_locations
;
12237 for (old_locp
= old_locations
;
12238 old_locp
< old_locations
+ old_locations_count
;
12241 struct bp_location
*old_loc
= *old_locp
;
12242 struct bp_location
**loc2p
;
12244 /* Tells if 'old_loc' is found among the new locations. If
12245 not, we have to free it. */
12246 int found_object
= 0;
12247 /* Tells if the location should remain inserted in the target. */
12248 int keep_in_target
= 0;
12251 /* Skip LOCP entries which will definitely never be needed.
12252 Stop either at or being the one matching OLD_LOC. */
12253 while (locp
< bp_locations
+ bp_locations_count
12254 && (*locp
)->address
< old_loc
->address
)
12258 (loc2p
< bp_locations
+ bp_locations_count
12259 && (*loc2p
)->address
== old_loc
->address
);
12262 /* Check if this is a new/duplicated location or a duplicated
12263 location that had its condition modified. If so, we want to send
12264 its condition to the target if evaluation of conditions is taking
12266 if ((*loc2p
)->condition_changed
== condition_modified
12267 && (last_addr
!= old_loc
->address
12268 || last_pspace_num
!= old_loc
->pspace
->num
))
12270 force_breakpoint_reinsertion (*loc2p
);
12271 last_pspace_num
= old_loc
->pspace
->num
;
12274 if (*loc2p
== old_loc
)
12278 /* We have already handled this address, update it so that we don't
12279 have to go through updates again. */
12280 last_addr
= old_loc
->address
;
12282 /* Target-side condition evaluation: Handle deleted locations. */
12284 force_breakpoint_reinsertion (old_loc
);
12286 /* If this location is no longer present, and inserted, look if
12287 there's maybe a new location at the same address. If so,
12288 mark that one inserted, and don't remove this one. This is
12289 needed so that we don't have a time window where a breakpoint
12290 at certain location is not inserted. */
12292 if (old_loc
->inserted
)
12294 /* If the location is inserted now, we might have to remove
12297 if (found_object
&& should_be_inserted (old_loc
))
12299 /* The location is still present in the location list,
12300 and still should be inserted. Don't do anything. */
12301 keep_in_target
= 1;
12305 /* This location still exists, but it won't be kept in the
12306 target since it may have been disabled. We proceed to
12307 remove its target-side condition. */
12309 /* The location is either no longer present, or got
12310 disabled. See if there's another location at the
12311 same address, in which case we don't need to remove
12312 this one from the target. */
12314 /* OLD_LOC comes from existing struct breakpoint. */
12315 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12318 (loc2p
< bp_locations
+ bp_locations_count
12319 && (*loc2p
)->address
== old_loc
->address
);
12322 struct bp_location
*loc2
= *loc2p
;
12324 if (breakpoint_locations_match (loc2
, old_loc
))
12326 /* Read watchpoint locations are switched to
12327 access watchpoints, if the former are not
12328 supported, but the latter are. */
12329 if (is_hardware_watchpoint (old_loc
->owner
))
12331 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12332 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12335 /* loc2 is a duplicated location. We need to check
12336 if it should be inserted in case it will be
12338 if (loc2
!= old_loc
12339 && unduplicated_should_be_inserted (loc2
))
12341 swap_insertion (old_loc
, loc2
);
12342 keep_in_target
= 1;
12350 if (!keep_in_target
)
12352 if (remove_breakpoint (old_loc
))
12354 /* This is just about all we can do. We could keep
12355 this location on the global list, and try to
12356 remove it next time, but there's no particular
12357 reason why we will succeed next time.
12359 Note that at this point, old_loc->owner is still
12360 valid, as delete_breakpoint frees the breakpoint
12361 only after calling us. */
12362 printf_filtered (_("warning: Error removing "
12363 "breakpoint %d\n"),
12364 old_loc
->owner
->number
);
12372 if (removed
&& target_is_non_stop_p ()
12373 && need_moribund_for_location_type (old_loc
))
12375 /* This location was removed from the target. In
12376 non-stop mode, a race condition is possible where
12377 we've removed a breakpoint, but stop events for that
12378 breakpoint are already queued and will arrive later.
12379 We apply an heuristic to be able to distinguish such
12380 SIGTRAPs from other random SIGTRAPs: we keep this
12381 breakpoint location for a bit, and will retire it
12382 after we see some number of events. The theory here
12383 is that reporting of events should, "on the average",
12384 be fair, so after a while we'll see events from all
12385 threads that have anything of interest, and no longer
12386 need to keep this breakpoint location around. We
12387 don't hold locations forever so to reduce chances of
12388 mistaking a non-breakpoint SIGTRAP for a breakpoint
12391 The heuristic failing can be disastrous on
12392 decr_pc_after_break targets.
12394 On decr_pc_after_break targets, like e.g., x86-linux,
12395 if we fail to recognize a late breakpoint SIGTRAP,
12396 because events_till_retirement has reached 0 too
12397 soon, we'll fail to do the PC adjustment, and report
12398 a random SIGTRAP to the user. When the user resumes
12399 the inferior, it will most likely immediately crash
12400 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12401 corrupted, because of being resumed e.g., in the
12402 middle of a multi-byte instruction, or skipped a
12403 one-byte instruction. This was actually seen happen
12404 on native x86-linux, and should be less rare on
12405 targets that do not support new thread events, like
12406 remote, due to the heuristic depending on
12409 Mistaking a random SIGTRAP for a breakpoint trap
12410 causes similar symptoms (PC adjustment applied when
12411 it shouldn't), but then again, playing with SIGTRAPs
12412 behind the debugger's back is asking for trouble.
12414 Since hardware watchpoint traps are always
12415 distinguishable from other traps, so we don't need to
12416 apply keep hardware watchpoint moribund locations
12417 around. We simply always ignore hardware watchpoint
12418 traps we can no longer explain. */
12420 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12421 old_loc
->owner
= NULL
;
12423 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12427 old_loc
->owner
= NULL
;
12428 decref_bp_location (&old_loc
);
12433 /* Rescan breakpoints at the same address and section, marking the
12434 first one as "first" and any others as "duplicates". This is so
12435 that the bpt instruction is only inserted once. If we have a
12436 permanent breakpoint at the same place as BPT, make that one the
12437 official one, and the rest as duplicates. Permanent breakpoints
12438 are sorted first for the same address.
12440 Do the same for hardware watchpoints, but also considering the
12441 watchpoint's type (regular/access/read) and length. */
12443 bp_loc_first
= NULL
;
12444 wp_loc_first
= NULL
;
12445 awp_loc_first
= NULL
;
12446 rwp_loc_first
= NULL
;
12447 ALL_BP_LOCATIONS (loc
, locp
)
12449 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12451 struct bp_location
**loc_first_p
;
12454 if (!unduplicated_should_be_inserted (loc
)
12455 || !breakpoint_address_is_meaningful (b
)
12456 /* Don't detect duplicate for tracepoint locations because they are
12457 never duplicated. See the comments in field `duplicate' of
12458 `struct bp_location'. */
12459 || is_tracepoint (b
))
12461 /* Clear the condition modification flag. */
12462 loc
->condition_changed
= condition_unchanged
;
12466 if (b
->type
== bp_hardware_watchpoint
)
12467 loc_first_p
= &wp_loc_first
;
12468 else if (b
->type
== bp_read_watchpoint
)
12469 loc_first_p
= &rwp_loc_first
;
12470 else if (b
->type
== bp_access_watchpoint
)
12471 loc_first_p
= &awp_loc_first
;
12473 loc_first_p
= &bp_loc_first
;
12475 if (*loc_first_p
== NULL
12476 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12477 || !breakpoint_locations_match (loc
, *loc_first_p
))
12479 *loc_first_p
= loc
;
12480 loc
->duplicate
= 0;
12482 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12484 loc
->needs_update
= 1;
12485 /* Clear the condition modification flag. */
12486 loc
->condition_changed
= condition_unchanged
;
12492 /* This and the above ensure the invariant that the first location
12493 is not duplicated, and is the inserted one.
12494 All following are marked as duplicated, and are not inserted. */
12496 swap_insertion (loc
, *loc_first_p
);
12497 loc
->duplicate
= 1;
12499 /* Clear the condition modification flag. */
12500 loc
->condition_changed
= condition_unchanged
;
12503 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12505 if (insert_mode
!= UGLL_DONT_INSERT
)
12506 insert_breakpoint_locations ();
12509 /* Even though the caller told us to not insert new
12510 locations, we may still need to update conditions on the
12511 target's side of breakpoints that were already inserted
12512 if the target is evaluating breakpoint conditions. We
12513 only update conditions for locations that are marked
12515 update_inserted_breakpoint_locations ();
12519 if (insert_mode
!= UGLL_DONT_INSERT
)
12520 download_tracepoint_locations ();
12522 do_cleanups (cleanups
);
12526 breakpoint_retire_moribund (void)
12528 struct bp_location
*loc
;
12531 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12532 if (--(loc
->events_till_retirement
) == 0)
12534 decref_bp_location (&loc
);
12535 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12541 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12546 update_global_location_list (insert_mode
);
12548 CATCH (e
, RETURN_MASK_ERROR
)
12554 /* Clear BKP from a BPS. */
12557 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12561 for (bs
= bps
; bs
; bs
= bs
->next
)
12562 if (bs
->breakpoint_at
== bpt
)
12564 bs
->breakpoint_at
= NULL
;
12565 bs
->old_val
= NULL
;
12566 /* bs->commands will be freed later. */
12570 /* Callback for iterate_over_threads. */
12572 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12574 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12576 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12580 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12584 say_where (struct breakpoint
*b
)
12586 struct value_print_options opts
;
12588 get_user_print_options (&opts
);
12590 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12592 if (b
->loc
== NULL
)
12594 /* For pending locations, the output differs slightly based
12595 on b->extra_string. If this is non-NULL, it contains either
12596 a condition or dprintf arguments. */
12597 if (b
->extra_string
== NULL
)
12599 printf_filtered (_(" (%s) pending."),
12600 event_location_to_string (b
->location
.get ()));
12602 else if (b
->type
== bp_dprintf
)
12604 printf_filtered (_(" (%s,%s) pending."),
12605 event_location_to_string (b
->location
.get ()),
12610 printf_filtered (_(" (%s %s) pending."),
12611 event_location_to_string (b
->location
.get ()),
12617 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12619 printf_filtered (" at ");
12620 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12623 if (b
->loc
->symtab
!= NULL
)
12625 /* If there is a single location, we can print the location
12627 if (b
->loc
->next
== NULL
)
12628 printf_filtered (": file %s, line %d.",
12629 symtab_to_filename_for_display (b
->loc
->symtab
),
12630 b
->loc
->line_number
);
12632 /* This is not ideal, but each location may have a
12633 different file name, and this at least reflects the
12634 real situation somewhat. */
12635 printf_filtered (": %s.",
12636 event_location_to_string (b
->location
.get ()));
12641 struct bp_location
*loc
= b
->loc
;
12643 for (; loc
; loc
= loc
->next
)
12645 printf_filtered (" (%d locations)", n
);
12650 /* Default bp_location_ops methods. */
12653 bp_location_dtor (struct bp_location
*self
)
12655 xfree (self
->function_name
);
12658 static const struct bp_location_ops bp_location_ops
=
12663 /* Destructor for the breakpoint base class. */
12665 breakpoint::~breakpoint ()
12667 decref_counted_command_line (&this->commands
);
12668 xfree (this->cond_string
);
12669 xfree (this->extra_string
);
12670 xfree (this->filter
);
12673 static struct bp_location
*
12674 base_breakpoint_allocate_location (struct breakpoint
*self
)
12676 return new bp_location (&bp_location_ops
, self
);
12680 base_breakpoint_re_set (struct breakpoint
*b
)
12682 /* Nothing to re-set. */
12685 #define internal_error_pure_virtual_called() \
12686 gdb_assert_not_reached ("pure virtual function called")
12689 base_breakpoint_insert_location (struct bp_location
*bl
)
12691 internal_error_pure_virtual_called ();
12695 base_breakpoint_remove_location (struct bp_location
*bl
,
12696 enum remove_bp_reason reason
)
12698 internal_error_pure_virtual_called ();
12702 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12703 struct address_space
*aspace
,
12705 const struct target_waitstatus
*ws
)
12707 internal_error_pure_virtual_called ();
12711 base_breakpoint_check_status (bpstat bs
)
12716 /* A "works_in_software_mode" breakpoint_ops method that just internal
12720 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12722 internal_error_pure_virtual_called ();
12725 /* A "resources_needed" breakpoint_ops method that just internal
12729 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12731 internal_error_pure_virtual_called ();
12734 static enum print_stop_action
12735 base_breakpoint_print_it (bpstat bs
)
12737 internal_error_pure_virtual_called ();
12741 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12742 struct ui_out
*uiout
)
12748 base_breakpoint_print_mention (struct breakpoint
*b
)
12750 internal_error_pure_virtual_called ();
12754 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12756 internal_error_pure_virtual_called ();
12760 base_breakpoint_create_sals_from_location
12761 (const struct event_location
*location
,
12762 struct linespec_result
*canonical
,
12763 enum bptype type_wanted
)
12765 internal_error_pure_virtual_called ();
12769 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12770 struct linespec_result
*c
,
12771 gdb::unique_xmalloc_ptr
<char> cond_string
,
12772 gdb::unique_xmalloc_ptr
<char> extra_string
,
12773 enum bptype type_wanted
,
12774 enum bpdisp disposition
,
12776 int task
, int ignore_count
,
12777 const struct breakpoint_ops
*o
,
12778 int from_tty
, int enabled
,
12779 int internal
, unsigned flags
)
12781 internal_error_pure_virtual_called ();
12784 static std::vector
<symtab_and_line
>
12785 base_breakpoint_decode_location (struct breakpoint
*b
,
12786 const struct event_location
*location
,
12787 struct program_space
*search_pspace
)
12789 internal_error_pure_virtual_called ();
12792 /* The default 'explains_signal' method. */
12795 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12800 /* The default "after_condition_true" method. */
12803 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12805 /* Nothing to do. */
12808 struct breakpoint_ops base_breakpoint_ops
=
12810 base_breakpoint_allocate_location
,
12811 base_breakpoint_re_set
,
12812 base_breakpoint_insert_location
,
12813 base_breakpoint_remove_location
,
12814 base_breakpoint_breakpoint_hit
,
12815 base_breakpoint_check_status
,
12816 base_breakpoint_resources_needed
,
12817 base_breakpoint_works_in_software_mode
,
12818 base_breakpoint_print_it
,
12820 base_breakpoint_print_one_detail
,
12821 base_breakpoint_print_mention
,
12822 base_breakpoint_print_recreate
,
12823 base_breakpoint_create_sals_from_location
,
12824 base_breakpoint_create_breakpoints_sal
,
12825 base_breakpoint_decode_location
,
12826 base_breakpoint_explains_signal
,
12827 base_breakpoint_after_condition_true
,
12830 /* Default breakpoint_ops methods. */
12833 bkpt_re_set (struct breakpoint
*b
)
12835 /* FIXME: is this still reachable? */
12836 if (breakpoint_event_location_empty_p (b
))
12838 /* Anything without a location can't be re-set. */
12839 delete_breakpoint (b
);
12843 breakpoint_re_set_default (b
);
12847 bkpt_insert_location (struct bp_location
*bl
)
12849 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12851 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12852 bl
->target_info
.placed_address
= addr
;
12854 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12855 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12857 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12861 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12863 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12864 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12866 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12870 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12871 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12872 const struct target_waitstatus
*ws
)
12874 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12875 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12878 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12882 if (overlay_debugging
/* unmapped overlay section */
12883 && section_is_overlay (bl
->section
)
12884 && !section_is_mapped (bl
->section
))
12891 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12892 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12893 const struct target_waitstatus
*ws
)
12895 if (dprintf_style
== dprintf_style_agent
12896 && target_can_run_breakpoint_commands ())
12898 /* An agent-style dprintf never causes a stop. If we see a trap
12899 for this address it must be for a breakpoint that happens to
12900 be set at the same address. */
12904 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12908 bkpt_resources_needed (const struct bp_location
*bl
)
12910 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12915 static enum print_stop_action
12916 bkpt_print_it (bpstat bs
)
12918 struct breakpoint
*b
;
12919 const struct bp_location
*bl
;
12921 struct ui_out
*uiout
= current_uiout
;
12923 gdb_assert (bs
->bp_location_at
!= NULL
);
12925 bl
= bs
->bp_location_at
;
12926 b
= bs
->breakpoint_at
;
12928 bp_temp
= b
->disposition
== disp_del
;
12929 if (bl
->address
!= bl
->requested_address
)
12930 breakpoint_adjustment_warning (bl
->requested_address
,
12933 annotate_breakpoint (b
->number
);
12934 maybe_print_thread_hit_breakpoint (uiout
);
12937 uiout
->text ("Temporary breakpoint ");
12939 uiout
->text ("Breakpoint ");
12940 if (uiout
->is_mi_like_p ())
12942 uiout
->field_string ("reason",
12943 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12944 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12946 uiout
->field_int ("bkptno", b
->number
);
12947 uiout
->text (", ");
12949 return PRINT_SRC_AND_LOC
;
12953 bkpt_print_mention (struct breakpoint
*b
)
12955 if (current_uiout
->is_mi_like_p ())
12960 case bp_breakpoint
:
12961 case bp_gnu_ifunc_resolver
:
12962 if (b
->disposition
== disp_del
)
12963 printf_filtered (_("Temporary breakpoint"));
12965 printf_filtered (_("Breakpoint"));
12966 printf_filtered (_(" %d"), b
->number
);
12967 if (b
->type
== bp_gnu_ifunc_resolver
)
12968 printf_filtered (_(" at gnu-indirect-function resolver"));
12970 case bp_hardware_breakpoint
:
12971 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12974 printf_filtered (_("Dprintf %d"), b
->number
);
12982 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12984 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12985 fprintf_unfiltered (fp
, "tbreak");
12986 else if (tp
->type
== bp_breakpoint
)
12987 fprintf_unfiltered (fp
, "break");
12988 else if (tp
->type
== bp_hardware_breakpoint
12989 && tp
->disposition
== disp_del
)
12990 fprintf_unfiltered (fp
, "thbreak");
12991 else if (tp
->type
== bp_hardware_breakpoint
)
12992 fprintf_unfiltered (fp
, "hbreak");
12994 internal_error (__FILE__
, __LINE__
,
12995 _("unhandled breakpoint type %d"), (int) tp
->type
);
12997 fprintf_unfiltered (fp
, " %s",
12998 event_location_to_string (tp
->location
.get ()));
13000 /* Print out extra_string if this breakpoint is pending. It might
13001 contain, for example, conditions that were set by the user. */
13002 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13003 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13005 print_recreate_thread (tp
, fp
);
13009 bkpt_create_sals_from_location (const struct event_location
*location
,
13010 struct linespec_result
*canonical
,
13011 enum bptype type_wanted
)
13013 create_sals_from_location_default (location
, canonical
, type_wanted
);
13017 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13018 struct linespec_result
*canonical
,
13019 gdb::unique_xmalloc_ptr
<char> cond_string
,
13020 gdb::unique_xmalloc_ptr
<char> extra_string
,
13021 enum bptype type_wanted
,
13022 enum bpdisp disposition
,
13024 int task
, int ignore_count
,
13025 const struct breakpoint_ops
*ops
,
13026 int from_tty
, int enabled
,
13027 int internal
, unsigned flags
)
13029 create_breakpoints_sal_default (gdbarch
, canonical
,
13030 std::move (cond_string
),
13031 std::move (extra_string
),
13033 disposition
, thread
, task
,
13034 ignore_count
, ops
, from_tty
,
13035 enabled
, internal
, flags
);
13038 static std::vector
<symtab_and_line
>
13039 bkpt_decode_location (struct breakpoint
*b
,
13040 const struct event_location
*location
,
13041 struct program_space
*search_pspace
)
13043 return decode_location_default (b
, location
, search_pspace
);
13046 /* Virtual table for internal breakpoints. */
13049 internal_bkpt_re_set (struct breakpoint
*b
)
13053 /* Delete overlay event and longjmp master breakpoints; they
13054 will be reset later by breakpoint_re_set. */
13055 case bp_overlay_event
:
13056 case bp_longjmp_master
:
13057 case bp_std_terminate_master
:
13058 case bp_exception_master
:
13059 delete_breakpoint (b
);
13062 /* This breakpoint is special, it's set up when the inferior
13063 starts and we really don't want to touch it. */
13064 case bp_shlib_event
:
13066 /* Like bp_shlib_event, this breakpoint type is special. Once
13067 it is set up, we do not want to touch it. */
13068 case bp_thread_event
:
13074 internal_bkpt_check_status (bpstat bs
)
13076 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13078 /* If requested, stop when the dynamic linker notifies GDB of
13079 events. This allows the user to get control and place
13080 breakpoints in initializer routines for dynamically loaded
13081 objects (among other things). */
13082 bs
->stop
= stop_on_solib_events
;
13083 bs
->print
= stop_on_solib_events
;
13089 static enum print_stop_action
13090 internal_bkpt_print_it (bpstat bs
)
13092 struct breakpoint
*b
;
13094 b
= bs
->breakpoint_at
;
13098 case bp_shlib_event
:
13099 /* Did we stop because the user set the stop_on_solib_events
13100 variable? (If so, we report this as a generic, "Stopped due
13101 to shlib event" message.) */
13102 print_solib_event (0);
13105 case bp_thread_event
:
13106 /* Not sure how we will get here.
13107 GDB should not stop for these breakpoints. */
13108 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13111 case bp_overlay_event
:
13112 /* By analogy with the thread event, GDB should not stop for these. */
13113 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13116 case bp_longjmp_master
:
13117 /* These should never be enabled. */
13118 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13121 case bp_std_terminate_master
:
13122 /* These should never be enabled. */
13123 printf_filtered (_("std::terminate Master Breakpoint: "
13124 "gdb should not stop!\n"));
13127 case bp_exception_master
:
13128 /* These should never be enabled. */
13129 printf_filtered (_("Exception Master Breakpoint: "
13130 "gdb should not stop!\n"));
13134 return PRINT_NOTHING
;
13138 internal_bkpt_print_mention (struct breakpoint
*b
)
13140 /* Nothing to mention. These breakpoints are internal. */
13143 /* Virtual table for momentary breakpoints */
13146 momentary_bkpt_re_set (struct breakpoint
*b
)
13148 /* Keep temporary breakpoints, which can be encountered when we step
13149 over a dlopen call and solib_add is resetting the breakpoints.
13150 Otherwise these should have been blown away via the cleanup chain
13151 or by breakpoint_init_inferior when we rerun the executable. */
13155 momentary_bkpt_check_status (bpstat bs
)
13157 /* Nothing. The point of these breakpoints is causing a stop. */
13160 static enum print_stop_action
13161 momentary_bkpt_print_it (bpstat bs
)
13163 return PRINT_UNKNOWN
;
13167 momentary_bkpt_print_mention (struct breakpoint
*b
)
13169 /* Nothing to mention. These breakpoints are internal. */
13172 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13174 It gets cleared already on the removal of the first one of such placed
13175 breakpoints. This is OK as they get all removed altogether. */
13177 longjmp_breakpoint::~longjmp_breakpoint ()
13179 thread_info
*tp
= find_thread_global_id (this->thread
);
13182 tp
->initiating_frame
= null_frame_id
;
13185 /* Specific methods for probe breakpoints. */
13188 bkpt_probe_insert_location (struct bp_location
*bl
)
13190 int v
= bkpt_insert_location (bl
);
13194 /* The insertion was successful, now let's set the probe's semaphore
13196 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13197 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13206 bkpt_probe_remove_location (struct bp_location
*bl
,
13207 enum remove_bp_reason reason
)
13209 /* Let's clear the semaphore before removing the location. */
13210 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13211 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13215 return bkpt_remove_location (bl
, reason
);
13219 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13220 struct linespec_result
*canonical
,
13221 enum bptype type_wanted
)
13223 struct linespec_sals lsal
;
13225 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13227 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13228 canonical
->lsals
.push_back (std::move (lsal
));
13231 static std::vector
<symtab_and_line
>
13232 bkpt_probe_decode_location (struct breakpoint
*b
,
13233 const struct event_location
*location
,
13234 struct program_space
*search_pspace
)
13236 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
13238 error (_("probe not found"));
13242 /* The breakpoint_ops structure to be used in tracepoints. */
13245 tracepoint_re_set (struct breakpoint
*b
)
13247 breakpoint_re_set_default (b
);
13251 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13252 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13253 const struct target_waitstatus
*ws
)
13255 /* By definition, the inferior does not report stops at
13261 tracepoint_print_one_detail (const struct breakpoint
*self
,
13262 struct ui_out
*uiout
)
13264 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13265 if (tp
->static_trace_marker_id
)
13267 gdb_assert (self
->type
== bp_static_tracepoint
);
13269 uiout
->text ("\tmarker id is ");
13270 uiout
->field_string ("static-tracepoint-marker-string-id",
13271 tp
->static_trace_marker_id
);
13272 uiout
->text ("\n");
13277 tracepoint_print_mention (struct breakpoint
*b
)
13279 if (current_uiout
->is_mi_like_p ())
13284 case bp_tracepoint
:
13285 printf_filtered (_("Tracepoint"));
13286 printf_filtered (_(" %d"), b
->number
);
13288 case bp_fast_tracepoint
:
13289 printf_filtered (_("Fast tracepoint"));
13290 printf_filtered (_(" %d"), b
->number
);
13292 case bp_static_tracepoint
:
13293 printf_filtered (_("Static tracepoint"));
13294 printf_filtered (_(" %d"), b
->number
);
13297 internal_error (__FILE__
, __LINE__
,
13298 _("unhandled tracepoint type %d"), (int) b
->type
);
13305 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13307 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13309 if (self
->type
== bp_fast_tracepoint
)
13310 fprintf_unfiltered (fp
, "ftrace");
13311 else if (self
->type
== bp_static_tracepoint
)
13312 fprintf_unfiltered (fp
, "strace");
13313 else if (self
->type
== bp_tracepoint
)
13314 fprintf_unfiltered (fp
, "trace");
13316 internal_error (__FILE__
, __LINE__
,
13317 _("unhandled tracepoint type %d"), (int) self
->type
);
13319 fprintf_unfiltered (fp
, " %s",
13320 event_location_to_string (self
->location
.get ()));
13321 print_recreate_thread (self
, fp
);
13323 if (tp
->pass_count
)
13324 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13328 tracepoint_create_sals_from_location (const struct event_location
*location
,
13329 struct linespec_result
*canonical
,
13330 enum bptype type_wanted
)
13332 create_sals_from_location_default (location
, canonical
, type_wanted
);
13336 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13337 struct linespec_result
*canonical
,
13338 gdb::unique_xmalloc_ptr
<char> cond_string
,
13339 gdb::unique_xmalloc_ptr
<char> extra_string
,
13340 enum bptype type_wanted
,
13341 enum bpdisp disposition
,
13343 int task
, int ignore_count
,
13344 const struct breakpoint_ops
*ops
,
13345 int from_tty
, int enabled
,
13346 int internal
, unsigned flags
)
13348 create_breakpoints_sal_default (gdbarch
, canonical
,
13349 std::move (cond_string
),
13350 std::move (extra_string
),
13352 disposition
, thread
, task
,
13353 ignore_count
, ops
, from_tty
,
13354 enabled
, internal
, flags
);
13357 static std::vector
<symtab_and_line
>
13358 tracepoint_decode_location (struct breakpoint
*b
,
13359 const struct event_location
*location
,
13360 struct program_space
*search_pspace
)
13362 return decode_location_default (b
, location
, search_pspace
);
13365 struct breakpoint_ops tracepoint_breakpoint_ops
;
13367 /* The breakpoint_ops structure to be use on tracepoints placed in a
13371 tracepoint_probe_create_sals_from_location
13372 (const struct event_location
*location
,
13373 struct linespec_result
*canonical
,
13374 enum bptype type_wanted
)
13376 /* We use the same method for breakpoint on probes. */
13377 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13380 static std::vector
<symtab_and_line
>
13381 tracepoint_probe_decode_location (struct breakpoint
*b
,
13382 const struct event_location
*location
,
13383 struct program_space
*search_pspace
)
13385 /* We use the same method for breakpoint on probes. */
13386 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13389 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13391 /* Dprintf breakpoint_ops methods. */
13394 dprintf_re_set (struct breakpoint
*b
)
13396 breakpoint_re_set_default (b
);
13398 /* extra_string should never be non-NULL for dprintf. */
13399 gdb_assert (b
->extra_string
!= NULL
);
13401 /* 1 - connect to target 1, that can run breakpoint commands.
13402 2 - create a dprintf, which resolves fine.
13403 3 - disconnect from target 1
13404 4 - connect to target 2, that can NOT run breakpoint commands.
13406 After steps #3/#4, you'll want the dprintf command list to
13407 be updated, because target 1 and 2 may well return different
13408 answers for target_can_run_breakpoint_commands().
13409 Given absence of finer grained resetting, we get to do
13410 it all the time. */
13411 if (b
->extra_string
!= NULL
)
13412 update_dprintf_command_list (b
);
13415 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13418 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13420 fprintf_unfiltered (fp
, "dprintf %s,%s",
13421 event_location_to_string (tp
->location
.get ()),
13423 print_recreate_thread (tp
, fp
);
13426 /* Implement the "after_condition_true" breakpoint_ops method for
13429 dprintf's are implemented with regular commands in their command
13430 list, but we run the commands here instead of before presenting the
13431 stop to the user, as dprintf's don't actually cause a stop. This
13432 also makes it so that the commands of multiple dprintfs at the same
13433 address are all handled. */
13436 dprintf_after_condition_true (struct bpstats
*bs
)
13438 struct cleanup
*old_chain
;
13439 struct bpstats tmp_bs
= { NULL
};
13440 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13442 /* dprintf's never cause a stop. This wasn't set in the
13443 check_status hook instead because that would make the dprintf's
13444 condition not be evaluated. */
13447 /* Run the command list here. Take ownership of it instead of
13448 copying. We never want these commands to run later in
13449 bpstat_do_actions, if a breakpoint that causes a stop happens to
13450 be set at same address as this dprintf, or even if running the
13451 commands here throws. */
13452 tmp_bs
.commands
= bs
->commands
;
13453 bs
->commands
= NULL
;
13454 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13456 bpstat_do_actions_1 (&tmp_bs_p
);
13458 /* 'tmp_bs.commands' will usually be NULL by now, but
13459 bpstat_do_actions_1 may return early without processing the whole
13461 do_cleanups (old_chain
);
13464 /* The breakpoint_ops structure to be used on static tracepoints with
13468 strace_marker_create_sals_from_location (const struct event_location
*location
,
13469 struct linespec_result
*canonical
,
13470 enum bptype type_wanted
)
13472 struct linespec_sals lsal
;
13473 const char *arg_start
, *arg
;
13475 struct cleanup
*cleanup
;
13477 arg
= arg_start
= get_linespec_location (location
);
13478 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13480 str
= savestring (arg_start
, arg
- arg_start
);
13481 cleanup
= make_cleanup (xfree
, str
);
13482 canonical
->location
= new_linespec_location (&str
);
13483 do_cleanups (cleanup
);
13486 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13487 canonical
->lsals
.push_back (std::move (lsal
));
13491 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13492 struct linespec_result
*canonical
,
13493 gdb::unique_xmalloc_ptr
<char> cond_string
,
13494 gdb::unique_xmalloc_ptr
<char> extra_string
,
13495 enum bptype type_wanted
,
13496 enum bpdisp disposition
,
13498 int task
, int ignore_count
,
13499 const struct breakpoint_ops
*ops
,
13500 int from_tty
, int enabled
,
13501 int internal
, unsigned flags
)
13503 const linespec_sals
&lsal
= canonical
->lsals
[0];
13505 /* If the user is creating a static tracepoint by marker id
13506 (strace -m MARKER_ID), then store the sals index, so that
13507 breakpoint_re_set can try to match up which of the newly
13508 found markers corresponds to this one, and, don't try to
13509 expand multiple locations for each sal, given than SALS
13510 already should contain all sals for MARKER_ID. */
13512 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13514 event_location_up location
13515 = copy_event_location (canonical
->location
.get ());
13517 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13518 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13519 std::move (location
), NULL
,
13520 std::move (cond_string
),
13521 std::move (extra_string
),
13522 type_wanted
, disposition
,
13523 thread
, task
, ignore_count
, ops
,
13524 from_tty
, enabled
, internal
, flags
,
13525 canonical
->special_display
);
13526 /* Given that its possible to have multiple markers with
13527 the same string id, if the user is creating a static
13528 tracepoint by marker id ("strace -m MARKER_ID"), then
13529 store the sals index, so that breakpoint_re_set can
13530 try to match up which of the newly found markers
13531 corresponds to this one */
13532 tp
->static_trace_marker_id_idx
= i
;
13534 install_breakpoint (internal
, std::move (tp
), 0);
13538 static std::vector
<symtab_and_line
>
13539 strace_marker_decode_location (struct breakpoint
*b
,
13540 const struct event_location
*location
,
13541 struct program_space
*search_pspace
)
13543 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13544 const char *s
= get_linespec_location (location
);
13546 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13547 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13549 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13554 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13557 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13560 strace_marker_p (struct breakpoint
*b
)
13562 return b
->ops
== &strace_marker_breakpoint_ops
;
13565 /* Delete a breakpoint and clean up all traces of it in the data
13569 delete_breakpoint (struct breakpoint
*bpt
)
13571 struct breakpoint
*b
;
13573 gdb_assert (bpt
!= NULL
);
13575 /* Has this bp already been deleted? This can happen because
13576 multiple lists can hold pointers to bp's. bpstat lists are
13579 One example of this happening is a watchpoint's scope bp. When
13580 the scope bp triggers, we notice that the watchpoint is out of
13581 scope, and delete it. We also delete its scope bp. But the
13582 scope bp is marked "auto-deleting", and is already on a bpstat.
13583 That bpstat is then checked for auto-deleting bp's, which are
13586 A real solution to this problem might involve reference counts in
13587 bp's, and/or giving them pointers back to their referencing
13588 bpstat's, and teaching delete_breakpoint to only free a bp's
13589 storage when no more references were extent. A cheaper bandaid
13591 if (bpt
->type
== bp_none
)
13594 /* At least avoid this stale reference until the reference counting
13595 of breakpoints gets resolved. */
13596 if (bpt
->related_breakpoint
!= bpt
)
13598 struct breakpoint
*related
;
13599 struct watchpoint
*w
;
13601 if (bpt
->type
== bp_watchpoint_scope
)
13602 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13603 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13604 w
= (struct watchpoint
*) bpt
;
13608 watchpoint_del_at_next_stop (w
);
13610 /* Unlink bpt from the bpt->related_breakpoint ring. */
13611 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13612 related
= related
->related_breakpoint
);
13613 related
->related_breakpoint
= bpt
->related_breakpoint
;
13614 bpt
->related_breakpoint
= bpt
;
13617 /* watch_command_1 creates a watchpoint but only sets its number if
13618 update_watchpoint succeeds in creating its bp_locations. If there's
13619 a problem in that process, we'll be asked to delete the half-created
13620 watchpoint. In that case, don't announce the deletion. */
13622 observer_notify_breakpoint_deleted (bpt
);
13624 if (breakpoint_chain
== bpt
)
13625 breakpoint_chain
= bpt
->next
;
13627 ALL_BREAKPOINTS (b
)
13628 if (b
->next
== bpt
)
13630 b
->next
= bpt
->next
;
13634 /* Be sure no bpstat's are pointing at the breakpoint after it's
13636 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13637 in all threads for now. Note that we cannot just remove bpstats
13638 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13639 commands are associated with the bpstat; if we remove it here,
13640 then the later call to bpstat_do_actions (&stop_bpstat); in
13641 event-top.c won't do anything, and temporary breakpoints with
13642 commands won't work. */
13644 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13646 /* Now that breakpoint is removed from breakpoint list, update the
13647 global location list. This will remove locations that used to
13648 belong to this breakpoint. Do this before freeing the breakpoint
13649 itself, since remove_breakpoint looks at location's owner. It
13650 might be better design to have location completely
13651 self-contained, but it's not the case now. */
13652 update_global_location_list (UGLL_DONT_INSERT
);
13654 /* On the chance that someone will soon try again to delete this
13655 same bp, we mark it as deleted before freeing its storage. */
13656 bpt
->type
= bp_none
;
13661 do_delete_breakpoint_cleanup (void *b
)
13663 delete_breakpoint ((struct breakpoint
*) b
);
13667 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13669 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13672 /* Iterator function to call a user-provided callback function once
13673 for each of B and its related breakpoints. */
13676 iterate_over_related_breakpoints (struct breakpoint
*b
,
13677 void (*function
) (struct breakpoint
*,
13681 struct breakpoint
*related
;
13686 struct breakpoint
*next
;
13688 /* FUNCTION may delete RELATED. */
13689 next
= related
->related_breakpoint
;
13691 if (next
== related
)
13693 /* RELATED is the last ring entry. */
13694 function (related
, data
);
13696 /* FUNCTION may have deleted it, so we'd never reach back to
13697 B. There's nothing left to do anyway, so just break
13702 function (related
, data
);
13706 while (related
!= b
);
13710 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13712 delete_breakpoint (b
);
13715 /* A callback for map_breakpoint_numbers that calls
13716 delete_breakpoint. */
13719 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13721 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13725 delete_command (char *arg
, int from_tty
)
13727 struct breakpoint
*b
, *b_tmp
;
13733 int breaks_to_delete
= 0;
13735 /* Delete all breakpoints if no argument. Do not delete
13736 internal breakpoints, these have to be deleted with an
13737 explicit breakpoint number argument. */
13738 ALL_BREAKPOINTS (b
)
13739 if (user_breakpoint_p (b
))
13741 breaks_to_delete
= 1;
13745 /* Ask user only if there are some breakpoints to delete. */
13747 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13749 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13750 if (user_breakpoint_p (b
))
13751 delete_breakpoint (b
);
13755 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13758 /* Return true if all locations of B bound to PSPACE are pending. If
13759 PSPACE is NULL, all locations of all program spaces are
13763 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13765 struct bp_location
*loc
;
13767 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13768 if ((pspace
== NULL
13769 || loc
->pspace
== pspace
)
13770 && !loc
->shlib_disabled
13771 && !loc
->pspace
->executing_startup
)
13776 /* Subroutine of update_breakpoint_locations to simplify it.
13777 Return non-zero if multiple fns in list LOC have the same name.
13778 Null names are ignored. */
13781 ambiguous_names_p (struct bp_location
*loc
)
13783 struct bp_location
*l
;
13784 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13785 (int (*) (const void *,
13786 const void *)) streq
,
13787 NULL
, xcalloc
, xfree
);
13789 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13792 const char *name
= l
->function_name
;
13794 /* Allow for some names to be NULL, ignore them. */
13798 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13800 /* NOTE: We can assume slot != NULL here because xcalloc never
13804 htab_delete (htab
);
13810 htab_delete (htab
);
13814 /* When symbols change, it probably means the sources changed as well,
13815 and it might mean the static tracepoint markers are no longer at
13816 the same address or line numbers they used to be at last we
13817 checked. Losing your static tracepoints whenever you rebuild is
13818 undesirable. This function tries to resync/rematch gdb static
13819 tracepoints with the markers on the target, for static tracepoints
13820 that have not been set by marker id. Static tracepoint that have
13821 been set by marker id are reset by marker id in breakpoint_re_set.
13824 1) For a tracepoint set at a specific address, look for a marker at
13825 the old PC. If one is found there, assume to be the same marker.
13826 If the name / string id of the marker found is different from the
13827 previous known name, assume that means the user renamed the marker
13828 in the sources, and output a warning.
13830 2) For a tracepoint set at a given line number, look for a marker
13831 at the new address of the old line number. If one is found there,
13832 assume to be the same marker. If the name / string id of the
13833 marker found is different from the previous known name, assume that
13834 means the user renamed the marker in the sources, and output a
13837 3) If a marker is no longer found at the same address or line, it
13838 may mean the marker no longer exists. But it may also just mean
13839 the code changed a bit. Maybe the user added a few lines of code
13840 that made the marker move up or down (in line number terms). Ask
13841 the target for info about the marker with the string id as we knew
13842 it. If found, update line number and address in the matching
13843 static tracepoint. This will get confused if there's more than one
13844 marker with the same ID (possible in UST, although unadvised
13845 precisely because it confuses tools). */
13847 static struct symtab_and_line
13848 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13850 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13851 struct static_tracepoint_marker marker
;
13856 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13858 if (target_static_tracepoint_marker_at (pc
, &marker
))
13860 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13861 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13863 tp
->static_trace_marker_id
, marker
.str_id
);
13865 xfree (tp
->static_trace_marker_id
);
13866 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13867 release_static_tracepoint_marker (&marker
);
13872 /* Old marker wasn't found on target at lineno. Try looking it up
13874 if (!sal
.explicit_pc
13876 && sal
.symtab
!= NULL
13877 && tp
->static_trace_marker_id
!= NULL
)
13879 VEC(static_tracepoint_marker_p
) *markers
;
13882 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13884 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13886 struct symtab_and_line sal2
;
13887 struct symbol
*sym
;
13888 struct static_tracepoint_marker
*tpmarker
;
13889 struct ui_out
*uiout
= current_uiout
;
13890 struct explicit_location explicit_loc
;
13892 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13894 xfree (tp
->static_trace_marker_id
);
13895 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13897 warning (_("marker for static tracepoint %d (%s) not "
13898 "found at previous line number"),
13899 b
->number
, tp
->static_trace_marker_id
);
13903 sal2
.pc
= tpmarker
->address
;
13905 sal2
= find_pc_line (tpmarker
->address
, 0);
13906 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13907 uiout
->text ("Now in ");
13910 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13911 uiout
->text (" at ");
13913 uiout
->field_string ("file",
13914 symtab_to_filename_for_display (sal2
.symtab
));
13917 if (uiout
->is_mi_like_p ())
13919 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13921 uiout
->field_string ("fullname", fullname
);
13924 uiout
->field_int ("line", sal2
.line
);
13925 uiout
->text ("\n");
13927 b
->loc
->line_number
= sal2
.line
;
13928 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13930 b
->location
.reset (NULL
);
13931 initialize_explicit_location (&explicit_loc
);
13932 explicit_loc
.source_filename
13933 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13934 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13935 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13936 b
->location
= new_explicit_location (&explicit_loc
);
13938 /* Might be nice to check if function changed, and warn if
13941 release_static_tracepoint_marker (tpmarker
);
13947 /* Returns 1 iff locations A and B are sufficiently same that
13948 we don't need to report breakpoint as changed. */
13951 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13955 if (a
->address
!= b
->address
)
13958 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13961 if (a
->enabled
!= b
->enabled
)
13968 if ((a
== NULL
) != (b
== NULL
))
13974 /* Split all locations of B that are bound to PSPACE out of B's
13975 location list to a separate list and return that list's head. If
13976 PSPACE is NULL, hoist out all locations of B. */
13978 static struct bp_location
*
13979 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13981 struct bp_location head
;
13982 struct bp_location
*i
= b
->loc
;
13983 struct bp_location
**i_link
= &b
->loc
;
13984 struct bp_location
*hoisted
= &head
;
13986 if (pspace
== NULL
)
13997 if (i
->pspace
== pspace
)
14012 /* Create new breakpoint locations for B (a hardware or software
14013 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14014 zero, then B is a ranged breakpoint. Only recreates locations for
14015 FILTER_PSPACE. Locations of other program spaces are left
14019 update_breakpoint_locations (struct breakpoint
*b
,
14020 struct program_space
*filter_pspace
,
14021 gdb::array_view
<const symtab_and_line
> sals
,
14022 gdb::array_view
<const symtab_and_line
> sals_end
)
14025 struct bp_location
*existing_locations
;
14027 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
14029 /* Ranged breakpoints have only one start location and one end
14031 b
->enable_state
= bp_disabled
;
14032 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14033 "multiple locations found\n"),
14038 /* If there's no new locations, and all existing locations are
14039 pending, don't do anything. This optimizes the common case where
14040 all locations are in the same shared library, that was unloaded.
14041 We'd like to retain the location, so that when the library is
14042 loaded again, we don't loose the enabled/disabled status of the
14043 individual locations. */
14044 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
14047 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14049 for (const auto &sal
: sals
)
14051 struct bp_location
*new_loc
;
14053 switch_to_program_space_and_thread (sal
.pspace
);
14055 new_loc
= add_location_to_breakpoint (b
, &sal
);
14057 /* Reparse conditions, they might contain references to the
14059 if (b
->cond_string
!= NULL
)
14063 s
= b
->cond_string
;
14066 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
14067 block_for_pc (sal
.pc
),
14070 CATCH (e
, RETURN_MASK_ERROR
)
14072 warning (_("failed to reevaluate condition "
14073 "for breakpoint %d: %s"),
14074 b
->number
, e
.message
);
14075 new_loc
->enabled
= 0;
14080 if (!sals_end
.empty ())
14082 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
14084 new_loc
->length
= end
- sals
[0].pc
+ 1;
14088 /* If possible, carry over 'disable' status from existing
14091 struct bp_location
*e
= existing_locations
;
14092 /* If there are multiple breakpoints with the same function name,
14093 e.g. for inline functions, comparing function names won't work.
14094 Instead compare pc addresses; this is just a heuristic as things
14095 may have moved, but in practice it gives the correct answer
14096 often enough until a better solution is found. */
14097 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14099 for (; e
; e
= e
->next
)
14101 if (!e
->enabled
&& e
->function_name
)
14103 struct bp_location
*l
= b
->loc
;
14104 if (have_ambiguous_names
)
14106 for (; l
; l
= l
->next
)
14107 if (breakpoint_locations_match (e
, l
))
14115 for (; l
; l
= l
->next
)
14116 if (l
->function_name
14117 && strcmp (e
->function_name
, l
->function_name
) == 0)
14127 if (!locations_are_equal (existing_locations
, b
->loc
))
14128 observer_notify_breakpoint_modified (b
);
14131 /* Find the SaL locations corresponding to the given LOCATION.
14132 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14134 static std::vector
<symtab_and_line
>
14135 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14136 struct program_space
*search_pspace
, int *found
)
14138 struct gdb_exception exception
= exception_none
;
14140 gdb_assert (b
->ops
!= NULL
);
14142 std::vector
<symtab_and_line
> sals
;
14146 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
14148 CATCH (e
, RETURN_MASK_ERROR
)
14150 int not_found_and_ok
= 0;
14154 /* For pending breakpoints, it's expected that parsing will
14155 fail until the right shared library is loaded. User has
14156 already told to create pending breakpoints and don't need
14157 extra messages. If breakpoint is in bp_shlib_disabled
14158 state, then user already saw the message about that
14159 breakpoint being disabled, and don't want to see more
14161 if (e
.error
== NOT_FOUND_ERROR
14162 && (b
->condition_not_parsed
14164 && search_pspace
!= NULL
14165 && b
->loc
->pspace
!= search_pspace
)
14166 || (b
->loc
&& b
->loc
->shlib_disabled
)
14167 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14168 || b
->enable_state
== bp_disabled
))
14169 not_found_and_ok
= 1;
14171 if (!not_found_and_ok
)
14173 /* We surely don't want to warn about the same breakpoint
14174 10 times. One solution, implemented here, is disable
14175 the breakpoint on error. Another solution would be to
14176 have separate 'warning emitted' flag. Since this
14177 happens only when a binary has changed, I don't know
14178 which approach is better. */
14179 b
->enable_state
= bp_disabled
;
14180 throw_exception (e
);
14185 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14187 for (auto &sal
: sals
)
14188 resolve_sal_pc (&sal
);
14189 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14191 char *cond_string
, *extra_string
;
14194 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
14195 &cond_string
, &thread
, &task
,
14197 gdb_assert (b
->cond_string
== NULL
);
14199 b
->cond_string
= cond_string
;
14200 b
->thread
= thread
;
14204 xfree (b
->extra_string
);
14205 b
->extra_string
= extra_string
;
14207 b
->condition_not_parsed
= 0;
14210 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14211 sals
[0] = update_static_tracepoint (b
, sals
[0]);
14221 /* The default re_set method, for typical hardware or software
14222 breakpoints. Reevaluate the breakpoint and recreate its
14226 breakpoint_re_set_default (struct breakpoint
*b
)
14228 struct program_space
*filter_pspace
= current_program_space
;
14229 std::vector
<symtab_and_line
> expanded
, expanded_end
;
14232 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
14233 filter_pspace
, &found
);
14235 expanded
= std::move (sals
);
14237 if (b
->location_range_end
!= NULL
)
14239 std::vector
<symtab_and_line
> sals_end
14240 = location_to_sals (b
, b
->location_range_end
.get (),
14241 filter_pspace
, &found
);
14243 expanded_end
= std::move (sals_end
);
14246 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14249 /* Default method for creating SALs from an address string. It basically
14250 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14253 create_sals_from_location_default (const struct event_location
*location
,
14254 struct linespec_result
*canonical
,
14255 enum bptype type_wanted
)
14257 parse_breakpoint_sals (location
, canonical
);
14260 /* Call create_breakpoints_sal for the given arguments. This is the default
14261 function for the `create_breakpoints_sal' method of
14265 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14266 struct linespec_result
*canonical
,
14267 gdb::unique_xmalloc_ptr
<char> cond_string
,
14268 gdb::unique_xmalloc_ptr
<char> extra_string
,
14269 enum bptype type_wanted
,
14270 enum bpdisp disposition
,
14272 int task
, int ignore_count
,
14273 const struct breakpoint_ops
*ops
,
14274 int from_tty
, int enabled
,
14275 int internal
, unsigned flags
)
14277 create_breakpoints_sal (gdbarch
, canonical
,
14278 std::move (cond_string
),
14279 std::move (extra_string
),
14280 type_wanted
, disposition
,
14281 thread
, task
, ignore_count
, ops
, from_tty
,
14282 enabled
, internal
, flags
);
14285 /* Decode the line represented by S by calling decode_line_full. This is the
14286 default function for the `decode_location' method of breakpoint_ops. */
14288 static std::vector
<symtab_and_line
>
14289 decode_location_default (struct breakpoint
*b
,
14290 const struct event_location
*location
,
14291 struct program_space
*search_pspace
)
14293 struct linespec_result canonical
;
14295 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14296 (struct symtab
*) NULL
, 0,
14297 &canonical
, multiple_symbols_all
,
14300 /* We should get 0 or 1 resulting SALs. */
14301 gdb_assert (canonical
.lsals
.size () < 2);
14303 if (!canonical
.lsals
.empty ())
14305 const linespec_sals
&lsal
= canonical
.lsals
[0];
14306 return std::move (lsal
.sals
);
14311 /* Prepare the global context for a re-set of breakpoint B. */
14313 static struct cleanup
*
14314 prepare_re_set_context (struct breakpoint
*b
)
14316 input_radix
= b
->input_radix
;
14317 set_language (b
->language
);
14319 return make_cleanup (null_cleanup
, NULL
);
14322 /* Reset a breakpoint given it's struct breakpoint * BINT.
14323 The value we return ends up being the return value from catch_errors.
14324 Unused in this case. */
14327 breakpoint_re_set_one (void *bint
)
14329 /* Get past catch_errs. */
14330 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14331 struct cleanup
*cleanups
;
14333 cleanups
= prepare_re_set_context (b
);
14334 b
->ops
->re_set (b
);
14335 do_cleanups (cleanups
);
14339 /* Re-set breakpoint locations for the current program space.
14340 Locations bound to other program spaces are left untouched. */
14343 breakpoint_re_set (void)
14345 struct breakpoint
*b
, *b_tmp
;
14346 enum language save_language
;
14347 int save_input_radix
;
14349 save_language
= current_language
->la_language
;
14350 save_input_radix
= input_radix
;
14353 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14355 /* Note: we must not try to insert locations until after all
14356 breakpoints have been re-set. Otherwise, e.g., when re-setting
14357 breakpoint 1, we'd insert the locations of breakpoint 2, which
14358 hadn't been re-set yet, and thus may have stale locations. */
14360 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14362 /* Format possible error msg. */
14363 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14365 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14366 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14367 do_cleanups (cleanups
);
14369 set_language (save_language
);
14370 input_radix
= save_input_radix
;
14372 jit_breakpoint_re_set ();
14375 create_overlay_event_breakpoint ();
14376 create_longjmp_master_breakpoint ();
14377 create_std_terminate_master_breakpoint ();
14378 create_exception_master_breakpoint ();
14380 /* Now we can insert. */
14381 update_global_location_list (UGLL_MAY_INSERT
);
14384 /* Reset the thread number of this breakpoint:
14386 - If the breakpoint is for all threads, leave it as-is.
14387 - Else, reset it to the current thread for inferior_ptid. */
14389 breakpoint_re_set_thread (struct breakpoint
*b
)
14391 if (b
->thread
!= -1)
14393 if (in_thread_list (inferior_ptid
))
14394 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14396 /* We're being called after following a fork. The new fork is
14397 selected as current, and unless this was a vfork will have a
14398 different program space from the original thread. Reset that
14400 b
->loc
->pspace
= current_program_space
;
14404 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14405 If from_tty is nonzero, it prints a message to that effect,
14406 which ends with a period (no newline). */
14409 set_ignore_count (int bptnum
, int count
, int from_tty
)
14411 struct breakpoint
*b
;
14416 ALL_BREAKPOINTS (b
)
14417 if (b
->number
== bptnum
)
14419 if (is_tracepoint (b
))
14421 if (from_tty
&& count
!= 0)
14422 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14427 b
->ignore_count
= count
;
14431 printf_filtered (_("Will stop next time "
14432 "breakpoint %d is reached."),
14434 else if (count
== 1)
14435 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14438 printf_filtered (_("Will ignore next %d "
14439 "crossings of breakpoint %d."),
14442 observer_notify_breakpoint_modified (b
);
14446 error (_("No breakpoint number %d."), bptnum
);
14449 /* Command to set ignore-count of breakpoint N to COUNT. */
14452 ignore_command (char *args
, int from_tty
)
14458 error_no_arg (_("a breakpoint number"));
14460 num
= get_number (&p
);
14462 error (_("bad breakpoint number: '%s'"), args
);
14464 error (_("Second argument (specified ignore-count) is missing."));
14466 set_ignore_count (num
,
14467 longest_to_int (value_as_long (parse_and_eval (p
))),
14470 printf_filtered ("\n");
14473 /* Call FUNCTION on each of the breakpoints
14474 whose numbers are given in ARGS. */
14477 map_breakpoint_numbers (const char *args
,
14478 void (*function
) (struct breakpoint
*,
14483 struct breakpoint
*b
, *tmp
;
14485 if (args
== 0 || *args
== '\0')
14486 error_no_arg (_("one or more breakpoint numbers"));
14488 number_or_range_parser
parser (args
);
14490 while (!parser
.finished ())
14492 const char *p
= parser
.cur_tok ();
14493 bool match
= false;
14495 num
= parser
.get_number ();
14498 warning (_("bad breakpoint number at or near '%s'"), p
);
14502 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14503 if (b
->number
== num
)
14506 function (b
, data
);
14510 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14515 static struct bp_location
*
14516 find_location_by_number (char *number
)
14518 char *dot
= strchr (number
, '.');
14522 struct breakpoint
*b
;
14523 struct bp_location
*loc
;
14528 bp_num
= get_number (&p1
);
14530 error (_("Bad breakpoint number '%s'"), number
);
14532 ALL_BREAKPOINTS (b
)
14533 if (b
->number
== bp_num
)
14538 if (!b
|| b
->number
!= bp_num
)
14539 error (_("Bad breakpoint number '%s'"), number
);
14542 loc_num
= get_number (&p1
);
14544 error (_("Bad breakpoint location number '%s'"), number
);
14548 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14551 error (_("Bad breakpoint location number '%s'"), dot
+1);
14557 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14558 If from_tty is nonzero, it prints a message to that effect,
14559 which ends with a period (no newline). */
14562 disable_breakpoint (struct breakpoint
*bpt
)
14564 /* Never disable a watchpoint scope breakpoint; we want to
14565 hit them when we leave scope so we can delete both the
14566 watchpoint and its scope breakpoint at that time. */
14567 if (bpt
->type
== bp_watchpoint_scope
)
14570 bpt
->enable_state
= bp_disabled
;
14572 /* Mark breakpoint locations modified. */
14573 mark_breakpoint_modified (bpt
);
14575 if (target_supports_enable_disable_tracepoint ()
14576 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14578 struct bp_location
*location
;
14580 for (location
= bpt
->loc
; location
; location
= location
->next
)
14581 target_disable_tracepoint (location
);
14584 update_global_location_list (UGLL_DONT_INSERT
);
14586 observer_notify_breakpoint_modified (bpt
);
14589 /* A callback for iterate_over_related_breakpoints. */
14592 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14594 disable_breakpoint (b
);
14597 /* A callback for map_breakpoint_numbers that calls
14598 disable_breakpoint. */
14601 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14603 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14607 disable_command (char *args
, int from_tty
)
14611 struct breakpoint
*bpt
;
14613 ALL_BREAKPOINTS (bpt
)
14614 if (user_breakpoint_p (bpt
))
14615 disable_breakpoint (bpt
);
14619 char *num
= extract_arg (&args
);
14623 if (strchr (num
, '.'))
14625 struct bp_location
*loc
= find_location_by_number (num
);
14632 mark_breakpoint_location_modified (loc
);
14634 if (target_supports_enable_disable_tracepoint ()
14635 && current_trace_status ()->running
&& loc
->owner
14636 && is_tracepoint (loc
->owner
))
14637 target_disable_tracepoint (loc
);
14639 update_global_location_list (UGLL_DONT_INSERT
);
14642 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14643 num
= extract_arg (&args
);
14649 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14652 int target_resources_ok
;
14654 if (bpt
->type
== bp_hardware_breakpoint
)
14657 i
= hw_breakpoint_used_count ();
14658 target_resources_ok
=
14659 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14661 if (target_resources_ok
== 0)
14662 error (_("No hardware breakpoint support in the target."));
14663 else if (target_resources_ok
< 0)
14664 error (_("Hardware breakpoints used exceeds limit."));
14667 if (is_watchpoint (bpt
))
14669 /* Initialize it just to avoid a GCC false warning. */
14670 enum enable_state orig_enable_state
= bp_disabled
;
14674 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14676 orig_enable_state
= bpt
->enable_state
;
14677 bpt
->enable_state
= bp_enabled
;
14678 update_watchpoint (w
, 1 /* reparse */);
14680 CATCH (e
, RETURN_MASK_ALL
)
14682 bpt
->enable_state
= orig_enable_state
;
14683 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14690 bpt
->enable_state
= bp_enabled
;
14692 /* Mark breakpoint locations modified. */
14693 mark_breakpoint_modified (bpt
);
14695 if (target_supports_enable_disable_tracepoint ()
14696 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14698 struct bp_location
*location
;
14700 for (location
= bpt
->loc
; location
; location
= location
->next
)
14701 target_enable_tracepoint (location
);
14704 bpt
->disposition
= disposition
;
14705 bpt
->enable_count
= count
;
14706 update_global_location_list (UGLL_MAY_INSERT
);
14708 observer_notify_breakpoint_modified (bpt
);
14713 enable_breakpoint (struct breakpoint
*bpt
)
14715 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14719 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14721 enable_breakpoint (bpt
);
14724 /* A callback for map_breakpoint_numbers that calls
14725 enable_breakpoint. */
14728 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14730 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14733 /* The enable command enables the specified breakpoints (or all defined
14734 breakpoints) so they once again become (or continue to be) effective
14735 in stopping the inferior. */
14738 enable_command (char *args
, int from_tty
)
14742 struct breakpoint
*bpt
;
14744 ALL_BREAKPOINTS (bpt
)
14745 if (user_breakpoint_p (bpt
))
14746 enable_breakpoint (bpt
);
14750 char *num
= extract_arg (&args
);
14754 if (strchr (num
, '.'))
14756 struct bp_location
*loc
= find_location_by_number (num
);
14763 mark_breakpoint_location_modified (loc
);
14765 if (target_supports_enable_disable_tracepoint ()
14766 && current_trace_status ()->running
&& loc
->owner
14767 && is_tracepoint (loc
->owner
))
14768 target_enable_tracepoint (loc
);
14770 update_global_location_list (UGLL_MAY_INSERT
);
14773 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14774 num
= extract_arg (&args
);
14779 /* This struct packages up disposition data for application to multiple
14789 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14791 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14793 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14797 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14799 struct disp_data disp
= { disp_disable
, 1 };
14801 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14805 enable_once_command (char *args
, int from_tty
)
14807 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14811 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14813 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14815 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14819 enable_count_command (char *args
, int from_tty
)
14824 error_no_arg (_("hit count"));
14826 count
= get_number (&args
);
14828 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14832 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14834 struct disp_data disp
= { disp_del
, 1 };
14836 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14840 enable_delete_command (char *args
, int from_tty
)
14842 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14846 set_breakpoint_cmd (char *args
, int from_tty
)
14851 show_breakpoint_cmd (char *args
, int from_tty
)
14855 /* Invalidate last known value of any hardware watchpoint if
14856 the memory which that value represents has been written to by
14860 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14861 CORE_ADDR addr
, ssize_t len
,
14862 const bfd_byte
*data
)
14864 struct breakpoint
*bp
;
14866 ALL_BREAKPOINTS (bp
)
14867 if (bp
->enable_state
== bp_enabled
14868 && bp
->type
== bp_hardware_watchpoint
)
14870 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14872 if (wp
->val_valid
&& wp
->val
)
14874 struct bp_location
*loc
;
14876 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14877 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14878 && loc
->address
+ loc
->length
> addr
14879 && addr
+ len
> loc
->address
)
14881 value_free (wp
->val
);
14889 /* Create and insert a breakpoint for software single step. */
14892 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14893 struct address_space
*aspace
,
14896 struct thread_info
*tp
= inferior_thread ();
14897 struct symtab_and_line sal
;
14898 CORE_ADDR pc
= next_pc
;
14900 if (tp
->control
.single_step_breakpoints
== NULL
)
14902 tp
->control
.single_step_breakpoints
14903 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14906 sal
= find_pc_line (pc
, 0);
14908 sal
.section
= find_pc_overlay (pc
);
14909 sal
.explicit_pc
= 1;
14910 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14912 update_global_location_list (UGLL_INSERT
);
14915 /* Insert single step breakpoints according to the current state. */
14918 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14920 struct regcache
*regcache
= get_current_regcache ();
14921 std::vector
<CORE_ADDR
> next_pcs
;
14923 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14925 if (!next_pcs
.empty ())
14927 struct frame_info
*frame
= get_current_frame ();
14928 struct address_space
*aspace
= get_frame_address_space (frame
);
14930 for (CORE_ADDR pc
: next_pcs
)
14931 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14939 /* See breakpoint.h. */
14942 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14943 struct address_space
*aspace
,
14946 struct bp_location
*loc
;
14948 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14950 && breakpoint_location_address_match (loc
, aspace
, pc
))
14956 /* Check whether a software single-step breakpoint is inserted at
14960 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14963 struct breakpoint
*bpt
;
14965 ALL_BREAKPOINTS (bpt
)
14967 if (bpt
->type
== bp_single_step
14968 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14974 /* Tracepoint-specific operations. */
14976 /* Set tracepoint count to NUM. */
14978 set_tracepoint_count (int num
)
14980 tracepoint_count
= num
;
14981 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14985 trace_command (char *arg
, int from_tty
)
14987 struct breakpoint_ops
*ops
;
14989 event_location_up location
= string_to_event_location (&arg
,
14991 if (location
!= NULL
14992 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14993 ops
= &tracepoint_probe_breakpoint_ops
;
14995 ops
= &tracepoint_breakpoint_ops
;
14997 create_breakpoint (get_current_arch (),
14999 NULL
, 0, arg
, 1 /* parse arg */,
15001 bp_tracepoint
/* type_wanted */,
15002 0 /* Ignore count */,
15003 pending_break_support
,
15007 0 /* internal */, 0);
15011 ftrace_command (char *arg
, int from_tty
)
15013 event_location_up location
= string_to_event_location (&arg
,
15015 create_breakpoint (get_current_arch (),
15017 NULL
, 0, arg
, 1 /* parse arg */,
15019 bp_fast_tracepoint
/* type_wanted */,
15020 0 /* Ignore count */,
15021 pending_break_support
,
15022 &tracepoint_breakpoint_ops
,
15025 0 /* internal */, 0);
15028 /* strace command implementation. Creates a static tracepoint. */
15031 strace_command (char *arg
, int from_tty
)
15033 struct breakpoint_ops
*ops
;
15034 event_location_up location
;
15035 struct cleanup
*back_to
;
15037 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15038 or with a normal static tracepoint. */
15039 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15041 ops
= &strace_marker_breakpoint_ops
;
15042 location
= new_linespec_location (&arg
);
15046 ops
= &tracepoint_breakpoint_ops
;
15047 location
= string_to_event_location (&arg
, current_language
);
15050 create_breakpoint (get_current_arch (),
15052 NULL
, 0, arg
, 1 /* parse arg */,
15054 bp_static_tracepoint
/* type_wanted */,
15055 0 /* Ignore count */,
15056 pending_break_support
,
15060 0 /* internal */, 0);
15063 /* Set up a fake reader function that gets command lines from a linked
15064 list that was acquired during tracepoint uploading. */
15066 static struct uploaded_tp
*this_utp
;
15067 static int next_cmd
;
15070 read_uploaded_action (void)
15074 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15081 /* Given information about a tracepoint as recorded on a target (which
15082 can be either a live system or a trace file), attempt to create an
15083 equivalent GDB tracepoint. This is not a reliable process, since
15084 the target does not necessarily have all the information used when
15085 the tracepoint was originally defined. */
15087 struct tracepoint
*
15088 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15090 char *addr_str
, small_buf
[100];
15091 struct tracepoint
*tp
;
15093 if (utp
->at_string
)
15094 addr_str
= utp
->at_string
;
15097 /* In the absence of a source location, fall back to raw
15098 address. Since there is no way to confirm that the address
15099 means the same thing as when the trace was started, warn the
15101 warning (_("Uploaded tracepoint %d has no "
15102 "source location, using raw address"),
15104 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15105 addr_str
= small_buf
;
15108 /* There's not much we can do with a sequence of bytecodes. */
15109 if (utp
->cond
&& !utp
->cond_string
)
15110 warning (_("Uploaded tracepoint %d condition "
15111 "has no source form, ignoring it"),
15114 event_location_up location
= string_to_event_location (&addr_str
,
15116 if (!create_breakpoint (get_current_arch (),
15118 utp
->cond_string
, -1, addr_str
,
15119 0 /* parse cond/thread */,
15121 utp
->type
/* type_wanted */,
15122 0 /* Ignore count */,
15123 pending_break_support
,
15124 &tracepoint_breakpoint_ops
,
15126 utp
->enabled
/* enabled */,
15128 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15131 /* Get the tracepoint we just created. */
15132 tp
= get_tracepoint (tracepoint_count
);
15133 gdb_assert (tp
!= NULL
);
15137 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15140 trace_pass_command (small_buf
, 0);
15143 /* If we have uploaded versions of the original commands, set up a
15144 special-purpose "reader" function and call the usual command line
15145 reader, then pass the result to the breakpoint command-setting
15147 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15149 command_line_up cmd_list
;
15154 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15156 breakpoint_set_commands (tp
, std::move (cmd_list
));
15158 else if (!VEC_empty (char_ptr
, utp
->actions
)
15159 || !VEC_empty (char_ptr
, utp
->step_actions
))
15160 warning (_("Uploaded tracepoint %d actions "
15161 "have no source form, ignoring them"),
15164 /* Copy any status information that might be available. */
15165 tp
->hit_count
= utp
->hit_count
;
15166 tp
->traceframe_usage
= utp
->traceframe_usage
;
15171 /* Print information on tracepoint number TPNUM_EXP, or all if
15175 info_tracepoints_command (char *args
, int from_tty
)
15177 struct ui_out
*uiout
= current_uiout
;
15180 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15182 if (num_printed
== 0)
15184 if (args
== NULL
|| *args
== '\0')
15185 uiout
->message ("No tracepoints.\n");
15187 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15190 default_collect_info ();
15193 /* The 'enable trace' command enables tracepoints.
15194 Not supported by all targets. */
15196 enable_trace_command (char *args
, int from_tty
)
15198 enable_command (args
, from_tty
);
15201 /* The 'disable trace' command disables tracepoints.
15202 Not supported by all targets. */
15204 disable_trace_command (char *args
, int from_tty
)
15206 disable_command (args
, from_tty
);
15209 /* Remove a tracepoint (or all if no argument). */
15211 delete_trace_command (char *arg
, int from_tty
)
15213 struct breakpoint
*b
, *b_tmp
;
15219 int breaks_to_delete
= 0;
15221 /* Delete all breakpoints if no argument.
15222 Do not delete internal or call-dummy breakpoints, these
15223 have to be deleted with an explicit breakpoint number
15225 ALL_TRACEPOINTS (b
)
15226 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15228 breaks_to_delete
= 1;
15232 /* Ask user only if there are some breakpoints to delete. */
15234 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15236 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15237 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15238 delete_breakpoint (b
);
15242 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15245 /* Helper function for trace_pass_command. */
15248 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15250 tp
->pass_count
= count
;
15251 observer_notify_breakpoint_modified (tp
);
15253 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15254 tp
->number
, count
);
15257 /* Set passcount for tracepoint.
15259 First command argument is passcount, second is tracepoint number.
15260 If tracepoint number omitted, apply to most recently defined.
15261 Also accepts special argument "all". */
15264 trace_pass_command (char *args
, int from_tty
)
15266 struct tracepoint
*t1
;
15267 unsigned int count
;
15269 if (args
== 0 || *args
== 0)
15270 error (_("passcount command requires an "
15271 "argument (count + optional TP num)"));
15273 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15275 args
= skip_spaces (args
);
15276 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15278 struct breakpoint
*b
;
15280 args
+= 3; /* Skip special argument "all". */
15282 error (_("Junk at end of arguments."));
15284 ALL_TRACEPOINTS (b
)
15286 t1
= (struct tracepoint
*) b
;
15287 trace_pass_set_count (t1
, count
, from_tty
);
15290 else if (*args
== '\0')
15292 t1
= get_tracepoint_by_number (&args
, NULL
);
15294 trace_pass_set_count (t1
, count
, from_tty
);
15298 number_or_range_parser
parser (args
);
15299 while (!parser
.finished ())
15301 t1
= get_tracepoint_by_number (&args
, &parser
);
15303 trace_pass_set_count (t1
, count
, from_tty
);
15308 struct tracepoint
*
15309 get_tracepoint (int num
)
15311 struct breakpoint
*t
;
15313 ALL_TRACEPOINTS (t
)
15314 if (t
->number
== num
)
15315 return (struct tracepoint
*) t
;
15320 /* Find the tracepoint with the given target-side number (which may be
15321 different from the tracepoint number after disconnecting and
15324 struct tracepoint
*
15325 get_tracepoint_by_number_on_target (int num
)
15327 struct breakpoint
*b
;
15329 ALL_TRACEPOINTS (b
)
15331 struct tracepoint
*t
= (struct tracepoint
*) b
;
15333 if (t
->number_on_target
== num
)
15340 /* Utility: parse a tracepoint number and look it up in the list.
15341 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15342 If the argument is missing, the most recent tracepoint
15343 (tracepoint_count) is returned. */
15345 struct tracepoint
*
15346 get_tracepoint_by_number (char **arg
,
15347 number_or_range_parser
*parser
)
15349 struct breakpoint
*t
;
15351 char *instring
= arg
== NULL
? NULL
: *arg
;
15353 if (parser
!= NULL
)
15355 gdb_assert (!parser
->finished ());
15356 tpnum
= parser
->get_number ();
15358 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15359 tpnum
= tracepoint_count
;
15361 tpnum
= get_number (arg
);
15365 if (instring
&& *instring
)
15366 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15369 printf_filtered (_("No previous tracepoint\n"));
15373 ALL_TRACEPOINTS (t
)
15374 if (t
->number
== tpnum
)
15376 return (struct tracepoint
*) t
;
15379 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15384 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15386 if (b
->thread
!= -1)
15387 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15390 fprintf_unfiltered (fp
, " task %d", b
->task
);
15392 fprintf_unfiltered (fp
, "\n");
15395 /* Save information on user settable breakpoints (watchpoints, etc) to
15396 a new script file named FILENAME. If FILTER is non-NULL, call it
15397 on each breakpoint and only include the ones for which it returns
15401 save_breakpoints (char *filename
, int from_tty
,
15402 int (*filter
) (const struct breakpoint
*))
15404 struct breakpoint
*tp
;
15406 int extra_trace_bits
= 0;
15408 if (filename
== 0 || *filename
== 0)
15409 error (_("Argument required (file name in which to save)"));
15411 /* See if we have anything to save. */
15412 ALL_BREAKPOINTS (tp
)
15414 /* Skip internal and momentary breakpoints. */
15415 if (!user_breakpoint_p (tp
))
15418 /* If we have a filter, only save the breakpoints it accepts. */
15419 if (filter
&& !filter (tp
))
15424 if (is_tracepoint (tp
))
15426 extra_trace_bits
= 1;
15428 /* We can stop searching. */
15435 warning (_("Nothing to save."));
15439 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15443 if (!fp
.open (expanded_filename
.get (), "w"))
15444 error (_("Unable to open file '%s' for saving (%s)"),
15445 expanded_filename
.get (), safe_strerror (errno
));
15447 if (extra_trace_bits
)
15448 save_trace_state_variables (&fp
);
15450 ALL_BREAKPOINTS (tp
)
15452 /* Skip internal and momentary breakpoints. */
15453 if (!user_breakpoint_p (tp
))
15456 /* If we have a filter, only save the breakpoints it accepts. */
15457 if (filter
&& !filter (tp
))
15460 tp
->ops
->print_recreate (tp
, &fp
);
15462 /* Note, we can't rely on tp->number for anything, as we can't
15463 assume the recreated breakpoint numbers will match. Use $bpnum
15466 if (tp
->cond_string
)
15467 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15469 if (tp
->ignore_count
)
15470 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15472 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15474 fp
.puts (" commands\n");
15476 current_uiout
->redirect (&fp
);
15479 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15481 CATCH (ex
, RETURN_MASK_ALL
)
15483 current_uiout
->redirect (NULL
);
15484 throw_exception (ex
);
15488 current_uiout
->redirect (NULL
);
15489 fp
.puts (" end\n");
15492 if (tp
->enable_state
== bp_disabled
)
15493 fp
.puts ("disable $bpnum\n");
15495 /* If this is a multi-location breakpoint, check if the locations
15496 should be individually disabled. Watchpoint locations are
15497 special, and not user visible. */
15498 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15500 struct bp_location
*loc
;
15503 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15505 fp
.printf ("disable $bpnum.%d\n", n
);
15509 if (extra_trace_bits
&& *default_collect
)
15510 fp
.printf ("set default-collect %s\n", default_collect
);
15513 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15516 /* The `save breakpoints' command. */
15519 save_breakpoints_command (char *args
, int from_tty
)
15521 save_breakpoints (args
, from_tty
, NULL
);
15524 /* The `save tracepoints' command. */
15527 save_tracepoints_command (char *args
, int from_tty
)
15529 save_breakpoints (args
, from_tty
, is_tracepoint
);
15532 /* Create a vector of all tracepoints. */
15534 VEC(breakpoint_p
) *
15535 all_tracepoints (void)
15537 VEC(breakpoint_p
) *tp_vec
= 0;
15538 struct breakpoint
*tp
;
15540 ALL_TRACEPOINTS (tp
)
15542 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15549 /* This help string is used to consolidate all the help string for specifying
15550 locations used by several commands. */
15552 #define LOCATION_HELP_STRING \
15553 "Linespecs are colon-separated lists of location parameters, such as\n\
15554 source filename, function name, label name, and line number.\n\
15555 Example: To specify the start of a label named \"the_top\" in the\n\
15556 function \"fact\" in the file \"factorial.c\", use\n\
15557 \"factorial.c:fact:the_top\".\n\
15559 Address locations begin with \"*\" and specify an exact address in the\n\
15560 program. Example: To specify the fourth byte past the start function\n\
15561 \"main\", use \"*main + 4\".\n\
15563 Explicit locations are similar to linespecs but use an option/argument\n\
15564 syntax to specify location parameters.\n\
15565 Example: To specify the start of the label named \"the_top\" in the\n\
15566 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15567 -function fact -label the_top\".\n"
15569 /* This help string is used for the break, hbreak, tbreak and thbreak
15570 commands. It is defined as a macro to prevent duplication.
15571 COMMAND should be a string constant containing the name of the
15574 #define BREAK_ARGS_HELP(command) \
15575 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15576 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15577 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15578 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15579 `-probe-dtrace' (for a DTrace probe).\n\
15580 LOCATION may be a linespec, address, or explicit location as described\n\
15583 With no LOCATION, uses current execution address of the selected\n\
15584 stack frame. This is useful for breaking on return to a stack frame.\n\
15586 THREADNUM is the number from \"info threads\".\n\
15587 CONDITION is a boolean expression.\n\
15588 \n" LOCATION_HELP_STRING "\n\
15589 Multiple breakpoints at one place are permitted, and useful if their\n\
15590 conditions are different.\n\
15592 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15594 /* List of subcommands for "catch". */
15595 static struct cmd_list_element
*catch_cmdlist
;
15597 /* List of subcommands for "tcatch". */
15598 static struct cmd_list_element
*tcatch_cmdlist
;
15601 add_catch_command (const char *name
, const char *docstring
,
15602 cmd_sfunc_ftype
*sfunc
,
15603 completer_ftype
*completer
,
15604 void *user_data_catch
,
15605 void *user_data_tcatch
)
15607 struct cmd_list_element
*command
;
15609 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15611 set_cmd_sfunc (command
, sfunc
);
15612 set_cmd_context (command
, user_data_catch
);
15613 set_cmd_completer (command
, completer
);
15615 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15617 set_cmd_sfunc (command
, sfunc
);
15618 set_cmd_context (command
, user_data_tcatch
);
15619 set_cmd_completer (command
, completer
);
15623 save_command (char *arg
, int from_tty
)
15625 printf_unfiltered (_("\"save\" must be followed by "
15626 "the name of a save subcommand.\n"));
15627 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15630 struct breakpoint
*
15631 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15634 struct breakpoint
*b
, *b_tmp
;
15636 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15638 if ((*callback
) (b
, data
))
15645 /* Zero if any of the breakpoint's locations could be a location where
15646 functions have been inlined, nonzero otherwise. */
15649 is_non_inline_function (struct breakpoint
*b
)
15651 /* The shared library event breakpoint is set on the address of a
15652 non-inline function. */
15653 if (b
->type
== bp_shlib_event
)
15659 /* Nonzero if the specified PC cannot be a location where functions
15660 have been inlined. */
15663 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15664 const struct target_waitstatus
*ws
)
15666 struct breakpoint
*b
;
15667 struct bp_location
*bl
;
15669 ALL_BREAKPOINTS (b
)
15671 if (!is_non_inline_function (b
))
15674 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15676 if (!bl
->shlib_disabled
15677 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15685 /* Remove any references to OBJFILE which is going to be freed. */
15688 breakpoint_free_objfile (struct objfile
*objfile
)
15690 struct bp_location
**locp
, *loc
;
15692 ALL_BP_LOCATIONS (loc
, locp
)
15693 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15694 loc
->symtab
= NULL
;
15698 initialize_breakpoint_ops (void)
15700 static int initialized
= 0;
15702 struct breakpoint_ops
*ops
;
15708 /* The breakpoint_ops structure to be inherit by all kinds of
15709 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15710 internal and momentary breakpoints, etc.). */
15711 ops
= &bkpt_base_breakpoint_ops
;
15712 *ops
= base_breakpoint_ops
;
15713 ops
->re_set
= bkpt_re_set
;
15714 ops
->insert_location
= bkpt_insert_location
;
15715 ops
->remove_location
= bkpt_remove_location
;
15716 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15717 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15718 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15719 ops
->decode_location
= bkpt_decode_location
;
15721 /* The breakpoint_ops structure to be used in regular breakpoints. */
15722 ops
= &bkpt_breakpoint_ops
;
15723 *ops
= bkpt_base_breakpoint_ops
;
15724 ops
->re_set
= bkpt_re_set
;
15725 ops
->resources_needed
= bkpt_resources_needed
;
15726 ops
->print_it
= bkpt_print_it
;
15727 ops
->print_mention
= bkpt_print_mention
;
15728 ops
->print_recreate
= bkpt_print_recreate
;
15730 /* Ranged breakpoints. */
15731 ops
= &ranged_breakpoint_ops
;
15732 *ops
= bkpt_breakpoint_ops
;
15733 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15734 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15735 ops
->print_it
= print_it_ranged_breakpoint
;
15736 ops
->print_one
= print_one_ranged_breakpoint
;
15737 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15738 ops
->print_mention
= print_mention_ranged_breakpoint
;
15739 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15741 /* Internal breakpoints. */
15742 ops
= &internal_breakpoint_ops
;
15743 *ops
= bkpt_base_breakpoint_ops
;
15744 ops
->re_set
= internal_bkpt_re_set
;
15745 ops
->check_status
= internal_bkpt_check_status
;
15746 ops
->print_it
= internal_bkpt_print_it
;
15747 ops
->print_mention
= internal_bkpt_print_mention
;
15749 /* Momentary breakpoints. */
15750 ops
= &momentary_breakpoint_ops
;
15751 *ops
= bkpt_base_breakpoint_ops
;
15752 ops
->re_set
= momentary_bkpt_re_set
;
15753 ops
->check_status
= momentary_bkpt_check_status
;
15754 ops
->print_it
= momentary_bkpt_print_it
;
15755 ops
->print_mention
= momentary_bkpt_print_mention
;
15757 /* Probe breakpoints. */
15758 ops
= &bkpt_probe_breakpoint_ops
;
15759 *ops
= bkpt_breakpoint_ops
;
15760 ops
->insert_location
= bkpt_probe_insert_location
;
15761 ops
->remove_location
= bkpt_probe_remove_location
;
15762 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15763 ops
->decode_location
= bkpt_probe_decode_location
;
15766 ops
= &watchpoint_breakpoint_ops
;
15767 *ops
= base_breakpoint_ops
;
15768 ops
->re_set
= re_set_watchpoint
;
15769 ops
->insert_location
= insert_watchpoint
;
15770 ops
->remove_location
= remove_watchpoint
;
15771 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15772 ops
->check_status
= check_status_watchpoint
;
15773 ops
->resources_needed
= resources_needed_watchpoint
;
15774 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15775 ops
->print_it
= print_it_watchpoint
;
15776 ops
->print_mention
= print_mention_watchpoint
;
15777 ops
->print_recreate
= print_recreate_watchpoint
;
15778 ops
->explains_signal
= explains_signal_watchpoint
;
15780 /* Masked watchpoints. */
15781 ops
= &masked_watchpoint_breakpoint_ops
;
15782 *ops
= watchpoint_breakpoint_ops
;
15783 ops
->insert_location
= insert_masked_watchpoint
;
15784 ops
->remove_location
= remove_masked_watchpoint
;
15785 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15786 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15787 ops
->print_it
= print_it_masked_watchpoint
;
15788 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15789 ops
->print_mention
= print_mention_masked_watchpoint
;
15790 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15793 ops
= &tracepoint_breakpoint_ops
;
15794 *ops
= base_breakpoint_ops
;
15795 ops
->re_set
= tracepoint_re_set
;
15796 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15797 ops
->print_one_detail
= tracepoint_print_one_detail
;
15798 ops
->print_mention
= tracepoint_print_mention
;
15799 ops
->print_recreate
= tracepoint_print_recreate
;
15800 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15801 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15802 ops
->decode_location
= tracepoint_decode_location
;
15804 /* Probe tracepoints. */
15805 ops
= &tracepoint_probe_breakpoint_ops
;
15806 *ops
= tracepoint_breakpoint_ops
;
15807 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15808 ops
->decode_location
= tracepoint_probe_decode_location
;
15810 /* Static tracepoints with marker (`-m'). */
15811 ops
= &strace_marker_breakpoint_ops
;
15812 *ops
= tracepoint_breakpoint_ops
;
15813 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15814 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15815 ops
->decode_location
= strace_marker_decode_location
;
15817 /* Fork catchpoints. */
15818 ops
= &catch_fork_breakpoint_ops
;
15819 *ops
= base_breakpoint_ops
;
15820 ops
->insert_location
= insert_catch_fork
;
15821 ops
->remove_location
= remove_catch_fork
;
15822 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15823 ops
->print_it
= print_it_catch_fork
;
15824 ops
->print_one
= print_one_catch_fork
;
15825 ops
->print_mention
= print_mention_catch_fork
;
15826 ops
->print_recreate
= print_recreate_catch_fork
;
15828 /* Vfork catchpoints. */
15829 ops
= &catch_vfork_breakpoint_ops
;
15830 *ops
= base_breakpoint_ops
;
15831 ops
->insert_location
= insert_catch_vfork
;
15832 ops
->remove_location
= remove_catch_vfork
;
15833 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15834 ops
->print_it
= print_it_catch_vfork
;
15835 ops
->print_one
= print_one_catch_vfork
;
15836 ops
->print_mention
= print_mention_catch_vfork
;
15837 ops
->print_recreate
= print_recreate_catch_vfork
;
15839 /* Exec catchpoints. */
15840 ops
= &catch_exec_breakpoint_ops
;
15841 *ops
= base_breakpoint_ops
;
15842 ops
->insert_location
= insert_catch_exec
;
15843 ops
->remove_location
= remove_catch_exec
;
15844 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15845 ops
->print_it
= print_it_catch_exec
;
15846 ops
->print_one
= print_one_catch_exec
;
15847 ops
->print_mention
= print_mention_catch_exec
;
15848 ops
->print_recreate
= print_recreate_catch_exec
;
15850 /* Solib-related catchpoints. */
15851 ops
= &catch_solib_breakpoint_ops
;
15852 *ops
= base_breakpoint_ops
;
15853 ops
->insert_location
= insert_catch_solib
;
15854 ops
->remove_location
= remove_catch_solib
;
15855 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15856 ops
->check_status
= check_status_catch_solib
;
15857 ops
->print_it
= print_it_catch_solib
;
15858 ops
->print_one
= print_one_catch_solib
;
15859 ops
->print_mention
= print_mention_catch_solib
;
15860 ops
->print_recreate
= print_recreate_catch_solib
;
15862 ops
= &dprintf_breakpoint_ops
;
15863 *ops
= bkpt_base_breakpoint_ops
;
15864 ops
->re_set
= dprintf_re_set
;
15865 ops
->resources_needed
= bkpt_resources_needed
;
15866 ops
->print_it
= bkpt_print_it
;
15867 ops
->print_mention
= bkpt_print_mention
;
15868 ops
->print_recreate
= dprintf_print_recreate
;
15869 ops
->after_condition_true
= dprintf_after_condition_true
;
15870 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15873 /* Chain containing all defined "enable breakpoint" subcommands. */
15875 static struct cmd_list_element
*enablebreaklist
= NULL
;
15878 _initialize_breakpoint (void)
15880 struct cmd_list_element
*c
;
15882 initialize_breakpoint_ops ();
15884 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15885 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15886 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15888 breakpoint_objfile_key
15889 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15891 breakpoint_chain
= 0;
15892 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15893 before a breakpoint is set. */
15894 breakpoint_count
= 0;
15896 tracepoint_count
= 0;
15898 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15899 Set ignore-count of breakpoint number N to COUNT.\n\
15900 Usage is `ignore N COUNT'."));
15902 add_com ("commands", class_breakpoint
, commands_command
, _("\
15903 Set commands to be executed when the given breakpoints are hit.\n\
15904 Give a space-separated breakpoint list as argument after \"commands\".\n\
15905 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15907 With no argument, the targeted breakpoint is the last one set.\n\
15908 The commands themselves follow starting on the next line.\n\
15909 Type a line containing \"end\" to indicate the end of them.\n\
15910 Give \"silent\" as the first line to make the breakpoint silent;\n\
15911 then no output is printed when it is hit, except what the commands print."));
15913 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15914 Specify breakpoint number N to break only if COND is true.\n\
15915 Usage is `condition N COND', where N is an integer and COND is an\n\
15916 expression to be evaluated whenever breakpoint N is reached."));
15917 set_cmd_completer (c
, condition_completer
);
15919 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15920 Set a temporary breakpoint.\n\
15921 Like \"break\" except the breakpoint is only temporary,\n\
15922 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15923 by using \"enable delete\" on the breakpoint number.\n\
15925 BREAK_ARGS_HELP ("tbreak")));
15926 set_cmd_completer (c
, location_completer
);
15928 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15929 Set a hardware assisted breakpoint.\n\
15930 Like \"break\" except the breakpoint requires hardware support,\n\
15931 some target hardware may not have this support.\n\
15933 BREAK_ARGS_HELP ("hbreak")));
15934 set_cmd_completer (c
, location_completer
);
15936 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15937 Set a temporary hardware assisted breakpoint.\n\
15938 Like \"hbreak\" except the breakpoint is only temporary,\n\
15939 so it will be deleted when hit.\n\
15941 BREAK_ARGS_HELP ("thbreak")));
15942 set_cmd_completer (c
, location_completer
);
15944 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15945 Enable some breakpoints.\n\
15946 Give breakpoint numbers (separated by spaces) as arguments.\n\
15947 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15948 This is used to cancel the effect of the \"disable\" command.\n\
15949 With a subcommand you can enable temporarily."),
15950 &enablelist
, "enable ", 1, &cmdlist
);
15952 add_com_alias ("en", "enable", class_breakpoint
, 1);
15954 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15955 Enable some breakpoints.\n\
15956 Give breakpoint numbers (separated by spaces) as arguments.\n\
15957 This is used to cancel the effect of the \"disable\" command.\n\
15958 May be abbreviated to simply \"enable\".\n"),
15959 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15961 add_cmd ("once", no_class
, enable_once_command
, _("\
15962 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15963 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15966 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15967 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15968 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15971 add_cmd ("count", no_class
, enable_count_command
, _("\
15972 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15973 If a breakpoint is hit while enabled in this fashion,\n\
15974 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15977 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15978 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15979 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15982 add_cmd ("once", no_class
, enable_once_command
, _("\
15983 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15984 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15987 add_cmd ("count", no_class
, enable_count_command
, _("\
15988 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15989 If a breakpoint is hit while enabled in this fashion,\n\
15990 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15993 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15994 Disable some breakpoints.\n\
15995 Arguments are breakpoint numbers with spaces in between.\n\
15996 To disable all breakpoints, give no argument.\n\
15997 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15998 &disablelist
, "disable ", 1, &cmdlist
);
15999 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16000 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16002 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16003 Disable some breakpoints.\n\
16004 Arguments are breakpoint numbers with spaces in between.\n\
16005 To disable all breakpoints, give no argument.\n\
16006 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16007 This command may be abbreviated \"disable\"."),
16010 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16011 Delete some breakpoints or auto-display expressions.\n\
16012 Arguments are breakpoint numbers with spaces in between.\n\
16013 To delete all breakpoints, give no argument.\n\
16015 Also a prefix command for deletion of other GDB objects.\n\
16016 The \"unset\" command is also an alias for \"delete\"."),
16017 &deletelist
, "delete ", 1, &cmdlist
);
16018 add_com_alias ("d", "delete", class_breakpoint
, 1);
16019 add_com_alias ("del", "delete", class_breakpoint
, 1);
16021 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16022 Delete some breakpoints or auto-display expressions.\n\
16023 Arguments are breakpoint numbers with spaces in between.\n\
16024 To delete all breakpoints, give no argument.\n\
16025 This command may be abbreviated \"delete\"."),
16028 add_com ("clear", class_breakpoint
, clear_command
, _("\
16029 Clear breakpoint at specified location.\n\
16030 Argument may be a linespec, explicit, or address location as described below.\n\
16032 With no argument, clears all breakpoints in the line that the selected frame\n\
16033 is executing in.\n"
16034 "\n" LOCATION_HELP_STRING
"\n\
16035 See also the \"delete\" command which clears breakpoints by number."));
16036 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16038 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16039 Set breakpoint at specified location.\n"
16040 BREAK_ARGS_HELP ("break")));
16041 set_cmd_completer (c
, location_completer
);
16043 add_com_alias ("b", "break", class_run
, 1);
16044 add_com_alias ("br", "break", class_run
, 1);
16045 add_com_alias ("bre", "break", class_run
, 1);
16046 add_com_alias ("brea", "break", class_run
, 1);
16050 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16051 Break in function/address or break at a line in the current file."),
16052 &stoplist
, "stop ", 1, &cmdlist
);
16053 add_cmd ("in", class_breakpoint
, stopin_command
,
16054 _("Break in function or address."), &stoplist
);
16055 add_cmd ("at", class_breakpoint
, stopat_command
,
16056 _("Break at a line in the current file."), &stoplist
);
16057 add_com ("status", class_info
, info_breakpoints_command
, _("\
16058 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16059 The \"Type\" column indicates one of:\n\
16060 \tbreakpoint - normal breakpoint\n\
16061 \twatchpoint - watchpoint\n\
16062 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16063 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16064 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16065 address and file/line number respectively.\n\
16067 Convenience variable \"$_\" and default examine address for \"x\"\n\
16068 are set to the address of the last breakpoint listed unless the command\n\
16069 is prefixed with \"server \".\n\n\
16070 Convenience variable \"$bpnum\" contains the number of the last\n\
16071 breakpoint set."));
16074 add_info ("breakpoints", info_breakpoints_command
, _("\
16075 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16076 The \"Type\" column indicates one of:\n\
16077 \tbreakpoint - normal breakpoint\n\
16078 \twatchpoint - watchpoint\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\
16088 breakpoint set."));
16090 add_info_alias ("b", "breakpoints", 1);
16092 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16093 Status of all breakpoints, or breakpoint number NUMBER.\n\
16094 The \"Type\" column indicates one of:\n\
16095 \tbreakpoint - normal breakpoint\n\
16096 \twatchpoint - watchpoint\n\
16097 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16098 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16099 \tuntil - internal breakpoint used by the \"until\" command\n\
16100 \tfinish - internal breakpoint used by the \"finish\" command\n\
16101 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16102 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16103 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16104 address and file/line number respectively.\n\
16106 Convenience variable \"$_\" and default examine address for \"x\"\n\
16107 are set to the address of the last breakpoint listed unless the command\n\
16108 is prefixed with \"server \".\n\n\
16109 Convenience variable \"$bpnum\" contains the number of the last\n\
16111 &maintenanceinfolist
);
16113 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16114 Set catchpoints to catch events."),
16115 &catch_cmdlist
, "catch ",
16116 0/*allow-unknown*/, &cmdlist
);
16118 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16119 Set temporary catchpoints to catch events."),
16120 &tcatch_cmdlist
, "tcatch ",
16121 0/*allow-unknown*/, &cmdlist
);
16123 add_catch_command ("fork", _("Catch calls to fork."),
16124 catch_fork_command_1
,
16126 (void *) (uintptr_t) catch_fork_permanent
,
16127 (void *) (uintptr_t) catch_fork_temporary
);
16128 add_catch_command ("vfork", _("Catch calls to vfork."),
16129 catch_fork_command_1
,
16131 (void *) (uintptr_t) catch_vfork_permanent
,
16132 (void *) (uintptr_t) catch_vfork_temporary
);
16133 add_catch_command ("exec", _("Catch calls to exec."),
16134 catch_exec_command_1
,
16138 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16139 Usage: catch load [REGEX]\n\
16140 If REGEX is given, only stop for libraries matching the regular expression."),
16141 catch_load_command_1
,
16145 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16146 Usage: catch unload [REGEX]\n\
16147 If REGEX is given, only stop for libraries matching the regular expression."),
16148 catch_unload_command_1
,
16153 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16154 Set a watchpoint for an expression.\n\
16155 Usage: watch [-l|-location] EXPRESSION\n\
16156 A watchpoint stops execution of your program whenever the value of\n\
16157 an expression changes.\n\
16158 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16159 the memory to which it refers."));
16160 set_cmd_completer (c
, expression_completer
);
16162 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16163 Set a read watchpoint for an expression.\n\
16164 Usage: rwatch [-l|-location] EXPRESSION\n\
16165 A watchpoint stops execution of your program whenever the value of\n\
16166 an expression is read.\n\
16167 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16168 the memory to which it refers."));
16169 set_cmd_completer (c
, expression_completer
);
16171 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16172 Set a watchpoint for an expression.\n\
16173 Usage: awatch [-l|-location] EXPRESSION\n\
16174 A watchpoint stops execution of your program whenever the value of\n\
16175 an expression is either read or written.\n\
16176 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16177 the memory to which it refers."));
16178 set_cmd_completer (c
, expression_completer
);
16180 add_info ("watchpoints", info_watchpoints_command
, _("\
16181 Status of specified watchpoints (all watchpoints if no argument)."));
16183 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16184 respond to changes - contrary to the description. */
16185 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16186 &can_use_hw_watchpoints
, _("\
16187 Set debugger's willingness to use watchpoint hardware."), _("\
16188 Show debugger's willingness to use watchpoint hardware."), _("\
16189 If zero, gdb will not use hardware for new watchpoints, even if\n\
16190 such is available. (However, any hardware watchpoints that were\n\
16191 created before setting this to nonzero, will continue to use watchpoint\n\
16194 show_can_use_hw_watchpoints
,
16195 &setlist
, &showlist
);
16197 can_use_hw_watchpoints
= 1;
16199 /* Tracepoint manipulation commands. */
16201 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16202 Set a tracepoint at specified location.\n\
16204 BREAK_ARGS_HELP ("trace") "\n\
16205 Do \"help tracepoints\" for info on other tracepoint commands."));
16206 set_cmd_completer (c
, location_completer
);
16208 add_com_alias ("tp", "trace", class_alias
, 0);
16209 add_com_alias ("tr", "trace", class_alias
, 1);
16210 add_com_alias ("tra", "trace", class_alias
, 1);
16211 add_com_alias ("trac", "trace", class_alias
, 1);
16213 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16214 Set a fast tracepoint at specified location.\n\
16216 BREAK_ARGS_HELP ("ftrace") "\n\
16217 Do \"help tracepoints\" for info on other tracepoint commands."));
16218 set_cmd_completer (c
, location_completer
);
16220 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16221 Set a static tracepoint at location or marker.\n\
16223 strace [LOCATION] [if CONDITION]\n\
16224 LOCATION may be a linespec, explicit, or address location (described below) \n\
16225 or -m MARKER_ID.\n\n\
16226 If a marker id is specified, probe the marker with that name. With\n\
16227 no LOCATION, uses current execution address of the selected stack frame.\n\
16228 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16229 This collects arbitrary user data passed in the probe point call to the\n\
16230 tracing library. You can inspect it when analyzing the trace buffer,\n\
16231 by printing the $_sdata variable like any other convenience variable.\n\
16233 CONDITION is a boolean expression.\n\
16234 \n" LOCATION_HELP_STRING
"\n\
16235 Multiple tracepoints at one place are permitted, and useful if their\n\
16236 conditions are different.\n\
16238 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16239 Do \"help tracepoints\" for info on other tracepoint commands."));
16240 set_cmd_completer (c
, location_completer
);
16242 add_info ("tracepoints", info_tracepoints_command
, _("\
16243 Status of specified tracepoints (all tracepoints if no argument).\n\
16244 Convenience variable \"$tpnum\" contains the number of the\n\
16245 last tracepoint set."));
16247 add_info_alias ("tp", "tracepoints", 1);
16249 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16250 Delete specified tracepoints.\n\
16251 Arguments are tracepoint numbers, separated by spaces.\n\
16252 No argument means delete all tracepoints."),
16254 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16256 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16257 Disable specified tracepoints.\n\
16258 Arguments are tracepoint numbers, separated by spaces.\n\
16259 No argument means disable all tracepoints."),
16261 deprecate_cmd (c
, "disable");
16263 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16264 Enable specified tracepoints.\n\
16265 Arguments are tracepoint numbers, separated by spaces.\n\
16266 No argument means enable all tracepoints."),
16268 deprecate_cmd (c
, "enable");
16270 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16271 Set the passcount for a tracepoint.\n\
16272 The trace will end when the tracepoint has been passed 'count' times.\n\
16273 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16274 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16276 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16277 _("Save breakpoint definitions as a script."),
16278 &save_cmdlist
, "save ",
16279 0/*allow-unknown*/, &cmdlist
);
16281 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16282 Save current breakpoint definitions as a script.\n\
16283 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16284 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16285 session to restore them."),
16287 set_cmd_completer (c
, filename_completer
);
16289 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16290 Save current tracepoint definitions as a script.\n\
16291 Use the 'source' command in another debug session to restore them."),
16293 set_cmd_completer (c
, filename_completer
);
16295 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16296 deprecate_cmd (c
, "save tracepoints");
16298 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16299 Breakpoint specific settings\n\
16300 Configure various breakpoint-specific variables such as\n\
16301 pending breakpoint behavior"),
16302 &breakpoint_set_cmdlist
, "set breakpoint ",
16303 0/*allow-unknown*/, &setlist
);
16304 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16305 Breakpoint specific settings\n\
16306 Configure various breakpoint-specific variables such as\n\
16307 pending breakpoint behavior"),
16308 &breakpoint_show_cmdlist
, "show breakpoint ",
16309 0/*allow-unknown*/, &showlist
);
16311 add_setshow_auto_boolean_cmd ("pending", no_class
,
16312 &pending_break_support
, _("\
16313 Set debugger's behavior regarding pending breakpoints."), _("\
16314 Show debugger's behavior regarding pending breakpoints."), _("\
16315 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16316 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16317 an error. If auto, an unrecognized breakpoint location results in a\n\
16318 user-query to see if a pending breakpoint should be created."),
16320 show_pending_break_support
,
16321 &breakpoint_set_cmdlist
,
16322 &breakpoint_show_cmdlist
);
16324 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16326 add_setshow_boolean_cmd ("auto-hw", no_class
,
16327 &automatic_hardware_breakpoints
, _("\
16328 Set automatic usage of hardware breakpoints."), _("\
16329 Show automatic usage of hardware breakpoints."), _("\
16330 If set, the debugger will automatically use hardware breakpoints for\n\
16331 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16332 a warning will be emitted for such breakpoints."),
16334 show_automatic_hardware_breakpoints
,
16335 &breakpoint_set_cmdlist
,
16336 &breakpoint_show_cmdlist
);
16338 add_setshow_boolean_cmd ("always-inserted", class_support
,
16339 &always_inserted_mode
, _("\
16340 Set mode for inserting breakpoints."), _("\
16341 Show mode for inserting breakpoints."), _("\
16342 When this mode is on, breakpoints are inserted immediately as soon as\n\
16343 they're created, kept inserted even when execution stops, and removed\n\
16344 only when the user deletes them. When this mode is off (the default),\n\
16345 breakpoints are inserted only when execution continues, and removed\n\
16346 when execution stops."),
16348 &show_always_inserted_mode
,
16349 &breakpoint_set_cmdlist
,
16350 &breakpoint_show_cmdlist
);
16352 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16353 condition_evaluation_enums
,
16354 &condition_evaluation_mode_1
, _("\
16355 Set mode of breakpoint condition evaluation."), _("\
16356 Show mode of breakpoint condition evaluation."), _("\
16357 When this is set to \"host\", breakpoint conditions will be\n\
16358 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16359 breakpoint conditions will be downloaded to the target (if the target\n\
16360 supports such feature) and conditions will be evaluated on the target's side.\n\
16361 If this is set to \"auto\" (default), this will be automatically set to\n\
16362 \"target\" if it supports condition evaluation, otherwise it will\n\
16363 be set to \"gdb\""),
16364 &set_condition_evaluation_mode
,
16365 &show_condition_evaluation_mode
,
16366 &breakpoint_set_cmdlist
,
16367 &breakpoint_show_cmdlist
);
16369 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16370 Set a breakpoint for an address range.\n\
16371 break-range START-LOCATION, END-LOCATION\n\
16372 where START-LOCATION and END-LOCATION can be one of the following:\n\
16373 LINENUM, for that line in the current file,\n\
16374 FILE:LINENUM, for that line in that file,\n\
16375 +OFFSET, for that number of lines after the current line\n\
16376 or the start of the range\n\
16377 FUNCTION, for the first line in that function,\n\
16378 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16379 *ADDRESS, for the instruction at that address.\n\
16381 The breakpoint will stop execution of the inferior whenever it executes\n\
16382 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16383 range (including START-LOCATION and END-LOCATION)."));
16385 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16386 Set a dynamic printf at specified location.\n\
16387 dprintf location,format string,arg1,arg2,...\n\
16388 location may be a linespec, explicit, or address location.\n"
16389 "\n" LOCATION_HELP_STRING
));
16390 set_cmd_completer (c
, location_completer
);
16392 add_setshow_enum_cmd ("dprintf-style", class_support
,
16393 dprintf_style_enums
, &dprintf_style
, _("\
16394 Set the style of usage for dynamic printf."), _("\
16395 Show the style of usage for dynamic printf."), _("\
16396 This setting chooses how GDB will do a dynamic printf.\n\
16397 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16398 console, as with the \"printf\" command.\n\
16399 If the value is \"call\", the print is done by calling a function in your\n\
16400 program; by default printf(), but you can choose a different function or\n\
16401 output stream by setting dprintf-function and dprintf-channel."),
16402 update_dprintf_commands
, NULL
,
16403 &setlist
, &showlist
);
16405 dprintf_function
= xstrdup ("printf");
16406 add_setshow_string_cmd ("dprintf-function", class_support
,
16407 &dprintf_function
, _("\
16408 Set the function to use for dynamic printf"), _("\
16409 Show the function to use for dynamic printf"), NULL
,
16410 update_dprintf_commands
, NULL
,
16411 &setlist
, &showlist
);
16413 dprintf_channel
= xstrdup ("");
16414 add_setshow_string_cmd ("dprintf-channel", class_support
,
16415 &dprintf_channel
, _("\
16416 Set the channel to use for dynamic printf"), _("\
16417 Show the channel to use for dynamic printf"), NULL
,
16418 update_dprintf_commands
, NULL
,
16419 &setlist
, &showlist
);
16421 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16422 &disconnected_dprintf
, _("\
16423 Set whether dprintf continues after GDB disconnects."), _("\
16424 Show whether dprintf continues after GDB disconnects."), _("\
16425 Use this to let dprintf commands continue to hit and produce output\n\
16426 even if GDB disconnects or detaches from the target."),
16429 &setlist
, &showlist
);
16431 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16432 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16433 (target agent only) This is useful for formatted output in user-defined commands."));
16435 automatic_hardware_breakpoints
= 1;
16437 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16438 observer_attach_thread_exit (remove_threaded_breakpoints
);