1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2015 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 "xml-syscall.h"
60 #include "parser-defs.h"
61 #include "gdb_regex.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "dummy-frame.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 /* Enums for exception-handling support. */
83 enum exception_event_kind
90 /* Prototypes for local functions. */
92 static void enable_delete_command (char *, int);
94 static void enable_once_command (char *, int);
96 static void enable_count_command (char *, int);
98 static void disable_command (char *, int);
100 static void enable_command (char *, int);
102 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
106 static void ignore_command (char *, int);
108 static int breakpoint_re_set_one (void *);
110 static void breakpoint_re_set_default (struct breakpoint
*);
112 static void create_sals_from_address_default (char **,
113 struct linespec_result
*,
117 static void create_breakpoints_sal_default (struct gdbarch
*,
118 struct linespec_result
*,
119 char *, char *, enum bptype
,
120 enum bpdisp
, int, int,
122 const struct breakpoint_ops
*,
123 int, int, int, unsigned);
125 static void decode_linespec_default (struct breakpoint
*, char **,
126 struct symtabs_and_lines
*);
128 static void clear_command (char *, int);
130 static void catch_command (char *, int);
132 static int can_use_hardware_watchpoint (struct value
*);
134 static void break_command_1 (char *, int, int);
136 static void mention (struct breakpoint
*);
138 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
140 const struct breakpoint_ops
*);
141 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
142 const struct symtab_and_line
*);
144 /* This function is used in gdbtk sources and thus can not be made
146 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
147 struct symtab_and_line
,
149 const struct breakpoint_ops
*);
151 static struct breakpoint
*
152 momentary_breakpoint_from_master (struct breakpoint
*orig
,
154 const struct breakpoint_ops
*ops
,
157 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
159 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
163 static void describe_other_breakpoints (struct gdbarch
*,
164 struct program_space
*, CORE_ADDR
,
165 struct obj_section
*, int);
167 static int watchpoint_locations_match (struct bp_location
*loc1
,
168 struct bp_location
*loc2
);
170 static int breakpoint_location_address_match (struct bp_location
*bl
,
171 struct address_space
*aspace
,
174 static void breakpoints_info (char *, int);
176 static void watchpoints_info (char *, int);
178 static int breakpoint_1 (char *, int,
179 int (*) (const struct breakpoint
*));
181 static int breakpoint_cond_eval (void *);
183 static void cleanup_executing_breakpoints (void *);
185 static void commands_command (char *, int);
187 static void condition_command (char *, int);
196 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
197 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
199 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
201 static int watchpoint_check (void *);
203 static void maintenance_info_breakpoints (char *, int);
205 static int hw_breakpoint_used_count (void);
207 static int hw_watchpoint_use_count (struct breakpoint
*);
209 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
211 int *other_type_used
);
213 static void hbreak_command (char *, int);
215 static void thbreak_command (char *, int);
217 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
220 static void stop_command (char *arg
, int from_tty
);
222 static void stopin_command (char *arg
, int from_tty
);
224 static void stopat_command (char *arg
, int from_tty
);
226 static void tcatch_command (char *arg
, int from_tty
);
228 static void free_bp_location (struct bp_location
*loc
);
229 static void incref_bp_location (struct bp_location
*loc
);
230 static void decref_bp_location (struct bp_location
**loc
);
232 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
234 /* update_global_location_list's modes of operation wrt to whether to
235 insert locations now. */
236 enum ugll_insert_mode
238 /* Don't insert any breakpoint locations into the inferior, only
239 remove already-inserted locations that no longer should be
240 inserted. Functions that delete a breakpoint or breakpoints
241 should specify this mode, so that deleting a breakpoint doesn't
242 have the side effect of inserting the locations of other
243 breakpoints that are marked not-inserted, but should_be_inserted
244 returns true on them.
246 This behavior is useful is situations close to tear-down -- e.g.,
247 after an exec, while the target still has execution, but
248 breakpoint shadows of the previous executable image should *NOT*
249 be restored to the new image; or before detaching, where the
250 target still has execution and wants to delete breakpoints from
251 GDB's lists, and all breakpoints had already been removed from
255 /* May insert breakpoints iff breakpoints_should_be_inserted_now
256 claims breakpoints should be inserted now. */
259 /* Insert locations now, irrespective of
260 breakpoints_should_be_inserted_now. E.g., say all threads are
261 stopped right now, and the user did "continue". We need to
262 insert breakpoints _before_ resuming the target, but
263 UGLL_MAY_INSERT wouldn't insert them, because
264 breakpoints_should_be_inserted_now returns false at that point,
265 as no thread is running yet. */
269 static void update_global_location_list (enum ugll_insert_mode
);
271 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
273 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
275 static void insert_breakpoint_locations (void);
277 static int syscall_catchpoint_p (struct breakpoint
*b
);
279 static void tracepoints_info (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num
);
291 static int is_masked_watchpoint (const struct breakpoint
*b
);
293 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint
*b
);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops
;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops
;
311 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
312 static struct breakpoint_ops longjmp_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 if (always_inserted_mode
)
476 /* The user wants breakpoints inserted even if all threads
481 if (threads_are_executing ())
487 static const char condition_evaluation_both
[] = "host or target";
489 /* Modes for breakpoint condition evaluation. */
490 static const char condition_evaluation_auto
[] = "auto";
491 static const char condition_evaluation_host
[] = "host";
492 static const char condition_evaluation_target
[] = "target";
493 static const char *const condition_evaluation_enums
[] = {
494 condition_evaluation_auto
,
495 condition_evaluation_host
,
496 condition_evaluation_target
,
500 /* Global that holds the current mode for breakpoint condition evaluation. */
501 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
503 /* Global that we use to display information to the user (gets its value from
504 condition_evaluation_mode_1. */
505 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
507 /* Translate a condition evaluation mode MODE into either "host"
508 or "target". This is used mostly to translate from "auto" to the
509 real setting that is being used. It returns the translated
513 translate_condition_evaluation_mode (const char *mode
)
515 if (mode
== condition_evaluation_auto
)
517 if (target_supports_evaluation_of_breakpoint_conditions ())
518 return condition_evaluation_target
;
520 return condition_evaluation_host
;
526 /* Discovers what condition_evaluation_auto translates to. */
529 breakpoint_condition_evaluation_mode (void)
531 return translate_condition_evaluation_mode (condition_evaluation_mode
);
534 /* Return true if GDB should evaluate breakpoint conditions or false
538 gdb_evaluates_breakpoint_condition_p (void)
540 const char *mode
= breakpoint_condition_evaluation_mode ();
542 return (mode
== condition_evaluation_host
);
545 void _initialize_breakpoint (void);
547 /* Are we executing breakpoint commands? */
548 static int executing_breakpoint_commands
;
550 /* Are overlay event breakpoints enabled? */
551 static int overlay_events_enabled
;
553 /* See description in breakpoint.h. */
554 int target_exact_watchpoints
= 0;
556 /* Walk the following statement or block through all breakpoints.
557 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
558 current breakpoint. */
560 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
562 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
563 for (B = breakpoint_chain; \
564 B ? (TMP=B->next, 1): 0; \
567 /* Similar iterator for the low-level breakpoints. SAFE variant is
568 not provided so update_global_location_list must not be called
569 while executing the block of ALL_BP_LOCATIONS. */
571 #define ALL_BP_LOCATIONS(B,BP_TMP) \
572 for (BP_TMP = bp_location; \
573 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
576 /* Iterates through locations with address ADDRESS for the currently selected
577 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
578 to where the loop should start from.
579 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
580 appropriate location to start with. */
582 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
583 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
584 BP_LOCP_TMP = BP_LOCP_START; \
586 && (BP_LOCP_TMP < bp_location + bp_location_count \
587 && (*BP_LOCP_TMP)->address == ADDRESS); \
590 /* Iterator for tracepoints only. */
592 #define ALL_TRACEPOINTS(B) \
593 for (B = breakpoint_chain; B; B = B->next) \
594 if (is_tracepoint (B))
596 /* Chains of all breakpoints defined. */
598 struct breakpoint
*breakpoint_chain
;
600 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
602 static struct bp_location
**bp_location
;
604 /* Number of elements of BP_LOCATION. */
606 static unsigned bp_location_count
;
608 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
609 ADDRESS for the current elements of BP_LOCATION which get a valid
610 result from bp_location_has_shadow. You can use it for roughly
611 limiting the subrange of BP_LOCATION to scan for shadow bytes for
612 an address you need to read. */
614 static CORE_ADDR bp_location_placed_address_before_address_max
;
616 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
617 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
618 BP_LOCATION which get a valid result from bp_location_has_shadow.
619 You can use it for roughly limiting the subrange of BP_LOCATION to
620 scan for shadow bytes for an address you need to read. */
622 static CORE_ADDR bp_location_shadow_len_after_address_max
;
624 /* The locations that no longer correspond to any breakpoint, unlinked
625 from bp_location array, but for which a hit may still be reported
627 VEC(bp_location_p
) *moribund_locations
= NULL
;
629 /* Number of last breakpoint made. */
631 static int breakpoint_count
;
633 /* The value of `breakpoint_count' before the last command that
634 created breakpoints. If the last (break-like) command created more
635 than one breakpoint, then the difference between BREAKPOINT_COUNT
636 and PREV_BREAKPOINT_COUNT is more than one. */
637 static int prev_breakpoint_count
;
639 /* Number of last tracepoint made. */
641 static int tracepoint_count
;
643 static struct cmd_list_element
*breakpoint_set_cmdlist
;
644 static struct cmd_list_element
*breakpoint_show_cmdlist
;
645 struct cmd_list_element
*save_cmdlist
;
647 /* Return whether a breakpoint is an active enabled breakpoint. */
649 breakpoint_enabled (struct breakpoint
*b
)
651 return (b
->enable_state
== bp_enabled
);
654 /* Set breakpoint count to NUM. */
657 set_breakpoint_count (int num
)
659 prev_breakpoint_count
= breakpoint_count
;
660 breakpoint_count
= num
;
661 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
664 /* Used by `start_rbreak_breakpoints' below, to record the current
665 breakpoint count before "rbreak" creates any breakpoint. */
666 static int rbreak_start_breakpoint_count
;
668 /* Called at the start an "rbreak" command to record the first
672 start_rbreak_breakpoints (void)
674 rbreak_start_breakpoint_count
= breakpoint_count
;
677 /* Called at the end of an "rbreak" command to record the last
681 end_rbreak_breakpoints (void)
683 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
686 /* Used in run_command to zero the hit count when a new run starts. */
689 clear_breakpoint_hit_counts (void)
691 struct breakpoint
*b
;
697 /* Allocate a new counted_command_line with reference count of 1.
698 The new structure owns COMMANDS. */
700 static struct counted_command_line
*
701 alloc_counted_command_line (struct command_line
*commands
)
703 struct counted_command_line
*result
704 = xmalloc (sizeof (struct counted_command_line
));
707 result
->commands
= commands
;
711 /* Increment reference count. This does nothing if CMD is NULL. */
714 incref_counted_command_line (struct counted_command_line
*cmd
)
720 /* Decrement reference count. If the reference count reaches 0,
721 destroy the counted_command_line. Sets *CMDP to NULL. This does
722 nothing if *CMDP is NULL. */
725 decref_counted_command_line (struct counted_command_line
**cmdp
)
729 if (--(*cmdp
)->refc
== 0)
731 free_command_lines (&(*cmdp
)->commands
);
738 /* A cleanup function that calls decref_counted_command_line. */
741 do_cleanup_counted_command_line (void *arg
)
743 decref_counted_command_line (arg
);
746 /* Create a cleanup that calls decref_counted_command_line on the
749 static struct cleanup
*
750 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
752 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
756 /* Return the breakpoint with the specified number, or NULL
757 if the number does not refer to an existing breakpoint. */
760 get_breakpoint (int num
)
762 struct breakpoint
*b
;
765 if (b
->number
== num
)
773 /* Mark locations as "conditions have changed" in case the target supports
774 evaluating conditions on its side. */
777 mark_breakpoint_modified (struct breakpoint
*b
)
779 struct bp_location
*loc
;
781 /* This is only meaningful if the target is
782 evaluating conditions and if the user has
783 opted for condition evaluation on the target's
785 if (gdb_evaluates_breakpoint_condition_p ()
786 || !target_supports_evaluation_of_breakpoint_conditions ())
789 if (!is_breakpoint (b
))
792 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
793 loc
->condition_changed
= condition_modified
;
796 /* Mark location as "conditions have changed" in case the target supports
797 evaluating conditions on its side. */
800 mark_breakpoint_location_modified (struct bp_location
*loc
)
802 /* This is only meaningful if the target is
803 evaluating conditions and if the user has
804 opted for condition evaluation on the target's
806 if (gdb_evaluates_breakpoint_condition_p ()
807 || !target_supports_evaluation_of_breakpoint_conditions ())
811 if (!is_breakpoint (loc
->owner
))
814 loc
->condition_changed
= condition_modified
;
817 /* Sets the condition-evaluation mode using the static global
818 condition_evaluation_mode. */
821 set_condition_evaluation_mode (char *args
, int from_tty
,
822 struct cmd_list_element
*c
)
824 const char *old_mode
, *new_mode
;
826 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
827 && !target_supports_evaluation_of_breakpoint_conditions ())
829 condition_evaluation_mode_1
= condition_evaluation_mode
;
830 warning (_("Target does not support breakpoint condition evaluation.\n"
831 "Using host evaluation mode instead."));
835 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
836 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
838 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
839 settings was "auto". */
840 condition_evaluation_mode
= condition_evaluation_mode_1
;
842 /* Only update the mode if the user picked a different one. */
843 if (new_mode
!= old_mode
)
845 struct bp_location
*loc
, **loc_tmp
;
846 /* If the user switched to a different evaluation mode, we
847 need to synch the changes with the target as follows:
849 "host" -> "target": Send all (valid) conditions to the target.
850 "target" -> "host": Remove all the conditions from the target.
853 if (new_mode
== condition_evaluation_target
)
855 /* Mark everything modified and synch conditions with the
857 ALL_BP_LOCATIONS (loc
, loc_tmp
)
858 mark_breakpoint_location_modified (loc
);
862 /* Manually mark non-duplicate locations to synch conditions
863 with the target. We do this to remove all the conditions the
864 target knows about. */
865 ALL_BP_LOCATIONS (loc
, loc_tmp
)
866 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
867 loc
->needs_update
= 1;
871 update_global_location_list (UGLL_MAY_INSERT
);
877 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
878 what "auto" is translating to. */
881 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
882 struct cmd_list_element
*c
, const char *value
)
884 if (condition_evaluation_mode
== condition_evaluation_auto
)
885 fprintf_filtered (file
,
886 _("Breakpoint condition evaluation "
887 "mode is %s (currently %s).\n"),
889 breakpoint_condition_evaluation_mode ());
891 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
895 /* A comparison function for bp_location AP and BP that is used by
896 bsearch. This comparison function only cares about addresses, unlike
897 the more general bp_location_compare function. */
900 bp_location_compare_addrs (const void *ap
, const void *bp
)
902 struct bp_location
*a
= *(void **) ap
;
903 struct bp_location
*b
= *(void **) bp
;
905 if (a
->address
== b
->address
)
908 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
911 /* Helper function to skip all bp_locations with addresses
912 less than ADDRESS. It returns the first bp_location that
913 is greater than or equal to ADDRESS. If none is found, just
916 static struct bp_location
**
917 get_first_locp_gte_addr (CORE_ADDR address
)
919 struct bp_location dummy_loc
;
920 struct bp_location
*dummy_locp
= &dummy_loc
;
921 struct bp_location
**locp_found
= NULL
;
923 /* Initialize the dummy location's address field. */
924 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
925 dummy_loc
.address
= address
;
927 /* Find a close match to the first location at ADDRESS. */
928 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
929 sizeof (struct bp_location
**),
930 bp_location_compare_addrs
);
932 /* Nothing was found, nothing left to do. */
933 if (locp_found
== NULL
)
936 /* We may have found a location that is at ADDRESS but is not the first in the
937 location's list. Go backwards (if possible) and locate the first one. */
938 while ((locp_found
- 1) >= bp_location
939 && (*(locp_found
- 1))->address
== address
)
946 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
949 xfree (b
->cond_string
);
950 b
->cond_string
= NULL
;
952 if (is_watchpoint (b
))
954 struct watchpoint
*w
= (struct watchpoint
*) b
;
961 struct bp_location
*loc
;
963 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
968 /* No need to free the condition agent expression
969 bytecode (if we have one). We will handle this
970 when we go through update_global_location_list. */
977 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
981 const char *arg
= exp
;
983 /* I don't know if it matters whether this is the string the user
984 typed in or the decompiled expression. */
985 b
->cond_string
= xstrdup (arg
);
986 b
->condition_not_parsed
= 0;
988 if (is_watchpoint (b
))
990 struct watchpoint
*w
= (struct watchpoint
*) b
;
992 innermost_block
= NULL
;
994 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
996 error (_("Junk at end of expression"));
997 w
->cond_exp_valid_block
= innermost_block
;
1001 struct bp_location
*loc
;
1003 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1007 parse_exp_1 (&arg
, loc
->address
,
1008 block_for_pc (loc
->address
), 0);
1010 error (_("Junk at end of expression"));
1014 mark_breakpoint_modified (b
);
1016 observer_notify_breakpoint_modified (b
);
1019 /* Completion for the "condition" command. */
1021 static VEC (char_ptr
) *
1022 condition_completer (struct cmd_list_element
*cmd
,
1023 const char *text
, const char *word
)
1027 text
= skip_spaces_const (text
);
1028 space
= skip_to_space_const (text
);
1032 struct breakpoint
*b
;
1033 VEC (char_ptr
) *result
= NULL
;
1037 /* We don't support completion of history indices. */
1038 if (isdigit (text
[1]))
1040 return complete_internalvar (&text
[1]);
1043 /* We're completing the breakpoint number. */
1044 len
= strlen (text
);
1050 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1052 if (strncmp (number
, text
, len
) == 0)
1053 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1059 /* We're completing the expression part. */
1060 text
= skip_spaces_const (space
);
1061 return expression_completer (cmd
, text
, word
);
1064 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1067 condition_command (char *arg
, int from_tty
)
1069 struct breakpoint
*b
;
1074 error_no_arg (_("breakpoint number"));
1077 bnum
= get_number (&p
);
1079 error (_("Bad breakpoint argument: '%s'"), arg
);
1082 if (b
->number
== bnum
)
1084 /* Check if this breakpoint has a "stop" method implemented in an
1085 extension language. This method and conditions entered into GDB
1086 from the CLI are mutually exclusive. */
1087 const struct extension_language_defn
*extlang
1088 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1090 if (extlang
!= NULL
)
1092 error (_("Only one stop condition allowed. There is currently"
1093 " a %s stop condition defined for this breakpoint."),
1094 ext_lang_capitalized_name (extlang
));
1096 set_breakpoint_condition (b
, p
, from_tty
);
1098 if (is_breakpoint (b
))
1099 update_global_location_list (UGLL_MAY_INSERT
);
1104 error (_("No breakpoint number %d."), bnum
);
1107 /* Check that COMMAND do not contain commands that are suitable
1108 only for tracepoints and not suitable for ordinary breakpoints.
1109 Throw if any such commands is found. */
1112 check_no_tracepoint_commands (struct command_line
*commands
)
1114 struct command_line
*c
;
1116 for (c
= commands
; c
; c
= c
->next
)
1120 if (c
->control_type
== while_stepping_control
)
1121 error (_("The 'while-stepping' command can "
1122 "only be used for tracepoints"));
1124 for (i
= 0; i
< c
->body_count
; ++i
)
1125 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1127 /* Not that command parsing removes leading whitespace and comment
1128 lines and also empty lines. So, we only need to check for
1129 command directly. */
1130 if (strstr (c
->line
, "collect ") == c
->line
)
1131 error (_("The 'collect' command can only be used for tracepoints"));
1133 if (strstr (c
->line
, "teval ") == c
->line
)
1134 error (_("The 'teval' command can only be used for tracepoints"));
1138 /* Encapsulate tests for different types of tracepoints. */
1141 is_tracepoint_type (enum bptype type
)
1143 return (type
== bp_tracepoint
1144 || type
== bp_fast_tracepoint
1145 || type
== bp_static_tracepoint
);
1149 is_tracepoint (const struct breakpoint
*b
)
1151 return is_tracepoint_type (b
->type
);
1154 /* A helper function that validates that COMMANDS are valid for a
1155 breakpoint. This function will throw an exception if a problem is
1159 validate_commands_for_breakpoint (struct breakpoint
*b
,
1160 struct command_line
*commands
)
1162 if (is_tracepoint (b
))
1164 struct tracepoint
*t
= (struct tracepoint
*) b
;
1165 struct command_line
*c
;
1166 struct command_line
*while_stepping
= 0;
1168 /* Reset the while-stepping step count. The previous commands
1169 might have included a while-stepping action, while the new
1173 /* We need to verify that each top-level element of commands is
1174 valid for tracepoints, that there's at most one
1175 while-stepping element, and that the while-stepping's body
1176 has valid tracing commands excluding nested while-stepping.
1177 We also need to validate the tracepoint action line in the
1178 context of the tracepoint --- validate_actionline actually
1179 has side effects, like setting the tracepoint's
1180 while-stepping STEP_COUNT, in addition to checking if the
1181 collect/teval actions parse and make sense in the
1182 tracepoint's context. */
1183 for (c
= commands
; c
; c
= c
->next
)
1185 if (c
->control_type
== while_stepping_control
)
1187 if (b
->type
== bp_fast_tracepoint
)
1188 error (_("The 'while-stepping' command "
1189 "cannot be used for fast tracepoint"));
1190 else if (b
->type
== bp_static_tracepoint
)
1191 error (_("The 'while-stepping' command "
1192 "cannot be used for static tracepoint"));
1195 error (_("The 'while-stepping' command "
1196 "can be used only once"));
1201 validate_actionline (c
->line
, b
);
1205 struct command_line
*c2
;
1207 gdb_assert (while_stepping
->body_count
== 1);
1208 c2
= while_stepping
->body_list
[0];
1209 for (; c2
; c2
= c2
->next
)
1211 if (c2
->control_type
== while_stepping_control
)
1212 error (_("The 'while-stepping' command cannot be nested"));
1218 check_no_tracepoint_commands (commands
);
1222 /* Return a vector of all the static tracepoints set at ADDR. The
1223 caller is responsible for releasing the vector. */
1226 static_tracepoints_here (CORE_ADDR addr
)
1228 struct breakpoint
*b
;
1229 VEC(breakpoint_p
) *found
= 0;
1230 struct bp_location
*loc
;
1233 if (b
->type
== bp_static_tracepoint
)
1235 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1236 if (loc
->address
== addr
)
1237 VEC_safe_push(breakpoint_p
, found
, b
);
1243 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1244 validate that only allowed commands are included. */
1247 breakpoint_set_commands (struct breakpoint
*b
,
1248 struct command_line
*commands
)
1250 validate_commands_for_breakpoint (b
, commands
);
1252 decref_counted_command_line (&b
->commands
);
1253 b
->commands
= alloc_counted_command_line (commands
);
1254 observer_notify_breakpoint_modified (b
);
1257 /* Set the internal `silent' flag on the breakpoint. Note that this
1258 is not the same as the "silent" that may appear in the breakpoint's
1262 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1264 int old_silent
= b
->silent
;
1267 if (old_silent
!= silent
)
1268 observer_notify_breakpoint_modified (b
);
1271 /* Set the thread for this breakpoint. If THREAD is -1, make the
1272 breakpoint work for any thread. */
1275 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1277 int old_thread
= b
->thread
;
1280 if (old_thread
!= thread
)
1281 observer_notify_breakpoint_modified (b
);
1284 /* Set the task for this breakpoint. If TASK is 0, make the
1285 breakpoint work for any task. */
1288 breakpoint_set_task (struct breakpoint
*b
, int task
)
1290 int old_task
= b
->task
;
1293 if (old_task
!= task
)
1294 observer_notify_breakpoint_modified (b
);
1298 check_tracepoint_command (char *line
, void *closure
)
1300 struct breakpoint
*b
= closure
;
1302 validate_actionline (line
, b
);
1305 /* A structure used to pass information through
1306 map_breakpoint_numbers. */
1308 struct commands_info
1310 /* True if the command was typed at a tty. */
1313 /* The breakpoint range spec. */
1316 /* Non-NULL if the body of the commands are being read from this
1317 already-parsed command. */
1318 struct command_line
*control
;
1320 /* The command lines read from the user, or NULL if they have not
1322 struct counted_command_line
*cmd
;
1325 /* A callback for map_breakpoint_numbers that sets the commands for
1326 commands_command. */
1329 do_map_commands_command (struct breakpoint
*b
, void *data
)
1331 struct commands_info
*info
= data
;
1333 if (info
->cmd
== NULL
)
1335 struct command_line
*l
;
1337 if (info
->control
!= NULL
)
1338 l
= copy_command_lines (info
->control
->body_list
[0]);
1341 struct cleanup
*old_chain
;
1344 str
= xstrprintf (_("Type commands for breakpoint(s) "
1345 "%s, one per line."),
1348 old_chain
= make_cleanup (xfree
, str
);
1350 l
= read_command_lines (str
,
1353 ? check_tracepoint_command
: 0),
1356 do_cleanups (old_chain
);
1359 info
->cmd
= alloc_counted_command_line (l
);
1362 /* If a breakpoint was on the list more than once, we don't need to
1364 if (b
->commands
!= info
->cmd
)
1366 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1367 incref_counted_command_line (info
->cmd
);
1368 decref_counted_command_line (&b
->commands
);
1369 b
->commands
= info
->cmd
;
1370 observer_notify_breakpoint_modified (b
);
1375 commands_command_1 (char *arg
, int from_tty
,
1376 struct command_line
*control
)
1378 struct cleanup
*cleanups
;
1379 struct commands_info info
;
1381 info
.from_tty
= from_tty
;
1382 info
.control
= control
;
1384 /* If we read command lines from the user, then `info' will hold an
1385 extra reference to the commands that we must clean up. */
1386 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1388 if (arg
== NULL
|| !*arg
)
1390 if (breakpoint_count
- prev_breakpoint_count
> 1)
1391 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1393 else if (breakpoint_count
> 0)
1394 arg
= xstrprintf ("%d", breakpoint_count
);
1397 /* So that we don't try to free the incoming non-NULL
1398 argument in the cleanup below. Mapping breakpoint
1399 numbers will fail in this case. */
1404 /* The command loop has some static state, so we need to preserve
1406 arg
= xstrdup (arg
);
1409 make_cleanup (xfree
, arg
);
1413 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1415 if (info
.cmd
== NULL
)
1416 error (_("No breakpoints specified."));
1418 do_cleanups (cleanups
);
1422 commands_command (char *arg
, int from_tty
)
1424 commands_command_1 (arg
, from_tty
, NULL
);
1427 /* Like commands_command, but instead of reading the commands from
1428 input stream, takes them from an already parsed command structure.
1430 This is used by cli-script.c to DTRT with breakpoint commands
1431 that are part of if and while bodies. */
1432 enum command_control_type
1433 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1435 commands_command_1 (arg
, 0, cmd
);
1436 return simple_control
;
1439 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1442 bp_location_has_shadow (struct bp_location
*bl
)
1444 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1448 if (bl
->target_info
.shadow_len
== 0)
1449 /* BL isn't valid, or doesn't shadow memory. */
1454 /* Update BUF, which is LEN bytes read from the target address
1455 MEMADDR, by replacing a memory breakpoint with its shadowed
1458 If READBUF is not NULL, this buffer must not overlap with the of
1459 the breakpoint location's shadow_contents buffer. Otherwise, a
1460 failed assertion internal error will be raised. */
1463 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1464 const gdb_byte
*writebuf_org
,
1465 ULONGEST memaddr
, LONGEST len
,
1466 struct bp_target_info
*target_info
,
1467 struct gdbarch
*gdbarch
)
1469 /* Now do full processing of the found relevant range of elements. */
1470 CORE_ADDR bp_addr
= 0;
1474 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1475 current_program_space
->aspace
, 0))
1477 /* The breakpoint is inserted in a different address space. */
1481 /* Addresses and length of the part of the breakpoint that
1483 bp_addr
= target_info
->placed_address
;
1484 bp_size
= target_info
->shadow_len
;
1486 if (bp_addr
+ bp_size
<= memaddr
)
1488 /* The breakpoint is entirely before the chunk of memory we are
1493 if (bp_addr
>= memaddr
+ len
)
1495 /* The breakpoint is entirely after the chunk of memory we are
1500 /* Offset within shadow_contents. */
1501 if (bp_addr
< memaddr
)
1503 /* Only copy the second part of the breakpoint. */
1504 bp_size
-= memaddr
- bp_addr
;
1505 bptoffset
= memaddr
- bp_addr
;
1509 if (bp_addr
+ bp_size
> memaddr
+ len
)
1511 /* Only copy the first part of the breakpoint. */
1512 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1515 if (readbuf
!= NULL
)
1517 /* Verify that the readbuf buffer does not overlap with the
1518 shadow_contents buffer. */
1519 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1520 || readbuf
>= (target_info
->shadow_contents
1521 + target_info
->shadow_len
));
1523 /* Update the read buffer with this inserted breakpoint's
1525 memcpy (readbuf
+ bp_addr
- memaddr
,
1526 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1530 const unsigned char *bp
;
1531 CORE_ADDR addr
= target_info
->reqstd_address
;
1534 /* Update the shadow with what we want to write to memory. */
1535 memcpy (target_info
->shadow_contents
+ bptoffset
,
1536 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1538 /* Determine appropriate breakpoint contents and size for this
1540 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1542 /* Update the final write buffer with this inserted
1543 breakpoint's INSN. */
1544 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1548 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1549 by replacing any memory breakpoints with their shadowed contents.
1551 If READBUF is not NULL, this buffer must not overlap with any of
1552 the breakpoint location's shadow_contents buffers. Otherwise,
1553 a failed assertion internal error will be raised.
1555 The range of shadowed area by each bp_location is:
1556 bl->address - bp_location_placed_address_before_address_max
1557 up to bl->address + bp_location_shadow_len_after_address_max
1558 The range we were requested to resolve shadows for is:
1559 memaddr ... memaddr + len
1560 Thus the safe cutoff boundaries for performance optimization are
1561 memaddr + len <= (bl->address
1562 - bp_location_placed_address_before_address_max)
1564 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1567 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1568 const gdb_byte
*writebuf_org
,
1569 ULONGEST memaddr
, LONGEST len
)
1571 /* Left boundary, right boundary and median element of our binary
1573 unsigned bc_l
, bc_r
, bc
;
1576 /* Find BC_L which is a leftmost element which may affect BUF
1577 content. It is safe to report lower value but a failure to
1578 report higher one. */
1581 bc_r
= bp_location_count
;
1582 while (bc_l
+ 1 < bc_r
)
1584 struct bp_location
*bl
;
1586 bc
= (bc_l
+ bc_r
) / 2;
1587 bl
= bp_location
[bc
];
1589 /* Check first BL->ADDRESS will not overflow due to the added
1590 constant. Then advance the left boundary only if we are sure
1591 the BC element can in no way affect the BUF content (MEMADDR
1592 to MEMADDR + LEN range).
1594 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1595 offset so that we cannot miss a breakpoint with its shadow
1596 range tail still reaching MEMADDR. */
1598 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1600 && (bl
->address
+ bp_location_shadow_len_after_address_max
1607 /* Due to the binary search above, we need to make sure we pick the
1608 first location that's at BC_L's address. E.g., if there are
1609 multiple locations at the same address, BC_L may end up pointing
1610 at a duplicate location, and miss the "master"/"inserted"
1611 location. Say, given locations L1, L2 and L3 at addresses A and
1614 L1@A, L2@A, L3@B, ...
1616 BC_L could end up pointing at location L2, while the "master"
1617 location could be L1. Since the `loc->inserted' flag is only set
1618 on "master" locations, we'd forget to restore the shadow of L1
1621 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1624 /* Now do full processing of the found relevant range of elements. */
1626 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1628 struct bp_location
*bl
= bp_location
[bc
];
1629 CORE_ADDR bp_addr
= 0;
1633 /* bp_location array has BL->OWNER always non-NULL. */
1634 if (bl
->owner
->type
== bp_none
)
1635 warning (_("reading through apparently deleted breakpoint #%d?"),
1638 /* Performance optimization: any further element can no longer affect BUF
1641 if (bl
->address
>= bp_location_placed_address_before_address_max
1642 && memaddr
+ len
<= (bl
->address
1643 - bp_location_placed_address_before_address_max
))
1646 if (!bp_location_has_shadow (bl
))
1649 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1650 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1656 /* Return true if BPT is either a software breakpoint or a hardware
1660 is_breakpoint (const struct breakpoint
*bpt
)
1662 return (bpt
->type
== bp_breakpoint
1663 || bpt
->type
== bp_hardware_breakpoint
1664 || bpt
->type
== bp_dprintf
);
1667 /* Return true if BPT is of any hardware watchpoint kind. */
1670 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1672 return (bpt
->type
== bp_hardware_watchpoint
1673 || bpt
->type
== bp_read_watchpoint
1674 || bpt
->type
== bp_access_watchpoint
);
1677 /* Return true if BPT is of any watchpoint kind, hardware or
1681 is_watchpoint (const struct breakpoint
*bpt
)
1683 return (is_hardware_watchpoint (bpt
)
1684 || bpt
->type
== bp_watchpoint
);
1687 /* Returns true if the current thread and its running state are safe
1688 to evaluate or update watchpoint B. Watchpoints on local
1689 expressions need to be evaluated in the context of the thread that
1690 was current when the watchpoint was created, and, that thread needs
1691 to be stopped to be able to select the correct frame context.
1692 Watchpoints on global expressions can be evaluated on any thread,
1693 and in any state. It is presently left to the target allowing
1694 memory accesses when threads are running. */
1697 watchpoint_in_thread_scope (struct watchpoint
*b
)
1699 return (b
->base
.pspace
== current_program_space
1700 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1701 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1702 && !is_executing (inferior_ptid
))));
1705 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1706 associated bp_watchpoint_scope breakpoint. */
1709 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1711 struct breakpoint
*b
= &w
->base
;
1713 if (b
->related_breakpoint
!= b
)
1715 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1716 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1717 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1718 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1719 b
->related_breakpoint
= b
;
1721 b
->disposition
= disp_del_at_next_stop
;
1724 /* Extract a bitfield value from value VAL using the bit parameters contained in
1727 static struct value
*
1728 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1730 struct value
*bit_val
;
1735 bit_val
= allocate_value (value_type (val
));
1737 unpack_value_bitfield (bit_val
,
1740 value_contents_for_printing (val
),
1747 /* Assuming that B is a watchpoint:
1748 - Reparse watchpoint expression, if REPARSE is non-zero
1749 - Evaluate expression and store the result in B->val
1750 - Evaluate the condition if there is one, and store the result
1752 - Update the list of values that must be watched in B->loc.
1754 If the watchpoint disposition is disp_del_at_next_stop, then do
1755 nothing. If this is local watchpoint that is out of scope, delete
1758 Even with `set breakpoint always-inserted on' the watchpoints are
1759 removed + inserted on each stop here. Normal breakpoints must
1760 never be removed because they might be missed by a running thread
1761 when debugging in non-stop mode. On the other hand, hardware
1762 watchpoints (is_hardware_watchpoint; processed here) are specific
1763 to each LWP since they are stored in each LWP's hardware debug
1764 registers. Therefore, such LWP must be stopped first in order to
1765 be able to modify its hardware watchpoints.
1767 Hardware watchpoints must be reset exactly once after being
1768 presented to the user. It cannot be done sooner, because it would
1769 reset the data used to present the watchpoint hit to the user. And
1770 it must not be done later because it could display the same single
1771 watchpoint hit during multiple GDB stops. Note that the latter is
1772 relevant only to the hardware watchpoint types bp_read_watchpoint
1773 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1774 not user-visible - its hit is suppressed if the memory content has
1777 The following constraints influence the location where we can reset
1778 hardware watchpoints:
1780 * target_stopped_by_watchpoint and target_stopped_data_address are
1781 called several times when GDB stops.
1784 * Multiple hardware watchpoints can be hit at the same time,
1785 causing GDB to stop. GDB only presents one hardware watchpoint
1786 hit at a time as the reason for stopping, and all the other hits
1787 are presented later, one after the other, each time the user
1788 requests the execution to be resumed. Execution is not resumed
1789 for the threads still having pending hit event stored in
1790 LWP_INFO->STATUS. While the watchpoint is already removed from
1791 the inferior on the first stop the thread hit event is kept being
1792 reported from its cached value by linux_nat_stopped_data_address
1793 until the real thread resume happens after the watchpoint gets
1794 presented and thus its LWP_INFO->STATUS gets reset.
1796 Therefore the hardware watchpoint hit can get safely reset on the
1797 watchpoint removal from inferior. */
1800 update_watchpoint (struct watchpoint
*b
, int reparse
)
1802 int within_current_scope
;
1803 struct frame_id saved_frame_id
;
1806 /* If this is a local watchpoint, we only want to check if the
1807 watchpoint frame is in scope if the current thread is the thread
1808 that was used to create the watchpoint. */
1809 if (!watchpoint_in_thread_scope (b
))
1812 if (b
->base
.disposition
== disp_del_at_next_stop
)
1817 /* Determine if the watchpoint is within scope. */
1818 if (b
->exp_valid_block
== NULL
)
1819 within_current_scope
= 1;
1822 struct frame_info
*fi
= get_current_frame ();
1823 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1824 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1826 /* If we're in a function epilogue, unwinding may not work
1827 properly, so do not attempt to recreate locations at this
1828 point. See similar comments in watchpoint_check. */
1829 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1832 /* Save the current frame's ID so we can restore it after
1833 evaluating the watchpoint expression on its own frame. */
1834 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1835 took a frame parameter, so that we didn't have to change the
1838 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1840 fi
= frame_find_by_id (b
->watchpoint_frame
);
1841 within_current_scope
= (fi
!= NULL
);
1842 if (within_current_scope
)
1846 /* We don't free locations. They are stored in the bp_location array
1847 and update_global_location_list will eventually delete them and
1848 remove breakpoints if needed. */
1851 if (within_current_scope
&& reparse
)
1860 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1861 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1862 /* If the meaning of expression itself changed, the old value is
1863 no longer relevant. We don't want to report a watchpoint hit
1864 to the user when the old value and the new value may actually
1865 be completely different objects. */
1866 value_free (b
->val
);
1870 /* Note that unlike with breakpoints, the watchpoint's condition
1871 expression is stored in the breakpoint object, not in the
1872 locations (re)created below. */
1873 if (b
->base
.cond_string
!= NULL
)
1875 if (b
->cond_exp
!= NULL
)
1877 xfree (b
->cond_exp
);
1881 s
= b
->base
.cond_string
;
1882 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1886 /* If we failed to parse the expression, for example because
1887 it refers to a global variable in a not-yet-loaded shared library,
1888 don't try to insert watchpoint. We don't automatically delete
1889 such watchpoint, though, since failure to parse expression
1890 is different from out-of-scope watchpoint. */
1891 if (!target_has_execution
)
1893 /* Without execution, memory can't change. No use to try and
1894 set watchpoint locations. The watchpoint will be reset when
1895 the target gains execution, through breakpoint_re_set. */
1896 if (!can_use_hw_watchpoints
)
1898 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1899 b
->base
.type
= bp_watchpoint
;
1901 error (_("Can't set read/access watchpoint when "
1902 "hardware watchpoints are disabled."));
1905 else if (within_current_scope
&& b
->exp
)
1908 struct value
*val_chain
, *v
, *result
, *next
;
1909 struct program_space
*frame_pspace
;
1911 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1913 /* Avoid setting b->val if it's already set. The meaning of
1914 b->val is 'the last value' user saw, and we should update
1915 it only if we reported that last value to user. As it
1916 happens, the code that reports it updates b->val directly.
1917 We don't keep track of the memory value for masked
1919 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1921 if (b
->val_bitsize
!= 0)
1923 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1931 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1933 /* Look at each value on the value chain. */
1934 for (v
= val_chain
; v
; v
= value_next (v
))
1936 /* If it's a memory location, and GDB actually needed
1937 its contents to evaluate the expression, then we
1938 must watch it. If the first value returned is
1939 still lazy, that means an error occurred reading it;
1940 watch it anyway in case it becomes readable. */
1941 if (VALUE_LVAL (v
) == lval_memory
1942 && (v
== val_chain
|| ! value_lazy (v
)))
1944 struct type
*vtype
= check_typedef (value_type (v
));
1946 /* We only watch structs and arrays if user asked
1947 for it explicitly, never if they just happen to
1948 appear in the middle of some value chain. */
1950 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1951 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1955 struct bp_location
*loc
, **tmp
;
1956 int bitpos
= 0, bitsize
= 0;
1958 if (value_bitsize (v
) != 0)
1960 /* Extract the bit parameters out from the bitfield
1962 bitpos
= value_bitpos (v
);
1963 bitsize
= value_bitsize (v
);
1965 else if (v
== result
&& b
->val_bitsize
!= 0)
1967 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1968 lvalue whose bit parameters are saved in the fields
1969 VAL_BITPOS and VAL_BITSIZE. */
1970 bitpos
= b
->val_bitpos
;
1971 bitsize
= b
->val_bitsize
;
1974 addr
= value_address (v
);
1977 /* Skip the bytes that don't contain the bitfield. */
1982 if (b
->base
.type
== bp_read_watchpoint
)
1984 else if (b
->base
.type
== bp_access_watchpoint
)
1987 loc
= allocate_bp_location (&b
->base
);
1988 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1991 loc
->gdbarch
= get_type_arch (value_type (v
));
1993 loc
->pspace
= frame_pspace
;
1994 loc
->address
= addr
;
1998 /* Just cover the bytes that make up the bitfield. */
1999 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2002 loc
->length
= TYPE_LENGTH (value_type (v
));
2004 loc
->watchpoint_type
= type
;
2009 /* Change the type of breakpoint between hardware assisted or
2010 an ordinary watchpoint depending on the hardware support
2011 and free hardware slots. REPARSE is set when the inferior
2016 enum bp_loc_type loc_type
;
2017 struct bp_location
*bl
;
2019 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2023 int i
, target_resources_ok
, other_type_used
;
2026 /* Use an exact watchpoint when there's only one memory region to be
2027 watched, and only one debug register is needed to watch it. */
2028 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2030 /* We need to determine how many resources are already
2031 used for all other hardware watchpoints plus this one
2032 to see if we still have enough resources to also fit
2033 this watchpoint in as well. */
2035 /* If this is a software watchpoint, we try to turn it
2036 to a hardware one -- count resources as if B was of
2037 hardware watchpoint type. */
2038 type
= b
->base
.type
;
2039 if (type
== bp_watchpoint
)
2040 type
= bp_hardware_watchpoint
;
2042 /* This watchpoint may or may not have been placed on
2043 the list yet at this point (it won't be in the list
2044 if we're trying to create it for the first time,
2045 through watch_command), so always account for it
2048 /* Count resources used by all watchpoints except B. */
2049 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2051 /* Add in the resources needed for B. */
2052 i
+= hw_watchpoint_use_count (&b
->base
);
2055 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2056 if (target_resources_ok
<= 0)
2058 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2060 if (target_resources_ok
== 0 && !sw_mode
)
2061 error (_("Target does not support this type of "
2062 "hardware watchpoint."));
2063 else if (target_resources_ok
< 0 && !sw_mode
)
2064 error (_("There are not enough available hardware "
2065 "resources for this watchpoint."));
2067 /* Downgrade to software watchpoint. */
2068 b
->base
.type
= bp_watchpoint
;
2072 /* If this was a software watchpoint, we've just
2073 found we have enough resources to turn it to a
2074 hardware watchpoint. Otherwise, this is a
2076 b
->base
.type
= type
;
2079 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2081 if (!can_use_hw_watchpoints
)
2082 error (_("Can't set read/access watchpoint when "
2083 "hardware watchpoints are disabled."));
2085 error (_("Expression cannot be implemented with "
2086 "read/access watchpoint."));
2089 b
->base
.type
= bp_watchpoint
;
2091 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2092 : bp_loc_hardware_watchpoint
);
2093 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2094 bl
->loc_type
= loc_type
;
2097 for (v
= val_chain
; v
; v
= next
)
2099 next
= value_next (v
);
2104 /* If a software watchpoint is not watching any memory, then the
2105 above left it without any location set up. But,
2106 bpstat_stop_status requires a location to be able to report
2107 stops, so make sure there's at least a dummy one. */
2108 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2110 struct breakpoint
*base
= &b
->base
;
2111 base
->loc
= allocate_bp_location (base
);
2112 base
->loc
->pspace
= frame_pspace
;
2113 base
->loc
->address
= -1;
2114 base
->loc
->length
= -1;
2115 base
->loc
->watchpoint_type
= -1;
2118 else if (!within_current_scope
)
2120 printf_filtered (_("\
2121 Watchpoint %d deleted because the program has left the block\n\
2122 in which its expression is valid.\n"),
2124 watchpoint_del_at_next_stop (b
);
2127 /* Restore the selected frame. */
2129 select_frame (frame_find_by_id (saved_frame_id
));
2133 /* Returns 1 iff breakpoint location should be
2134 inserted in the inferior. We don't differentiate the type of BL's owner
2135 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2136 breakpoint_ops is not defined, because in insert_bp_location,
2137 tracepoint's insert_location will not be called. */
2139 should_be_inserted (struct bp_location
*bl
)
2141 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2144 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2147 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2150 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2153 /* This is set for example, when we're attached to the parent of a
2154 vfork, and have detached from the child. The child is running
2155 free, and we expect it to do an exec or exit, at which point the
2156 OS makes the parent schedulable again (and the target reports
2157 that the vfork is done). Until the child is done with the shared
2158 memory region, do not insert breakpoints in the parent, otherwise
2159 the child could still trip on the parent's breakpoints. Since
2160 the parent is blocked anyway, it won't miss any breakpoint. */
2161 if (bl
->pspace
->breakpoints_not_allowed
)
2164 /* Don't insert a breakpoint if we're trying to step past its
2166 if ((bl
->loc_type
== bp_loc_software_breakpoint
2167 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2168 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2173 fprintf_unfiltered (gdb_stdlog
,
2174 "infrun: skipping breakpoint: "
2175 "stepping past insn at: %s\n",
2176 paddress (bl
->gdbarch
, bl
->address
));
2181 /* Don't insert watchpoints if we're trying to step past the
2182 instruction that triggered one. */
2183 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2184 && stepping_past_nonsteppable_watchpoint ())
2188 fprintf_unfiltered (gdb_stdlog
,
2189 "infrun: stepping past non-steppable watchpoint. "
2190 "skipping watchpoint at %s:%d\n",
2191 paddress (bl
->gdbarch
, bl
->address
),
2200 /* Same as should_be_inserted but does the check assuming
2201 that the location is not duplicated. */
2204 unduplicated_should_be_inserted (struct bp_location
*bl
)
2207 const int save_duplicate
= bl
->duplicate
;
2210 result
= should_be_inserted (bl
);
2211 bl
->duplicate
= save_duplicate
;
2215 /* Parses a conditional described by an expression COND into an
2216 agent expression bytecode suitable for evaluation
2217 by the bytecode interpreter. Return NULL if there was
2218 any error during parsing. */
2220 static struct agent_expr
*
2221 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2223 struct agent_expr
*aexpr
= NULL
;
2224 volatile struct gdb_exception ex
;
2229 /* We don't want to stop processing, so catch any errors
2230 that may show up. */
2231 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2233 aexpr
= gen_eval_for_expr (scope
, cond
);
2238 /* If we got here, it means the condition could not be parsed to a valid
2239 bytecode expression and thus can't be evaluated on the target's side.
2240 It's no use iterating through the conditions. */
2244 /* We have a valid agent expression. */
2248 /* Based on location BL, create a list of breakpoint conditions to be
2249 passed on to the target. If we have duplicated locations with different
2250 conditions, we will add such conditions to the list. The idea is that the
2251 target will evaluate the list of conditions and will only notify GDB when
2252 one of them is true. */
2255 build_target_condition_list (struct bp_location
*bl
)
2257 struct bp_location
**locp
= NULL
, **loc2p
;
2258 int null_condition_or_parse_error
= 0;
2259 int modified
= bl
->needs_update
;
2260 struct bp_location
*loc
;
2262 /* Release conditions left over from a previous insert. */
2263 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2265 /* This is only meaningful if the target is
2266 evaluating conditions and if the user has
2267 opted for condition evaluation on the target's
2269 if (gdb_evaluates_breakpoint_condition_p ()
2270 || !target_supports_evaluation_of_breakpoint_conditions ())
2273 /* Do a first pass to check for locations with no assigned
2274 conditions or conditions that fail to parse to a valid agent expression
2275 bytecode. If any of these happen, then it's no use to send conditions
2276 to the target since this location will always trigger and generate a
2277 response back to GDB. */
2278 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2281 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2285 struct agent_expr
*aexpr
;
2287 /* Re-parse the conditions since something changed. In that
2288 case we already freed the condition bytecodes (see
2289 force_breakpoint_reinsertion). We just
2290 need to parse the condition to bytecodes again. */
2291 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2292 loc
->cond_bytecode
= aexpr
;
2294 /* Check if we managed to parse the conditional expression
2295 correctly. If not, we will not send this condition
2301 /* If we have a NULL bytecode expression, it means something
2302 went wrong or we have a null condition expression. */
2303 if (!loc
->cond_bytecode
)
2305 null_condition_or_parse_error
= 1;
2311 /* If any of these happened, it means we will have to evaluate the conditions
2312 for the location's address on gdb's side. It is no use keeping bytecodes
2313 for all the other duplicate locations, thus we free all of them here.
2315 This is so we have a finer control over which locations' conditions are
2316 being evaluated by GDB or the remote stub. */
2317 if (null_condition_or_parse_error
)
2319 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2322 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2324 /* Only go as far as the first NULL bytecode is
2326 if (!loc
->cond_bytecode
)
2329 free_agent_expr (loc
->cond_bytecode
);
2330 loc
->cond_bytecode
= NULL
;
2335 /* No NULL conditions or failed bytecode generation. Build a condition list
2336 for this location's address. */
2337 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2341 && is_breakpoint (loc
->owner
)
2342 && loc
->pspace
->num
== bl
->pspace
->num
2343 && loc
->owner
->enable_state
== bp_enabled
2345 /* Add the condition to the vector. This will be used later to send the
2346 conditions to the target. */
2347 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2348 loc
->cond_bytecode
);
2354 /* Parses a command described by string CMD into an agent expression
2355 bytecode suitable for evaluation by the bytecode interpreter.
2356 Return NULL if there was any error during parsing. */
2358 static struct agent_expr
*
2359 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2361 struct cleanup
*old_cleanups
= 0;
2362 struct expression
*expr
, **argvec
;
2363 struct agent_expr
*aexpr
= NULL
;
2364 volatile struct gdb_exception ex
;
2365 const char *cmdrest
;
2366 const char *format_start
, *format_end
;
2367 struct format_piece
*fpieces
;
2369 struct gdbarch
*gdbarch
= get_current_arch ();
2376 if (*cmdrest
== ',')
2378 cmdrest
= skip_spaces_const (cmdrest
);
2380 if (*cmdrest
++ != '"')
2381 error (_("No format string following the location"));
2383 format_start
= cmdrest
;
2385 fpieces
= parse_format_string (&cmdrest
);
2387 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2389 format_end
= cmdrest
;
2391 if (*cmdrest
++ != '"')
2392 error (_("Bad format string, non-terminated '\"'."));
2394 cmdrest
= skip_spaces_const (cmdrest
);
2396 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2397 error (_("Invalid argument syntax"));
2399 if (*cmdrest
== ',')
2401 cmdrest
= skip_spaces_const (cmdrest
);
2403 /* For each argument, make an expression. */
2405 argvec
= (struct expression
**) alloca (strlen (cmd
)
2406 * sizeof (struct expression
*));
2409 while (*cmdrest
!= '\0')
2414 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2415 argvec
[nargs
++] = expr
;
2417 if (*cmdrest
== ',')
2421 /* We don't want to stop processing, so catch any errors
2422 that may show up. */
2423 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2425 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2426 format_start
, format_end
- format_start
,
2427 fpieces
, nargs
, argvec
);
2430 do_cleanups (old_cleanups
);
2434 /* If we got here, it means the command could not be parsed to a valid
2435 bytecode expression and thus can't be evaluated on the target's side.
2436 It's no use iterating through the other commands. */
2440 /* We have a valid agent expression, return it. */
2444 /* Based on location BL, create a list of breakpoint commands to be
2445 passed on to the target. If we have duplicated locations with
2446 different commands, we will add any such to the list. */
2449 build_target_command_list (struct bp_location
*bl
)
2451 struct bp_location
**locp
= NULL
, **loc2p
;
2452 int null_command_or_parse_error
= 0;
2453 int modified
= bl
->needs_update
;
2454 struct bp_location
*loc
;
2456 /* Release commands left over from a previous insert. */
2457 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2459 if (!target_can_run_breakpoint_commands ())
2462 /* For now, limit to agent-style dprintf breakpoints. */
2463 if (dprintf_style
!= dprintf_style_agent
)
2466 /* For now, if we have any duplicate location that isn't a dprintf,
2467 don't install the target-side commands, as that would make the
2468 breakpoint not be reported to the core, and we'd lose
2470 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2473 if (is_breakpoint (loc
->owner
)
2474 && loc
->pspace
->num
== bl
->pspace
->num
2475 && loc
->owner
->type
!= bp_dprintf
)
2479 /* Do a first pass to check for locations with no assigned
2480 conditions or conditions that fail to parse to a valid agent expression
2481 bytecode. If any of these happen, then it's no use to send conditions
2482 to the target since this location will always trigger and generate a
2483 response back to GDB. */
2484 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2487 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2491 struct agent_expr
*aexpr
;
2493 /* Re-parse the commands since something changed. In that
2494 case we already freed the command bytecodes (see
2495 force_breakpoint_reinsertion). We just
2496 need to parse the command to bytecodes again. */
2497 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2498 loc
->owner
->extra_string
);
2499 loc
->cmd_bytecode
= aexpr
;
2505 /* If we have a NULL bytecode expression, it means something
2506 went wrong or we have a null command expression. */
2507 if (!loc
->cmd_bytecode
)
2509 null_command_or_parse_error
= 1;
2515 /* If anything failed, then we're not doing target-side commands,
2517 if (null_command_or_parse_error
)
2519 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2522 if (is_breakpoint (loc
->owner
)
2523 && loc
->pspace
->num
== bl
->pspace
->num
)
2525 /* Only go as far as the first NULL bytecode is
2527 if (loc
->cmd_bytecode
== NULL
)
2530 free_agent_expr (loc
->cmd_bytecode
);
2531 loc
->cmd_bytecode
= NULL
;
2536 /* No NULL commands or failed bytecode generation. Build a command list
2537 for this location's address. */
2538 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2541 if (loc
->owner
->extra_string
2542 && is_breakpoint (loc
->owner
)
2543 && loc
->pspace
->num
== bl
->pspace
->num
2544 && loc
->owner
->enable_state
== bp_enabled
2546 /* Add the command to the vector. This will be used later
2547 to send the commands to the target. */
2548 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2552 bl
->target_info
.persist
= 0;
2553 /* Maybe flag this location as persistent. */
2554 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2555 bl
->target_info
.persist
= 1;
2558 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2559 location. Any error messages are printed to TMP_ERROR_STREAM; and
2560 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2561 Returns 0 for success, 1 if the bp_location type is not supported or
2564 NOTE drow/2003-09-09: This routine could be broken down to an
2565 object-style method for each breakpoint or catchpoint type. */
2567 insert_bp_location (struct bp_location
*bl
,
2568 struct ui_file
*tmp_error_stream
,
2569 int *disabled_breaks
,
2570 int *hw_breakpoint_error
,
2571 int *hw_bp_error_explained_already
)
2573 enum errors bp_err
= GDB_NO_ERROR
;
2574 const char *bp_err_message
= NULL
;
2575 volatile struct gdb_exception e
;
2577 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2580 /* Note we don't initialize bl->target_info, as that wipes out
2581 the breakpoint location's shadow_contents if the breakpoint
2582 is still inserted at that location. This in turn breaks
2583 target_read_memory which depends on these buffers when
2584 a memory read is requested at the breakpoint location:
2585 Once the target_info has been wiped, we fail to see that
2586 we have a breakpoint inserted at that address and thus
2587 read the breakpoint instead of returning the data saved in
2588 the breakpoint location's shadow contents. */
2589 bl
->target_info
.reqstd_address
= bl
->address
;
2590 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2591 bl
->target_info
.length
= bl
->length
;
2593 /* When working with target-side conditions, we must pass all the conditions
2594 for the same breakpoint address down to the target since GDB will not
2595 insert those locations. With a list of breakpoint conditions, the target
2596 can decide when to stop and notify GDB. */
2598 if (is_breakpoint (bl
->owner
))
2600 build_target_condition_list (bl
);
2601 build_target_command_list (bl
);
2602 /* Reset the modification marker. */
2603 bl
->needs_update
= 0;
2606 if (bl
->loc_type
== bp_loc_software_breakpoint
2607 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2609 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2611 /* If the explicitly specified breakpoint type
2612 is not hardware breakpoint, check the memory map to see
2613 if the breakpoint address is in read only memory or not.
2615 Two important cases are:
2616 - location type is not hardware breakpoint, memory
2617 is readonly. We change the type of the location to
2618 hardware breakpoint.
2619 - location type is hardware breakpoint, memory is
2620 read-write. This means we've previously made the
2621 location hardware one, but then the memory map changed,
2624 When breakpoints are removed, remove_breakpoints will use
2625 location types we've just set here, the only possible
2626 problem is that memory map has changed during running
2627 program, but it's not going to work anyway with current
2629 struct mem_region
*mr
2630 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2634 if (automatic_hardware_breakpoints
)
2636 enum bp_loc_type new_type
;
2638 if (mr
->attrib
.mode
!= MEM_RW
)
2639 new_type
= bp_loc_hardware_breakpoint
;
2641 new_type
= bp_loc_software_breakpoint
;
2643 if (new_type
!= bl
->loc_type
)
2645 static int said
= 0;
2647 bl
->loc_type
= new_type
;
2650 fprintf_filtered (gdb_stdout
,
2651 _("Note: automatically using "
2652 "hardware breakpoints for "
2653 "read-only addresses.\n"));
2658 else if (bl
->loc_type
== bp_loc_software_breakpoint
2659 && mr
->attrib
.mode
!= MEM_RW
)
2661 fprintf_unfiltered (tmp_error_stream
,
2662 _("Cannot insert breakpoint %d.\n"
2663 "Cannot set software breakpoint "
2664 "at read-only address %s\n"),
2666 paddress (bl
->gdbarch
, bl
->address
));
2672 /* First check to see if we have to handle an overlay. */
2673 if (overlay_debugging
== ovly_off
2674 || bl
->section
== NULL
2675 || !(section_is_overlay (bl
->section
)))
2677 /* No overlay handling: just set the breakpoint. */
2678 TRY_CATCH (e
, RETURN_MASK_ALL
)
2682 val
= bl
->owner
->ops
->insert_location (bl
);
2684 bp_err
= GENERIC_ERROR
;
2689 bp_err_message
= e
.message
;
2694 /* This breakpoint is in an overlay section.
2695 Shall we set a breakpoint at the LMA? */
2696 if (!overlay_events_enabled
)
2698 /* Yes -- overlay event support is not active,
2699 so we must try to set a breakpoint at the LMA.
2700 This will not work for a hardware breakpoint. */
2701 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2702 warning (_("hardware breakpoint %d not supported in overlay!"),
2706 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2708 /* Set a software (trap) breakpoint at the LMA. */
2709 bl
->overlay_target_info
= bl
->target_info
;
2710 bl
->overlay_target_info
.reqstd_address
= addr
;
2712 /* No overlay handling: just set the breakpoint. */
2713 TRY_CATCH (e
, RETURN_MASK_ALL
)
2717 val
= target_insert_breakpoint (bl
->gdbarch
,
2718 &bl
->overlay_target_info
);
2720 bp_err
= GENERIC_ERROR
;
2725 bp_err_message
= e
.message
;
2728 if (bp_err
!= GDB_NO_ERROR
)
2729 fprintf_unfiltered (tmp_error_stream
,
2730 "Overlay breakpoint %d "
2731 "failed: in ROM?\n",
2735 /* Shall we set a breakpoint at the VMA? */
2736 if (section_is_mapped (bl
->section
))
2738 /* Yes. This overlay section is mapped into memory. */
2739 TRY_CATCH (e
, RETURN_MASK_ALL
)
2743 val
= bl
->owner
->ops
->insert_location (bl
);
2745 bp_err
= GENERIC_ERROR
;
2750 bp_err_message
= e
.message
;
2755 /* No. This breakpoint will not be inserted.
2756 No error, but do not mark the bp as 'inserted'. */
2761 if (bp_err
!= GDB_NO_ERROR
)
2763 /* Can't set the breakpoint. */
2765 /* In some cases, we might not be able to insert a
2766 breakpoint in a shared library that has already been
2767 removed, but we have not yet processed the shlib unload
2768 event. Unfortunately, some targets that implement
2769 breakpoint insertion themselves can't tell why the
2770 breakpoint insertion failed (e.g., the remote target
2771 doesn't define error codes), so we must treat generic
2772 errors as memory errors. */
2773 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2774 && bl
->loc_type
== bp_loc_software_breakpoint
2775 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2776 || shared_objfile_contains_address_p (bl
->pspace
,
2779 /* See also: disable_breakpoints_in_shlibs. */
2780 bl
->shlib_disabled
= 1;
2781 observer_notify_breakpoint_modified (bl
->owner
);
2782 if (!*disabled_breaks
)
2784 fprintf_unfiltered (tmp_error_stream
,
2785 "Cannot insert breakpoint %d.\n",
2787 fprintf_unfiltered (tmp_error_stream
,
2788 "Temporarily disabling shared "
2789 "library breakpoints:\n");
2791 *disabled_breaks
= 1;
2792 fprintf_unfiltered (tmp_error_stream
,
2793 "breakpoint #%d\n", bl
->owner
->number
);
2798 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2800 *hw_breakpoint_error
= 1;
2801 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2802 fprintf_unfiltered (tmp_error_stream
,
2803 "Cannot insert hardware breakpoint %d%s",
2804 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2805 if (bp_err_message
!= NULL
)
2806 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2810 if (bp_err_message
== NULL
)
2813 = memory_error_message (TARGET_XFER_E_IO
,
2814 bl
->gdbarch
, bl
->address
);
2815 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2817 fprintf_unfiltered (tmp_error_stream
,
2818 "Cannot insert breakpoint %d.\n"
2820 bl
->owner
->number
, message
);
2821 do_cleanups (old_chain
);
2825 fprintf_unfiltered (tmp_error_stream
,
2826 "Cannot insert breakpoint %d: %s\n",
2841 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2842 /* NOTE drow/2003-09-08: This state only exists for removing
2843 watchpoints. It's not clear that it's necessary... */
2844 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2848 gdb_assert (bl
->owner
->ops
!= NULL
2849 && bl
->owner
->ops
->insert_location
!= NULL
);
2851 val
= bl
->owner
->ops
->insert_location (bl
);
2853 /* If trying to set a read-watchpoint, and it turns out it's not
2854 supported, try emulating one with an access watchpoint. */
2855 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2857 struct bp_location
*loc
, **loc_temp
;
2859 /* But don't try to insert it, if there's already another
2860 hw_access location that would be considered a duplicate
2862 ALL_BP_LOCATIONS (loc
, loc_temp
)
2864 && loc
->watchpoint_type
== hw_access
2865 && watchpoint_locations_match (bl
, loc
))
2869 bl
->target_info
= loc
->target_info
;
2870 bl
->watchpoint_type
= hw_access
;
2877 bl
->watchpoint_type
= hw_access
;
2878 val
= bl
->owner
->ops
->insert_location (bl
);
2881 /* Back to the original value. */
2882 bl
->watchpoint_type
= hw_read
;
2886 bl
->inserted
= (val
== 0);
2889 else if (bl
->owner
->type
== bp_catchpoint
)
2893 gdb_assert (bl
->owner
->ops
!= NULL
2894 && bl
->owner
->ops
->insert_location
!= NULL
);
2896 val
= bl
->owner
->ops
->insert_location (bl
);
2899 bl
->owner
->enable_state
= bp_disabled
;
2903 Error inserting catchpoint %d: Your system does not support this type\n\
2904 of catchpoint."), bl
->owner
->number
);
2906 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2909 bl
->inserted
= (val
== 0);
2911 /* We've already printed an error message if there was a problem
2912 inserting this catchpoint, and we've disabled the catchpoint,
2913 so just return success. */
2920 /* This function is called when program space PSPACE is about to be
2921 deleted. It takes care of updating breakpoints to not reference
2925 breakpoint_program_space_exit (struct program_space
*pspace
)
2927 struct breakpoint
*b
, *b_temp
;
2928 struct bp_location
*loc
, **loc_temp
;
2930 /* Remove any breakpoint that was set through this program space. */
2931 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2933 if (b
->pspace
== pspace
)
2934 delete_breakpoint (b
);
2937 /* Breakpoints set through other program spaces could have locations
2938 bound to PSPACE as well. Remove those. */
2939 ALL_BP_LOCATIONS (loc
, loc_temp
)
2941 struct bp_location
*tmp
;
2943 if (loc
->pspace
== pspace
)
2945 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2946 if (loc
->owner
->loc
== loc
)
2947 loc
->owner
->loc
= loc
->next
;
2949 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2950 if (tmp
->next
== loc
)
2952 tmp
->next
= loc
->next
;
2958 /* Now update the global location list to permanently delete the
2959 removed locations above. */
2960 update_global_location_list (UGLL_DONT_INSERT
);
2963 /* Make sure all breakpoints are inserted in inferior.
2964 Throws exception on any error.
2965 A breakpoint that is already inserted won't be inserted
2966 again, so calling this function twice is safe. */
2968 insert_breakpoints (void)
2970 struct breakpoint
*bpt
;
2972 ALL_BREAKPOINTS (bpt
)
2973 if (is_hardware_watchpoint (bpt
))
2975 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2977 update_watchpoint (w
, 0 /* don't reparse. */);
2980 /* Updating watchpoints creates new locations, so update the global
2981 location list. Explicitly tell ugll to insert locations and
2982 ignore breakpoints_always_inserted_mode. */
2983 update_global_location_list (UGLL_INSERT
);
2986 /* Invoke CALLBACK for each of bp_location. */
2989 iterate_over_bp_locations (walk_bp_location_callback callback
)
2991 struct bp_location
*loc
, **loc_tmp
;
2993 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2995 callback (loc
, NULL
);
2999 /* This is used when we need to synch breakpoint conditions between GDB and the
3000 target. It is the case with deleting and disabling of breakpoints when using
3001 always-inserted mode. */
3004 update_inserted_breakpoint_locations (void)
3006 struct bp_location
*bl
, **blp_tmp
;
3009 int disabled_breaks
= 0;
3010 int hw_breakpoint_error
= 0;
3011 int hw_bp_details_reported
= 0;
3013 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3014 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3016 /* Explicitly mark the warning -- this will only be printed if
3017 there was an error. */
3018 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3020 save_current_space_and_thread ();
3022 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3024 /* We only want to update software breakpoints and hardware
3026 if (!is_breakpoint (bl
->owner
))
3029 /* We only want to update locations that are already inserted
3030 and need updating. This is to avoid unwanted insertion during
3031 deletion of breakpoints. */
3032 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3035 switch_to_program_space_and_thread (bl
->pspace
);
3037 /* For targets that support global breakpoints, there's no need
3038 to select an inferior to insert breakpoint to. In fact, even
3039 if we aren't attached to any process yet, we should still
3040 insert breakpoints. */
3041 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3042 && ptid_equal (inferior_ptid
, null_ptid
))
3045 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3046 &hw_breakpoint_error
, &hw_bp_details_reported
);
3053 target_terminal_ours_for_output ();
3054 error_stream (tmp_error_stream
);
3057 do_cleanups (cleanups
);
3060 /* Used when starting or continuing the program. */
3063 insert_breakpoint_locations (void)
3065 struct breakpoint
*bpt
;
3066 struct bp_location
*bl
, **blp_tmp
;
3069 int disabled_breaks
= 0;
3070 int hw_breakpoint_error
= 0;
3071 int hw_bp_error_explained_already
= 0;
3073 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3074 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3076 /* Explicitly mark the warning -- this will only be printed if
3077 there was an error. */
3078 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3080 save_current_space_and_thread ();
3082 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3084 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3087 /* There is no point inserting thread-specific breakpoints if
3088 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3089 has BL->OWNER always non-NULL. */
3090 if (bl
->owner
->thread
!= -1
3091 && !valid_thread_id (bl
->owner
->thread
))
3094 switch_to_program_space_and_thread (bl
->pspace
);
3096 /* For targets that support global breakpoints, there's no need
3097 to select an inferior to insert breakpoint to. In fact, even
3098 if we aren't attached to any process yet, we should still
3099 insert breakpoints. */
3100 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3101 && ptid_equal (inferior_ptid
, null_ptid
))
3104 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3105 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3110 /* If we failed to insert all locations of a watchpoint, remove
3111 them, as half-inserted watchpoint is of limited use. */
3112 ALL_BREAKPOINTS (bpt
)
3114 int some_failed
= 0;
3115 struct bp_location
*loc
;
3117 if (!is_hardware_watchpoint (bpt
))
3120 if (!breakpoint_enabled (bpt
))
3123 if (bpt
->disposition
== disp_del_at_next_stop
)
3126 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3127 if (!loc
->inserted
&& should_be_inserted (loc
))
3134 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3136 remove_breakpoint (loc
, mark_uninserted
);
3138 hw_breakpoint_error
= 1;
3139 fprintf_unfiltered (tmp_error_stream
,
3140 "Could not insert hardware watchpoint %d.\n",
3148 /* If a hardware breakpoint or watchpoint was inserted, add a
3149 message about possibly exhausted resources. */
3150 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3152 fprintf_unfiltered (tmp_error_stream
,
3153 "Could not insert hardware breakpoints:\n\
3154 You may have requested too many hardware breakpoints/watchpoints.\n");
3156 target_terminal_ours_for_output ();
3157 error_stream (tmp_error_stream
);
3160 do_cleanups (cleanups
);
3163 /* Used when the program stops.
3164 Returns zero if successful, or non-zero if there was a problem
3165 removing a breakpoint location. */
3168 remove_breakpoints (void)
3170 struct bp_location
*bl
, **blp_tmp
;
3173 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3175 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3176 val
|= remove_breakpoint (bl
, mark_uninserted
);
3181 /* When a thread exits, remove breakpoints that are related to
3185 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3187 struct breakpoint
*b
, *b_tmp
;
3189 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3191 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3193 b
->disposition
= disp_del_at_next_stop
;
3195 printf_filtered (_("\
3196 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3197 b
->number
, tp
->num
);
3199 /* Hide it from the user. */
3205 /* Remove breakpoints of process PID. */
3208 remove_breakpoints_pid (int pid
)
3210 struct bp_location
*bl
, **blp_tmp
;
3212 struct inferior
*inf
= find_inferior_pid (pid
);
3214 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3216 if (bl
->pspace
!= inf
->pspace
)
3219 if (bl
->inserted
&& !bl
->target_info
.persist
)
3221 val
= remove_breakpoint (bl
, mark_uninserted
);
3230 reattach_breakpoints (int pid
)
3232 struct cleanup
*old_chain
;
3233 struct bp_location
*bl
, **blp_tmp
;
3235 struct ui_file
*tmp_error_stream
;
3236 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3237 struct inferior
*inf
;
3238 struct thread_info
*tp
;
3240 tp
= any_live_thread_of_process (pid
);
3244 inf
= find_inferior_pid (pid
);
3245 old_chain
= save_inferior_ptid ();
3247 inferior_ptid
= tp
->ptid
;
3249 tmp_error_stream
= mem_fileopen ();
3250 make_cleanup_ui_file_delete (tmp_error_stream
);
3252 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3254 if (bl
->pspace
!= inf
->pspace
)
3260 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3263 do_cleanups (old_chain
);
3268 do_cleanups (old_chain
);
3272 static int internal_breakpoint_number
= -1;
3274 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3275 If INTERNAL is non-zero, the breakpoint number will be populated
3276 from internal_breakpoint_number and that variable decremented.
3277 Otherwise the breakpoint number will be populated from
3278 breakpoint_count and that value incremented. Internal breakpoints
3279 do not set the internal var bpnum. */
3281 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3284 b
->number
= internal_breakpoint_number
--;
3287 set_breakpoint_count (breakpoint_count
+ 1);
3288 b
->number
= breakpoint_count
;
3292 static struct breakpoint
*
3293 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3294 CORE_ADDR address
, enum bptype type
,
3295 const struct breakpoint_ops
*ops
)
3297 struct symtab_and_line sal
;
3298 struct breakpoint
*b
;
3300 init_sal (&sal
); /* Initialize to zeroes. */
3303 sal
.section
= find_pc_overlay (sal
.pc
);
3304 sal
.pspace
= current_program_space
;
3306 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3307 b
->number
= internal_breakpoint_number
--;
3308 b
->disposition
= disp_donttouch
;
3313 static const char *const longjmp_names
[] =
3315 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3317 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3319 /* Per-objfile data private to breakpoint.c. */
3320 struct breakpoint_objfile_data
3322 /* Minimal symbol for "_ovly_debug_event" (if any). */
3323 struct bound_minimal_symbol overlay_msym
;
3325 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3326 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3328 /* True if we have looked for longjmp probes. */
3329 int longjmp_searched
;
3331 /* SystemTap probe points for longjmp (if any). */
3332 VEC (probe_p
) *longjmp_probes
;
3334 /* Minimal symbol for "std::terminate()" (if any). */
3335 struct bound_minimal_symbol terminate_msym
;
3337 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3338 struct bound_minimal_symbol exception_msym
;
3340 /* True if we have looked for exception probes. */
3341 int exception_searched
;
3343 /* SystemTap probe points for unwinding (if any). */
3344 VEC (probe_p
) *exception_probes
;
3347 static const struct objfile_data
*breakpoint_objfile_key
;
3349 /* Minimal symbol not found sentinel. */
3350 static struct minimal_symbol msym_not_found
;
3352 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3355 msym_not_found_p (const struct minimal_symbol
*msym
)
3357 return msym
== &msym_not_found
;
3360 /* Return per-objfile data needed by breakpoint.c.
3361 Allocate the data if necessary. */
3363 static struct breakpoint_objfile_data
*
3364 get_breakpoint_objfile_data (struct objfile
*objfile
)
3366 struct breakpoint_objfile_data
*bp_objfile_data
;
3368 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3369 if (bp_objfile_data
== NULL
)
3371 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3372 sizeof (*bp_objfile_data
));
3374 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3375 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3377 return bp_objfile_data
;
3381 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3383 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3385 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3386 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3390 create_overlay_event_breakpoint (void)
3392 struct objfile
*objfile
;
3393 const char *const func_name
= "_ovly_debug_event";
3395 ALL_OBJFILES (objfile
)
3397 struct breakpoint
*b
;
3398 struct breakpoint_objfile_data
*bp_objfile_data
;
3401 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3403 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3406 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3408 struct bound_minimal_symbol m
;
3410 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3411 if (m
.minsym
== NULL
)
3413 /* Avoid future lookups in this objfile. */
3414 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3417 bp_objfile_data
->overlay_msym
= m
;
3420 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3421 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3423 &internal_breakpoint_ops
);
3424 b
->addr_string
= xstrdup (func_name
);
3426 if (overlay_debugging
== ovly_auto
)
3428 b
->enable_state
= bp_enabled
;
3429 overlay_events_enabled
= 1;
3433 b
->enable_state
= bp_disabled
;
3434 overlay_events_enabled
= 0;
3437 update_global_location_list (UGLL_MAY_INSERT
);
3441 create_longjmp_master_breakpoint (void)
3443 struct program_space
*pspace
;
3444 struct cleanup
*old_chain
;
3446 old_chain
= save_current_program_space ();
3448 ALL_PSPACES (pspace
)
3450 struct objfile
*objfile
;
3452 set_current_program_space (pspace
);
3454 ALL_OBJFILES (objfile
)
3457 struct gdbarch
*gdbarch
;
3458 struct breakpoint_objfile_data
*bp_objfile_data
;
3460 gdbarch
= get_objfile_arch (objfile
);
3462 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3464 if (!bp_objfile_data
->longjmp_searched
)
3468 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3471 /* We are only interested in checking one element. */
3472 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3474 if (!can_evaluate_probe_arguments (p
))
3476 /* We cannot use the probe interface here, because it does
3477 not know how to evaluate arguments. */
3478 VEC_free (probe_p
, ret
);
3482 bp_objfile_data
->longjmp_probes
= ret
;
3483 bp_objfile_data
->longjmp_searched
= 1;
3486 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3489 struct probe
*probe
;
3490 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3493 VEC_iterate (probe_p
,
3494 bp_objfile_data
->longjmp_probes
,
3498 struct breakpoint
*b
;
3500 b
= create_internal_breakpoint (gdbarch
,
3501 get_probe_address (probe
,
3504 &internal_breakpoint_ops
);
3505 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3506 b
->enable_state
= bp_disabled
;
3512 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3515 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3517 struct breakpoint
*b
;
3518 const char *func_name
;
3521 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3524 func_name
= longjmp_names
[i
];
3525 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3527 struct bound_minimal_symbol m
;
3529 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3530 if (m
.minsym
== NULL
)
3532 /* Prevent future lookups in this objfile. */
3533 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3536 bp_objfile_data
->longjmp_msym
[i
] = m
;
3539 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3540 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3541 &internal_breakpoint_ops
);
3542 b
->addr_string
= xstrdup (func_name
);
3543 b
->enable_state
= bp_disabled
;
3547 update_global_location_list (UGLL_MAY_INSERT
);
3549 do_cleanups (old_chain
);
3552 /* Create a master std::terminate breakpoint. */
3554 create_std_terminate_master_breakpoint (void)
3556 struct program_space
*pspace
;
3557 struct cleanup
*old_chain
;
3558 const char *const func_name
= "std::terminate()";
3560 old_chain
= save_current_program_space ();
3562 ALL_PSPACES (pspace
)
3564 struct objfile
*objfile
;
3567 set_current_program_space (pspace
);
3569 ALL_OBJFILES (objfile
)
3571 struct breakpoint
*b
;
3572 struct breakpoint_objfile_data
*bp_objfile_data
;
3574 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3576 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3579 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3581 struct bound_minimal_symbol m
;
3583 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3584 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3585 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3587 /* Prevent future lookups in this objfile. */
3588 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3591 bp_objfile_data
->terminate_msym
= m
;
3594 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3595 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3596 bp_std_terminate_master
,
3597 &internal_breakpoint_ops
);
3598 b
->addr_string
= xstrdup (func_name
);
3599 b
->enable_state
= bp_disabled
;
3603 update_global_location_list (UGLL_MAY_INSERT
);
3605 do_cleanups (old_chain
);
3608 /* Install a master breakpoint on the unwinder's debug hook. */
3611 create_exception_master_breakpoint (void)
3613 struct objfile
*objfile
;
3614 const char *const func_name
= "_Unwind_DebugHook";
3616 ALL_OBJFILES (objfile
)
3618 struct breakpoint
*b
;
3619 struct gdbarch
*gdbarch
;
3620 struct breakpoint_objfile_data
*bp_objfile_data
;
3623 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3625 /* We prefer the SystemTap probe point if it exists. */
3626 if (!bp_objfile_data
->exception_searched
)
3630 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3634 /* We are only interested in checking one element. */
3635 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3637 if (!can_evaluate_probe_arguments (p
))
3639 /* We cannot use the probe interface here, because it does
3640 not know how to evaluate arguments. */
3641 VEC_free (probe_p
, ret
);
3645 bp_objfile_data
->exception_probes
= ret
;
3646 bp_objfile_data
->exception_searched
= 1;
3649 if (bp_objfile_data
->exception_probes
!= NULL
)
3651 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3653 struct probe
*probe
;
3656 VEC_iterate (probe_p
,
3657 bp_objfile_data
->exception_probes
,
3661 struct breakpoint
*b
;
3663 b
= create_internal_breakpoint (gdbarch
,
3664 get_probe_address (probe
,
3666 bp_exception_master
,
3667 &internal_breakpoint_ops
);
3668 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3669 b
->enable_state
= bp_disabled
;
3675 /* Otherwise, try the hook function. */
3677 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3680 gdbarch
= get_objfile_arch (objfile
);
3682 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3684 struct bound_minimal_symbol debug_hook
;
3686 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3687 if (debug_hook
.minsym
== NULL
)
3689 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3693 bp_objfile_data
->exception_msym
= debug_hook
;
3696 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3697 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3699 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3700 &internal_breakpoint_ops
);
3701 b
->addr_string
= xstrdup (func_name
);
3702 b
->enable_state
= bp_disabled
;
3705 update_global_location_list (UGLL_MAY_INSERT
);
3709 update_breakpoints_after_exec (void)
3711 struct breakpoint
*b
, *b_tmp
;
3712 struct bp_location
*bploc
, **bplocp_tmp
;
3714 /* We're about to delete breakpoints from GDB's lists. If the
3715 INSERTED flag is true, GDB will try to lift the breakpoints by
3716 writing the breakpoints' "shadow contents" back into memory. The
3717 "shadow contents" are NOT valid after an exec, so GDB should not
3718 do that. Instead, the target is responsible from marking
3719 breakpoints out as soon as it detects an exec. We don't do that
3720 here instead, because there may be other attempts to delete
3721 breakpoints after detecting an exec and before reaching here. */
3722 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3723 if (bploc
->pspace
== current_program_space
)
3724 gdb_assert (!bploc
->inserted
);
3726 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3728 if (b
->pspace
!= current_program_space
)
3731 /* Solib breakpoints must be explicitly reset after an exec(). */
3732 if (b
->type
== bp_shlib_event
)
3734 delete_breakpoint (b
);
3738 /* JIT breakpoints must be explicitly reset after an exec(). */
3739 if (b
->type
== bp_jit_event
)
3741 delete_breakpoint (b
);
3745 /* Thread event breakpoints must be set anew after an exec(),
3746 as must overlay event and longjmp master breakpoints. */
3747 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3748 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3749 || b
->type
== bp_exception_master
)
3751 delete_breakpoint (b
);
3755 /* Step-resume breakpoints are meaningless after an exec(). */
3756 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3758 delete_breakpoint (b
);
3762 /* Just like single-step breakpoints. */
3763 if (b
->type
== bp_single_step
)
3765 delete_breakpoint (b
);
3769 /* Longjmp and longjmp-resume breakpoints are also meaningless
3771 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3772 || b
->type
== bp_longjmp_call_dummy
3773 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3775 delete_breakpoint (b
);
3779 if (b
->type
== bp_catchpoint
)
3781 /* For now, none of the bp_catchpoint breakpoints need to
3782 do anything at this point. In the future, if some of
3783 the catchpoints need to something, we will need to add
3784 a new method, and call this method from here. */
3788 /* bp_finish is a special case. The only way we ought to be able
3789 to see one of these when an exec() has happened, is if the user
3790 caught a vfork, and then said "finish". Ordinarily a finish just
3791 carries them to the call-site of the current callee, by setting
3792 a temporary bp there and resuming. But in this case, the finish
3793 will carry them entirely through the vfork & exec.
3795 We don't want to allow a bp_finish to remain inserted now. But
3796 we can't safely delete it, 'cause finish_command has a handle to
3797 the bp on a bpstat, and will later want to delete it. There's a
3798 chance (and I've seen it happen) that if we delete the bp_finish
3799 here, that its storage will get reused by the time finish_command
3800 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3801 We really must allow finish_command to delete a bp_finish.
3803 In the absence of a general solution for the "how do we know
3804 it's safe to delete something others may have handles to?"
3805 problem, what we'll do here is just uninsert the bp_finish, and
3806 let finish_command delete it.
3808 (We know the bp_finish is "doomed" in the sense that it's
3809 momentary, and will be deleted as soon as finish_command sees
3810 the inferior stopped. So it doesn't matter that the bp's
3811 address is probably bogus in the new a.out, unlike e.g., the
3812 solib breakpoints.) */
3814 if (b
->type
== bp_finish
)
3819 /* Without a symbolic address, we have little hope of the
3820 pre-exec() address meaning the same thing in the post-exec()
3822 if (b
->addr_string
== NULL
)
3824 delete_breakpoint (b
);
3831 detach_breakpoints (ptid_t ptid
)
3833 struct bp_location
*bl
, **blp_tmp
;
3835 struct cleanup
*old_chain
= save_inferior_ptid ();
3836 struct inferior
*inf
= current_inferior ();
3838 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3839 error (_("Cannot detach breakpoints of inferior_ptid"));
3841 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3842 inferior_ptid
= ptid
;
3843 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3845 if (bl
->pspace
!= inf
->pspace
)
3848 /* This function must physically remove breakpoints locations
3849 from the specified ptid, without modifying the breakpoint
3850 package's state. Locations of type bp_loc_other are only
3851 maintained at GDB side. So, there is no need to remove
3852 these bp_loc_other locations. Moreover, removing these
3853 would modify the breakpoint package's state. */
3854 if (bl
->loc_type
== bp_loc_other
)
3858 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3861 do_cleanups (old_chain
);
3865 /* Remove the breakpoint location BL from the current address space.
3866 Note that this is used to detach breakpoints from a child fork.
3867 When we get here, the child isn't in the inferior list, and neither
3868 do we have objects to represent its address space --- we should
3869 *not* look at bl->pspace->aspace here. */
3872 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3876 /* BL is never in moribund_locations by our callers. */
3877 gdb_assert (bl
->owner
!= NULL
);
3880 /* Permanent breakpoints cannot be inserted or removed. */
3883 /* The type of none suggests that owner is actually deleted.
3884 This should not ever happen. */
3885 gdb_assert (bl
->owner
->type
!= bp_none
);
3887 if (bl
->loc_type
== bp_loc_software_breakpoint
3888 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3890 /* "Normal" instruction breakpoint: either the standard
3891 trap-instruction bp (bp_breakpoint), or a
3892 bp_hardware_breakpoint. */
3894 /* First check to see if we have to handle an overlay. */
3895 if (overlay_debugging
== ovly_off
3896 || bl
->section
== NULL
3897 || !(section_is_overlay (bl
->section
)))
3899 /* No overlay handling: just remove the breakpoint. */
3901 /* If we're trying to uninsert a memory breakpoint that we
3902 know is set in a dynamic object that is marked
3903 shlib_disabled, then either the dynamic object was
3904 removed with "remove-symbol-file" or with
3905 "nosharedlibrary". In the former case, we don't know
3906 whether another dynamic object might have loaded over the
3907 breakpoint's address -- the user might well let us know
3908 about it next with add-symbol-file (the whole point of
3909 add-symbol-file is letting the user manually maintain a
3910 list of dynamically loaded objects). If we have the
3911 breakpoint's shadow memory, that is, this is a software
3912 breakpoint managed by GDB, check whether the breakpoint
3913 is still inserted in memory, to avoid overwriting wrong
3914 code with stale saved shadow contents. Note that HW
3915 breakpoints don't have shadow memory, as they're
3916 implemented using a mechanism that is not dependent on
3917 being able to modify the target's memory, and as such
3918 they should always be removed. */
3919 if (bl
->shlib_disabled
3920 && bl
->target_info
.shadow_len
!= 0
3921 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3924 val
= bl
->owner
->ops
->remove_location (bl
);
3928 /* This breakpoint is in an overlay section.
3929 Did we set a breakpoint at the LMA? */
3930 if (!overlay_events_enabled
)
3932 /* Yes -- overlay event support is not active, so we
3933 should have set a breakpoint at the LMA. Remove it.
3935 /* Ignore any failures: if the LMA is in ROM, we will
3936 have already warned when we failed to insert it. */
3937 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3938 target_remove_hw_breakpoint (bl
->gdbarch
,
3939 &bl
->overlay_target_info
);
3941 target_remove_breakpoint (bl
->gdbarch
,
3942 &bl
->overlay_target_info
);
3944 /* Did we set a breakpoint at the VMA?
3945 If so, we will have marked the breakpoint 'inserted'. */
3948 /* Yes -- remove it. Previously we did not bother to
3949 remove the breakpoint if the section had been
3950 unmapped, but let's not rely on that being safe. We
3951 don't know what the overlay manager might do. */
3953 /* However, we should remove *software* breakpoints only
3954 if the section is still mapped, or else we overwrite
3955 wrong code with the saved shadow contents. */
3956 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3957 || section_is_mapped (bl
->section
))
3958 val
= bl
->owner
->ops
->remove_location (bl
);
3964 /* No -- not inserted, so no need to remove. No error. */
3969 /* In some cases, we might not be able to remove a breakpoint in
3970 a shared library that has already been removed, but we have
3971 not yet processed the shlib unload event. Similarly for an
3972 unloaded add-symbol-file object - the user might not yet have
3973 had the chance to remove-symbol-file it. shlib_disabled will
3974 be set if the library/object has already been removed, but
3975 the breakpoint hasn't been uninserted yet, e.g., after
3976 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3977 always-inserted mode. */
3979 && (bl
->loc_type
== bp_loc_software_breakpoint
3980 && (bl
->shlib_disabled
3981 || solib_name_from_address (bl
->pspace
, bl
->address
)
3982 || shared_objfile_contains_address_p (bl
->pspace
,
3988 bl
->inserted
= (is
== mark_inserted
);
3990 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3992 gdb_assert (bl
->owner
->ops
!= NULL
3993 && bl
->owner
->ops
->remove_location
!= NULL
);
3995 bl
->inserted
= (is
== mark_inserted
);
3996 bl
->owner
->ops
->remove_location (bl
);
3998 /* Failure to remove any of the hardware watchpoints comes here. */
3999 if ((is
== mark_uninserted
) && (bl
->inserted
))
4000 warning (_("Could not remove hardware watchpoint %d."),
4003 else if (bl
->owner
->type
== bp_catchpoint
4004 && breakpoint_enabled (bl
->owner
)
4007 gdb_assert (bl
->owner
->ops
!= NULL
4008 && bl
->owner
->ops
->remove_location
!= NULL
);
4010 val
= bl
->owner
->ops
->remove_location (bl
);
4014 bl
->inserted
= (is
== mark_inserted
);
4021 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4024 struct cleanup
*old_chain
;
4026 /* BL is never in moribund_locations by our callers. */
4027 gdb_assert (bl
->owner
!= NULL
);
4030 /* Permanent breakpoints cannot be inserted or removed. */
4033 /* The type of none suggests that owner is actually deleted.
4034 This should not ever happen. */
4035 gdb_assert (bl
->owner
->type
!= bp_none
);
4037 old_chain
= save_current_space_and_thread ();
4039 switch_to_program_space_and_thread (bl
->pspace
);
4041 ret
= remove_breakpoint_1 (bl
, is
);
4043 do_cleanups (old_chain
);
4047 /* Clear the "inserted" flag in all breakpoints. */
4050 mark_breakpoints_out (void)
4052 struct bp_location
*bl
, **blp_tmp
;
4054 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4055 if (bl
->pspace
== current_program_space
4060 /* Clear the "inserted" flag in all breakpoints and delete any
4061 breakpoints which should go away between runs of the program.
4063 Plus other such housekeeping that has to be done for breakpoints
4066 Note: this function gets called at the end of a run (by
4067 generic_mourn_inferior) and when a run begins (by
4068 init_wait_for_inferior). */
4073 breakpoint_init_inferior (enum inf_context context
)
4075 struct breakpoint
*b
, *b_tmp
;
4076 struct bp_location
*bl
, **blp_tmp
;
4078 struct program_space
*pspace
= current_program_space
;
4080 /* If breakpoint locations are shared across processes, then there's
4082 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4085 mark_breakpoints_out ();
4087 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4089 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4095 case bp_longjmp_call_dummy
:
4097 /* If the call dummy breakpoint is at the entry point it will
4098 cause problems when the inferior is rerun, so we better get
4101 case bp_watchpoint_scope
:
4103 /* Also get rid of scope breakpoints. */
4105 case bp_shlib_event
:
4107 /* Also remove solib event breakpoints. Their addresses may
4108 have changed since the last time we ran the program.
4109 Actually we may now be debugging against different target;
4110 and so the solib backend that installed this breakpoint may
4111 not be used in by the target. E.g.,
4113 (gdb) file prog-linux
4114 (gdb) run # native linux target
4117 (gdb) file prog-win.exe
4118 (gdb) tar rem :9999 # remote Windows gdbserver.
4121 case bp_step_resume
:
4123 /* Also remove step-resume breakpoints. */
4125 case bp_single_step
:
4127 /* Also remove single-step breakpoints. */
4129 delete_breakpoint (b
);
4133 case bp_hardware_watchpoint
:
4134 case bp_read_watchpoint
:
4135 case bp_access_watchpoint
:
4137 struct watchpoint
*w
= (struct watchpoint
*) b
;
4139 /* Likewise for watchpoints on local expressions. */
4140 if (w
->exp_valid_block
!= NULL
)
4141 delete_breakpoint (b
);
4142 else if (context
== inf_starting
)
4144 /* Reset val field to force reread of starting value in
4145 insert_breakpoints. */
4147 value_free (w
->val
);
4158 /* Get rid of the moribund locations. */
4159 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4160 decref_bp_location (&bl
);
4161 VEC_free (bp_location_p
, moribund_locations
);
4164 /* These functions concern about actual breakpoints inserted in the
4165 target --- to e.g. check if we need to do decr_pc adjustment or if
4166 we need to hop over the bkpt --- so we check for address space
4167 match, not program space. */
4169 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4170 exists at PC. It returns ordinary_breakpoint_here if it's an
4171 ordinary breakpoint, or permanent_breakpoint_here if it's a
4172 permanent breakpoint.
4173 - When continuing from a location with an ordinary breakpoint, we
4174 actually single step once before calling insert_breakpoints.
4175 - When continuing from a location with a permanent breakpoint, we
4176 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4177 the target, to advance the PC past the breakpoint. */
4179 enum breakpoint_here
4180 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4182 struct bp_location
*bl
, **blp_tmp
;
4183 int any_breakpoint_here
= 0;
4185 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4187 if (bl
->loc_type
!= bp_loc_software_breakpoint
4188 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4191 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4192 if ((breakpoint_enabled (bl
->owner
)
4194 && breakpoint_location_address_match (bl
, aspace
, pc
))
4196 if (overlay_debugging
4197 && section_is_overlay (bl
->section
)
4198 && !section_is_mapped (bl
->section
))
4199 continue; /* unmapped overlay -- can't be a match */
4200 else if (bl
->permanent
)
4201 return permanent_breakpoint_here
;
4203 any_breakpoint_here
= 1;
4207 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4210 /* Return true if there's a moribund breakpoint at PC. */
4213 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4215 struct bp_location
*loc
;
4218 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4219 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4225 /* Returns non-zero iff BL is inserted at PC, in address space
4229 bp_location_inserted_here_p (struct bp_location
*bl
,
4230 struct address_space
*aspace
, CORE_ADDR pc
)
4233 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4236 if (overlay_debugging
4237 && section_is_overlay (bl
->section
)
4238 && !section_is_mapped (bl
->section
))
4239 return 0; /* unmapped overlay -- can't be a match */
4246 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4249 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4251 struct bp_location
**blp
, **blp_tmp
= NULL
;
4252 struct bp_location
*bl
;
4254 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4256 struct bp_location
*bl
= *blp
;
4258 if (bl
->loc_type
!= bp_loc_software_breakpoint
4259 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4262 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4268 /* This function returns non-zero iff there is a software breakpoint
4272 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4275 struct bp_location
**blp
, **blp_tmp
= NULL
;
4276 struct bp_location
*bl
;
4278 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4280 struct bp_location
*bl
= *blp
;
4282 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4285 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4292 /* See breakpoint.h. */
4295 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4298 struct bp_location
**blp
, **blp_tmp
= NULL
;
4299 struct bp_location
*bl
;
4301 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4303 struct bp_location
*bl
= *blp
;
4305 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4308 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4316 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4317 CORE_ADDR addr
, ULONGEST len
)
4319 struct breakpoint
*bpt
;
4321 ALL_BREAKPOINTS (bpt
)
4323 struct bp_location
*loc
;
4325 if (bpt
->type
!= bp_hardware_watchpoint
4326 && bpt
->type
!= bp_access_watchpoint
)
4329 if (!breakpoint_enabled (bpt
))
4332 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4333 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4337 /* Check for intersection. */
4338 l
= max (loc
->address
, addr
);
4339 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4348 /* bpstat stuff. External routines' interfaces are documented
4352 is_catchpoint (struct breakpoint
*ep
)
4354 return (ep
->type
== bp_catchpoint
);
4357 /* Frees any storage that is part of a bpstat. Does not walk the
4361 bpstat_free (bpstat bs
)
4363 if (bs
->old_val
!= NULL
)
4364 value_free (bs
->old_val
);
4365 decref_counted_command_line (&bs
->commands
);
4366 decref_bp_location (&bs
->bp_location_at
);
4370 /* Clear a bpstat so that it says we are not at any breakpoint.
4371 Also free any storage that is part of a bpstat. */
4374 bpstat_clear (bpstat
*bsp
)
4391 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4392 is part of the bpstat is copied as well. */
4395 bpstat_copy (bpstat bs
)
4399 bpstat retval
= NULL
;
4404 for (; bs
!= NULL
; bs
= bs
->next
)
4406 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4407 memcpy (tmp
, bs
, sizeof (*tmp
));
4408 incref_counted_command_line (tmp
->commands
);
4409 incref_bp_location (tmp
->bp_location_at
);
4410 if (bs
->old_val
!= NULL
)
4412 tmp
->old_val
= value_copy (bs
->old_val
);
4413 release_value (tmp
->old_val
);
4417 /* This is the first thing in the chain. */
4427 /* Find the bpstat associated with this breakpoint. */
4430 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4435 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4437 if (bsp
->breakpoint_at
== breakpoint
)
4443 /* See breakpoint.h. */
4446 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4448 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4450 if (bsp
->breakpoint_at
== NULL
)
4452 /* A moribund location can never explain a signal other than
4454 if (sig
== GDB_SIGNAL_TRAP
)
4459 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4468 /* Put in *NUM the breakpoint number of the first breakpoint we are
4469 stopped at. *BSP upon return is a bpstat which points to the
4470 remaining breakpoints stopped at (but which is not guaranteed to be
4471 good for anything but further calls to bpstat_num).
4473 Return 0 if passed a bpstat which does not indicate any breakpoints.
4474 Return -1 if stopped at a breakpoint that has been deleted since
4476 Return 1 otherwise. */
4479 bpstat_num (bpstat
*bsp
, int *num
)
4481 struct breakpoint
*b
;
4484 return 0; /* No more breakpoint values */
4486 /* We assume we'll never have several bpstats that correspond to a
4487 single breakpoint -- otherwise, this function might return the
4488 same number more than once and this will look ugly. */
4489 b
= (*bsp
)->breakpoint_at
;
4490 *bsp
= (*bsp
)->next
;
4492 return -1; /* breakpoint that's been deleted since */
4494 *num
= b
->number
; /* We have its number */
4498 /* See breakpoint.h. */
4501 bpstat_clear_actions (void)
4503 struct thread_info
*tp
;
4506 if (ptid_equal (inferior_ptid
, null_ptid
))
4509 tp
= find_thread_ptid (inferior_ptid
);
4513 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4515 decref_counted_command_line (&bs
->commands
);
4517 if (bs
->old_val
!= NULL
)
4519 value_free (bs
->old_val
);
4525 /* Called when a command is about to proceed the inferior. */
4528 breakpoint_about_to_proceed (void)
4530 if (!ptid_equal (inferior_ptid
, null_ptid
))
4532 struct thread_info
*tp
= inferior_thread ();
4534 /* Allow inferior function calls in breakpoint commands to not
4535 interrupt the command list. When the call finishes
4536 successfully, the inferior will be standing at the same
4537 breakpoint as if nothing happened. */
4538 if (tp
->control
.in_infcall
)
4542 breakpoint_proceeded
= 1;
4545 /* Stub for cleaning up our state if we error-out of a breakpoint
4548 cleanup_executing_breakpoints (void *ignore
)
4550 executing_breakpoint_commands
= 0;
4553 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4554 or its equivalent. */
4557 command_line_is_silent (struct command_line
*cmd
)
4559 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4560 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4563 /* Execute all the commands associated with all the breakpoints at
4564 this location. Any of these commands could cause the process to
4565 proceed beyond this point, etc. We look out for such changes by
4566 checking the global "breakpoint_proceeded" after each command.
4568 Returns true if a breakpoint command resumed the inferior. In that
4569 case, it is the caller's responsibility to recall it again with the
4570 bpstat of the current thread. */
4573 bpstat_do_actions_1 (bpstat
*bsp
)
4576 struct cleanup
*old_chain
;
4579 /* Avoid endless recursion if a `source' command is contained
4581 if (executing_breakpoint_commands
)
4584 executing_breakpoint_commands
= 1;
4585 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4587 prevent_dont_repeat ();
4589 /* This pointer will iterate over the list of bpstat's. */
4592 breakpoint_proceeded
= 0;
4593 for (; bs
!= NULL
; bs
= bs
->next
)
4595 struct counted_command_line
*ccmd
;
4596 struct command_line
*cmd
;
4597 struct cleanup
*this_cmd_tree_chain
;
4599 /* Take ownership of the BSP's command tree, if it has one.
4601 The command tree could legitimately contain commands like
4602 'step' and 'next', which call clear_proceed_status, which
4603 frees stop_bpstat's command tree. To make sure this doesn't
4604 free the tree we're executing out from under us, we need to
4605 take ownership of the tree ourselves. Since a given bpstat's
4606 commands are only executed once, we don't need to copy it; we
4607 can clear the pointer in the bpstat, and make sure we free
4608 the tree when we're done. */
4609 ccmd
= bs
->commands
;
4610 bs
->commands
= NULL
;
4611 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4612 cmd
= ccmd
? ccmd
->commands
: NULL
;
4613 if (command_line_is_silent (cmd
))
4615 /* The action has been already done by bpstat_stop_status. */
4621 execute_control_command (cmd
);
4623 if (breakpoint_proceeded
)
4629 /* We can free this command tree now. */
4630 do_cleanups (this_cmd_tree_chain
);
4632 if (breakpoint_proceeded
)
4634 if (interpreter_async
&& target_can_async_p ())
4635 /* If we are in async mode, then the target might be still
4636 running, not stopped at any breakpoint, so nothing for
4637 us to do here -- just return to the event loop. */
4640 /* In sync mode, when execute_control_command returns
4641 we're already standing on the next breakpoint.
4642 Breakpoint commands for that stop were not run, since
4643 execute_command does not run breakpoint commands --
4644 only command_line_handler does, but that one is not
4645 involved in execution of breakpoint commands. So, we
4646 can now execute breakpoint commands. It should be
4647 noted that making execute_command do bpstat actions is
4648 not an option -- in this case we'll have recursive
4649 invocation of bpstat for each breakpoint with a
4650 command, and can easily blow up GDB stack. Instead, we
4651 return true, which will trigger the caller to recall us
4652 with the new stop_bpstat. */
4657 do_cleanups (old_chain
);
4662 bpstat_do_actions (void)
4664 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4666 /* Do any commands attached to breakpoint we are stopped at. */
4667 while (!ptid_equal (inferior_ptid
, null_ptid
)
4668 && target_has_execution
4669 && !is_exited (inferior_ptid
)
4670 && !is_executing (inferior_ptid
))
4671 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4672 and only return when it is stopped at the next breakpoint, we
4673 keep doing breakpoint actions until it returns false to
4674 indicate the inferior was not resumed. */
4675 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4678 discard_cleanups (cleanup_if_error
);
4681 /* Print out the (old or new) value associated with a watchpoint. */
4684 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4687 fprintf_unfiltered (stream
, _("<unreadable>"));
4690 struct value_print_options opts
;
4691 get_user_print_options (&opts
);
4692 value_print (val
, stream
, &opts
);
4696 /* Generic routine for printing messages indicating why we
4697 stopped. The behavior of this function depends on the value
4698 'print_it' in the bpstat structure. Under some circumstances we
4699 may decide not to print anything here and delegate the task to
4702 static enum print_stop_action
4703 print_bp_stop_message (bpstat bs
)
4705 switch (bs
->print_it
)
4708 /* Nothing should be printed for this bpstat entry. */
4709 return PRINT_UNKNOWN
;
4713 /* We still want to print the frame, but we already printed the
4714 relevant messages. */
4715 return PRINT_SRC_AND_LOC
;
4718 case print_it_normal
:
4720 struct breakpoint
*b
= bs
->breakpoint_at
;
4722 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4723 which has since been deleted. */
4725 return PRINT_UNKNOWN
;
4727 /* Normal case. Call the breakpoint's print_it method. */
4728 return b
->ops
->print_it (bs
);
4733 internal_error (__FILE__
, __LINE__
,
4734 _("print_bp_stop_message: unrecognized enum value"));
4739 /* A helper function that prints a shared library stopped event. */
4742 print_solib_event (int is_catchpoint
)
4745 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4747 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4751 if (any_added
|| any_deleted
)
4752 ui_out_text (current_uiout
,
4753 _("Stopped due to shared library event:\n"));
4755 ui_out_text (current_uiout
,
4756 _("Stopped due to shared library event (no "
4757 "libraries added or removed)\n"));
4760 if (ui_out_is_mi_like_p (current_uiout
))
4761 ui_out_field_string (current_uiout
, "reason",
4762 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4766 struct cleanup
*cleanup
;
4770 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4771 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4774 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4779 ui_out_text (current_uiout
, " ");
4780 ui_out_field_string (current_uiout
, "library", name
);
4781 ui_out_text (current_uiout
, "\n");
4784 do_cleanups (cleanup
);
4789 struct so_list
*iter
;
4791 struct cleanup
*cleanup
;
4793 ui_out_text (current_uiout
, _(" Inferior loaded "));
4794 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4797 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4802 ui_out_text (current_uiout
, " ");
4803 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4804 ui_out_text (current_uiout
, "\n");
4807 do_cleanups (cleanup
);
4811 /* Print a message indicating what happened. This is called from
4812 normal_stop(). The input to this routine is the head of the bpstat
4813 list - a list of the eventpoints that caused this stop. KIND is
4814 the target_waitkind for the stopping event. This
4815 routine calls the generic print routine for printing a message
4816 about reasons for stopping. This will print (for example) the
4817 "Breakpoint n," part of the output. The return value of this
4820 PRINT_UNKNOWN: Means we printed nothing.
4821 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4822 code to print the location. An example is
4823 "Breakpoint 1, " which should be followed by
4825 PRINT_SRC_ONLY: Means we printed something, but there is no need
4826 to also print the location part of the message.
4827 An example is the catch/throw messages, which
4828 don't require a location appended to the end.
4829 PRINT_NOTHING: We have done some printing and we don't need any
4830 further info to be printed. */
4832 enum print_stop_action
4833 bpstat_print (bpstat bs
, int kind
)
4837 /* Maybe another breakpoint in the chain caused us to stop.
4838 (Currently all watchpoints go on the bpstat whether hit or not.
4839 That probably could (should) be changed, provided care is taken
4840 with respect to bpstat_explains_signal). */
4841 for (; bs
; bs
= bs
->next
)
4843 val
= print_bp_stop_message (bs
);
4844 if (val
== PRINT_SRC_ONLY
4845 || val
== PRINT_SRC_AND_LOC
4846 || val
== PRINT_NOTHING
)
4850 /* If we had hit a shared library event breakpoint,
4851 print_bp_stop_message would print out this message. If we hit an
4852 OS-level shared library event, do the same thing. */
4853 if (kind
== TARGET_WAITKIND_LOADED
)
4855 print_solib_event (0);
4856 return PRINT_NOTHING
;
4859 /* We reached the end of the chain, or we got a null BS to start
4860 with and nothing was printed. */
4861 return PRINT_UNKNOWN
;
4864 /* Evaluate the expression EXP and return 1 if value is zero.
4865 This returns the inverse of the condition because it is called
4866 from catch_errors which returns 0 if an exception happened, and if an
4867 exception happens we want execution to stop.
4868 The argument is a "struct expression *" that has been cast to a
4869 "void *" to make it pass through catch_errors. */
4872 breakpoint_cond_eval (void *exp
)
4874 struct value
*mark
= value_mark ();
4875 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4877 value_free_to_mark (mark
);
4881 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4884 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4888 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4890 **bs_link_pointer
= bs
;
4891 *bs_link_pointer
= &bs
->next
;
4892 bs
->breakpoint_at
= bl
->owner
;
4893 bs
->bp_location_at
= bl
;
4894 incref_bp_location (bl
);
4895 /* If the condition is false, etc., don't do the commands. */
4896 bs
->commands
= NULL
;
4898 bs
->print_it
= print_it_normal
;
4902 /* The target has stopped with waitstatus WS. Check if any hardware
4903 watchpoints have triggered, according to the target. */
4906 watchpoints_triggered (struct target_waitstatus
*ws
)
4908 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4910 struct breakpoint
*b
;
4912 if (!stopped_by_watchpoint
)
4914 /* We were not stopped by a watchpoint. Mark all watchpoints
4915 as not triggered. */
4917 if (is_hardware_watchpoint (b
))
4919 struct watchpoint
*w
= (struct watchpoint
*) b
;
4921 w
->watchpoint_triggered
= watch_triggered_no
;
4927 if (!target_stopped_data_address (¤t_target
, &addr
))
4929 /* We were stopped by a watchpoint, but we don't know where.
4930 Mark all watchpoints as unknown. */
4932 if (is_hardware_watchpoint (b
))
4934 struct watchpoint
*w
= (struct watchpoint
*) b
;
4936 w
->watchpoint_triggered
= watch_triggered_unknown
;
4942 /* The target could report the data address. Mark watchpoints
4943 affected by this data address as triggered, and all others as not
4947 if (is_hardware_watchpoint (b
))
4949 struct watchpoint
*w
= (struct watchpoint
*) b
;
4950 struct bp_location
*loc
;
4952 w
->watchpoint_triggered
= watch_triggered_no
;
4953 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4955 if (is_masked_watchpoint (b
))
4957 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4958 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4960 if (newaddr
== start
)
4962 w
->watchpoint_triggered
= watch_triggered_yes
;
4966 /* Exact match not required. Within range is sufficient. */
4967 else if (target_watchpoint_addr_within_range (¤t_target
,
4971 w
->watchpoint_triggered
= watch_triggered_yes
;
4980 /* Possible return values for watchpoint_check (this can't be an enum
4981 because of check_errors). */
4982 /* The watchpoint has been deleted. */
4983 #define WP_DELETED 1
4984 /* The value has changed. */
4985 #define WP_VALUE_CHANGED 2
4986 /* The value has not changed. */
4987 #define WP_VALUE_NOT_CHANGED 3
4988 /* Ignore this watchpoint, no matter if the value changed or not. */
4991 #define BP_TEMPFLAG 1
4992 #define BP_HARDWAREFLAG 2
4994 /* Evaluate watchpoint condition expression and check if its value
4997 P should be a pointer to struct bpstat, but is defined as a void *
4998 in order for this function to be usable with catch_errors. */
5001 watchpoint_check (void *p
)
5003 bpstat bs
= (bpstat
) p
;
5004 struct watchpoint
*b
;
5005 struct frame_info
*fr
;
5006 int within_current_scope
;
5008 /* BS is built from an existing struct breakpoint. */
5009 gdb_assert (bs
->breakpoint_at
!= NULL
);
5010 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5012 /* If this is a local watchpoint, we only want to check if the
5013 watchpoint frame is in scope if the current thread is the thread
5014 that was used to create the watchpoint. */
5015 if (!watchpoint_in_thread_scope (b
))
5018 if (b
->exp_valid_block
== NULL
)
5019 within_current_scope
= 1;
5022 struct frame_info
*frame
= get_current_frame ();
5023 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5024 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5026 /* in_function_epilogue_p() returns a non-zero value if we're
5027 still in the function but the stack frame has already been
5028 invalidated. Since we can't rely on the values of local
5029 variables after the stack has been destroyed, we are treating
5030 the watchpoint in that state as `not changed' without further
5031 checking. Don't mark watchpoints as changed if the current
5032 frame is in an epilogue - even if they are in some other
5033 frame, our view of the stack is likely to be wrong and
5034 frame_find_by_id could error out. */
5035 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
5038 fr
= frame_find_by_id (b
->watchpoint_frame
);
5039 within_current_scope
= (fr
!= NULL
);
5041 /* If we've gotten confused in the unwinder, we might have
5042 returned a frame that can't describe this variable. */
5043 if (within_current_scope
)
5045 struct symbol
*function
;
5047 function
= get_frame_function (fr
);
5048 if (function
== NULL
5049 || !contained_in (b
->exp_valid_block
,
5050 SYMBOL_BLOCK_VALUE (function
)))
5051 within_current_scope
= 0;
5054 if (within_current_scope
)
5055 /* If we end up stopping, the current frame will get selected
5056 in normal_stop. So this call to select_frame won't affect
5061 if (within_current_scope
)
5063 /* We use value_{,free_to_}mark because it could be a *long*
5064 time before we return to the command level and call
5065 free_all_values. We can't call free_all_values because we
5066 might be in the middle of evaluating a function call. */
5070 struct value
*new_val
;
5072 if (is_masked_watchpoint (&b
->base
))
5073 /* Since we don't know the exact trigger address (from
5074 stopped_data_address), just tell the user we've triggered
5075 a mask watchpoint. */
5076 return WP_VALUE_CHANGED
;
5078 mark
= value_mark ();
5079 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5081 if (b
->val_bitsize
!= 0)
5082 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5084 /* We use value_equal_contents instead of value_equal because
5085 the latter coerces an array to a pointer, thus comparing just
5086 the address of the array instead of its contents. This is
5087 not what we want. */
5088 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5089 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5091 if (new_val
!= NULL
)
5093 release_value (new_val
);
5094 value_free_to_mark (mark
);
5096 bs
->old_val
= b
->val
;
5099 return WP_VALUE_CHANGED
;
5103 /* Nothing changed. */
5104 value_free_to_mark (mark
);
5105 return WP_VALUE_NOT_CHANGED
;
5110 struct ui_out
*uiout
= current_uiout
;
5112 /* This seems like the only logical thing to do because
5113 if we temporarily ignored the watchpoint, then when
5114 we reenter the block in which it is valid it contains
5115 garbage (in the case of a function, it may have two
5116 garbage values, one before and one after the prologue).
5117 So we can't even detect the first assignment to it and
5118 watch after that (since the garbage may or may not equal
5119 the first value assigned). */
5120 /* We print all the stop information in
5121 breakpoint_ops->print_it, but in this case, by the time we
5122 call breakpoint_ops->print_it this bp will be deleted
5123 already. So we have no choice but print the information
5125 if (ui_out_is_mi_like_p (uiout
))
5127 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5128 ui_out_text (uiout
, "\nWatchpoint ");
5129 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5131 " deleted because the program has left the block in\n\
5132 which its expression is valid.\n");
5134 /* Make sure the watchpoint's commands aren't executed. */
5135 decref_counted_command_line (&b
->base
.commands
);
5136 watchpoint_del_at_next_stop (b
);
5142 /* Return true if it looks like target has stopped due to hitting
5143 breakpoint location BL. This function does not check if we should
5144 stop, only if BL explains the stop. */
5147 bpstat_check_location (const struct bp_location
*bl
,
5148 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5149 const struct target_waitstatus
*ws
)
5151 struct breakpoint
*b
= bl
->owner
;
5153 /* BL is from an existing breakpoint. */
5154 gdb_assert (b
!= NULL
);
5156 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5159 /* Determine if the watched values have actually changed, and we
5160 should stop. If not, set BS->stop to 0. */
5163 bpstat_check_watchpoint (bpstat bs
)
5165 const struct bp_location
*bl
;
5166 struct watchpoint
*b
;
5168 /* BS is built for existing struct breakpoint. */
5169 bl
= bs
->bp_location_at
;
5170 gdb_assert (bl
!= NULL
);
5171 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5172 gdb_assert (b
!= NULL
);
5175 int must_check_value
= 0;
5177 if (b
->base
.type
== bp_watchpoint
)
5178 /* For a software watchpoint, we must always check the
5180 must_check_value
= 1;
5181 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5182 /* We have a hardware watchpoint (read, write, or access)
5183 and the target earlier reported an address watched by
5185 must_check_value
= 1;
5186 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5187 && b
->base
.type
== bp_hardware_watchpoint
)
5188 /* We were stopped by a hardware watchpoint, but the target could
5189 not report the data address. We must check the watchpoint's
5190 value. Access and read watchpoints are out of luck; without
5191 a data address, we can't figure it out. */
5192 must_check_value
= 1;
5194 if (must_check_value
)
5197 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5199 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5200 int e
= catch_errors (watchpoint_check
, bs
, message
,
5202 do_cleanups (cleanups
);
5206 /* We've already printed what needs to be printed. */
5207 bs
->print_it
= print_it_done
;
5211 bs
->print_it
= print_it_noop
;
5214 case WP_VALUE_CHANGED
:
5215 if (b
->base
.type
== bp_read_watchpoint
)
5217 /* There are two cases to consider here:
5219 1. We're watching the triggered memory for reads.
5220 In that case, trust the target, and always report
5221 the watchpoint hit to the user. Even though
5222 reads don't cause value changes, the value may
5223 have changed since the last time it was read, and
5224 since we're not trapping writes, we will not see
5225 those, and as such we should ignore our notion of
5228 2. We're watching the triggered memory for both
5229 reads and writes. There are two ways this may
5232 2.1. This is a target that can't break on data
5233 reads only, but can break on accesses (reads or
5234 writes), such as e.g., x86. We detect this case
5235 at the time we try to insert read watchpoints.
5237 2.2. Otherwise, the target supports read
5238 watchpoints, but, the user set an access or write
5239 watchpoint watching the same memory as this read
5242 If we're watching memory writes as well as reads,
5243 ignore watchpoint hits when we find that the
5244 value hasn't changed, as reads don't cause
5245 changes. This still gives false positives when
5246 the program writes the same value to memory as
5247 what there was already in memory (we will confuse
5248 it for a read), but it's much better than
5251 int other_write_watchpoint
= 0;
5253 if (bl
->watchpoint_type
== hw_read
)
5255 struct breakpoint
*other_b
;
5257 ALL_BREAKPOINTS (other_b
)
5258 if (other_b
->type
== bp_hardware_watchpoint
5259 || other_b
->type
== bp_access_watchpoint
)
5261 struct watchpoint
*other_w
=
5262 (struct watchpoint
*) other_b
;
5264 if (other_w
->watchpoint_triggered
5265 == watch_triggered_yes
)
5267 other_write_watchpoint
= 1;
5273 if (other_write_watchpoint
5274 || bl
->watchpoint_type
== hw_access
)
5276 /* We're watching the same memory for writes,
5277 and the value changed since the last time we
5278 updated it, so this trap must be for a write.
5280 bs
->print_it
= print_it_noop
;
5285 case WP_VALUE_NOT_CHANGED
:
5286 if (b
->base
.type
== bp_hardware_watchpoint
5287 || b
->base
.type
== bp_watchpoint
)
5289 /* Don't stop: write watchpoints shouldn't fire if
5290 the value hasn't changed. */
5291 bs
->print_it
= print_it_noop
;
5299 /* Error from catch_errors. */
5300 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5301 watchpoint_del_at_next_stop (b
);
5302 /* We've already printed what needs to be printed. */
5303 bs
->print_it
= print_it_done
;
5307 else /* must_check_value == 0 */
5309 /* This is a case where some watchpoint(s) triggered, but
5310 not at the address of this watchpoint, or else no
5311 watchpoint triggered after all. So don't print
5312 anything for this watchpoint. */
5313 bs
->print_it
= print_it_noop
;
5319 /* For breakpoints that are currently marked as telling gdb to stop,
5320 check conditions (condition proper, frame, thread and ignore count)
5321 of breakpoint referred to by BS. If we should not stop for this
5322 breakpoint, set BS->stop to 0. */
5325 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5327 const struct bp_location
*bl
;
5328 struct breakpoint
*b
;
5329 int value_is_zero
= 0;
5330 struct expression
*cond
;
5332 gdb_assert (bs
->stop
);
5334 /* BS is built for existing struct breakpoint. */
5335 bl
= bs
->bp_location_at
;
5336 gdb_assert (bl
!= NULL
);
5337 b
= bs
->breakpoint_at
;
5338 gdb_assert (b
!= NULL
);
5340 /* Even if the target evaluated the condition on its end and notified GDB, we
5341 need to do so again since GDB does not know if we stopped due to a
5342 breakpoint or a single step breakpoint. */
5344 if (frame_id_p (b
->frame_id
)
5345 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5351 /* If this is a thread/task-specific breakpoint, don't waste cpu
5352 evaluating the condition if this isn't the specified
5354 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5355 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5362 /* Evaluate extension language breakpoints that have a "stop" method
5364 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5366 if (is_watchpoint (b
))
5368 struct watchpoint
*w
= (struct watchpoint
*) b
;
5375 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5377 int within_current_scope
= 1;
5378 struct watchpoint
* w
;
5380 /* We use value_mark and value_free_to_mark because it could
5381 be a long time before we return to the command level and
5382 call free_all_values. We can't call free_all_values
5383 because we might be in the middle of evaluating a
5385 struct value
*mark
= value_mark ();
5387 if (is_watchpoint (b
))
5388 w
= (struct watchpoint
*) b
;
5392 /* Need to select the frame, with all that implies so that
5393 the conditions will have the right context. Because we
5394 use the frame, we will not see an inlined function's
5395 variables when we arrive at a breakpoint at the start
5396 of the inlined function; the current frame will be the
5398 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5399 select_frame (get_current_frame ());
5402 struct frame_info
*frame
;
5404 /* For local watchpoint expressions, which particular
5405 instance of a local is being watched matters, so we
5406 keep track of the frame to evaluate the expression
5407 in. To evaluate the condition however, it doesn't
5408 really matter which instantiation of the function
5409 where the condition makes sense triggers the
5410 watchpoint. This allows an expression like "watch
5411 global if q > 10" set in `func', catch writes to
5412 global on all threads that call `func', or catch
5413 writes on all recursive calls of `func' by a single
5414 thread. We simply always evaluate the condition in
5415 the innermost frame that's executing where it makes
5416 sense to evaluate the condition. It seems
5418 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5420 select_frame (frame
);
5422 within_current_scope
= 0;
5424 if (within_current_scope
)
5426 = catch_errors (breakpoint_cond_eval
, cond
,
5427 "Error in testing breakpoint condition:\n",
5431 warning (_("Watchpoint condition cannot be tested "
5432 "in the current scope"));
5433 /* If we failed to set the right context for this
5434 watchpoint, unconditionally report it. */
5437 /* FIXME-someday, should give breakpoint #. */
5438 value_free_to_mark (mark
);
5441 if (cond
&& value_is_zero
)
5445 else if (b
->ignore_count
> 0)
5449 /* Increase the hit count even though we don't stop. */
5451 observer_notify_breakpoint_modified (b
);
5456 /* Get a bpstat associated with having just stopped at address
5457 BP_ADDR in thread PTID.
5459 Determine whether we stopped at a breakpoint, etc, or whether we
5460 don't understand this stop. Result is a chain of bpstat's such
5463 if we don't understand the stop, the result is a null pointer.
5465 if we understand why we stopped, the result is not null.
5467 Each element of the chain refers to a particular breakpoint or
5468 watchpoint at which we have stopped. (We may have stopped for
5469 several reasons concurrently.)
5471 Each element of the chain has valid next, breakpoint_at,
5472 commands, FIXME??? fields. */
5475 bpstat_stop_status (struct address_space
*aspace
,
5476 CORE_ADDR bp_addr
, ptid_t ptid
,
5477 const struct target_waitstatus
*ws
)
5479 struct breakpoint
*b
= NULL
;
5480 struct bp_location
*bl
;
5481 struct bp_location
*loc
;
5482 /* First item of allocated bpstat's. */
5483 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5484 /* Pointer to the last thing in the chain currently. */
5487 int need_remove_insert
;
5490 /* First, build the bpstat chain with locations that explain a
5491 target stop, while being careful to not set the target running,
5492 as that may invalidate locations (in particular watchpoint
5493 locations are recreated). Resuming will happen here with
5494 breakpoint conditions or watchpoint expressions that include
5495 inferior function calls. */
5499 if (!breakpoint_enabled (b
))
5502 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5504 /* For hardware watchpoints, we look only at the first
5505 location. The watchpoint_check function will work on the
5506 entire expression, not the individual locations. For
5507 read watchpoints, the watchpoints_triggered function has
5508 checked all locations already. */
5509 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5512 if (!bl
->enabled
|| bl
->shlib_disabled
)
5515 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5518 /* Come here if it's a watchpoint, or if the break address
5521 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5524 /* Assume we stop. Should we find a watchpoint that is not
5525 actually triggered, or if the condition of the breakpoint
5526 evaluates as false, we'll reset 'stop' to 0. */
5530 /* If this is a scope breakpoint, mark the associated
5531 watchpoint as triggered so that we will handle the
5532 out-of-scope event. We'll get to the watchpoint next
5534 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5536 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5538 w
->watchpoint_triggered
= watch_triggered_yes
;
5543 /* Check if a moribund breakpoint explains the stop. */
5544 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5546 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5548 bs
= bpstat_alloc (loc
, &bs_link
);
5549 /* For hits of moribund locations, we should just proceed. */
5552 bs
->print_it
= print_it_noop
;
5556 /* A bit of special processing for shlib breakpoints. We need to
5557 process solib loading here, so that the lists of loaded and
5558 unloaded libraries are correct before we handle "catch load" and
5560 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5562 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5564 handle_solib_event ();
5569 /* Now go through the locations that caused the target to stop, and
5570 check whether we're interested in reporting this stop to higher
5571 layers, or whether we should resume the target transparently. */
5575 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5580 b
= bs
->breakpoint_at
;
5581 b
->ops
->check_status (bs
);
5584 bpstat_check_breakpoint_conditions (bs
, ptid
);
5589 observer_notify_breakpoint_modified (b
);
5591 /* We will stop here. */
5592 if (b
->disposition
== disp_disable
)
5594 --(b
->enable_count
);
5595 if (b
->enable_count
<= 0)
5596 b
->enable_state
= bp_disabled
;
5601 bs
->commands
= b
->commands
;
5602 incref_counted_command_line (bs
->commands
);
5603 if (command_line_is_silent (bs
->commands
5604 ? bs
->commands
->commands
: NULL
))
5607 b
->ops
->after_condition_true (bs
);
5612 /* Print nothing for this entry if we don't stop or don't
5614 if (!bs
->stop
|| !bs
->print
)
5615 bs
->print_it
= print_it_noop
;
5618 /* If we aren't stopping, the value of some hardware watchpoint may
5619 not have changed, but the intermediate memory locations we are
5620 watching may have. Don't bother if we're stopping; this will get
5622 need_remove_insert
= 0;
5623 if (! bpstat_causes_stop (bs_head
))
5624 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5626 && bs
->breakpoint_at
5627 && is_hardware_watchpoint (bs
->breakpoint_at
))
5629 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5631 update_watchpoint (w
, 0 /* don't reparse. */);
5632 need_remove_insert
= 1;
5635 if (need_remove_insert
)
5636 update_global_location_list (UGLL_MAY_INSERT
);
5637 else if (removed_any
)
5638 update_global_location_list (UGLL_DONT_INSERT
);
5644 handle_jit_event (void)
5646 struct frame_info
*frame
;
5647 struct gdbarch
*gdbarch
;
5649 /* Switch terminal for any messages produced by
5650 breakpoint_re_set. */
5651 target_terminal_ours_for_output ();
5653 frame
= get_current_frame ();
5654 gdbarch
= get_frame_arch (frame
);
5656 jit_event_handler (gdbarch
);
5658 target_terminal_inferior ();
5661 /* Prepare WHAT final decision for infrun. */
5663 /* Decide what infrun needs to do with this bpstat. */
5666 bpstat_what (bpstat bs_head
)
5668 struct bpstat_what retval
;
5672 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5673 retval
.call_dummy
= STOP_NONE
;
5674 retval
.is_longjmp
= 0;
5676 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5678 /* Extract this BS's action. After processing each BS, we check
5679 if its action overrides all we've seem so far. */
5680 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5683 if (bs
->breakpoint_at
== NULL
)
5685 /* I suspect this can happen if it was a momentary
5686 breakpoint which has since been deleted. */
5690 bptype
= bs
->breakpoint_at
->type
;
5697 case bp_hardware_breakpoint
:
5698 case bp_single_step
:
5701 case bp_shlib_event
:
5705 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5707 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5710 this_action
= BPSTAT_WHAT_SINGLE
;
5713 case bp_hardware_watchpoint
:
5714 case bp_read_watchpoint
:
5715 case bp_access_watchpoint
:
5719 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5721 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5725 /* There was a watchpoint, but we're not stopping.
5726 This requires no further action. */
5730 case bp_longjmp_call_dummy
:
5732 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5733 retval
.is_longjmp
= bptype
!= bp_exception
;
5735 case bp_longjmp_resume
:
5736 case bp_exception_resume
:
5737 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5738 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5740 case bp_step_resume
:
5742 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5745 /* It is for the wrong frame. */
5746 this_action
= BPSTAT_WHAT_SINGLE
;
5749 case bp_hp_step_resume
:
5751 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5754 /* It is for the wrong frame. */
5755 this_action
= BPSTAT_WHAT_SINGLE
;
5758 case bp_watchpoint_scope
:
5759 case bp_thread_event
:
5760 case bp_overlay_event
:
5761 case bp_longjmp_master
:
5762 case bp_std_terminate_master
:
5763 case bp_exception_master
:
5764 this_action
= BPSTAT_WHAT_SINGLE
;
5770 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5772 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5776 /* There was a catchpoint, but we're not stopping.
5777 This requires no further action. */
5782 this_action
= BPSTAT_WHAT_SINGLE
;
5785 /* Make sure the action is stop (silent or noisy),
5786 so infrun.c pops the dummy frame. */
5787 retval
.call_dummy
= STOP_STACK_DUMMY
;
5788 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5790 case bp_std_terminate
:
5791 /* Make sure the action is stop (silent or noisy),
5792 so infrun.c pops the dummy frame. */
5793 retval
.call_dummy
= STOP_STD_TERMINATE
;
5794 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5797 case bp_fast_tracepoint
:
5798 case bp_static_tracepoint
:
5799 /* Tracepoint hits should not be reported back to GDB, and
5800 if one got through somehow, it should have been filtered
5802 internal_error (__FILE__
, __LINE__
,
5803 _("bpstat_what: tracepoint encountered"));
5805 case bp_gnu_ifunc_resolver
:
5806 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5807 this_action
= BPSTAT_WHAT_SINGLE
;
5809 case bp_gnu_ifunc_resolver_return
:
5810 /* The breakpoint will be removed, execution will restart from the
5811 PC of the former breakpoint. */
5812 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5817 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5819 this_action
= BPSTAT_WHAT_SINGLE
;
5823 internal_error (__FILE__
, __LINE__
,
5824 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5827 retval
.main_action
= max (retval
.main_action
, this_action
);
5830 /* These operations may affect the bs->breakpoint_at state so they are
5831 delayed after MAIN_ACTION is decided above. */
5836 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5838 handle_jit_event ();
5841 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5843 struct breakpoint
*b
= bs
->breakpoint_at
;
5849 case bp_gnu_ifunc_resolver
:
5850 gnu_ifunc_resolver_stop (b
);
5852 case bp_gnu_ifunc_resolver_return
:
5853 gnu_ifunc_resolver_return_stop (b
);
5861 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5862 without hardware support). This isn't related to a specific bpstat,
5863 just to things like whether watchpoints are set. */
5866 bpstat_should_step (void)
5868 struct breakpoint
*b
;
5871 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5877 bpstat_causes_stop (bpstat bs
)
5879 for (; bs
!= NULL
; bs
= bs
->next
)
5888 /* Compute a string of spaces suitable to indent the next line
5889 so it starts at the position corresponding to the table column
5890 named COL_NAME in the currently active table of UIOUT. */
5893 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5895 static char wrap_indent
[80];
5896 int i
, total_width
, width
, align
;
5900 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5902 if (strcmp (text
, col_name
) == 0)
5904 gdb_assert (total_width
< sizeof wrap_indent
);
5905 memset (wrap_indent
, ' ', total_width
);
5906 wrap_indent
[total_width
] = 0;
5911 total_width
+= width
+ 1;
5917 /* Determine if the locations of this breakpoint will have their conditions
5918 evaluated by the target, host or a mix of both. Returns the following:
5920 "host": Host evals condition.
5921 "host or target": Host or Target evals condition.
5922 "target": Target evals condition.
5926 bp_condition_evaluator (struct breakpoint
*b
)
5928 struct bp_location
*bl
;
5929 char host_evals
= 0;
5930 char target_evals
= 0;
5935 if (!is_breakpoint (b
))
5938 if (gdb_evaluates_breakpoint_condition_p ()
5939 || !target_supports_evaluation_of_breakpoint_conditions ())
5940 return condition_evaluation_host
;
5942 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5944 if (bl
->cond_bytecode
)
5950 if (host_evals
&& target_evals
)
5951 return condition_evaluation_both
;
5952 else if (target_evals
)
5953 return condition_evaluation_target
;
5955 return condition_evaluation_host
;
5958 /* Determine the breakpoint location's condition evaluator. This is
5959 similar to bp_condition_evaluator, but for locations. */
5962 bp_location_condition_evaluator (struct bp_location
*bl
)
5964 if (bl
&& !is_breakpoint (bl
->owner
))
5967 if (gdb_evaluates_breakpoint_condition_p ()
5968 || !target_supports_evaluation_of_breakpoint_conditions ())
5969 return condition_evaluation_host
;
5971 if (bl
&& bl
->cond_bytecode
)
5972 return condition_evaluation_target
;
5974 return condition_evaluation_host
;
5977 /* Print the LOC location out of the list of B->LOC locations. */
5980 print_breakpoint_location (struct breakpoint
*b
,
5981 struct bp_location
*loc
)
5983 struct ui_out
*uiout
= current_uiout
;
5984 struct cleanup
*old_chain
= save_current_program_space ();
5986 if (loc
!= NULL
&& loc
->shlib_disabled
)
5990 set_current_program_space (loc
->pspace
);
5992 if (b
->display_canonical
)
5993 ui_out_field_string (uiout
, "what", b
->addr_string
);
5994 else if (loc
&& loc
->symtab
)
5997 = find_pc_sect_function (loc
->address
, loc
->section
);
6000 ui_out_text (uiout
, "in ");
6001 ui_out_field_string (uiout
, "func",
6002 SYMBOL_PRINT_NAME (sym
));
6003 ui_out_text (uiout
, " ");
6004 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6005 ui_out_text (uiout
, "at ");
6007 ui_out_field_string (uiout
, "file",
6008 symtab_to_filename_for_display (loc
->symtab
));
6009 ui_out_text (uiout
, ":");
6011 if (ui_out_is_mi_like_p (uiout
))
6012 ui_out_field_string (uiout
, "fullname",
6013 symtab_to_fullname (loc
->symtab
));
6015 ui_out_field_int (uiout
, "line", loc
->line_number
);
6019 struct ui_file
*stb
= mem_fileopen ();
6020 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6022 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6024 ui_out_field_stream (uiout
, "at", stb
);
6026 do_cleanups (stb_chain
);
6029 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6031 if (loc
&& is_breakpoint (b
)
6032 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6033 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6035 ui_out_text (uiout
, " (");
6036 ui_out_field_string (uiout
, "evaluated-by",
6037 bp_location_condition_evaluator (loc
));
6038 ui_out_text (uiout
, ")");
6041 do_cleanups (old_chain
);
6045 bptype_string (enum bptype type
)
6047 struct ep_type_description
6052 static struct ep_type_description bptypes
[] =
6054 {bp_none
, "?deleted?"},
6055 {bp_breakpoint
, "breakpoint"},
6056 {bp_hardware_breakpoint
, "hw breakpoint"},
6057 {bp_single_step
, "sw single-step"},
6058 {bp_until
, "until"},
6059 {bp_finish
, "finish"},
6060 {bp_watchpoint
, "watchpoint"},
6061 {bp_hardware_watchpoint
, "hw watchpoint"},
6062 {bp_read_watchpoint
, "read watchpoint"},
6063 {bp_access_watchpoint
, "acc watchpoint"},
6064 {bp_longjmp
, "longjmp"},
6065 {bp_longjmp_resume
, "longjmp resume"},
6066 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6067 {bp_exception
, "exception"},
6068 {bp_exception_resume
, "exception resume"},
6069 {bp_step_resume
, "step resume"},
6070 {bp_hp_step_resume
, "high-priority step resume"},
6071 {bp_watchpoint_scope
, "watchpoint scope"},
6072 {bp_call_dummy
, "call dummy"},
6073 {bp_std_terminate
, "std::terminate"},
6074 {bp_shlib_event
, "shlib events"},
6075 {bp_thread_event
, "thread events"},
6076 {bp_overlay_event
, "overlay events"},
6077 {bp_longjmp_master
, "longjmp master"},
6078 {bp_std_terminate_master
, "std::terminate master"},
6079 {bp_exception_master
, "exception master"},
6080 {bp_catchpoint
, "catchpoint"},
6081 {bp_tracepoint
, "tracepoint"},
6082 {bp_fast_tracepoint
, "fast tracepoint"},
6083 {bp_static_tracepoint
, "static tracepoint"},
6084 {bp_dprintf
, "dprintf"},
6085 {bp_jit_event
, "jit events"},
6086 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6087 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6090 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6091 || ((int) type
!= bptypes
[(int) type
].type
))
6092 internal_error (__FILE__
, __LINE__
,
6093 _("bptypes table does not describe type #%d."),
6096 return bptypes
[(int) type
].description
;
6099 /* For MI, output a field named 'thread-groups' with a list as the value.
6100 For CLI, prefix the list with the string 'inf'. */
6103 output_thread_groups (struct ui_out
*uiout
,
6104 const char *field_name
,
6108 struct cleanup
*back_to
;
6109 int is_mi
= ui_out_is_mi_like_p (uiout
);
6113 /* For backward compatibility, don't display inferiors in CLI unless
6114 there are several. Always display them for MI. */
6115 if (!is_mi
&& mi_only
)
6118 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6120 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6126 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6127 ui_out_field_string (uiout
, NULL
, mi_group
);
6132 ui_out_text (uiout
, " inf ");
6134 ui_out_text (uiout
, ", ");
6136 ui_out_text (uiout
, plongest (inf
));
6140 do_cleanups (back_to
);
6143 /* Print B to gdb_stdout. */
6146 print_one_breakpoint_location (struct breakpoint
*b
,
6147 struct bp_location
*loc
,
6149 struct bp_location
**last_loc
,
6152 struct command_line
*l
;
6153 static char bpenables
[] = "nynny";
6155 struct ui_out
*uiout
= current_uiout
;
6156 int header_of_multiple
= 0;
6157 int part_of_multiple
= (loc
!= NULL
);
6158 struct value_print_options opts
;
6160 get_user_print_options (&opts
);
6162 gdb_assert (!loc
|| loc_number
!= 0);
6163 /* See comment in print_one_breakpoint concerning treatment of
6164 breakpoints with single disabled location. */
6167 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6168 header_of_multiple
= 1;
6176 if (part_of_multiple
)
6179 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6180 ui_out_field_string (uiout
, "number", formatted
);
6185 ui_out_field_int (uiout
, "number", b
->number
);
6190 if (part_of_multiple
)
6191 ui_out_field_skip (uiout
, "type");
6193 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6197 if (part_of_multiple
)
6198 ui_out_field_skip (uiout
, "disp");
6200 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6205 if (part_of_multiple
)
6206 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6208 ui_out_field_fmt (uiout
, "enabled", "%c",
6209 bpenables
[(int) b
->enable_state
]);
6210 ui_out_spaces (uiout
, 2);
6214 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6216 /* Although the print_one can possibly print all locations,
6217 calling it here is not likely to get any nice result. So,
6218 make sure there's just one location. */
6219 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6220 b
->ops
->print_one (b
, last_loc
);
6226 internal_error (__FILE__
, __LINE__
,
6227 _("print_one_breakpoint: bp_none encountered\n"));
6231 case bp_hardware_watchpoint
:
6232 case bp_read_watchpoint
:
6233 case bp_access_watchpoint
:
6235 struct watchpoint
*w
= (struct watchpoint
*) b
;
6237 /* Field 4, the address, is omitted (which makes the columns
6238 not line up too nicely with the headers, but the effect
6239 is relatively readable). */
6240 if (opts
.addressprint
)
6241 ui_out_field_skip (uiout
, "addr");
6243 ui_out_field_string (uiout
, "what", w
->exp_string
);
6248 case bp_hardware_breakpoint
:
6249 case bp_single_step
:
6253 case bp_longjmp_resume
:
6254 case bp_longjmp_call_dummy
:
6256 case bp_exception_resume
:
6257 case bp_step_resume
:
6258 case bp_hp_step_resume
:
6259 case bp_watchpoint_scope
:
6261 case bp_std_terminate
:
6262 case bp_shlib_event
:
6263 case bp_thread_event
:
6264 case bp_overlay_event
:
6265 case bp_longjmp_master
:
6266 case bp_std_terminate_master
:
6267 case bp_exception_master
:
6269 case bp_fast_tracepoint
:
6270 case bp_static_tracepoint
:
6273 case bp_gnu_ifunc_resolver
:
6274 case bp_gnu_ifunc_resolver_return
:
6275 if (opts
.addressprint
)
6278 if (header_of_multiple
)
6279 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6280 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6281 ui_out_field_string (uiout
, "addr", "<PENDING>");
6283 ui_out_field_core_addr (uiout
, "addr",
6284 loc
->gdbarch
, loc
->address
);
6287 if (!header_of_multiple
)
6288 print_breakpoint_location (b
, loc
);
6295 if (loc
!= NULL
&& !header_of_multiple
)
6297 struct inferior
*inf
;
6298 VEC(int) *inf_num
= NULL
;
6303 if (inf
->pspace
== loc
->pspace
)
6304 VEC_safe_push (int, inf_num
, inf
->num
);
6307 /* For backward compatibility, don't display inferiors in CLI unless
6308 there are several. Always display for MI. */
6310 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6311 && (number_of_program_spaces () > 1
6312 || number_of_inferiors () > 1)
6313 /* LOC is for existing B, it cannot be in
6314 moribund_locations and thus having NULL OWNER. */
6315 && loc
->owner
->type
!= bp_catchpoint
))
6317 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6318 VEC_free (int, inf_num
);
6321 if (!part_of_multiple
)
6323 if (b
->thread
!= -1)
6325 /* FIXME: This seems to be redundant and lost here; see the
6326 "stop only in" line a little further down. */
6327 ui_out_text (uiout
, " thread ");
6328 ui_out_field_int (uiout
, "thread", b
->thread
);
6330 else if (b
->task
!= 0)
6332 ui_out_text (uiout
, " task ");
6333 ui_out_field_int (uiout
, "task", b
->task
);
6337 ui_out_text (uiout
, "\n");
6339 if (!part_of_multiple
)
6340 b
->ops
->print_one_detail (b
, uiout
);
6342 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6345 ui_out_text (uiout
, "\tstop only in stack frame at ");
6346 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6348 ui_out_field_core_addr (uiout
, "frame",
6349 b
->gdbarch
, b
->frame_id
.stack_addr
);
6350 ui_out_text (uiout
, "\n");
6353 if (!part_of_multiple
&& b
->cond_string
)
6356 if (is_tracepoint (b
))
6357 ui_out_text (uiout
, "\ttrace only if ");
6359 ui_out_text (uiout
, "\tstop only if ");
6360 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6362 /* Print whether the target is doing the breakpoint's condition
6363 evaluation. If GDB is doing the evaluation, don't print anything. */
6364 if (is_breakpoint (b
)
6365 && breakpoint_condition_evaluation_mode ()
6366 == condition_evaluation_target
)
6368 ui_out_text (uiout
, " (");
6369 ui_out_field_string (uiout
, "evaluated-by",
6370 bp_condition_evaluator (b
));
6371 ui_out_text (uiout
, " evals)");
6373 ui_out_text (uiout
, "\n");
6376 if (!part_of_multiple
&& b
->thread
!= -1)
6378 /* FIXME should make an annotation for this. */
6379 ui_out_text (uiout
, "\tstop only in thread ");
6380 ui_out_field_int (uiout
, "thread", b
->thread
);
6381 ui_out_text (uiout
, "\n");
6384 if (!part_of_multiple
)
6388 /* FIXME should make an annotation for this. */
6389 if (is_catchpoint (b
))
6390 ui_out_text (uiout
, "\tcatchpoint");
6391 else if (is_tracepoint (b
))
6392 ui_out_text (uiout
, "\ttracepoint");
6394 ui_out_text (uiout
, "\tbreakpoint");
6395 ui_out_text (uiout
, " already hit ");
6396 ui_out_field_int (uiout
, "times", b
->hit_count
);
6397 if (b
->hit_count
== 1)
6398 ui_out_text (uiout
, " time\n");
6400 ui_out_text (uiout
, " times\n");
6404 /* Output the count also if it is zero, but only if this is mi. */
6405 if (ui_out_is_mi_like_p (uiout
))
6406 ui_out_field_int (uiout
, "times", b
->hit_count
);
6410 if (!part_of_multiple
&& b
->ignore_count
)
6413 ui_out_text (uiout
, "\tignore next ");
6414 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6415 ui_out_text (uiout
, " hits\n");
6418 /* Note that an enable count of 1 corresponds to "enable once"
6419 behavior, which is reported by the combination of enablement and
6420 disposition, so we don't need to mention it here. */
6421 if (!part_of_multiple
&& b
->enable_count
> 1)
6424 ui_out_text (uiout
, "\tdisable after ");
6425 /* Tweak the wording to clarify that ignore and enable counts
6426 are distinct, and have additive effect. */
6427 if (b
->ignore_count
)
6428 ui_out_text (uiout
, "additional ");
6430 ui_out_text (uiout
, "next ");
6431 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6432 ui_out_text (uiout
, " hits\n");
6435 if (!part_of_multiple
&& is_tracepoint (b
))
6437 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6439 if (tp
->traceframe_usage
)
6441 ui_out_text (uiout
, "\ttrace buffer usage ");
6442 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6443 ui_out_text (uiout
, " bytes\n");
6447 l
= b
->commands
? b
->commands
->commands
: NULL
;
6448 if (!part_of_multiple
&& l
)
6450 struct cleanup
*script_chain
;
6453 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6454 print_command_lines (uiout
, l
, 4);
6455 do_cleanups (script_chain
);
6458 if (is_tracepoint (b
))
6460 struct tracepoint
*t
= (struct tracepoint
*) b
;
6462 if (!part_of_multiple
&& t
->pass_count
)
6464 annotate_field (10);
6465 ui_out_text (uiout
, "\tpass count ");
6466 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6467 ui_out_text (uiout
, " \n");
6470 /* Don't display it when tracepoint or tracepoint location is
6472 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6474 annotate_field (11);
6476 if (ui_out_is_mi_like_p (uiout
))
6477 ui_out_field_string (uiout
, "installed",
6478 loc
->inserted
? "y" : "n");
6482 ui_out_text (uiout
, "\t");
6484 ui_out_text (uiout
, "\tnot ");
6485 ui_out_text (uiout
, "installed on target\n");
6490 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6492 if (is_watchpoint (b
))
6494 struct watchpoint
*w
= (struct watchpoint
*) b
;
6496 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6498 else if (b
->addr_string
)
6499 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6504 print_one_breakpoint (struct breakpoint
*b
,
6505 struct bp_location
**last_loc
,
6508 struct cleanup
*bkpt_chain
;
6509 struct ui_out
*uiout
= current_uiout
;
6511 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6513 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6514 do_cleanups (bkpt_chain
);
6516 /* If this breakpoint has custom print function,
6517 it's already printed. Otherwise, print individual
6518 locations, if any. */
6519 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6521 /* If breakpoint has a single location that is disabled, we
6522 print it as if it had several locations, since otherwise it's
6523 hard to represent "breakpoint enabled, location disabled"
6526 Note that while hardware watchpoints have several locations
6527 internally, that's not a property exposed to user. */
6529 && !is_hardware_watchpoint (b
)
6530 && (b
->loc
->next
|| !b
->loc
->enabled
))
6532 struct bp_location
*loc
;
6535 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6537 struct cleanup
*inner2
=
6538 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6539 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6540 do_cleanups (inner2
);
6547 breakpoint_address_bits (struct breakpoint
*b
)
6549 int print_address_bits
= 0;
6550 struct bp_location
*loc
;
6552 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6556 /* Software watchpoints that aren't watching memory don't have
6557 an address to print. */
6558 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6561 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6562 if (addr_bit
> print_address_bits
)
6563 print_address_bits
= addr_bit
;
6566 return print_address_bits
;
6569 struct captured_breakpoint_query_args
6575 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6577 struct captured_breakpoint_query_args
*args
= data
;
6578 struct breakpoint
*b
;
6579 struct bp_location
*dummy_loc
= NULL
;
6583 if (args
->bnum
== b
->number
)
6585 print_one_breakpoint (b
, &dummy_loc
, 0);
6593 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6594 char **error_message
)
6596 struct captured_breakpoint_query_args args
;
6599 /* For the moment we don't trust print_one_breakpoint() to not throw
6601 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6602 error_message
, RETURN_MASK_ALL
) < 0)
6608 /* Return true if this breakpoint was set by the user, false if it is
6609 internal or momentary. */
6612 user_breakpoint_p (struct breakpoint
*b
)
6614 return b
->number
> 0;
6617 /* Print information on user settable breakpoint (watchpoint, etc)
6618 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6619 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6620 FILTER is non-NULL, call it on each breakpoint and only include the
6621 ones for which it returns non-zero. Return the total number of
6622 breakpoints listed. */
6625 breakpoint_1 (char *args
, int allflag
,
6626 int (*filter
) (const struct breakpoint
*))
6628 struct breakpoint
*b
;
6629 struct bp_location
*last_loc
= NULL
;
6630 int nr_printable_breakpoints
;
6631 struct cleanup
*bkpttbl_chain
;
6632 struct value_print_options opts
;
6633 int print_address_bits
= 0;
6634 int print_type_col_width
= 14;
6635 struct ui_out
*uiout
= current_uiout
;
6637 get_user_print_options (&opts
);
6639 /* Compute the number of rows in the table, as well as the size
6640 required for address fields. */
6641 nr_printable_breakpoints
= 0;
6644 /* If we have a filter, only list the breakpoints it accepts. */
6645 if (filter
&& !filter (b
))
6648 /* If we have an "args" string, it is a list of breakpoints to
6649 accept. Skip the others. */
6650 if (args
!= NULL
&& *args
!= '\0')
6652 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6654 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6658 if (allflag
|| user_breakpoint_p (b
))
6660 int addr_bit
, type_len
;
6662 addr_bit
= breakpoint_address_bits (b
);
6663 if (addr_bit
> print_address_bits
)
6664 print_address_bits
= addr_bit
;
6666 type_len
= strlen (bptype_string (b
->type
));
6667 if (type_len
> print_type_col_width
)
6668 print_type_col_width
= type_len
;
6670 nr_printable_breakpoints
++;
6674 if (opts
.addressprint
)
6676 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6677 nr_printable_breakpoints
,
6681 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6682 nr_printable_breakpoints
,
6685 if (nr_printable_breakpoints
> 0)
6686 annotate_breakpoints_headers ();
6687 if (nr_printable_breakpoints
> 0)
6689 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6690 if (nr_printable_breakpoints
> 0)
6692 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6693 "type", "Type"); /* 2 */
6694 if (nr_printable_breakpoints
> 0)
6696 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6697 if (nr_printable_breakpoints
> 0)
6699 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6700 if (opts
.addressprint
)
6702 if (nr_printable_breakpoints
> 0)
6704 if (print_address_bits
<= 32)
6705 ui_out_table_header (uiout
, 10, ui_left
,
6706 "addr", "Address"); /* 5 */
6708 ui_out_table_header (uiout
, 18, ui_left
,
6709 "addr", "Address"); /* 5 */
6711 if (nr_printable_breakpoints
> 0)
6713 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6714 ui_out_table_body (uiout
);
6715 if (nr_printable_breakpoints
> 0)
6716 annotate_breakpoints_table ();
6721 /* If we have a filter, only list the breakpoints it accepts. */
6722 if (filter
&& !filter (b
))
6725 /* If we have an "args" string, it is a list of breakpoints to
6726 accept. Skip the others. */
6728 if (args
!= NULL
&& *args
!= '\0')
6730 if (allflag
) /* maintenance info breakpoint */
6732 if (parse_and_eval_long (args
) != b
->number
)
6735 else /* all others */
6737 if (!number_is_in_list (args
, b
->number
))
6741 /* We only print out user settable breakpoints unless the
6743 if (allflag
|| user_breakpoint_p (b
))
6744 print_one_breakpoint (b
, &last_loc
, allflag
);
6747 do_cleanups (bkpttbl_chain
);
6749 if (nr_printable_breakpoints
== 0)
6751 /* If there's a filter, let the caller decide how to report
6755 if (args
== NULL
|| *args
== '\0')
6756 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6758 ui_out_message (uiout
, 0,
6759 "No breakpoint or watchpoint matching '%s'.\n",
6765 if (last_loc
&& !server_command
)
6766 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6769 /* FIXME? Should this be moved up so that it is only called when
6770 there have been breakpoints? */
6771 annotate_breakpoints_table_end ();
6773 return nr_printable_breakpoints
;
6776 /* Display the value of default-collect in a way that is generally
6777 compatible with the breakpoint list. */
6780 default_collect_info (void)
6782 struct ui_out
*uiout
= current_uiout
;
6784 /* If it has no value (which is frequently the case), say nothing; a
6785 message like "No default-collect." gets in user's face when it's
6787 if (!*default_collect
)
6790 /* The following phrase lines up nicely with per-tracepoint collect
6792 ui_out_text (uiout
, "default collect ");
6793 ui_out_field_string (uiout
, "default-collect", default_collect
);
6794 ui_out_text (uiout
, " \n");
6798 breakpoints_info (char *args
, int from_tty
)
6800 breakpoint_1 (args
, 0, NULL
);
6802 default_collect_info ();
6806 watchpoints_info (char *args
, int from_tty
)
6808 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6809 struct ui_out
*uiout
= current_uiout
;
6811 if (num_printed
== 0)
6813 if (args
== NULL
|| *args
== '\0')
6814 ui_out_message (uiout
, 0, "No watchpoints.\n");
6816 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6821 maintenance_info_breakpoints (char *args
, int from_tty
)
6823 breakpoint_1 (args
, 1, NULL
);
6825 default_collect_info ();
6829 breakpoint_has_pc (struct breakpoint
*b
,
6830 struct program_space
*pspace
,
6831 CORE_ADDR pc
, struct obj_section
*section
)
6833 struct bp_location
*bl
= b
->loc
;
6835 for (; bl
; bl
= bl
->next
)
6837 if (bl
->pspace
== pspace
6838 && bl
->address
== pc
6839 && (!overlay_debugging
|| bl
->section
== section
))
6845 /* Print a message describing any user-breakpoints set at PC. This
6846 concerns with logical breakpoints, so we match program spaces, not
6850 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6851 struct program_space
*pspace
, CORE_ADDR pc
,
6852 struct obj_section
*section
, int thread
)
6855 struct breakpoint
*b
;
6858 others
+= (user_breakpoint_p (b
)
6859 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6863 printf_filtered (_("Note: breakpoint "));
6864 else /* if (others == ???) */
6865 printf_filtered (_("Note: breakpoints "));
6867 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6870 printf_filtered ("%d", b
->number
);
6871 if (b
->thread
== -1 && thread
!= -1)
6872 printf_filtered (" (all threads)");
6873 else if (b
->thread
!= -1)
6874 printf_filtered (" (thread %d)", b
->thread
);
6875 printf_filtered ("%s%s ",
6876 ((b
->enable_state
== bp_disabled
6877 || b
->enable_state
== bp_call_disabled
)
6881 : ((others
== 1) ? " and" : ""));
6883 printf_filtered (_("also set at pc "));
6884 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6885 printf_filtered (".\n");
6890 /* Return true iff it is meaningful to use the address member of
6891 BPT. For some breakpoint types, the address member is irrelevant
6892 and it makes no sense to attempt to compare it to other addresses
6893 (or use it for any other purpose either).
6895 More specifically, each of the following breakpoint types will
6896 always have a zero valued address and we don't want to mark
6897 breakpoints of any of these types to be a duplicate of an actual
6898 breakpoint at address zero:
6906 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6908 enum bptype type
= bpt
->type
;
6910 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6913 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6914 true if LOC1 and LOC2 represent the same watchpoint location. */
6917 watchpoint_locations_match (struct bp_location
*loc1
,
6918 struct bp_location
*loc2
)
6920 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6921 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6923 /* Both of them must exist. */
6924 gdb_assert (w1
!= NULL
);
6925 gdb_assert (w2
!= NULL
);
6927 /* If the target can evaluate the condition expression in hardware,
6928 then we we need to insert both watchpoints even if they are at
6929 the same place. Otherwise the watchpoint will only trigger when
6930 the condition of whichever watchpoint was inserted evaluates to
6931 true, not giving a chance for GDB to check the condition of the
6932 other watchpoint. */
6934 && target_can_accel_watchpoint_condition (loc1
->address
,
6936 loc1
->watchpoint_type
,
6939 && target_can_accel_watchpoint_condition (loc2
->address
,
6941 loc2
->watchpoint_type
,
6945 /* Note that this checks the owner's type, not the location's. In
6946 case the target does not support read watchpoints, but does
6947 support access watchpoints, we'll have bp_read_watchpoint
6948 watchpoints with hw_access locations. Those should be considered
6949 duplicates of hw_read locations. The hw_read locations will
6950 become hw_access locations later. */
6951 return (loc1
->owner
->type
== loc2
->owner
->type
6952 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6953 && loc1
->address
== loc2
->address
6954 && loc1
->length
== loc2
->length
);
6957 /* See breakpoint.h. */
6960 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6961 struct address_space
*aspace2
, CORE_ADDR addr2
)
6963 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6964 || aspace1
== aspace2
)
6968 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6969 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6970 matches ASPACE2. On targets that have global breakpoints, the address
6971 space doesn't really matter. */
6974 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6975 int len1
, struct address_space
*aspace2
,
6978 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6979 || aspace1
== aspace2
)
6980 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6983 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6984 a ranged breakpoint. In most targets, a match happens only if ASPACE
6985 matches the breakpoint's address space. On targets that have global
6986 breakpoints, the address space doesn't really matter. */
6989 breakpoint_location_address_match (struct bp_location
*bl
,
6990 struct address_space
*aspace
,
6993 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6996 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6997 bl
->address
, bl
->length
,
7001 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7002 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7003 true, otherwise returns false. */
7006 tracepoint_locations_match (struct bp_location
*loc1
,
7007 struct bp_location
*loc2
)
7009 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7010 /* Since tracepoint locations are never duplicated with others', tracepoint
7011 locations at the same address of different tracepoints are regarded as
7012 different locations. */
7013 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7018 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7019 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7020 represent the same location. */
7023 breakpoint_locations_match (struct bp_location
*loc1
,
7024 struct bp_location
*loc2
)
7026 int hw_point1
, hw_point2
;
7028 /* Both of them must not be in moribund_locations. */
7029 gdb_assert (loc1
->owner
!= NULL
);
7030 gdb_assert (loc2
->owner
!= NULL
);
7032 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7033 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7035 if (hw_point1
!= hw_point2
)
7038 return watchpoint_locations_match (loc1
, loc2
);
7039 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7040 return tracepoint_locations_match (loc1
, loc2
);
7042 /* We compare bp_location.length in order to cover ranged breakpoints. */
7043 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7044 loc2
->pspace
->aspace
, loc2
->address
)
7045 && loc1
->length
== loc2
->length
);
7049 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7050 int bnum
, int have_bnum
)
7052 /* The longest string possibly returned by hex_string_custom
7053 is 50 chars. These must be at least that big for safety. */
7057 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7058 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7060 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7061 bnum
, astr1
, astr2
);
7063 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7066 /* Adjust a breakpoint's address to account for architectural
7067 constraints on breakpoint placement. Return the adjusted address.
7068 Note: Very few targets require this kind of adjustment. For most
7069 targets, this function is simply the identity function. */
7072 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7073 CORE_ADDR bpaddr
, enum bptype bptype
)
7075 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7077 /* Very few targets need any kind of breakpoint adjustment. */
7080 else if (bptype
== bp_watchpoint
7081 || bptype
== bp_hardware_watchpoint
7082 || bptype
== bp_read_watchpoint
7083 || bptype
== bp_access_watchpoint
7084 || bptype
== bp_catchpoint
)
7086 /* Watchpoints and the various bp_catch_* eventpoints should not
7087 have their addresses modified. */
7090 else if (bptype
== bp_single_step
)
7092 /* Single-step breakpoints should not have their addresses
7093 modified. If there's any architectural constrain that
7094 applies to this address, then it should have already been
7095 taken into account when the breakpoint was created in the
7096 first place. If we didn't do this, stepping through e.g.,
7097 Thumb-2 IT blocks would break. */
7102 CORE_ADDR adjusted_bpaddr
;
7104 /* Some targets have architectural constraints on the placement
7105 of breakpoint instructions. Obtain the adjusted address. */
7106 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7108 /* An adjusted breakpoint address can significantly alter
7109 a user's expectations. Print a warning if an adjustment
7111 if (adjusted_bpaddr
!= bpaddr
)
7112 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7114 return adjusted_bpaddr
;
7119 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7120 struct breakpoint
*owner
)
7122 memset (loc
, 0, sizeof (*loc
));
7124 gdb_assert (ops
!= NULL
);
7129 loc
->cond_bytecode
= NULL
;
7130 loc
->shlib_disabled
= 0;
7133 switch (owner
->type
)
7136 case bp_single_step
:
7140 case bp_longjmp_resume
:
7141 case bp_longjmp_call_dummy
:
7143 case bp_exception_resume
:
7144 case bp_step_resume
:
7145 case bp_hp_step_resume
:
7146 case bp_watchpoint_scope
:
7148 case bp_std_terminate
:
7149 case bp_shlib_event
:
7150 case bp_thread_event
:
7151 case bp_overlay_event
:
7153 case bp_longjmp_master
:
7154 case bp_std_terminate_master
:
7155 case bp_exception_master
:
7156 case bp_gnu_ifunc_resolver
:
7157 case bp_gnu_ifunc_resolver_return
:
7159 loc
->loc_type
= bp_loc_software_breakpoint
;
7160 mark_breakpoint_location_modified (loc
);
7162 case bp_hardware_breakpoint
:
7163 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7164 mark_breakpoint_location_modified (loc
);
7166 case bp_hardware_watchpoint
:
7167 case bp_read_watchpoint
:
7168 case bp_access_watchpoint
:
7169 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7174 case bp_fast_tracepoint
:
7175 case bp_static_tracepoint
:
7176 loc
->loc_type
= bp_loc_other
;
7179 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7185 /* Allocate a struct bp_location. */
7187 static struct bp_location
*
7188 allocate_bp_location (struct breakpoint
*bpt
)
7190 return bpt
->ops
->allocate_location (bpt
);
7194 free_bp_location (struct bp_location
*loc
)
7196 loc
->ops
->dtor (loc
);
7200 /* Increment reference count. */
7203 incref_bp_location (struct bp_location
*bl
)
7208 /* Decrement reference count. If the reference count reaches 0,
7209 destroy the bp_location. Sets *BLP to NULL. */
7212 decref_bp_location (struct bp_location
**blp
)
7214 gdb_assert ((*blp
)->refc
> 0);
7216 if (--(*blp
)->refc
== 0)
7217 free_bp_location (*blp
);
7221 /* Add breakpoint B at the end of the global breakpoint chain. */
7224 add_to_breakpoint_chain (struct breakpoint
*b
)
7226 struct breakpoint
*b1
;
7228 /* Add this breakpoint to the end of the chain so that a list of
7229 breakpoints will come out in order of increasing numbers. */
7231 b1
= breakpoint_chain
;
7233 breakpoint_chain
= b
;
7242 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7245 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7246 struct gdbarch
*gdbarch
,
7248 const struct breakpoint_ops
*ops
)
7250 memset (b
, 0, sizeof (*b
));
7252 gdb_assert (ops
!= NULL
);
7256 b
->gdbarch
= gdbarch
;
7257 b
->language
= current_language
->la_language
;
7258 b
->input_radix
= input_radix
;
7260 b
->enable_state
= bp_enabled
;
7263 b
->ignore_count
= 0;
7265 b
->frame_id
= null_frame_id
;
7266 b
->condition_not_parsed
= 0;
7267 b
->py_bp_object
= NULL
;
7268 b
->related_breakpoint
= b
;
7271 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7272 that has type BPTYPE and has no locations as yet. */
7274 static struct breakpoint
*
7275 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7277 const struct breakpoint_ops
*ops
)
7279 struct breakpoint
*b
= XNEW (struct breakpoint
);
7281 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7282 add_to_breakpoint_chain (b
);
7286 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7287 resolutions should be made as the user specified the location explicitly
7291 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7293 gdb_assert (loc
->owner
!= NULL
);
7295 if (loc
->owner
->type
== bp_breakpoint
7296 || loc
->owner
->type
== bp_hardware_breakpoint
7297 || is_tracepoint (loc
->owner
))
7300 const char *function_name
;
7301 CORE_ADDR func_addr
;
7303 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7304 &func_addr
, NULL
, &is_gnu_ifunc
);
7306 if (is_gnu_ifunc
&& !explicit_loc
)
7308 struct breakpoint
*b
= loc
->owner
;
7310 gdb_assert (loc
->pspace
== current_program_space
);
7311 if (gnu_ifunc_resolve_name (function_name
,
7312 &loc
->requested_address
))
7314 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7315 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7316 loc
->requested_address
,
7319 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7320 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7322 /* Create only the whole new breakpoint of this type but do not
7323 mess more complicated breakpoints with multiple locations. */
7324 b
->type
= bp_gnu_ifunc_resolver
;
7325 /* Remember the resolver's address for use by the return
7327 loc
->related_address
= func_addr
;
7332 loc
->function_name
= xstrdup (function_name
);
7336 /* Attempt to determine architecture of location identified by SAL. */
7338 get_sal_arch (struct symtab_and_line sal
)
7341 return get_objfile_arch (sal
.section
->objfile
);
7343 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7348 /* Low level routine for partially initializing a breakpoint of type
7349 BPTYPE. The newly created breakpoint's address, section, source
7350 file name, and line number are provided by SAL.
7352 It is expected that the caller will complete the initialization of
7353 the newly created breakpoint struct as well as output any status
7354 information regarding the creation of a new breakpoint. */
7357 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7358 struct symtab_and_line sal
, enum bptype bptype
,
7359 const struct breakpoint_ops
*ops
)
7361 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7363 add_location_to_breakpoint (b
, &sal
);
7365 if (bptype
!= bp_catchpoint
)
7366 gdb_assert (sal
.pspace
!= NULL
);
7368 /* Store the program space that was used to set the breakpoint,
7369 except for ordinary breakpoints, which are independent of the
7371 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7372 b
->pspace
= sal
.pspace
;
7375 /* set_raw_breakpoint is a low level routine for allocating and
7376 partially initializing a breakpoint of type BPTYPE. The newly
7377 created breakpoint's address, section, source file name, and line
7378 number are provided by SAL. The newly created and partially
7379 initialized breakpoint is added to the breakpoint chain and
7380 is also returned as the value of this function.
7382 It is expected that the caller will complete the initialization of
7383 the newly created breakpoint struct as well as output any status
7384 information regarding the creation of a new breakpoint. In
7385 particular, set_raw_breakpoint does NOT set the breakpoint
7386 number! Care should be taken to not allow an error to occur
7387 prior to completing the initialization of the breakpoint. If this
7388 should happen, a bogus breakpoint will be left on the chain. */
7391 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7392 struct symtab_and_line sal
, enum bptype bptype
,
7393 const struct breakpoint_ops
*ops
)
7395 struct breakpoint
*b
= XNEW (struct breakpoint
);
7397 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7398 add_to_breakpoint_chain (b
);
7403 /* Note that the breakpoint object B describes a permanent breakpoint
7404 instruction, hard-wired into the inferior's code. */
7406 make_breakpoint_permanent (struct breakpoint
*b
)
7408 struct bp_location
*bl
;
7410 /* By definition, permanent breakpoints are already present in the
7411 code. Mark all locations as inserted. For now,
7412 make_breakpoint_permanent is called in just one place, so it's
7413 hard to say if it's reasonable to have permanent breakpoint with
7414 multiple locations or not, but it's easy to implement. */
7415 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7422 /* Call this routine when stepping and nexting to enable a breakpoint
7423 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7424 initiated the operation. */
7427 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7429 struct breakpoint
*b
, *b_tmp
;
7430 int thread
= tp
->num
;
7432 /* To avoid having to rescan all objfile symbols at every step,
7433 we maintain a list of continually-inserted but always disabled
7434 longjmp "master" breakpoints. Here, we simply create momentary
7435 clones of those and enable them for the requested thread. */
7436 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7437 if (b
->pspace
== current_program_space
7438 && (b
->type
== bp_longjmp_master
7439 || b
->type
== bp_exception_master
))
7441 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7442 struct breakpoint
*clone
;
7444 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7445 after their removal. */
7446 clone
= momentary_breakpoint_from_master (b
, type
,
7447 &longjmp_breakpoint_ops
, 1);
7448 clone
->thread
= thread
;
7451 tp
->initiating_frame
= frame
;
7454 /* Delete all longjmp breakpoints from THREAD. */
7456 delete_longjmp_breakpoint (int thread
)
7458 struct breakpoint
*b
, *b_tmp
;
7460 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7461 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7463 if (b
->thread
== thread
)
7464 delete_breakpoint (b
);
7469 delete_longjmp_breakpoint_at_next_stop (int thread
)
7471 struct breakpoint
*b
, *b_tmp
;
7473 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7474 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7476 if (b
->thread
== thread
)
7477 b
->disposition
= disp_del_at_next_stop
;
7481 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7482 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7483 pointer to any of them. Return NULL if this system cannot place longjmp
7487 set_longjmp_breakpoint_for_call_dummy (void)
7489 struct breakpoint
*b
, *retval
= NULL
;
7492 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7494 struct breakpoint
*new_b
;
7496 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7497 &momentary_breakpoint_ops
,
7499 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7501 /* Link NEW_B into the chain of RETVAL breakpoints. */
7503 gdb_assert (new_b
->related_breakpoint
== new_b
);
7506 new_b
->related_breakpoint
= retval
;
7507 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7508 retval
= retval
->related_breakpoint
;
7509 retval
->related_breakpoint
= new_b
;
7515 /* Verify all existing dummy frames and their associated breakpoints for
7516 TP. Remove those which can no longer be found in the current frame
7519 You should call this function only at places where it is safe to currently
7520 unwind the whole stack. Failed stack unwind would discard live dummy
7524 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7526 struct breakpoint
*b
, *b_tmp
;
7528 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7529 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7531 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7533 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7534 dummy_b
= dummy_b
->related_breakpoint
;
7535 if (dummy_b
->type
!= bp_call_dummy
7536 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7539 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7541 while (b
->related_breakpoint
!= b
)
7543 if (b_tmp
== b
->related_breakpoint
)
7544 b_tmp
= b
->related_breakpoint
->next
;
7545 delete_breakpoint (b
->related_breakpoint
);
7547 delete_breakpoint (b
);
7552 enable_overlay_breakpoints (void)
7554 struct breakpoint
*b
;
7557 if (b
->type
== bp_overlay_event
)
7559 b
->enable_state
= bp_enabled
;
7560 update_global_location_list (UGLL_MAY_INSERT
);
7561 overlay_events_enabled
= 1;
7566 disable_overlay_breakpoints (void)
7568 struct breakpoint
*b
;
7571 if (b
->type
== bp_overlay_event
)
7573 b
->enable_state
= bp_disabled
;
7574 update_global_location_list (UGLL_DONT_INSERT
);
7575 overlay_events_enabled
= 0;
7579 /* Set an active std::terminate breakpoint for each std::terminate
7580 master breakpoint. */
7582 set_std_terminate_breakpoint (void)
7584 struct breakpoint
*b
, *b_tmp
;
7586 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7587 if (b
->pspace
== current_program_space
7588 && b
->type
== bp_std_terminate_master
)
7590 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7591 &momentary_breakpoint_ops
, 1);
7595 /* Delete all the std::terminate breakpoints. */
7597 delete_std_terminate_breakpoint (void)
7599 struct breakpoint
*b
, *b_tmp
;
7601 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7602 if (b
->type
== bp_std_terminate
)
7603 delete_breakpoint (b
);
7607 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7609 struct breakpoint
*b
;
7611 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7612 &internal_breakpoint_ops
);
7614 b
->enable_state
= bp_enabled
;
7615 /* addr_string has to be used or breakpoint_re_set will delete me. */
7617 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7619 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7625 remove_thread_event_breakpoints (void)
7627 struct breakpoint
*b
, *b_tmp
;
7629 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7630 if (b
->type
== bp_thread_event
7631 && b
->loc
->pspace
== current_program_space
)
7632 delete_breakpoint (b
);
7635 struct lang_and_radix
7641 /* Create a breakpoint for JIT code registration and unregistration. */
7644 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7646 struct breakpoint
*b
;
7648 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7649 &internal_breakpoint_ops
);
7650 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7654 /* Remove JIT code registration and unregistration breakpoint(s). */
7657 remove_jit_event_breakpoints (void)
7659 struct breakpoint
*b
, *b_tmp
;
7661 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7662 if (b
->type
== bp_jit_event
7663 && b
->loc
->pspace
== current_program_space
)
7664 delete_breakpoint (b
);
7668 remove_solib_event_breakpoints (void)
7670 struct breakpoint
*b
, *b_tmp
;
7672 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7673 if (b
->type
== bp_shlib_event
7674 && b
->loc
->pspace
== current_program_space
)
7675 delete_breakpoint (b
);
7678 /* See breakpoint.h. */
7681 remove_solib_event_breakpoints_at_next_stop (void)
7683 struct breakpoint
*b
, *b_tmp
;
7685 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7686 if (b
->type
== bp_shlib_event
7687 && b
->loc
->pspace
== current_program_space
)
7688 b
->disposition
= disp_del_at_next_stop
;
7691 /* Helper for create_solib_event_breakpoint /
7692 create_and_insert_solib_event_breakpoint. Allows specifying which
7693 INSERT_MODE to pass through to update_global_location_list. */
7695 static struct breakpoint
*
7696 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7697 enum ugll_insert_mode insert_mode
)
7699 struct breakpoint
*b
;
7701 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7702 &internal_breakpoint_ops
);
7703 update_global_location_list_nothrow (insert_mode
);
7708 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7710 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7713 /* See breakpoint.h. */
7716 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7718 struct breakpoint
*b
;
7720 /* Explicitly tell update_global_location_list to insert
7722 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7723 if (!b
->loc
->inserted
)
7725 delete_breakpoint (b
);
7731 /* Disable any breakpoints that are on code in shared libraries. Only
7732 apply to enabled breakpoints, disabled ones can just stay disabled. */
7735 disable_breakpoints_in_shlibs (void)
7737 struct bp_location
*loc
, **locp_tmp
;
7739 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7741 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7742 struct breakpoint
*b
= loc
->owner
;
7744 /* We apply the check to all breakpoints, including disabled for
7745 those with loc->duplicate set. This is so that when breakpoint
7746 becomes enabled, or the duplicate is removed, gdb will try to
7747 insert all breakpoints. If we don't set shlib_disabled here,
7748 we'll try to insert those breakpoints and fail. */
7749 if (((b
->type
== bp_breakpoint
)
7750 || (b
->type
== bp_jit_event
)
7751 || (b
->type
== bp_hardware_breakpoint
)
7752 || (is_tracepoint (b
)))
7753 && loc
->pspace
== current_program_space
7754 && !loc
->shlib_disabled
7755 && solib_name_from_address (loc
->pspace
, loc
->address
)
7758 loc
->shlib_disabled
= 1;
7763 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7764 notification of unloaded_shlib. Only apply to enabled breakpoints,
7765 disabled ones can just stay disabled. */
7768 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7770 struct bp_location
*loc
, **locp_tmp
;
7771 int disabled_shlib_breaks
= 0;
7773 /* SunOS a.out shared libraries are always mapped, so do not
7774 disable breakpoints; they will only be reported as unloaded
7775 through clear_solib when GDB discards its shared library
7776 list. See clear_solib for more information. */
7777 if (exec_bfd
!= NULL
7778 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7781 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7783 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7784 struct breakpoint
*b
= loc
->owner
;
7786 if (solib
->pspace
== loc
->pspace
7787 && !loc
->shlib_disabled
7788 && (((b
->type
== bp_breakpoint
7789 || b
->type
== bp_jit_event
7790 || b
->type
== bp_hardware_breakpoint
)
7791 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7792 || loc
->loc_type
== bp_loc_software_breakpoint
))
7793 || is_tracepoint (b
))
7794 && solib_contains_address_p (solib
, loc
->address
))
7796 loc
->shlib_disabled
= 1;
7797 /* At this point, we cannot rely on remove_breakpoint
7798 succeeding so we must mark the breakpoint as not inserted
7799 to prevent future errors occurring in remove_breakpoints. */
7802 /* This may cause duplicate notifications for the same breakpoint. */
7803 observer_notify_breakpoint_modified (b
);
7805 if (!disabled_shlib_breaks
)
7807 target_terminal_ours_for_output ();
7808 warning (_("Temporarily disabling breakpoints "
7809 "for unloaded shared library \"%s\""),
7812 disabled_shlib_breaks
= 1;
7817 /* Disable any breakpoints and tracepoints in OBJFILE upon
7818 notification of free_objfile. Only apply to enabled breakpoints,
7819 disabled ones can just stay disabled. */
7822 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7824 struct breakpoint
*b
;
7826 if (objfile
== NULL
)
7829 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7830 managed by the user with add-symbol-file/remove-symbol-file.
7831 Similarly to how breakpoints in shared libraries are handled in
7832 response to "nosharedlibrary", mark breakpoints in such modules
7833 shlib_disabled so they end up uninserted on the next global
7834 location list update. Shared libraries not loaded by the user
7835 aren't handled here -- they're already handled in
7836 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7837 solib_unloaded observer. We skip objfiles that are not
7838 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7840 if ((objfile
->flags
& OBJF_SHARED
) == 0
7841 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7846 struct bp_location
*loc
;
7847 int bp_modified
= 0;
7849 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7852 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7854 CORE_ADDR loc_addr
= loc
->address
;
7856 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7857 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7860 if (loc
->shlib_disabled
!= 0)
7863 if (objfile
->pspace
!= loc
->pspace
)
7866 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7867 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7870 if (is_addr_in_objfile (loc_addr
, objfile
))
7872 loc
->shlib_disabled
= 1;
7873 /* At this point, we don't know whether the object was
7874 unmapped from the inferior or not, so leave the
7875 inserted flag alone. We'll handle failure to
7876 uninsert quietly, in case the object was indeed
7879 mark_breakpoint_location_modified (loc
);
7886 observer_notify_breakpoint_modified (b
);
7890 /* FORK & VFORK catchpoints. */
7892 /* An instance of this type is used to represent a fork or vfork
7893 catchpoint. It includes a "struct breakpoint" as a kind of base
7894 class; users downcast to "struct breakpoint *" when needed. A
7895 breakpoint is really of this type iff its ops pointer points to
7896 CATCH_FORK_BREAKPOINT_OPS. */
7898 struct fork_catchpoint
7900 /* The base class. */
7901 struct breakpoint base
;
7903 /* Process id of a child process whose forking triggered this
7904 catchpoint. This field is only valid immediately after this
7905 catchpoint has triggered. */
7906 ptid_t forked_inferior_pid
;
7909 /* Implement the "insert" breakpoint_ops method for fork
7913 insert_catch_fork (struct bp_location
*bl
)
7915 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7918 /* Implement the "remove" breakpoint_ops method for fork
7922 remove_catch_fork (struct bp_location
*bl
)
7924 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7927 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7931 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7932 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7933 const struct target_waitstatus
*ws
)
7935 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7937 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7940 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7944 /* Implement the "print_it" breakpoint_ops method for fork
7947 static enum print_stop_action
7948 print_it_catch_fork (bpstat bs
)
7950 struct ui_out
*uiout
= current_uiout
;
7951 struct breakpoint
*b
= bs
->breakpoint_at
;
7952 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7954 annotate_catchpoint (b
->number
);
7955 if (b
->disposition
== disp_del
)
7956 ui_out_text (uiout
, "\nTemporary catchpoint ");
7958 ui_out_text (uiout
, "\nCatchpoint ");
7959 if (ui_out_is_mi_like_p (uiout
))
7961 ui_out_field_string (uiout
, "reason",
7962 async_reason_lookup (EXEC_ASYNC_FORK
));
7963 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7965 ui_out_field_int (uiout
, "bkptno", b
->number
);
7966 ui_out_text (uiout
, " (forked process ");
7967 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7968 ui_out_text (uiout
, "), ");
7969 return PRINT_SRC_AND_LOC
;
7972 /* Implement the "print_one" breakpoint_ops method for fork
7976 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7978 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7979 struct value_print_options opts
;
7980 struct ui_out
*uiout
= current_uiout
;
7982 get_user_print_options (&opts
);
7984 /* Field 4, the address, is omitted (which makes the columns not
7985 line up too nicely with the headers, but the effect is relatively
7987 if (opts
.addressprint
)
7988 ui_out_field_skip (uiout
, "addr");
7990 ui_out_text (uiout
, "fork");
7991 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7993 ui_out_text (uiout
, ", process ");
7994 ui_out_field_int (uiout
, "what",
7995 ptid_get_pid (c
->forked_inferior_pid
));
7996 ui_out_spaces (uiout
, 1);
7999 if (ui_out_is_mi_like_p (uiout
))
8000 ui_out_field_string (uiout
, "catch-type", "fork");
8003 /* Implement the "print_mention" breakpoint_ops method for fork
8007 print_mention_catch_fork (struct breakpoint
*b
)
8009 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8012 /* Implement the "print_recreate" breakpoint_ops method for fork
8016 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8018 fprintf_unfiltered (fp
, "catch fork");
8019 print_recreate_thread (b
, fp
);
8022 /* The breakpoint_ops structure to be used in fork catchpoints. */
8024 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8026 /* Implement the "insert" breakpoint_ops method for vfork
8030 insert_catch_vfork (struct bp_location
*bl
)
8032 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8035 /* Implement the "remove" breakpoint_ops method for vfork
8039 remove_catch_vfork (struct bp_location
*bl
)
8041 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8044 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8048 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8049 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8050 const struct target_waitstatus
*ws
)
8052 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8054 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8057 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8061 /* Implement the "print_it" breakpoint_ops method for vfork
8064 static enum print_stop_action
8065 print_it_catch_vfork (bpstat bs
)
8067 struct ui_out
*uiout
= current_uiout
;
8068 struct breakpoint
*b
= bs
->breakpoint_at
;
8069 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8071 annotate_catchpoint (b
->number
);
8072 if (b
->disposition
== disp_del
)
8073 ui_out_text (uiout
, "\nTemporary catchpoint ");
8075 ui_out_text (uiout
, "\nCatchpoint ");
8076 if (ui_out_is_mi_like_p (uiout
))
8078 ui_out_field_string (uiout
, "reason",
8079 async_reason_lookup (EXEC_ASYNC_VFORK
));
8080 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8082 ui_out_field_int (uiout
, "bkptno", b
->number
);
8083 ui_out_text (uiout
, " (vforked process ");
8084 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8085 ui_out_text (uiout
, "), ");
8086 return PRINT_SRC_AND_LOC
;
8089 /* Implement the "print_one" breakpoint_ops method for vfork
8093 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8095 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8096 struct value_print_options opts
;
8097 struct ui_out
*uiout
= current_uiout
;
8099 get_user_print_options (&opts
);
8100 /* Field 4, the address, is omitted (which makes the columns not
8101 line up too nicely with the headers, but the effect is relatively
8103 if (opts
.addressprint
)
8104 ui_out_field_skip (uiout
, "addr");
8106 ui_out_text (uiout
, "vfork");
8107 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8109 ui_out_text (uiout
, ", process ");
8110 ui_out_field_int (uiout
, "what",
8111 ptid_get_pid (c
->forked_inferior_pid
));
8112 ui_out_spaces (uiout
, 1);
8115 if (ui_out_is_mi_like_p (uiout
))
8116 ui_out_field_string (uiout
, "catch-type", "vfork");
8119 /* Implement the "print_mention" breakpoint_ops method for vfork
8123 print_mention_catch_vfork (struct breakpoint
*b
)
8125 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8128 /* Implement the "print_recreate" breakpoint_ops method for vfork
8132 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8134 fprintf_unfiltered (fp
, "catch vfork");
8135 print_recreate_thread (b
, fp
);
8138 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8140 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8142 /* An instance of this type is used to represent an solib catchpoint.
8143 It includes a "struct breakpoint" as a kind of base class; users
8144 downcast to "struct breakpoint *" when needed. A breakpoint is
8145 really of this type iff its ops pointer points to
8146 CATCH_SOLIB_BREAKPOINT_OPS. */
8148 struct solib_catchpoint
8150 /* The base class. */
8151 struct breakpoint base
;
8153 /* True for "catch load", false for "catch unload". */
8154 unsigned char is_load
;
8156 /* Regular expression to match, if any. COMPILED is only valid when
8157 REGEX is non-NULL. */
8163 dtor_catch_solib (struct breakpoint
*b
)
8165 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8168 regfree (&self
->compiled
);
8169 xfree (self
->regex
);
8171 base_breakpoint_ops
.dtor (b
);
8175 insert_catch_solib (struct bp_location
*ignore
)
8181 remove_catch_solib (struct bp_location
*ignore
)
8187 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8188 struct address_space
*aspace
,
8190 const struct target_waitstatus
*ws
)
8192 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8193 struct breakpoint
*other
;
8195 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8198 ALL_BREAKPOINTS (other
)
8200 struct bp_location
*other_bl
;
8202 if (other
== bl
->owner
)
8205 if (other
->type
!= bp_shlib_event
)
8208 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8211 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8213 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8222 check_status_catch_solib (struct bpstats
*bs
)
8224 struct solib_catchpoint
*self
8225 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8230 struct so_list
*iter
;
8233 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8238 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8247 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8252 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8258 bs
->print_it
= print_it_noop
;
8261 static enum print_stop_action
8262 print_it_catch_solib (bpstat bs
)
8264 struct breakpoint
*b
= bs
->breakpoint_at
;
8265 struct ui_out
*uiout
= current_uiout
;
8267 annotate_catchpoint (b
->number
);
8268 if (b
->disposition
== disp_del
)
8269 ui_out_text (uiout
, "\nTemporary catchpoint ");
8271 ui_out_text (uiout
, "\nCatchpoint ");
8272 ui_out_field_int (uiout
, "bkptno", b
->number
);
8273 ui_out_text (uiout
, "\n");
8274 if (ui_out_is_mi_like_p (uiout
))
8275 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8276 print_solib_event (1);
8277 return PRINT_SRC_AND_LOC
;
8281 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8283 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8284 struct value_print_options opts
;
8285 struct ui_out
*uiout
= current_uiout
;
8288 get_user_print_options (&opts
);
8289 /* Field 4, the address, is omitted (which makes the columns not
8290 line up too nicely with the headers, but the effect is relatively
8292 if (opts
.addressprint
)
8295 ui_out_field_skip (uiout
, "addr");
8302 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8304 msg
= xstrdup (_("load of library"));
8309 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8311 msg
= xstrdup (_("unload of library"));
8313 ui_out_field_string (uiout
, "what", msg
);
8316 if (ui_out_is_mi_like_p (uiout
))
8317 ui_out_field_string (uiout
, "catch-type",
8318 self
->is_load
? "load" : "unload");
8322 print_mention_catch_solib (struct breakpoint
*b
)
8324 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8326 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8327 self
->is_load
? "load" : "unload");
8331 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8333 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8335 fprintf_unfiltered (fp
, "%s %s",
8336 b
->disposition
== disp_del
? "tcatch" : "catch",
8337 self
->is_load
? "load" : "unload");
8339 fprintf_unfiltered (fp
, " %s", self
->regex
);
8340 fprintf_unfiltered (fp
, "\n");
8343 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8345 /* Shared helper function (MI and CLI) for creating and installing
8346 a shared object event catchpoint. If IS_LOAD is non-zero then
8347 the events to be caught are load events, otherwise they are
8348 unload events. If IS_TEMP is non-zero the catchpoint is a
8349 temporary one. If ENABLED is non-zero the catchpoint is
8350 created in an enabled state. */
8353 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8355 struct solib_catchpoint
*c
;
8356 struct gdbarch
*gdbarch
= get_current_arch ();
8357 struct cleanup
*cleanup
;
8361 arg
= skip_spaces (arg
);
8363 c
= XCNEW (struct solib_catchpoint
);
8364 cleanup
= make_cleanup (xfree
, c
);
8370 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8373 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8375 make_cleanup (xfree
, err
);
8376 error (_("Invalid regexp (%s): %s"), err
, arg
);
8378 c
->regex
= xstrdup (arg
);
8381 c
->is_load
= is_load
;
8382 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8383 &catch_solib_breakpoint_ops
);
8385 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8387 discard_cleanups (cleanup
);
8388 install_breakpoint (0, &c
->base
, 1);
8391 /* A helper function that does all the work for "catch load" and
8395 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8396 struct cmd_list_element
*command
)
8399 const int enabled
= 1;
8401 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8403 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8407 catch_load_command_1 (char *arg
, int from_tty
,
8408 struct cmd_list_element
*command
)
8410 catch_load_or_unload (arg
, from_tty
, 1, command
);
8414 catch_unload_command_1 (char *arg
, int from_tty
,
8415 struct cmd_list_element
*command
)
8417 catch_load_or_unload (arg
, from_tty
, 0, command
);
8420 /* An instance of this type is used to represent a syscall catchpoint.
8421 It includes a "struct breakpoint" as a kind of base class; users
8422 downcast to "struct breakpoint *" when needed. A breakpoint is
8423 really of this type iff its ops pointer points to
8424 CATCH_SYSCALL_BREAKPOINT_OPS. */
8426 struct syscall_catchpoint
8428 /* The base class. */
8429 struct breakpoint base
;
8431 /* Syscall numbers used for the 'catch syscall' feature. If no
8432 syscall has been specified for filtering, its value is NULL.
8433 Otherwise, it holds a list of all syscalls to be caught. The
8434 list elements are allocated with xmalloc. */
8435 VEC(int) *syscalls_to_be_caught
;
8438 /* Implement the "dtor" breakpoint_ops method for syscall
8442 dtor_catch_syscall (struct breakpoint
*b
)
8444 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8446 VEC_free (int, c
->syscalls_to_be_caught
);
8448 base_breakpoint_ops
.dtor (b
);
8451 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8453 struct catch_syscall_inferior_data
8455 /* We keep a count of the number of times the user has requested a
8456 particular syscall to be tracked, and pass this information to the
8457 target. This lets capable targets implement filtering directly. */
8459 /* Number of times that "any" syscall is requested. */
8460 int any_syscall_count
;
8462 /* Count of each system call. */
8463 VEC(int) *syscalls_counts
;
8465 /* This counts all syscall catch requests, so we can readily determine
8466 if any catching is necessary. */
8467 int total_syscalls_count
;
8470 static struct catch_syscall_inferior_data
*
8471 get_catch_syscall_inferior_data (struct inferior
*inf
)
8473 struct catch_syscall_inferior_data
*inf_data
;
8475 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8476 if (inf_data
== NULL
)
8478 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8479 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8486 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8492 /* Implement the "insert" breakpoint_ops method for syscall
8496 insert_catch_syscall (struct bp_location
*bl
)
8498 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8499 struct inferior
*inf
= current_inferior ();
8500 struct catch_syscall_inferior_data
*inf_data
8501 = get_catch_syscall_inferior_data (inf
);
8503 ++inf_data
->total_syscalls_count
;
8504 if (!c
->syscalls_to_be_caught
)
8505 ++inf_data
->any_syscall_count
;
8511 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8516 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8518 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8519 uintptr_t vec_addr_offset
8520 = old_size
* ((uintptr_t) sizeof (int));
8522 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8523 vec_addr
= ((uintptr_t) VEC_address (int,
8524 inf_data
->syscalls_counts
)
8526 memset ((void *) vec_addr
, 0,
8527 (iter
+ 1 - old_size
) * sizeof (int));
8529 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8530 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8534 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8535 inf_data
->total_syscalls_count
!= 0,
8536 inf_data
->any_syscall_count
,
8538 inf_data
->syscalls_counts
),
8540 inf_data
->syscalls_counts
));
8543 /* Implement the "remove" breakpoint_ops method for syscall
8547 remove_catch_syscall (struct bp_location
*bl
)
8549 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8550 struct inferior
*inf
= current_inferior ();
8551 struct catch_syscall_inferior_data
*inf_data
8552 = get_catch_syscall_inferior_data (inf
);
8554 --inf_data
->total_syscalls_count
;
8555 if (!c
->syscalls_to_be_caught
)
8556 --inf_data
->any_syscall_count
;
8562 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8566 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8567 /* Shouldn't happen. */
8569 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8570 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8574 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8575 inf_data
->total_syscalls_count
!= 0,
8576 inf_data
->any_syscall_count
,
8578 inf_data
->syscalls_counts
),
8580 inf_data
->syscalls_counts
));
8583 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8587 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8588 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8589 const struct target_waitstatus
*ws
)
8591 /* We must check if we are catching specific syscalls in this
8592 breakpoint. If we are, then we must guarantee that the called
8593 syscall is the same syscall we are catching. */
8594 int syscall_number
= 0;
8595 const struct syscall_catchpoint
*c
8596 = (const struct syscall_catchpoint
*) bl
->owner
;
8598 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8599 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8602 syscall_number
= ws
->value
.syscall_number
;
8604 /* Now, checking if the syscall is the same. */
8605 if (c
->syscalls_to_be_caught
)
8610 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8612 if (syscall_number
== iter
)
8621 /* Implement the "print_it" breakpoint_ops method for syscall
8624 static enum print_stop_action
8625 print_it_catch_syscall (bpstat bs
)
8627 struct ui_out
*uiout
= current_uiout
;
8628 struct breakpoint
*b
= bs
->breakpoint_at
;
8629 /* These are needed because we want to know in which state a
8630 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8631 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8632 must print "called syscall" or "returned from syscall". */
8634 struct target_waitstatus last
;
8636 struct gdbarch
*gdbarch
= bs
->bp_location_at
->gdbarch
;
8638 get_last_target_status (&ptid
, &last
);
8640 get_syscall_by_number (gdbarch
, last
.value
.syscall_number
, &s
);
8642 annotate_catchpoint (b
->number
);
8644 if (b
->disposition
== disp_del
)
8645 ui_out_text (uiout
, "\nTemporary catchpoint ");
8647 ui_out_text (uiout
, "\nCatchpoint ");
8648 if (ui_out_is_mi_like_p (uiout
))
8650 ui_out_field_string (uiout
, "reason",
8651 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8652 ? EXEC_ASYNC_SYSCALL_ENTRY
8653 : EXEC_ASYNC_SYSCALL_RETURN
));
8654 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8656 ui_out_field_int (uiout
, "bkptno", b
->number
);
8658 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8659 ui_out_text (uiout
, " (call to syscall ");
8661 ui_out_text (uiout
, " (returned from syscall ");
8663 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8664 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8666 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8668 ui_out_text (uiout
, "), ");
8670 return PRINT_SRC_AND_LOC
;
8673 /* Implement the "print_one" breakpoint_ops method for syscall
8677 print_one_catch_syscall (struct breakpoint
*b
,
8678 struct bp_location
**last_loc
)
8680 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8681 struct value_print_options opts
;
8682 struct ui_out
*uiout
= current_uiout
;
8683 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8685 get_user_print_options (&opts
);
8686 /* Field 4, the address, is omitted (which makes the columns not
8687 line up too nicely with the headers, but the effect is relatively
8689 if (opts
.addressprint
)
8690 ui_out_field_skip (uiout
, "addr");
8693 if (c
->syscalls_to_be_caught
8694 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8695 ui_out_text (uiout
, "syscalls \"");
8697 ui_out_text (uiout
, "syscall \"");
8699 if (c
->syscalls_to_be_caught
)
8702 char *text
= xstrprintf ("%s", "");
8705 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8710 get_syscall_by_number (gdbarch
, iter
, &s
);
8713 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8715 text
= xstrprintf ("%s%d, ", text
, iter
);
8717 /* We have to xfree the last 'text' (now stored at 'x')
8718 because xstrprintf dynamically allocates new space for it
8722 /* Remove the last comma. */
8723 text
[strlen (text
) - 2] = '\0';
8724 ui_out_field_string (uiout
, "what", text
);
8727 ui_out_field_string (uiout
, "what", "<any syscall>");
8728 ui_out_text (uiout
, "\" ");
8730 if (ui_out_is_mi_like_p (uiout
))
8731 ui_out_field_string (uiout
, "catch-type", "syscall");
8734 /* Implement the "print_mention" breakpoint_ops method for syscall
8738 print_mention_catch_syscall (struct breakpoint
*b
)
8740 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8741 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8743 if (c
->syscalls_to_be_caught
)
8747 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8748 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8750 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8753 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8757 get_syscall_by_number (gdbarch
, iter
, &s
);
8760 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8762 printf_filtered (" %d", s
.number
);
8764 printf_filtered (")");
8767 printf_filtered (_("Catchpoint %d (any syscall)"),
8771 /* Implement the "print_recreate" breakpoint_ops method for syscall
8775 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8777 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8778 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8780 fprintf_unfiltered (fp
, "catch syscall");
8782 if (c
->syscalls_to_be_caught
)
8787 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8792 get_syscall_by_number (gdbarch
, iter
, &s
);
8794 fprintf_unfiltered (fp
, " %s", s
.name
);
8796 fprintf_unfiltered (fp
, " %d", s
.number
);
8799 print_recreate_thread (b
, fp
);
8802 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8804 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8806 /* Returns non-zero if 'b' is a syscall catchpoint. */
8809 syscall_catchpoint_p (struct breakpoint
*b
)
8811 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8814 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8815 is non-zero, then make the breakpoint temporary. If COND_STRING is
8816 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8817 the breakpoint_ops structure associated to the catchpoint. */
8820 init_catchpoint (struct breakpoint
*b
,
8821 struct gdbarch
*gdbarch
, int tempflag
,
8823 const struct breakpoint_ops
*ops
)
8825 struct symtab_and_line sal
;
8828 sal
.pspace
= current_program_space
;
8830 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8832 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8833 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8837 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8839 add_to_breakpoint_chain (b
);
8840 set_breakpoint_number (internal
, b
);
8841 if (is_tracepoint (b
))
8842 set_tracepoint_count (breakpoint_count
);
8845 observer_notify_breakpoint_created (b
);
8848 update_global_location_list (UGLL_MAY_INSERT
);
8852 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8853 int tempflag
, char *cond_string
,
8854 const struct breakpoint_ops
*ops
)
8856 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8858 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8860 c
->forked_inferior_pid
= null_ptid
;
8862 install_breakpoint (0, &c
->base
, 1);
8865 /* Exec catchpoints. */
8867 /* An instance of this type is used to represent an exec catchpoint.
8868 It includes a "struct breakpoint" as a kind of base class; users
8869 downcast to "struct breakpoint *" when needed. A breakpoint is
8870 really of this type iff its ops pointer points to
8871 CATCH_EXEC_BREAKPOINT_OPS. */
8873 struct exec_catchpoint
8875 /* The base class. */
8876 struct breakpoint base
;
8878 /* Filename of a program whose exec triggered this catchpoint.
8879 This field is only valid immediately after this catchpoint has
8881 char *exec_pathname
;
8884 /* Implement the "dtor" breakpoint_ops method for exec
8888 dtor_catch_exec (struct breakpoint
*b
)
8890 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8892 xfree (c
->exec_pathname
);
8894 base_breakpoint_ops
.dtor (b
);
8898 insert_catch_exec (struct bp_location
*bl
)
8900 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8904 remove_catch_exec (struct bp_location
*bl
)
8906 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8910 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8911 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8912 const struct target_waitstatus
*ws
)
8914 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8916 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8919 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8923 static enum print_stop_action
8924 print_it_catch_exec (bpstat bs
)
8926 struct ui_out
*uiout
= current_uiout
;
8927 struct breakpoint
*b
= bs
->breakpoint_at
;
8928 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8930 annotate_catchpoint (b
->number
);
8931 if (b
->disposition
== disp_del
)
8932 ui_out_text (uiout
, "\nTemporary catchpoint ");
8934 ui_out_text (uiout
, "\nCatchpoint ");
8935 if (ui_out_is_mi_like_p (uiout
))
8937 ui_out_field_string (uiout
, "reason",
8938 async_reason_lookup (EXEC_ASYNC_EXEC
));
8939 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8941 ui_out_field_int (uiout
, "bkptno", b
->number
);
8942 ui_out_text (uiout
, " (exec'd ");
8943 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8944 ui_out_text (uiout
, "), ");
8946 return PRINT_SRC_AND_LOC
;
8950 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8952 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8953 struct value_print_options opts
;
8954 struct ui_out
*uiout
= current_uiout
;
8956 get_user_print_options (&opts
);
8958 /* Field 4, the address, is omitted (which makes the columns
8959 not line up too nicely with the headers, but the effect
8960 is relatively readable). */
8961 if (opts
.addressprint
)
8962 ui_out_field_skip (uiout
, "addr");
8964 ui_out_text (uiout
, "exec");
8965 if (c
->exec_pathname
!= NULL
)
8967 ui_out_text (uiout
, ", program \"");
8968 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8969 ui_out_text (uiout
, "\" ");
8972 if (ui_out_is_mi_like_p (uiout
))
8973 ui_out_field_string (uiout
, "catch-type", "exec");
8977 print_mention_catch_exec (struct breakpoint
*b
)
8979 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8982 /* Implement the "print_recreate" breakpoint_ops method for exec
8986 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8988 fprintf_unfiltered (fp
, "catch exec");
8989 print_recreate_thread (b
, fp
);
8992 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8995 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8996 const struct breakpoint_ops
*ops
)
8998 struct syscall_catchpoint
*c
;
8999 struct gdbarch
*gdbarch
= get_current_arch ();
9001 c
= XNEW (struct syscall_catchpoint
);
9002 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
9003 c
->syscalls_to_be_caught
= filter
;
9005 install_breakpoint (0, &c
->base
, 1);
9009 hw_breakpoint_used_count (void)
9012 struct breakpoint
*b
;
9013 struct bp_location
*bl
;
9017 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
9018 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9020 /* Special types of hardware breakpoints may use more than
9022 i
+= b
->ops
->resources_needed (bl
);
9029 /* Returns the resources B would use if it were a hardware
9033 hw_watchpoint_use_count (struct breakpoint
*b
)
9036 struct bp_location
*bl
;
9038 if (!breakpoint_enabled (b
))
9041 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9043 /* Special types of hardware watchpoints may use more than
9045 i
+= b
->ops
->resources_needed (bl
);
9051 /* Returns the sum the used resources of all hardware watchpoints of
9052 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9053 the sum of the used resources of all hardware watchpoints of other
9054 types _not_ TYPE. */
9057 hw_watchpoint_used_count_others (struct breakpoint
*except
,
9058 enum bptype type
, int *other_type_used
)
9061 struct breakpoint
*b
;
9063 *other_type_used
= 0;
9068 if (!breakpoint_enabled (b
))
9071 if (b
->type
== type
)
9072 i
+= hw_watchpoint_use_count (b
);
9073 else if (is_hardware_watchpoint (b
))
9074 *other_type_used
= 1;
9081 disable_watchpoints_before_interactive_call_start (void)
9083 struct breakpoint
*b
;
9087 if (is_watchpoint (b
) && breakpoint_enabled (b
))
9089 b
->enable_state
= bp_call_disabled
;
9090 update_global_location_list (UGLL_DONT_INSERT
);
9096 enable_watchpoints_after_interactive_call_stop (void)
9098 struct breakpoint
*b
;
9102 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
9104 b
->enable_state
= bp_enabled
;
9105 update_global_location_list (UGLL_MAY_INSERT
);
9111 disable_breakpoints_before_startup (void)
9113 current_program_space
->executing_startup
= 1;
9114 update_global_location_list (UGLL_DONT_INSERT
);
9118 enable_breakpoints_after_startup (void)
9120 current_program_space
->executing_startup
= 0;
9121 breakpoint_re_set ();
9124 /* Create a new single-step breakpoint for thread THREAD, with no
9127 static struct breakpoint
*
9128 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
9130 struct breakpoint
*b
= XNEW (struct breakpoint
);
9132 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
9133 &momentary_breakpoint_ops
);
9135 b
->disposition
= disp_donttouch
;
9136 b
->frame_id
= null_frame_id
;
9139 gdb_assert (b
->thread
!= 0);
9141 add_to_breakpoint_chain (b
);
9146 /* Set a momentary breakpoint of type TYPE at address specified by
9147 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
9151 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9152 struct frame_id frame_id
, enum bptype type
)
9154 struct breakpoint
*b
;
9156 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9158 gdb_assert (!frame_id_artificial_p (frame_id
));
9160 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9161 b
->enable_state
= bp_enabled
;
9162 b
->disposition
= disp_donttouch
;
9163 b
->frame_id
= frame_id
;
9165 /* If we're debugging a multi-threaded program, then we want
9166 momentary breakpoints to be active in only a single thread of
9168 if (in_thread_list (inferior_ptid
))
9169 b
->thread
= pid_to_thread_id (inferior_ptid
);
9171 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
9176 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9177 The new breakpoint will have type TYPE, use OPS as its
9178 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9180 static struct breakpoint
*
9181 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9183 const struct breakpoint_ops
*ops
,
9186 struct breakpoint
*copy
;
9188 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9189 copy
->loc
= allocate_bp_location (copy
);
9190 set_breakpoint_location_function (copy
->loc
, 1);
9192 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9193 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9194 copy
->loc
->address
= orig
->loc
->address
;
9195 copy
->loc
->section
= orig
->loc
->section
;
9196 copy
->loc
->pspace
= orig
->loc
->pspace
;
9197 copy
->loc
->probe
= orig
->loc
->probe
;
9198 copy
->loc
->line_number
= orig
->loc
->line_number
;
9199 copy
->loc
->symtab
= orig
->loc
->symtab
;
9200 copy
->loc
->enabled
= loc_enabled
;
9201 copy
->frame_id
= orig
->frame_id
;
9202 copy
->thread
= orig
->thread
;
9203 copy
->pspace
= orig
->pspace
;
9205 copy
->enable_state
= bp_enabled
;
9206 copy
->disposition
= disp_donttouch
;
9207 copy
->number
= internal_breakpoint_number
--;
9209 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9213 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9217 clone_momentary_breakpoint (struct breakpoint
*orig
)
9219 /* If there's nothing to clone, then return nothing. */
9223 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9227 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9230 struct symtab_and_line sal
;
9232 sal
= find_pc_line (pc
, 0);
9234 sal
.section
= find_pc_overlay (pc
);
9235 sal
.explicit_pc
= 1;
9237 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9241 /* Tell the user we have just set a breakpoint B. */
9244 mention (struct breakpoint
*b
)
9246 b
->ops
->print_mention (b
);
9247 if (ui_out_is_mi_like_p (current_uiout
))
9249 printf_filtered ("\n");
9253 static int bp_loc_is_permanent (struct bp_location
*loc
);
9255 static struct bp_location
*
9256 add_location_to_breakpoint (struct breakpoint
*b
,
9257 const struct symtab_and_line
*sal
)
9259 struct bp_location
*loc
, **tmp
;
9260 CORE_ADDR adjusted_address
;
9261 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9263 if (loc_gdbarch
== NULL
)
9264 loc_gdbarch
= b
->gdbarch
;
9266 /* Adjust the breakpoint's address prior to allocating a location.
9267 Once we call allocate_bp_location(), that mostly uninitialized
9268 location will be placed on the location chain. Adjustment of the
9269 breakpoint may cause target_read_memory() to be called and we do
9270 not want its scan of the location chain to find a breakpoint and
9271 location that's only been partially initialized. */
9272 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9275 /* Sort the locations by their ADDRESS. */
9276 loc
= allocate_bp_location (b
);
9277 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9278 tmp
= &((*tmp
)->next
))
9283 loc
->requested_address
= sal
->pc
;
9284 loc
->address
= adjusted_address
;
9285 loc
->pspace
= sal
->pspace
;
9286 loc
->probe
.probe
= sal
->probe
;
9287 loc
->probe
.objfile
= sal
->objfile
;
9288 gdb_assert (loc
->pspace
!= NULL
);
9289 loc
->section
= sal
->section
;
9290 loc
->gdbarch
= loc_gdbarch
;
9291 loc
->line_number
= sal
->line
;
9292 loc
->symtab
= sal
->symtab
;
9294 set_breakpoint_location_function (loc
,
9295 sal
->explicit_pc
|| sal
->explicit_line
);
9297 if (bp_loc_is_permanent (loc
))
9307 /* Return 1 if LOC is pointing to a permanent breakpoint,
9308 return 0 otherwise. */
9311 bp_loc_is_permanent (struct bp_location
*loc
)
9315 const gdb_byte
*bpoint
;
9316 gdb_byte
*target_mem
;
9317 struct cleanup
*cleanup
;
9320 gdb_assert (loc
!= NULL
);
9322 /* bp_call_dummy breakpoint locations are usually memory locations
9323 where GDB just wrote a breakpoint instruction, making it look
9324 as if there is a permanent breakpoint at that location. Considering
9325 it permanent makes GDB rely on that breakpoint instruction to stop
9326 the program, thus removing the need to insert its own breakpoint
9327 there. This is normally expected to work, except that some versions
9328 of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap
9329 0x02 while interrupts disabled, Error state) instead of reporting
9330 a SIGTRAP. QEMU should probably be fixed, but in the interest of
9331 compatibility with versions that behave this way, we always consider
9332 bp_call_dummy breakpoint locations as non-permanent. */
9333 if (loc
->owner
->type
== bp_call_dummy
)
9336 addr
= loc
->address
;
9337 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9339 /* Software breakpoints unsupported? */
9343 target_mem
= alloca (len
);
9345 /* Enable the automatic memory restoration from breakpoints while
9346 we read the memory. Otherwise we could say about our temporary
9347 breakpoints they are permanent. */
9348 cleanup
= save_current_space_and_thread ();
9350 switch_to_program_space_and_thread (loc
->pspace
);
9351 make_show_memory_breakpoints_cleanup (0);
9353 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9354 && memcmp (target_mem
, bpoint
, len
) == 0)
9357 do_cleanups (cleanup
);
9362 /* Build a command list for the dprintf corresponding to the current
9363 settings of the dprintf style options. */
9366 update_dprintf_command_list (struct breakpoint
*b
)
9368 char *dprintf_args
= b
->extra_string
;
9369 char *printf_line
= NULL
;
9374 dprintf_args
= skip_spaces (dprintf_args
);
9376 /* Allow a comma, as it may have terminated a location, but don't
9378 if (*dprintf_args
== ',')
9380 dprintf_args
= skip_spaces (dprintf_args
);
9382 if (*dprintf_args
!= '"')
9383 error (_("Bad format string, missing '\"'."));
9385 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9386 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9387 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9389 if (!dprintf_function
)
9390 error (_("No function supplied for dprintf call"));
9392 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9393 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9398 printf_line
= xstrprintf ("call (void) %s (%s)",
9402 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9404 if (target_can_run_breakpoint_commands ())
9405 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9408 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9409 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9413 internal_error (__FILE__
, __LINE__
,
9414 _("Invalid dprintf style."));
9416 gdb_assert (printf_line
!= NULL
);
9417 /* Manufacture a printf sequence. */
9419 struct command_line
*printf_cmd_line
9420 = xmalloc (sizeof (struct command_line
));
9422 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9423 printf_cmd_line
->control_type
= simple_control
;
9424 printf_cmd_line
->body_count
= 0;
9425 printf_cmd_line
->body_list
= NULL
;
9426 printf_cmd_line
->next
= NULL
;
9427 printf_cmd_line
->line
= printf_line
;
9429 breakpoint_set_commands (b
, printf_cmd_line
);
9433 /* Update all dprintf commands, making their command lists reflect
9434 current style settings. */
9437 update_dprintf_commands (char *args
, int from_tty
,
9438 struct cmd_list_element
*c
)
9440 struct breakpoint
*b
;
9444 if (b
->type
== bp_dprintf
)
9445 update_dprintf_command_list (b
);
9449 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9450 as textual description of the location, and COND_STRING
9451 as condition expression. */
9454 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9455 struct symtabs_and_lines sals
, char *addr_string
,
9456 char *filter
, char *cond_string
,
9458 enum bptype type
, enum bpdisp disposition
,
9459 int thread
, int task
, int ignore_count
,
9460 const struct breakpoint_ops
*ops
, int from_tty
,
9461 int enabled
, int internal
, unsigned flags
,
9462 int display_canonical
)
9466 if (type
== bp_hardware_breakpoint
)
9468 int target_resources_ok
;
9470 i
= hw_breakpoint_used_count ();
9471 target_resources_ok
=
9472 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9474 if (target_resources_ok
== 0)
9475 error (_("No hardware breakpoint support in the target."));
9476 else if (target_resources_ok
< 0)
9477 error (_("Hardware breakpoints used exceeds limit."));
9480 gdb_assert (sals
.nelts
> 0);
9482 for (i
= 0; i
< sals
.nelts
; ++i
)
9484 struct symtab_and_line sal
= sals
.sals
[i
];
9485 struct bp_location
*loc
;
9489 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9491 loc_gdbarch
= gdbarch
;
9493 describe_other_breakpoints (loc_gdbarch
,
9494 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9499 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9503 b
->cond_string
= cond_string
;
9504 b
->extra_string
= extra_string
;
9505 b
->ignore_count
= ignore_count
;
9506 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9507 b
->disposition
= disposition
;
9509 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9510 b
->loc
->inserted
= 1;
9512 if (type
== bp_static_tracepoint
)
9514 struct tracepoint
*t
= (struct tracepoint
*) b
;
9515 struct static_tracepoint_marker marker
;
9517 if (strace_marker_p (b
))
9519 /* We already know the marker exists, otherwise, we
9520 wouldn't see a sal for it. */
9521 char *p
= &addr_string
[3];
9525 p
= skip_spaces (p
);
9527 endp
= skip_to_space (p
);
9529 marker_str
= savestring (p
, endp
- p
);
9530 t
->static_trace_marker_id
= marker_str
;
9532 printf_filtered (_("Probed static tracepoint "
9534 t
->static_trace_marker_id
);
9536 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9538 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9539 release_static_tracepoint_marker (&marker
);
9541 printf_filtered (_("Probed static tracepoint "
9543 t
->static_trace_marker_id
);
9546 warning (_("Couldn't determine the static "
9547 "tracepoint marker to probe"));
9554 loc
= add_location_to_breakpoint (b
, &sal
);
9555 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9561 const char *arg
= b
->cond_string
;
9563 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9564 block_for_pc (loc
->address
), 0);
9566 error (_("Garbage '%s' follows condition"), arg
);
9569 /* Dynamic printf requires and uses additional arguments on the
9570 command line, otherwise it's an error. */
9571 if (type
== bp_dprintf
)
9573 if (b
->extra_string
)
9574 update_dprintf_command_list (b
);
9576 error (_("Format string required"));
9578 else if (b
->extra_string
)
9579 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9582 b
->display_canonical
= display_canonical
;
9584 b
->addr_string
= addr_string
;
9586 /* addr_string has to be used or breakpoint_re_set will delete
9589 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9594 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9595 struct symtabs_and_lines sals
, char *addr_string
,
9596 char *filter
, char *cond_string
,
9598 enum bptype type
, enum bpdisp disposition
,
9599 int thread
, int task
, int ignore_count
,
9600 const struct breakpoint_ops
*ops
, int from_tty
,
9601 int enabled
, int internal
, unsigned flags
,
9602 int display_canonical
)
9604 struct breakpoint
*b
;
9605 struct cleanup
*old_chain
;
9607 if (is_tracepoint_type (type
))
9609 struct tracepoint
*t
;
9611 t
= XCNEW (struct tracepoint
);
9615 b
= XNEW (struct breakpoint
);
9617 old_chain
= make_cleanup (xfree
, b
);
9619 init_breakpoint_sal (b
, gdbarch
,
9621 filter
, cond_string
, extra_string
,
9623 thread
, task
, ignore_count
,
9625 enabled
, internal
, flags
,
9627 discard_cleanups (old_chain
);
9629 install_breakpoint (internal
, b
, 0);
9632 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9633 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9634 value. COND_STRING, if not NULL, specified the condition to be
9635 used for all breakpoints. Essentially the only case where
9636 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9637 function. In that case, it's still not possible to specify
9638 separate conditions for different overloaded functions, so
9639 we take just a single condition string.
9641 NOTE: If the function succeeds, the caller is expected to cleanup
9642 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9643 array contents). If the function fails (error() is called), the
9644 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9645 COND and SALS arrays and each of those arrays contents. */
9648 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9649 struct linespec_result
*canonical
,
9650 char *cond_string
, char *extra_string
,
9651 enum bptype type
, enum bpdisp disposition
,
9652 int thread
, int task
, int ignore_count
,
9653 const struct breakpoint_ops
*ops
, int from_tty
,
9654 int enabled
, int internal
, unsigned flags
)
9657 struct linespec_sals
*lsal
;
9659 if (canonical
->pre_expanded
)
9660 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9662 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9664 /* Note that 'addr_string' can be NULL in the case of a plain
9665 'break', without arguments. */
9666 char *addr_string
= (canonical
->addr_string
9667 ? xstrdup (canonical
->addr_string
)
9669 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9670 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9672 make_cleanup (xfree
, filter_string
);
9673 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9676 cond_string
, extra_string
,
9678 thread
, task
, ignore_count
, ops
,
9679 from_tty
, enabled
, internal
, flags
,
9680 canonical
->special_display
);
9681 discard_cleanups (inner
);
9685 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9686 followed by conditionals. On return, SALS contains an array of SAL
9687 addresses found. ADDR_STRING contains a vector of (canonical)
9688 address strings. ADDRESS points to the end of the SAL.
9690 The array and the line spec strings are allocated on the heap, it is
9691 the caller's responsibility to free them. */
9694 parse_breakpoint_sals (char **address
,
9695 struct linespec_result
*canonical
)
9697 /* If no arg given, or if first arg is 'if ', use the default
9699 if ((*address
) == NULL
9700 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9702 /* The last displayed codepoint, if it's valid, is our default breakpoint
9704 if (last_displayed_sal_is_valid ())
9706 struct linespec_sals lsal
;
9707 struct symtab_and_line sal
;
9710 init_sal (&sal
); /* Initialize to zeroes. */
9711 lsal
.sals
.sals
= (struct symtab_and_line
*)
9712 xmalloc (sizeof (struct symtab_and_line
));
9714 /* Set sal's pspace, pc, symtab, and line to the values
9715 corresponding to the last call to print_frame_info.
9716 Be sure to reinitialize LINE with NOTCURRENT == 0
9717 as the breakpoint line number is inappropriate otherwise.
9718 find_pc_line would adjust PC, re-set it back. */
9719 get_last_displayed_sal (&sal
);
9721 sal
= find_pc_line (pc
, 0);
9723 /* "break" without arguments is equivalent to "break *PC"
9724 where PC is the last displayed codepoint's address. So
9725 make sure to set sal.explicit_pc to prevent GDB from
9726 trying to expand the list of sals to include all other
9727 instances with the same symtab and line. */
9729 sal
.explicit_pc
= 1;
9731 lsal
.sals
.sals
[0] = sal
;
9732 lsal
.sals
.nelts
= 1;
9733 lsal
.canonical
= NULL
;
9735 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9738 error (_("No default breakpoint address now."));
9742 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9744 /* Force almost all breakpoints to be in terms of the
9745 current_source_symtab (which is decode_line_1's default).
9746 This should produce the results we want almost all of the
9747 time while leaving default_breakpoint_* alone.
9749 ObjC: However, don't match an Objective-C method name which
9750 may have a '+' or '-' succeeded by a '['. */
9751 if (last_displayed_sal_is_valid ()
9753 || ((strchr ("+-", (*address
)[0]) != NULL
)
9754 && ((*address
)[1] != '['))))
9755 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9756 get_last_displayed_symtab (),
9757 get_last_displayed_line (),
9758 canonical
, NULL
, NULL
);
9760 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9761 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9766 /* Convert each SAL into a real PC. Verify that the PC can be
9767 inserted as a breakpoint. If it can't throw an error. */
9770 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9774 for (i
= 0; i
< sals
->nelts
; i
++)
9775 resolve_sal_pc (&sals
->sals
[i
]);
9778 /* Fast tracepoints may have restrictions on valid locations. For
9779 instance, a fast tracepoint using a jump instead of a trap will
9780 likely have to overwrite more bytes than a trap would, and so can
9781 only be placed where the instruction is longer than the jump, or a
9782 multi-instruction sequence does not have a jump into the middle of
9786 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9787 struct symtabs_and_lines
*sals
)
9790 struct symtab_and_line
*sal
;
9792 struct cleanup
*old_chain
;
9794 for (i
= 0; i
< sals
->nelts
; i
++)
9796 struct gdbarch
*sarch
;
9798 sal
= &sals
->sals
[i
];
9800 sarch
= get_sal_arch (*sal
);
9801 /* We fall back to GDBARCH if there is no architecture
9802 associated with SAL. */
9805 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9807 old_chain
= make_cleanup (xfree
, msg
);
9810 error (_("May not have a fast tracepoint at 0x%s%s"),
9811 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9813 do_cleanups (old_chain
);
9817 /* Issue an invalid thread ID error. */
9819 static void ATTRIBUTE_NORETURN
9820 invalid_thread_id_error (int id
)
9822 error (_("Unknown thread %d."), id
);
9825 /* Given TOK, a string specification of condition and thread, as
9826 accepted by the 'break' command, extract the condition
9827 string and thread number and set *COND_STRING and *THREAD.
9828 PC identifies the context at which the condition should be parsed.
9829 If no condition is found, *COND_STRING is set to NULL.
9830 If no thread is found, *THREAD is set to -1. */
9833 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9834 char **cond_string
, int *thread
, int *task
,
9837 *cond_string
= NULL
;
9844 const char *end_tok
;
9846 const char *cond_start
= NULL
;
9847 const char *cond_end
= NULL
;
9849 tok
= skip_spaces_const (tok
);
9851 if ((*tok
== '"' || *tok
== ',') && rest
)
9853 *rest
= savestring (tok
, strlen (tok
));
9857 end_tok
= skip_to_space_const (tok
);
9859 toklen
= end_tok
- tok
;
9861 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9863 struct expression
*expr
;
9865 tok
= cond_start
= end_tok
+ 1;
9866 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9869 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9871 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9876 *thread
= strtol (tok
, &tmptok
, 0);
9878 error (_("Junk after thread keyword."));
9879 if (!valid_thread_id (*thread
))
9880 invalid_thread_id_error (*thread
);
9883 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9888 *task
= strtol (tok
, &tmptok
, 0);
9890 error (_("Junk after task keyword."));
9891 if (!valid_task_id (*task
))
9892 error (_("Unknown task %d."), *task
);
9897 *rest
= savestring (tok
, strlen (tok
));
9901 error (_("Junk at end of arguments."));
9905 /* Decode a static tracepoint marker spec. */
9907 static struct symtabs_and_lines
9908 decode_static_tracepoint_spec (char **arg_p
)
9910 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9911 struct symtabs_and_lines sals
;
9912 struct cleanup
*old_chain
;
9913 char *p
= &(*arg_p
)[3];
9918 p
= skip_spaces (p
);
9920 endp
= skip_to_space (p
);
9922 marker_str
= savestring (p
, endp
- p
);
9923 old_chain
= make_cleanup (xfree
, marker_str
);
9925 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9926 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9927 error (_("No known static tracepoint marker named %s"), marker_str
);
9929 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9930 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9932 for (i
= 0; i
< sals
.nelts
; i
++)
9934 struct static_tracepoint_marker
*marker
;
9936 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9938 init_sal (&sals
.sals
[i
]);
9940 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9941 sals
.sals
[i
].pc
= marker
->address
;
9943 release_static_tracepoint_marker (marker
);
9946 do_cleanups (old_chain
);
9952 /* Set a breakpoint. This function is shared between CLI and MI
9953 functions for setting a breakpoint. This function has two major
9954 modes of operations, selected by the PARSE_ARG parameter. If
9955 non-zero, the function will parse ARG, extracting location,
9956 condition, thread and extra string. Otherwise, ARG is just the
9957 breakpoint's location, with condition, thread, and extra string
9958 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9959 If INTERNAL is non-zero, the breakpoint number will be allocated
9960 from the internal breakpoint count. Returns true if any breakpoint
9961 was created; false otherwise. */
9964 create_breakpoint (struct gdbarch
*gdbarch
,
9965 char *arg
, char *cond_string
,
9966 int thread
, char *extra_string
,
9968 int tempflag
, enum bptype type_wanted
,
9970 enum auto_boolean pending_break_support
,
9971 const struct breakpoint_ops
*ops
,
9972 int from_tty
, int enabled
, int internal
,
9975 volatile struct gdb_exception e
;
9976 char *copy_arg
= NULL
;
9977 char *addr_start
= arg
;
9978 struct linespec_result canonical
;
9979 struct cleanup
*old_chain
;
9980 struct cleanup
*bkpt_chain
= NULL
;
9983 int prev_bkpt_count
= breakpoint_count
;
9985 gdb_assert (ops
!= NULL
);
9987 init_linespec_result (&canonical
);
9989 TRY_CATCH (e
, RETURN_MASK_ALL
)
9991 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9992 addr_start
, ©_arg
);
9995 /* If caller is interested in rc value from parse, set value. */
9999 if (VEC_empty (linespec_sals
, canonical
.sals
))
10005 case NOT_FOUND_ERROR
:
10007 /* If pending breakpoint support is turned off, throw
10010 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
10011 throw_exception (e
);
10013 exception_print (gdb_stderr
, e
);
10015 /* If pending breakpoint support is auto query and the user
10016 selects no, then simply return the error code. */
10017 if (pending_break_support
== AUTO_BOOLEAN_AUTO
10018 && !nquery (_("Make %s pending on future shared library load? "),
10019 bptype_string (type_wanted
)))
10022 /* At this point, either the user was queried about setting
10023 a pending breakpoint and selected yes, or pending
10024 breakpoint behavior is on and thus a pending breakpoint
10025 is defaulted on behalf of the user. */
10027 struct linespec_sals lsal
;
10029 copy_arg
= xstrdup (addr_start
);
10030 lsal
.canonical
= xstrdup (copy_arg
);
10031 lsal
.sals
.nelts
= 1;
10032 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
10033 init_sal (&lsal
.sals
.sals
[0]);
10035 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
10039 throw_exception (e
);
10043 throw_exception (e
);
10046 /* Create a chain of things that always need to be cleaned up. */
10047 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
10049 /* ----------------------------- SNIP -----------------------------
10050 Anything added to the cleanup chain beyond this point is assumed
10051 to be part of a breakpoint. If the breakpoint create succeeds
10052 then the memory is not reclaimed. */
10053 bkpt_chain
= make_cleanup (null_cleanup
, 0);
10055 /* Resolve all line numbers to PC's and verify that the addresses
10056 are ok for the target. */
10060 struct linespec_sals
*iter
;
10062 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10063 breakpoint_sals_to_pc (&iter
->sals
);
10066 /* Fast tracepoints may have additional restrictions on location. */
10067 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
10070 struct linespec_sals
*iter
;
10072 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10073 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
10076 /* Verify that condition can be parsed, before setting any
10077 breakpoints. Allocate a separate condition expression for each
10084 struct linespec_sals
*lsal
;
10086 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
10088 /* Here we only parse 'arg' to separate condition
10089 from thread number, so parsing in context of first
10090 sal is OK. When setting the breakpoint we'll
10091 re-parse it in context of each sal. */
10093 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
10094 &thread
, &task
, &rest
);
10096 make_cleanup (xfree
, cond_string
);
10098 make_cleanup (xfree
, rest
);
10100 extra_string
= rest
;
10105 error (_("Garbage '%s' at end of location"), arg
);
10107 /* Create a private copy of condition string. */
10110 cond_string
= xstrdup (cond_string
);
10111 make_cleanup (xfree
, cond_string
);
10113 /* Create a private copy of any extra string. */
10116 extra_string
= xstrdup (extra_string
);
10117 make_cleanup (xfree
, extra_string
);
10121 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
10122 cond_string
, extra_string
, type_wanted
,
10123 tempflag
? disp_del
: disp_donttouch
,
10124 thread
, task
, ignore_count
, ops
,
10125 from_tty
, enabled
, internal
, flags
);
10129 struct breakpoint
*b
;
10131 make_cleanup (xfree
, copy_arg
);
10133 if (is_tracepoint_type (type_wanted
))
10135 struct tracepoint
*t
;
10137 t
= XCNEW (struct tracepoint
);
10141 b
= XNEW (struct breakpoint
);
10143 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
10145 b
->addr_string
= copy_arg
;
10147 b
->cond_string
= NULL
;
10150 /* Create a private copy of condition string. */
10153 cond_string
= xstrdup (cond_string
);
10154 make_cleanup (xfree
, cond_string
);
10156 b
->cond_string
= cond_string
;
10158 b
->extra_string
= NULL
;
10159 b
->ignore_count
= ignore_count
;
10160 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10161 b
->condition_not_parsed
= 1;
10162 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10163 if ((type_wanted
!= bp_breakpoint
10164 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
10165 b
->pspace
= current_program_space
;
10167 install_breakpoint (internal
, b
, 0);
10170 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
10172 warning (_("Multiple breakpoints were set.\nUse the "
10173 "\"delete\" command to delete unwanted breakpoints."));
10174 prev_breakpoint_count
= prev_bkpt_count
;
10177 /* That's it. Discard the cleanups for data inserted into the
10179 discard_cleanups (bkpt_chain
);
10180 /* But cleanup everything else. */
10181 do_cleanups (old_chain
);
10183 /* error call may happen here - have BKPT_CHAIN already discarded. */
10184 update_global_location_list (UGLL_MAY_INSERT
);
10189 /* Set a breakpoint.
10190 ARG is a string describing breakpoint address,
10191 condition, and thread.
10192 FLAG specifies if a breakpoint is hardware on,
10193 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10194 and BP_TEMPFLAG. */
10197 break_command_1 (char *arg
, int flag
, int from_tty
)
10199 int tempflag
= flag
& BP_TEMPFLAG
;
10200 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10201 ? bp_hardware_breakpoint
10203 struct breakpoint_ops
*ops
;
10204 const char *arg_cp
= arg
;
10206 /* Matching breakpoints on probes. */
10207 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10208 ops
= &bkpt_probe_breakpoint_ops
;
10210 ops
= &bkpt_breakpoint_ops
;
10212 create_breakpoint (get_current_arch (),
10214 NULL
, 0, NULL
, 1 /* parse arg */,
10215 tempflag
, type_wanted
,
10216 0 /* Ignore count */,
10217 pending_break_support
,
10225 /* Helper function for break_command_1 and disassemble_command. */
10228 resolve_sal_pc (struct symtab_and_line
*sal
)
10232 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10234 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10235 error (_("No line %d in file \"%s\"."),
10236 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10239 /* If this SAL corresponds to a breakpoint inserted using a line
10240 number, then skip the function prologue if necessary. */
10241 if (sal
->explicit_line
)
10242 skip_prologue_sal (sal
);
10245 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10247 const struct blockvector
*bv
;
10248 const struct block
*b
;
10249 struct symbol
*sym
;
10251 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10252 SYMTAB_COMPUNIT (sal
->symtab
));
10255 sym
= block_linkage_function (b
);
10258 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10259 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10264 /* It really is worthwhile to have the section, so we'll
10265 just have to look harder. This case can be executed
10266 if we have line numbers but no functions (as can
10267 happen in assembly source). */
10269 struct bound_minimal_symbol msym
;
10270 struct cleanup
*old_chain
= save_current_space_and_thread ();
10272 switch_to_program_space_and_thread (sal
->pspace
);
10274 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10276 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10278 do_cleanups (old_chain
);
10285 break_command (char *arg
, int from_tty
)
10287 break_command_1 (arg
, 0, from_tty
);
10291 tbreak_command (char *arg
, int from_tty
)
10293 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10297 hbreak_command (char *arg
, int from_tty
)
10299 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10303 thbreak_command (char *arg
, int from_tty
)
10305 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10309 stop_command (char *arg
, int from_tty
)
10311 printf_filtered (_("Specify the type of breakpoint to set.\n\
10312 Usage: stop in <function | address>\n\
10313 stop at <line>\n"));
10317 stopin_command (char *arg
, int from_tty
)
10321 if (arg
== (char *) NULL
)
10323 else if (*arg
!= '*')
10325 char *argptr
= arg
;
10328 /* Look for a ':'. If this is a line number specification, then
10329 say it is bad, otherwise, it should be an address or
10330 function/method name. */
10331 while (*argptr
&& !hasColon
)
10333 hasColon
= (*argptr
== ':');
10338 badInput
= (*argptr
!= ':'); /* Not a class::method */
10340 badInput
= isdigit (*arg
); /* a simple line number */
10344 printf_filtered (_("Usage: stop in <function | address>\n"));
10346 break_command_1 (arg
, 0, from_tty
);
10350 stopat_command (char *arg
, int from_tty
)
10354 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10358 char *argptr
= arg
;
10361 /* Look for a ':'. If there is a '::' then get out, otherwise
10362 it is probably a line number. */
10363 while (*argptr
&& !hasColon
)
10365 hasColon
= (*argptr
== ':');
10370 badInput
= (*argptr
== ':'); /* we have class::method */
10372 badInput
= !isdigit (*arg
); /* not a line number */
10376 printf_filtered (_("Usage: stop at <line>\n"));
10378 break_command_1 (arg
, 0, from_tty
);
10381 /* The dynamic printf command is mostly like a regular breakpoint, but
10382 with a prewired command list consisting of a single output command,
10383 built from extra arguments supplied on the dprintf command
10387 dprintf_command (char *arg
, int from_tty
)
10389 create_breakpoint (get_current_arch (),
10391 NULL
, 0, NULL
, 1 /* parse arg */,
10393 0 /* Ignore count */,
10394 pending_break_support
,
10395 &dprintf_breakpoint_ops
,
10403 agent_printf_command (char *arg
, int from_tty
)
10405 error (_("May only run agent-printf on the target"));
10408 /* Implement the "breakpoint_hit" breakpoint_ops method for
10409 ranged breakpoints. */
10412 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10413 struct address_space
*aspace
,
10415 const struct target_waitstatus
*ws
)
10417 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10418 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10421 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10422 bl
->length
, aspace
, bp_addr
);
10425 /* Implement the "resources_needed" breakpoint_ops method for
10426 ranged breakpoints. */
10429 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10431 return target_ranged_break_num_registers ();
10434 /* Implement the "print_it" breakpoint_ops method for
10435 ranged breakpoints. */
10437 static enum print_stop_action
10438 print_it_ranged_breakpoint (bpstat bs
)
10440 struct breakpoint
*b
= bs
->breakpoint_at
;
10441 struct bp_location
*bl
= b
->loc
;
10442 struct ui_out
*uiout
= current_uiout
;
10444 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10446 /* Ranged breakpoints have only one location. */
10447 gdb_assert (bl
&& bl
->next
== NULL
);
10449 annotate_breakpoint (b
->number
);
10450 if (b
->disposition
== disp_del
)
10451 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10453 ui_out_text (uiout
, "\nRanged breakpoint ");
10454 if (ui_out_is_mi_like_p (uiout
))
10456 ui_out_field_string (uiout
, "reason",
10457 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10458 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10460 ui_out_field_int (uiout
, "bkptno", b
->number
);
10461 ui_out_text (uiout
, ", ");
10463 return PRINT_SRC_AND_LOC
;
10466 /* Implement the "print_one" breakpoint_ops method for
10467 ranged breakpoints. */
10470 print_one_ranged_breakpoint (struct breakpoint
*b
,
10471 struct bp_location
**last_loc
)
10473 struct bp_location
*bl
= b
->loc
;
10474 struct value_print_options opts
;
10475 struct ui_out
*uiout
= current_uiout
;
10477 /* Ranged breakpoints have only one location. */
10478 gdb_assert (bl
&& bl
->next
== NULL
);
10480 get_user_print_options (&opts
);
10482 if (opts
.addressprint
)
10483 /* We don't print the address range here, it will be printed later
10484 by print_one_detail_ranged_breakpoint. */
10485 ui_out_field_skip (uiout
, "addr");
10486 annotate_field (5);
10487 print_breakpoint_location (b
, bl
);
10491 /* Implement the "print_one_detail" breakpoint_ops method for
10492 ranged breakpoints. */
10495 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10496 struct ui_out
*uiout
)
10498 CORE_ADDR address_start
, address_end
;
10499 struct bp_location
*bl
= b
->loc
;
10500 struct ui_file
*stb
= mem_fileopen ();
10501 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10505 address_start
= bl
->address
;
10506 address_end
= address_start
+ bl
->length
- 1;
10508 ui_out_text (uiout
, "\taddress range: ");
10509 fprintf_unfiltered (stb
, "[%s, %s]",
10510 print_core_address (bl
->gdbarch
, address_start
),
10511 print_core_address (bl
->gdbarch
, address_end
));
10512 ui_out_field_stream (uiout
, "addr", stb
);
10513 ui_out_text (uiout
, "\n");
10515 do_cleanups (cleanup
);
10518 /* Implement the "print_mention" breakpoint_ops method for
10519 ranged breakpoints. */
10522 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10524 struct bp_location
*bl
= b
->loc
;
10525 struct ui_out
*uiout
= current_uiout
;
10528 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10530 if (ui_out_is_mi_like_p (uiout
))
10533 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10534 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10535 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10538 /* Implement the "print_recreate" breakpoint_ops method for
10539 ranged breakpoints. */
10542 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10544 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10545 b
->addr_string_range_end
);
10546 print_recreate_thread (b
, fp
);
10549 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10551 static struct breakpoint_ops ranged_breakpoint_ops
;
10553 /* Find the address where the end of the breakpoint range should be
10554 placed, given the SAL of the end of the range. This is so that if
10555 the user provides a line number, the end of the range is set to the
10556 last instruction of the given line. */
10559 find_breakpoint_range_end (struct symtab_and_line sal
)
10563 /* If the user provided a PC value, use it. Otherwise,
10564 find the address of the end of the given location. */
10565 if (sal
.explicit_pc
)
10572 ret
= find_line_pc_range (sal
, &start
, &end
);
10574 error (_("Could not find location of the end of the range."));
10576 /* find_line_pc_range returns the start of the next line. */
10583 /* Implement the "break-range" CLI command. */
10586 break_range_command (char *arg
, int from_tty
)
10588 char *arg_start
, *addr_string_start
, *addr_string_end
;
10589 struct linespec_result canonical_start
, canonical_end
;
10590 int bp_count
, can_use_bp
, length
;
10592 struct breakpoint
*b
;
10593 struct symtab_and_line sal_start
, sal_end
;
10594 struct cleanup
*cleanup_bkpt
;
10595 struct linespec_sals
*lsal_start
, *lsal_end
;
10597 /* We don't support software ranged breakpoints. */
10598 if (target_ranged_break_num_registers () < 0)
10599 error (_("This target does not support hardware ranged breakpoints."));
10601 bp_count
= hw_breakpoint_used_count ();
10602 bp_count
+= target_ranged_break_num_registers ();
10603 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10605 if (can_use_bp
< 0)
10606 error (_("Hardware breakpoints used exceeds limit."));
10608 arg
= skip_spaces (arg
);
10609 if (arg
== NULL
|| arg
[0] == '\0')
10610 error(_("No address range specified."));
10612 init_linespec_result (&canonical_start
);
10615 parse_breakpoint_sals (&arg
, &canonical_start
);
10617 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10620 error (_("Too few arguments."));
10621 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10622 error (_("Could not find location of the beginning of the range."));
10624 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10626 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10627 || lsal_start
->sals
.nelts
!= 1)
10628 error (_("Cannot create a ranged breakpoint with multiple locations."));
10630 sal_start
= lsal_start
->sals
.sals
[0];
10631 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10632 make_cleanup (xfree
, addr_string_start
);
10634 arg
++; /* Skip the comma. */
10635 arg
= skip_spaces (arg
);
10637 /* Parse the end location. */
10639 init_linespec_result (&canonical_end
);
10642 /* We call decode_line_full directly here instead of using
10643 parse_breakpoint_sals because we need to specify the start location's
10644 symtab and line as the default symtab and line for the end of the
10645 range. This makes it possible to have ranges like "foo.c:27, +14",
10646 where +14 means 14 lines from the start location. */
10647 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10648 sal_start
.symtab
, sal_start
.line
,
10649 &canonical_end
, NULL
, NULL
);
10651 make_cleanup_destroy_linespec_result (&canonical_end
);
10653 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10654 error (_("Could not find location of the end of the range."));
10656 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10657 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10658 || lsal_end
->sals
.nelts
!= 1)
10659 error (_("Cannot create a ranged breakpoint with multiple locations."));
10661 sal_end
= lsal_end
->sals
.sals
[0];
10662 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10663 make_cleanup (xfree
, addr_string_end
);
10665 end
= find_breakpoint_range_end (sal_end
);
10666 if (sal_start
.pc
> end
)
10667 error (_("Invalid address range, end precedes start."));
10669 length
= end
- sal_start
.pc
+ 1;
10671 /* Length overflowed. */
10672 error (_("Address range too large."));
10673 else if (length
== 1)
10675 /* This range is simple enough to be handled by
10676 the `hbreak' command. */
10677 hbreak_command (addr_string_start
, 1);
10679 do_cleanups (cleanup_bkpt
);
10684 /* Now set up the breakpoint. */
10685 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10686 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10687 set_breakpoint_count (breakpoint_count
+ 1);
10688 b
->number
= breakpoint_count
;
10689 b
->disposition
= disp_donttouch
;
10690 b
->addr_string
= xstrdup (addr_string_start
);
10691 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10692 b
->loc
->length
= length
;
10694 do_cleanups (cleanup_bkpt
);
10697 observer_notify_breakpoint_created (b
);
10698 update_global_location_list (UGLL_MAY_INSERT
);
10701 /* Return non-zero if EXP is verified as constant. Returned zero
10702 means EXP is variable. Also the constant detection may fail for
10703 some constant expressions and in such case still falsely return
10707 watchpoint_exp_is_const (const struct expression
*exp
)
10709 int i
= exp
->nelts
;
10715 /* We are only interested in the descriptor of each element. */
10716 operator_length (exp
, i
, &oplenp
, &argsp
);
10719 switch (exp
->elts
[i
].opcode
)
10729 case BINOP_LOGICAL_AND
:
10730 case BINOP_LOGICAL_OR
:
10731 case BINOP_BITWISE_AND
:
10732 case BINOP_BITWISE_IOR
:
10733 case BINOP_BITWISE_XOR
:
10735 case BINOP_NOTEQUAL
:
10762 case OP_OBJC_NSSTRING
:
10765 case UNOP_LOGICAL_NOT
:
10766 case UNOP_COMPLEMENT
:
10771 case UNOP_CAST_TYPE
:
10772 case UNOP_REINTERPRET_CAST
:
10773 case UNOP_DYNAMIC_CAST
:
10774 /* Unary, binary and ternary operators: We have to check
10775 their operands. If they are constant, then so is the
10776 result of that operation. For instance, if A and B are
10777 determined to be constants, then so is "A + B".
10779 UNOP_IND is one exception to the rule above, because the
10780 value of *ADDR is not necessarily a constant, even when
10785 /* Check whether the associated symbol is a constant.
10787 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10788 possible that a buggy compiler could mark a variable as
10789 constant even when it is not, and TYPE_CONST would return
10790 true in this case, while SYMBOL_CLASS wouldn't.
10792 We also have to check for function symbols because they
10793 are always constant. */
10795 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10797 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10798 && SYMBOL_CLASS (s
) != LOC_CONST
10799 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10804 /* The default action is to return 0 because we are using
10805 the optimistic approach here: If we don't know something,
10806 then it is not a constant. */
10815 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10818 dtor_watchpoint (struct breakpoint
*self
)
10820 struct watchpoint
*w
= (struct watchpoint
*) self
;
10822 xfree (w
->cond_exp
);
10824 xfree (w
->exp_string
);
10825 xfree (w
->exp_string_reparse
);
10826 value_free (w
->val
);
10828 base_breakpoint_ops
.dtor (self
);
10831 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10834 re_set_watchpoint (struct breakpoint
*b
)
10836 struct watchpoint
*w
= (struct watchpoint
*) b
;
10838 /* Watchpoint can be either on expression using entirely global
10839 variables, or it can be on local variables.
10841 Watchpoints of the first kind are never auto-deleted, and even
10842 persist across program restarts. Since they can use variables
10843 from shared libraries, we need to reparse expression as libraries
10844 are loaded and unloaded.
10846 Watchpoints on local variables can also change meaning as result
10847 of solib event. For example, if a watchpoint uses both a local
10848 and a global variables in expression, it's a local watchpoint,
10849 but unloading of a shared library will make the expression
10850 invalid. This is not a very common use case, but we still
10851 re-evaluate expression, to avoid surprises to the user.
10853 Note that for local watchpoints, we re-evaluate it only if
10854 watchpoints frame id is still valid. If it's not, it means the
10855 watchpoint is out of scope and will be deleted soon. In fact,
10856 I'm not sure we'll ever be called in this case.
10858 If a local watchpoint's frame id is still valid, then
10859 w->exp_valid_block is likewise valid, and we can safely use it.
10861 Don't do anything about disabled watchpoints, since they will be
10862 reevaluated again when enabled. */
10863 update_watchpoint (w
, 1 /* reparse */);
10866 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10869 insert_watchpoint (struct bp_location
*bl
)
10871 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10872 int length
= w
->exact
? 1 : bl
->length
;
10874 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10878 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10881 remove_watchpoint (struct bp_location
*bl
)
10883 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10884 int length
= w
->exact
? 1 : bl
->length
;
10886 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10891 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10892 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10893 const struct target_waitstatus
*ws
)
10895 struct breakpoint
*b
= bl
->owner
;
10896 struct watchpoint
*w
= (struct watchpoint
*) b
;
10898 /* Continuable hardware watchpoints are treated as non-existent if the
10899 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10900 some data address). Otherwise gdb won't stop on a break instruction
10901 in the code (not from a breakpoint) when a hardware watchpoint has
10902 been defined. Also skip watchpoints which we know did not trigger
10903 (did not match the data address). */
10904 if (is_hardware_watchpoint (b
)
10905 && w
->watchpoint_triggered
== watch_triggered_no
)
10912 check_status_watchpoint (bpstat bs
)
10914 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10916 bpstat_check_watchpoint (bs
);
10919 /* Implement the "resources_needed" breakpoint_ops method for
10920 hardware watchpoints. */
10923 resources_needed_watchpoint (const struct bp_location
*bl
)
10925 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10926 int length
= w
->exact
? 1 : bl
->length
;
10928 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10931 /* Implement the "works_in_software_mode" breakpoint_ops method for
10932 hardware watchpoints. */
10935 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10937 /* Read and access watchpoints only work with hardware support. */
10938 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10941 static enum print_stop_action
10942 print_it_watchpoint (bpstat bs
)
10944 struct cleanup
*old_chain
;
10945 struct breakpoint
*b
;
10946 struct ui_file
*stb
;
10947 enum print_stop_action result
;
10948 struct watchpoint
*w
;
10949 struct ui_out
*uiout
= current_uiout
;
10951 gdb_assert (bs
->bp_location_at
!= NULL
);
10953 b
= bs
->breakpoint_at
;
10954 w
= (struct watchpoint
*) b
;
10956 stb
= mem_fileopen ();
10957 old_chain
= make_cleanup_ui_file_delete (stb
);
10961 case bp_watchpoint
:
10962 case bp_hardware_watchpoint
:
10963 annotate_watchpoint (b
->number
);
10964 if (ui_out_is_mi_like_p (uiout
))
10965 ui_out_field_string
10967 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10969 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10970 ui_out_text (uiout
, "\nOld value = ");
10971 watchpoint_value_print (bs
->old_val
, stb
);
10972 ui_out_field_stream (uiout
, "old", stb
);
10973 ui_out_text (uiout
, "\nNew value = ");
10974 watchpoint_value_print (w
->val
, stb
);
10975 ui_out_field_stream (uiout
, "new", stb
);
10976 ui_out_text (uiout
, "\n");
10977 /* More than one watchpoint may have been triggered. */
10978 result
= PRINT_UNKNOWN
;
10981 case bp_read_watchpoint
:
10982 if (ui_out_is_mi_like_p (uiout
))
10983 ui_out_field_string
10985 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10987 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10988 ui_out_text (uiout
, "\nValue = ");
10989 watchpoint_value_print (w
->val
, stb
);
10990 ui_out_field_stream (uiout
, "value", stb
);
10991 ui_out_text (uiout
, "\n");
10992 result
= PRINT_UNKNOWN
;
10995 case bp_access_watchpoint
:
10996 if (bs
->old_val
!= NULL
)
10998 annotate_watchpoint (b
->number
);
10999 if (ui_out_is_mi_like_p (uiout
))
11000 ui_out_field_string
11002 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11004 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11005 ui_out_text (uiout
, "\nOld value = ");
11006 watchpoint_value_print (bs
->old_val
, stb
);
11007 ui_out_field_stream (uiout
, "old", stb
);
11008 ui_out_text (uiout
, "\nNew value = ");
11013 if (ui_out_is_mi_like_p (uiout
))
11014 ui_out_field_string
11016 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11017 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11018 ui_out_text (uiout
, "\nValue = ");
11020 watchpoint_value_print (w
->val
, stb
);
11021 ui_out_field_stream (uiout
, "new", stb
);
11022 ui_out_text (uiout
, "\n");
11023 result
= PRINT_UNKNOWN
;
11026 result
= PRINT_UNKNOWN
;
11029 do_cleanups (old_chain
);
11033 /* Implement the "print_mention" breakpoint_ops method for hardware
11037 print_mention_watchpoint (struct breakpoint
*b
)
11039 struct cleanup
*ui_out_chain
;
11040 struct watchpoint
*w
= (struct watchpoint
*) b
;
11041 struct ui_out
*uiout
= current_uiout
;
11045 case bp_watchpoint
:
11046 ui_out_text (uiout
, "Watchpoint ");
11047 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11049 case bp_hardware_watchpoint
:
11050 ui_out_text (uiout
, "Hardware watchpoint ");
11051 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11053 case bp_read_watchpoint
:
11054 ui_out_text (uiout
, "Hardware read watchpoint ");
11055 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11057 case bp_access_watchpoint
:
11058 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
11059 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11062 internal_error (__FILE__
, __LINE__
,
11063 _("Invalid hardware watchpoint type."));
11066 ui_out_field_int (uiout
, "number", b
->number
);
11067 ui_out_text (uiout
, ": ");
11068 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11069 do_cleanups (ui_out_chain
);
11072 /* Implement the "print_recreate" breakpoint_ops method for
11076 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11078 struct watchpoint
*w
= (struct watchpoint
*) b
;
11082 case bp_watchpoint
:
11083 case bp_hardware_watchpoint
:
11084 fprintf_unfiltered (fp
, "watch");
11086 case bp_read_watchpoint
:
11087 fprintf_unfiltered (fp
, "rwatch");
11089 case bp_access_watchpoint
:
11090 fprintf_unfiltered (fp
, "awatch");
11093 internal_error (__FILE__
, __LINE__
,
11094 _("Invalid watchpoint type."));
11097 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
11098 print_recreate_thread (b
, fp
);
11101 /* Implement the "explains_signal" breakpoint_ops method for
11105 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
11107 /* A software watchpoint cannot cause a signal other than
11108 GDB_SIGNAL_TRAP. */
11109 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
11115 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11117 static struct breakpoint_ops watchpoint_breakpoint_ops
;
11119 /* Implement the "insert" breakpoint_ops method for
11120 masked hardware watchpoints. */
11123 insert_masked_watchpoint (struct bp_location
*bl
)
11125 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11127 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11128 bl
->watchpoint_type
);
11131 /* Implement the "remove" breakpoint_ops method for
11132 masked hardware watchpoints. */
11135 remove_masked_watchpoint (struct bp_location
*bl
)
11137 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11139 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11140 bl
->watchpoint_type
);
11143 /* Implement the "resources_needed" breakpoint_ops method for
11144 masked hardware watchpoints. */
11147 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11149 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11151 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11154 /* Implement the "works_in_software_mode" breakpoint_ops method for
11155 masked hardware watchpoints. */
11158 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11163 /* Implement the "print_it" breakpoint_ops method for
11164 masked hardware watchpoints. */
11166 static enum print_stop_action
11167 print_it_masked_watchpoint (bpstat bs
)
11169 struct breakpoint
*b
= bs
->breakpoint_at
;
11170 struct ui_out
*uiout
= current_uiout
;
11172 /* Masked watchpoints have only one location. */
11173 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11177 case bp_hardware_watchpoint
:
11178 annotate_watchpoint (b
->number
);
11179 if (ui_out_is_mi_like_p (uiout
))
11180 ui_out_field_string
11182 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11185 case bp_read_watchpoint
:
11186 if (ui_out_is_mi_like_p (uiout
))
11187 ui_out_field_string
11189 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11192 case bp_access_watchpoint
:
11193 if (ui_out_is_mi_like_p (uiout
))
11194 ui_out_field_string
11196 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11199 internal_error (__FILE__
, __LINE__
,
11200 _("Invalid hardware watchpoint type."));
11204 ui_out_text (uiout
, _("\n\
11205 Check the underlying instruction at PC for the memory\n\
11206 address and value which triggered this watchpoint.\n"));
11207 ui_out_text (uiout
, "\n");
11209 /* More than one watchpoint may have been triggered. */
11210 return PRINT_UNKNOWN
;
11213 /* Implement the "print_one_detail" breakpoint_ops method for
11214 masked hardware watchpoints. */
11217 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11218 struct ui_out
*uiout
)
11220 struct watchpoint
*w
= (struct watchpoint
*) b
;
11222 /* Masked watchpoints have only one location. */
11223 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11225 ui_out_text (uiout
, "\tmask ");
11226 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11227 ui_out_text (uiout
, "\n");
11230 /* Implement the "print_mention" breakpoint_ops method for
11231 masked hardware watchpoints. */
11234 print_mention_masked_watchpoint (struct breakpoint
*b
)
11236 struct watchpoint
*w
= (struct watchpoint
*) b
;
11237 struct ui_out
*uiout
= current_uiout
;
11238 struct cleanup
*ui_out_chain
;
11242 case bp_hardware_watchpoint
:
11243 ui_out_text (uiout
, "Masked hardware watchpoint ");
11244 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11246 case bp_read_watchpoint
:
11247 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11248 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11250 case bp_access_watchpoint
:
11251 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11252 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11255 internal_error (__FILE__
, __LINE__
,
11256 _("Invalid hardware watchpoint type."));
11259 ui_out_field_int (uiout
, "number", b
->number
);
11260 ui_out_text (uiout
, ": ");
11261 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11262 do_cleanups (ui_out_chain
);
11265 /* Implement the "print_recreate" breakpoint_ops method for
11266 masked hardware watchpoints. */
11269 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11271 struct watchpoint
*w
= (struct watchpoint
*) b
;
11276 case bp_hardware_watchpoint
:
11277 fprintf_unfiltered (fp
, "watch");
11279 case bp_read_watchpoint
:
11280 fprintf_unfiltered (fp
, "rwatch");
11282 case bp_access_watchpoint
:
11283 fprintf_unfiltered (fp
, "awatch");
11286 internal_error (__FILE__
, __LINE__
,
11287 _("Invalid hardware watchpoint type."));
11290 sprintf_vma (tmp
, w
->hw_wp_mask
);
11291 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11292 print_recreate_thread (b
, fp
);
11295 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11297 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11299 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11302 is_masked_watchpoint (const struct breakpoint
*b
)
11304 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11307 /* accessflag: hw_write: watch write,
11308 hw_read: watch read,
11309 hw_access: watch access (read or write) */
11311 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11312 int just_location
, int internal
)
11314 volatile struct gdb_exception e
;
11315 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11316 struct expression
*exp
;
11317 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11318 struct value
*val
, *mark
, *result
;
11319 int saved_bitpos
= 0, saved_bitsize
= 0;
11320 struct frame_info
*frame
;
11321 const char *exp_start
= NULL
;
11322 const char *exp_end
= NULL
;
11323 const char *tok
, *end_tok
;
11325 const char *cond_start
= NULL
;
11326 const char *cond_end
= NULL
;
11327 enum bptype bp_type
;
11330 /* Flag to indicate whether we are going to use masks for
11331 the hardware watchpoint. */
11333 CORE_ADDR mask
= 0;
11334 struct watchpoint
*w
;
11336 struct cleanup
*back_to
;
11338 /* Make sure that we actually have parameters to parse. */
11339 if (arg
!= NULL
&& arg
[0] != '\0')
11341 const char *value_start
;
11343 exp_end
= arg
+ strlen (arg
);
11345 /* Look for "parameter value" pairs at the end
11346 of the arguments string. */
11347 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11349 /* Skip whitespace at the end of the argument list. */
11350 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11353 /* Find the beginning of the last token.
11354 This is the value of the parameter. */
11355 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11357 value_start
= tok
+ 1;
11359 /* Skip whitespace. */
11360 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11365 /* Find the beginning of the second to last token.
11366 This is the parameter itself. */
11367 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11370 toklen
= end_tok
- tok
+ 1;
11372 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11374 /* At this point we've found a "thread" token, which means
11375 the user is trying to set a watchpoint that triggers
11376 only in a specific thread. */
11380 error(_("You can specify only one thread."));
11382 /* Extract the thread ID from the next token. */
11383 thread
= strtol (value_start
, &endp
, 0);
11385 /* Check if the user provided a valid numeric value for the
11387 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11388 error (_("Invalid thread ID specification %s."), value_start
);
11390 /* Check if the thread actually exists. */
11391 if (!valid_thread_id (thread
))
11392 invalid_thread_id_error (thread
);
11394 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11396 /* We've found a "mask" token, which means the user wants to
11397 create a hardware watchpoint that is going to have the mask
11399 struct value
*mask_value
, *mark
;
11402 error(_("You can specify only one mask."));
11404 use_mask
= just_location
= 1;
11406 mark
= value_mark ();
11407 mask_value
= parse_to_comma_and_eval (&value_start
);
11408 mask
= value_as_address (mask_value
);
11409 value_free_to_mark (mark
);
11412 /* We didn't recognize what we found. We should stop here. */
11415 /* Truncate the string and get rid of the "parameter value" pair before
11416 the arguments string is parsed by the parse_exp_1 function. */
11423 /* Parse the rest of the arguments. From here on out, everything
11424 is in terms of a newly allocated string instead of the original
11426 innermost_block
= NULL
;
11427 expression
= savestring (arg
, exp_end
- arg
);
11428 back_to
= make_cleanup (xfree
, expression
);
11429 exp_start
= arg
= expression
;
11430 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11432 /* Remove trailing whitespace from the expression before saving it.
11433 This makes the eventual display of the expression string a bit
11435 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11438 /* Checking if the expression is not constant. */
11439 if (watchpoint_exp_is_const (exp
))
11443 len
= exp_end
- exp_start
;
11444 while (len
> 0 && isspace (exp_start
[len
- 1]))
11446 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11449 exp_valid_block
= innermost_block
;
11450 mark
= value_mark ();
11451 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11453 if (val
!= NULL
&& just_location
)
11455 saved_bitpos
= value_bitpos (val
);
11456 saved_bitsize
= value_bitsize (val
);
11463 exp_valid_block
= NULL
;
11464 val
= value_addr (result
);
11465 release_value (val
);
11466 value_free_to_mark (mark
);
11470 ret
= target_masked_watch_num_registers (value_as_address (val
),
11473 error (_("This target does not support masked watchpoints."));
11474 else if (ret
== -2)
11475 error (_("Invalid mask or memory region."));
11478 else if (val
!= NULL
)
11479 release_value (val
);
11481 tok
= skip_spaces_const (arg
);
11482 end_tok
= skip_to_space_const (tok
);
11484 toklen
= end_tok
- tok
;
11485 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11487 struct expression
*cond
;
11489 innermost_block
= NULL
;
11490 tok
= cond_start
= end_tok
+ 1;
11491 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11493 /* The watchpoint expression may not be local, but the condition
11494 may still be. E.g.: `watch global if local > 0'. */
11495 cond_exp_valid_block
= innermost_block
;
11501 error (_("Junk at end of command."));
11503 frame
= block_innermost_frame (exp_valid_block
);
11505 /* If the expression is "local", then set up a "watchpoint scope"
11506 breakpoint at the point where we've left the scope of the watchpoint
11507 expression. Create the scope breakpoint before the watchpoint, so
11508 that we will encounter it first in bpstat_stop_status. */
11509 if (exp_valid_block
&& frame
)
11511 if (frame_id_p (frame_unwind_caller_id (frame
)))
11514 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11515 frame_unwind_caller_pc (frame
),
11516 bp_watchpoint_scope
,
11517 &momentary_breakpoint_ops
);
11519 scope_breakpoint
->enable_state
= bp_enabled
;
11521 /* Automatically delete the breakpoint when it hits. */
11522 scope_breakpoint
->disposition
= disp_del
;
11524 /* Only break in the proper frame (help with recursion). */
11525 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11527 /* Set the address at which we will stop. */
11528 scope_breakpoint
->loc
->gdbarch
11529 = frame_unwind_caller_arch (frame
);
11530 scope_breakpoint
->loc
->requested_address
11531 = frame_unwind_caller_pc (frame
);
11532 scope_breakpoint
->loc
->address
11533 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11534 scope_breakpoint
->loc
->requested_address
,
11535 scope_breakpoint
->type
);
11539 /* Now set up the breakpoint. We create all watchpoints as hardware
11540 watchpoints here even if hardware watchpoints are turned off, a call
11541 to update_watchpoint later in this function will cause the type to
11542 drop back to bp_watchpoint (software watchpoint) if required. */
11544 if (accessflag
== hw_read
)
11545 bp_type
= bp_read_watchpoint
;
11546 else if (accessflag
== hw_access
)
11547 bp_type
= bp_access_watchpoint
;
11549 bp_type
= bp_hardware_watchpoint
;
11551 w
= XCNEW (struct watchpoint
);
11554 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11555 &masked_watchpoint_breakpoint_ops
);
11557 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11558 &watchpoint_breakpoint_ops
);
11559 b
->thread
= thread
;
11560 b
->disposition
= disp_donttouch
;
11561 b
->pspace
= current_program_space
;
11563 w
->exp_valid_block
= exp_valid_block
;
11564 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11567 struct type
*t
= value_type (val
);
11568 CORE_ADDR addr
= value_as_address (val
);
11571 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11572 name
= type_to_string (t
);
11574 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11575 core_addr_to_string (addr
));
11578 w
->exp_string
= xstrprintf ("-location %.*s",
11579 (int) (exp_end
- exp_start
), exp_start
);
11581 /* The above expression is in C. */
11582 b
->language
= language_c
;
11585 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11589 w
->hw_wp_mask
= mask
;
11594 w
->val_bitpos
= saved_bitpos
;
11595 w
->val_bitsize
= saved_bitsize
;
11600 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11602 b
->cond_string
= 0;
11606 w
->watchpoint_frame
= get_frame_id (frame
);
11607 w
->watchpoint_thread
= inferior_ptid
;
11611 w
->watchpoint_frame
= null_frame_id
;
11612 w
->watchpoint_thread
= null_ptid
;
11615 if (scope_breakpoint
!= NULL
)
11617 /* The scope breakpoint is related to the watchpoint. We will
11618 need to act on them together. */
11619 b
->related_breakpoint
= scope_breakpoint
;
11620 scope_breakpoint
->related_breakpoint
= b
;
11623 if (!just_location
)
11624 value_free_to_mark (mark
);
11626 TRY_CATCH (e
, RETURN_MASK_ALL
)
11628 /* Finally update the new watchpoint. This creates the locations
11629 that should be inserted. */
11630 update_watchpoint (w
, 1);
11634 delete_breakpoint (b
);
11635 throw_exception (e
);
11638 install_breakpoint (internal
, b
, 1);
11639 do_cleanups (back_to
);
11642 /* Return count of debug registers needed to watch the given expression.
11643 If the watchpoint cannot be handled in hardware return zero. */
11646 can_use_hardware_watchpoint (struct value
*v
)
11648 int found_memory_cnt
= 0;
11649 struct value
*head
= v
;
11651 /* Did the user specifically forbid us to use hardware watchpoints? */
11652 if (!can_use_hw_watchpoints
)
11655 /* Make sure that the value of the expression depends only upon
11656 memory contents, and values computed from them within GDB. If we
11657 find any register references or function calls, we can't use a
11658 hardware watchpoint.
11660 The idea here is that evaluating an expression generates a series
11661 of values, one holding the value of every subexpression. (The
11662 expression a*b+c has five subexpressions: a, b, a*b, c, and
11663 a*b+c.) GDB's values hold almost enough information to establish
11664 the criteria given above --- they identify memory lvalues,
11665 register lvalues, computed values, etcetera. So we can evaluate
11666 the expression, and then scan the chain of values that leaves
11667 behind to decide whether we can detect any possible change to the
11668 expression's final value using only hardware watchpoints.
11670 However, I don't think that the values returned by inferior
11671 function calls are special in any way. So this function may not
11672 notice that an expression involving an inferior function call
11673 can't be watched with hardware watchpoints. FIXME. */
11674 for (; v
; v
= value_next (v
))
11676 if (VALUE_LVAL (v
) == lval_memory
)
11678 if (v
!= head
&& value_lazy (v
))
11679 /* A lazy memory lvalue in the chain is one that GDB never
11680 needed to fetch; we either just used its address (e.g.,
11681 `a' in `a.b') or we never needed it at all (e.g., `a'
11682 in `a,b'). This doesn't apply to HEAD; if that is
11683 lazy then it was not readable, but watch it anyway. */
11687 /* Ahh, memory we actually used! Check if we can cover
11688 it with hardware watchpoints. */
11689 struct type
*vtype
= check_typedef (value_type (v
));
11691 /* We only watch structs and arrays if user asked for it
11692 explicitly, never if they just happen to appear in a
11693 middle of some value chain. */
11695 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11696 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11698 CORE_ADDR vaddr
= value_address (v
);
11702 len
= (target_exact_watchpoints
11703 && is_scalar_type_recursive (vtype
))?
11704 1 : TYPE_LENGTH (value_type (v
));
11706 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11710 found_memory_cnt
+= num_regs
;
11714 else if (VALUE_LVAL (v
) != not_lval
11715 && deprecated_value_modifiable (v
) == 0)
11716 return 0; /* These are values from the history (e.g., $1). */
11717 else if (VALUE_LVAL (v
) == lval_register
)
11718 return 0; /* Cannot watch a register with a HW watchpoint. */
11721 /* The expression itself looks suitable for using a hardware
11722 watchpoint, but give the target machine a chance to reject it. */
11723 return found_memory_cnt
;
11727 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11729 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11732 /* A helper function that looks for the "-location" argument and then
11733 calls watch_command_1. */
11736 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11738 int just_location
= 0;
11741 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11742 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11744 arg
= skip_spaces (arg
);
11748 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11752 watch_command (char *arg
, int from_tty
)
11754 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11758 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11760 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11764 rwatch_command (char *arg
, int from_tty
)
11766 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11770 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11772 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11776 awatch_command (char *arg
, int from_tty
)
11778 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11782 /* Helper routines for the until_command routine in infcmd.c. Here
11783 because it uses the mechanisms of breakpoints. */
11785 struct until_break_command_continuation_args
11787 struct breakpoint
*breakpoint
;
11788 struct breakpoint
*breakpoint2
;
11792 /* This function is called by fetch_inferior_event via the
11793 cmd_continuation pointer, to complete the until command. It takes
11794 care of cleaning up the temporary breakpoints set up by the until
11797 until_break_command_continuation (void *arg
, int err
)
11799 struct until_break_command_continuation_args
*a
= arg
;
11801 delete_breakpoint (a
->breakpoint
);
11802 if (a
->breakpoint2
)
11803 delete_breakpoint (a
->breakpoint2
);
11804 delete_longjmp_breakpoint (a
->thread_num
);
11808 until_break_command (char *arg
, int from_tty
, int anywhere
)
11810 struct symtabs_and_lines sals
;
11811 struct symtab_and_line sal
;
11812 struct frame_info
*frame
;
11813 struct gdbarch
*frame_gdbarch
;
11814 struct frame_id stack_frame_id
;
11815 struct frame_id caller_frame_id
;
11816 struct breakpoint
*breakpoint
;
11817 struct breakpoint
*breakpoint2
= NULL
;
11818 struct cleanup
*old_chain
;
11820 struct thread_info
*tp
;
11822 clear_proceed_status (0);
11824 /* Set a breakpoint where the user wants it and at return from
11827 if (last_displayed_sal_is_valid ())
11828 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11829 get_last_displayed_symtab (),
11830 get_last_displayed_line ());
11832 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11833 (struct symtab
*) NULL
, 0);
11835 if (sals
.nelts
!= 1)
11836 error (_("Couldn't get information on specified line."));
11838 sal
= sals
.sals
[0];
11839 xfree (sals
.sals
); /* malloc'd, so freed. */
11842 error (_("Junk at end of arguments."));
11844 resolve_sal_pc (&sal
);
11846 tp
= inferior_thread ();
11849 old_chain
= make_cleanup (null_cleanup
, NULL
);
11851 /* Note linespec handling above invalidates the frame chain.
11852 Installing a breakpoint also invalidates the frame chain (as it
11853 may need to switch threads), so do any frame handling before
11856 frame
= get_selected_frame (NULL
);
11857 frame_gdbarch
= get_frame_arch (frame
);
11858 stack_frame_id
= get_stack_frame_id (frame
);
11859 caller_frame_id
= frame_unwind_caller_id (frame
);
11861 /* Keep within the current frame, or in frames called by the current
11864 if (frame_id_p (caller_frame_id
))
11866 struct symtab_and_line sal2
;
11868 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11869 sal2
.pc
= frame_unwind_caller_pc (frame
);
11870 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11874 make_cleanup_delete_breakpoint (breakpoint2
);
11876 set_longjmp_breakpoint (tp
, caller_frame_id
);
11877 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11880 /* set_momentary_breakpoint could invalidate FRAME. */
11884 /* If the user told us to continue until a specified location,
11885 we don't specify a frame at which we need to stop. */
11886 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11887 null_frame_id
, bp_until
);
11889 /* Otherwise, specify the selected frame, because we want to stop
11890 only at the very same frame. */
11891 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11892 stack_frame_id
, bp_until
);
11893 make_cleanup_delete_breakpoint (breakpoint
);
11895 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11897 /* If we are running asynchronously, and proceed call above has
11898 actually managed to start the target, arrange for breakpoints to
11899 be deleted when the target stops. Otherwise, we're already
11900 stopped and delete breakpoints via cleanup chain. */
11902 if (target_can_async_p () && is_running (inferior_ptid
))
11904 struct until_break_command_continuation_args
*args
;
11905 args
= xmalloc (sizeof (*args
));
11907 args
->breakpoint
= breakpoint
;
11908 args
->breakpoint2
= breakpoint2
;
11909 args
->thread_num
= thread
;
11911 discard_cleanups (old_chain
);
11912 add_continuation (inferior_thread (),
11913 until_break_command_continuation
, args
,
11917 do_cleanups (old_chain
);
11920 /* This function attempts to parse an optional "if <cond>" clause
11921 from the arg string. If one is not found, it returns NULL.
11923 Else, it returns a pointer to the condition string. (It does not
11924 attempt to evaluate the string against a particular block.) And,
11925 it updates arg to point to the first character following the parsed
11926 if clause in the arg string. */
11929 ep_parse_optional_if_clause (char **arg
)
11933 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11936 /* Skip the "if" keyword. */
11939 /* Skip any extra leading whitespace, and record the start of the
11940 condition string. */
11941 *arg
= skip_spaces (*arg
);
11942 cond_string
= *arg
;
11944 /* Assume that the condition occupies the remainder of the arg
11946 (*arg
) += strlen (cond_string
);
11948 return cond_string
;
11951 /* Commands to deal with catching events, such as signals, exceptions,
11952 process start/exit, etc. */
11956 catch_fork_temporary
, catch_vfork_temporary
,
11957 catch_fork_permanent
, catch_vfork_permanent
11962 catch_fork_command_1 (char *arg
, int from_tty
,
11963 struct cmd_list_element
*command
)
11965 struct gdbarch
*gdbarch
= get_current_arch ();
11966 char *cond_string
= NULL
;
11967 catch_fork_kind fork_kind
;
11970 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11971 tempflag
= (fork_kind
== catch_fork_temporary
11972 || fork_kind
== catch_vfork_temporary
);
11976 arg
= skip_spaces (arg
);
11978 /* The allowed syntax is:
11980 catch [v]fork if <cond>
11982 First, check if there's an if clause. */
11983 cond_string
= ep_parse_optional_if_clause (&arg
);
11985 if ((*arg
!= '\0') && !isspace (*arg
))
11986 error (_("Junk at end of arguments."));
11988 /* If this target supports it, create a fork or vfork catchpoint
11989 and enable reporting of such events. */
11992 case catch_fork_temporary
:
11993 case catch_fork_permanent
:
11994 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11995 &catch_fork_breakpoint_ops
);
11997 case catch_vfork_temporary
:
11998 case catch_vfork_permanent
:
11999 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
12000 &catch_vfork_breakpoint_ops
);
12003 error (_("unsupported or unknown fork kind; cannot catch it"));
12009 catch_exec_command_1 (char *arg
, int from_tty
,
12010 struct cmd_list_element
*command
)
12012 struct exec_catchpoint
*c
;
12013 struct gdbarch
*gdbarch
= get_current_arch ();
12015 char *cond_string
= NULL
;
12017 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12021 arg
= skip_spaces (arg
);
12023 /* The allowed syntax is:
12025 catch exec if <cond>
12027 First, check if there's an if clause. */
12028 cond_string
= ep_parse_optional_if_clause (&arg
);
12030 if ((*arg
!= '\0') && !isspace (*arg
))
12031 error (_("Junk at end of arguments."));
12033 c
= XNEW (struct exec_catchpoint
);
12034 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
12035 &catch_exec_breakpoint_ops
);
12036 c
->exec_pathname
= NULL
;
12038 install_breakpoint (0, &c
->base
, 1);
12042 init_ada_exception_breakpoint (struct breakpoint
*b
,
12043 struct gdbarch
*gdbarch
,
12044 struct symtab_and_line sal
,
12046 const struct breakpoint_ops
*ops
,
12053 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
12055 loc_gdbarch
= gdbarch
;
12057 describe_other_breakpoints (loc_gdbarch
,
12058 sal
.pspace
, sal
.pc
, sal
.section
, -1);
12059 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12060 version for exception catchpoints, because two catchpoints
12061 used for different exception names will use the same address.
12062 In this case, a "breakpoint ... also set at..." warning is
12063 unproductive. Besides, the warning phrasing is also a bit
12064 inappropriate, we should use the word catchpoint, and tell
12065 the user what type of catchpoint it is. The above is good
12066 enough for now, though. */
12069 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12071 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12072 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12073 b
->addr_string
= addr_string
;
12074 b
->language
= language_ada
;
12077 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12078 filter list, or NULL if no filtering is required. */
12080 catch_syscall_split_args (char *arg
)
12082 VEC(int) *result
= NULL
;
12083 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
12084 struct gdbarch
*gdbarch
= target_gdbarch ();
12086 while (*arg
!= '\0')
12088 int i
, syscall_number
;
12090 char cur_name
[128];
12093 /* Skip whitespace. */
12094 arg
= skip_spaces (arg
);
12096 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
12097 cur_name
[i
] = arg
[i
];
12098 cur_name
[i
] = '\0';
12101 /* Check if the user provided a syscall name or a number. */
12102 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
12103 if (*endptr
== '\0')
12104 get_syscall_by_number (gdbarch
, syscall_number
, &s
);
12107 /* We have a name. Let's check if it's valid and convert it
12109 get_syscall_by_name (gdbarch
, cur_name
, &s
);
12111 if (s
.number
== UNKNOWN_SYSCALL
)
12112 /* Here we have to issue an error instead of a warning,
12113 because GDB cannot do anything useful if there's no
12114 syscall number to be caught. */
12115 error (_("Unknown syscall name '%s'."), cur_name
);
12118 /* Ok, it's valid. */
12119 VEC_safe_push (int, result
, s
.number
);
12122 discard_cleanups (cleanup
);
12126 /* Implement the "catch syscall" command. */
12129 catch_syscall_command_1 (char *arg
, int from_tty
,
12130 struct cmd_list_element
*command
)
12135 struct gdbarch
*gdbarch
= get_current_arch ();
12137 /* Checking if the feature if supported. */
12138 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
12139 error (_("The feature 'catch syscall' is not supported on \
12140 this architecture yet."));
12142 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12144 arg
= skip_spaces (arg
);
12146 /* We need to do this first "dummy" translation in order
12147 to get the syscall XML file loaded or, most important,
12148 to display a warning to the user if there's no XML file
12149 for his/her architecture. */
12150 get_syscall_by_number (gdbarch
, 0, &s
);
12152 /* The allowed syntax is:
12154 catch syscall <name | number> [<name | number> ... <name | number>]
12156 Let's check if there's a syscall name. */
12159 filter
= catch_syscall_split_args (arg
);
12163 create_syscall_event_catchpoint (tempflag
, filter
,
12164 &catch_syscall_breakpoint_ops
);
12168 catch_command (char *arg
, int from_tty
)
12170 error (_("Catch requires an event name."));
12175 tcatch_command (char *arg
, int from_tty
)
12177 error (_("Catch requires an event name."));
12180 /* A qsort comparison function that sorts breakpoints in order. */
12183 compare_breakpoints (const void *a
, const void *b
)
12185 const breakpoint_p
*ba
= a
;
12186 uintptr_t ua
= (uintptr_t) *ba
;
12187 const breakpoint_p
*bb
= b
;
12188 uintptr_t ub
= (uintptr_t) *bb
;
12190 if ((*ba
)->number
< (*bb
)->number
)
12192 else if ((*ba
)->number
> (*bb
)->number
)
12195 /* Now sort by address, in case we see, e..g, two breakpoints with
12199 return ua
> ub
? 1 : 0;
12202 /* Delete breakpoints by address or line. */
12205 clear_command (char *arg
, int from_tty
)
12207 struct breakpoint
*b
, *prev
;
12208 VEC(breakpoint_p
) *found
= 0;
12211 struct symtabs_and_lines sals
;
12212 struct symtab_and_line sal
;
12214 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12218 sals
= decode_line_with_current_source (arg
,
12219 (DECODE_LINE_FUNFIRSTLINE
12220 | DECODE_LINE_LIST_MODE
));
12221 make_cleanup (xfree
, sals
.sals
);
12226 sals
.sals
= (struct symtab_and_line
*)
12227 xmalloc (sizeof (struct symtab_and_line
));
12228 make_cleanup (xfree
, sals
.sals
);
12229 init_sal (&sal
); /* Initialize to zeroes. */
12231 /* Set sal's line, symtab, pc, and pspace to the values
12232 corresponding to the last call to print_frame_info. If the
12233 codepoint is not valid, this will set all the fields to 0. */
12234 get_last_displayed_sal (&sal
);
12235 if (sal
.symtab
== 0)
12236 error (_("No source file specified."));
12238 sals
.sals
[0] = sal
;
12244 /* We don't call resolve_sal_pc here. That's not as bad as it
12245 seems, because all existing breakpoints typically have both
12246 file/line and pc set. So, if clear is given file/line, we can
12247 match this to existing breakpoint without obtaining pc at all.
12249 We only support clearing given the address explicitly
12250 present in breakpoint table. Say, we've set breakpoint
12251 at file:line. There were several PC values for that file:line,
12252 due to optimization, all in one block.
12254 We've picked one PC value. If "clear" is issued with another
12255 PC corresponding to the same file:line, the breakpoint won't
12256 be cleared. We probably can still clear the breakpoint, but
12257 since the other PC value is never presented to user, user
12258 can only find it by guessing, and it does not seem important
12259 to support that. */
12261 /* For each line spec given, delete bps which correspond to it. Do
12262 it in two passes, solely to preserve the current behavior that
12263 from_tty is forced true if we delete more than one
12267 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12268 for (i
= 0; i
< sals
.nelts
; i
++)
12270 const char *sal_fullname
;
12272 /* If exact pc given, clear bpts at that pc.
12273 If line given (pc == 0), clear all bpts on specified line.
12274 If defaulting, clear all bpts on default line
12277 defaulting sal.pc != 0 tests to do
12282 1 0 <can't happen> */
12284 sal
= sals
.sals
[i
];
12285 sal_fullname
= (sal
.symtab
== NULL
12286 ? NULL
: symtab_to_fullname (sal
.symtab
));
12288 /* Find all matching breakpoints and add them to 'found'. */
12289 ALL_BREAKPOINTS (b
)
12292 /* Are we going to delete b? */
12293 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12295 struct bp_location
*loc
= b
->loc
;
12296 for (; loc
; loc
= loc
->next
)
12298 /* If the user specified file:line, don't allow a PC
12299 match. This matches historical gdb behavior. */
12300 int pc_match
= (!sal
.explicit_line
12302 && (loc
->pspace
== sal
.pspace
)
12303 && (loc
->address
== sal
.pc
)
12304 && (!section_is_overlay (loc
->section
)
12305 || loc
->section
== sal
.section
));
12306 int line_match
= 0;
12308 if ((default_match
|| sal
.explicit_line
)
12309 && loc
->symtab
!= NULL
12310 && sal_fullname
!= NULL
12311 && sal
.pspace
== loc
->pspace
12312 && loc
->line_number
== sal
.line
12313 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12314 sal_fullname
) == 0)
12317 if (pc_match
|| line_match
)
12326 VEC_safe_push(breakpoint_p
, found
, b
);
12330 /* Now go thru the 'found' chain and delete them. */
12331 if (VEC_empty(breakpoint_p
, found
))
12334 error (_("No breakpoint at %s."), arg
);
12336 error (_("No breakpoint at this line."));
12339 /* Remove duplicates from the vec. */
12340 qsort (VEC_address (breakpoint_p
, found
),
12341 VEC_length (breakpoint_p
, found
),
12342 sizeof (breakpoint_p
),
12343 compare_breakpoints
);
12344 prev
= VEC_index (breakpoint_p
, found
, 0);
12345 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12349 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12354 if (VEC_length(breakpoint_p
, found
) > 1)
12355 from_tty
= 1; /* Always report if deleted more than one. */
12358 if (VEC_length(breakpoint_p
, found
) == 1)
12359 printf_unfiltered (_("Deleted breakpoint "));
12361 printf_unfiltered (_("Deleted breakpoints "));
12364 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12367 printf_unfiltered ("%d ", b
->number
);
12368 delete_breakpoint (b
);
12371 putchar_unfiltered ('\n');
12373 do_cleanups (cleanups
);
12376 /* Delete breakpoint in BS if they are `delete' breakpoints and
12377 all breakpoints that are marked for deletion, whether hit or not.
12378 This is called after any breakpoint is hit, or after errors. */
12381 breakpoint_auto_delete (bpstat bs
)
12383 struct breakpoint
*b
, *b_tmp
;
12385 for (; bs
; bs
= bs
->next
)
12386 if (bs
->breakpoint_at
12387 && bs
->breakpoint_at
->disposition
== disp_del
12389 delete_breakpoint (bs
->breakpoint_at
);
12391 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12393 if (b
->disposition
== disp_del_at_next_stop
)
12394 delete_breakpoint (b
);
12398 /* A comparison function for bp_location AP and BP being interfaced to
12399 qsort. Sort elements primarily by their ADDRESS (no matter what
12400 does breakpoint_address_is_meaningful say for its OWNER),
12401 secondarily by ordering first permanent elements and
12402 terciarily just ensuring the array is sorted stable way despite
12403 qsort being an unstable algorithm. */
12406 bp_location_compare (const void *ap
, const void *bp
)
12408 struct bp_location
*a
= *(void **) ap
;
12409 struct bp_location
*b
= *(void **) bp
;
12411 if (a
->address
!= b
->address
)
12412 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12414 /* Sort locations at the same address by their pspace number, keeping
12415 locations of the same inferior (in a multi-inferior environment)
12418 if (a
->pspace
->num
!= b
->pspace
->num
)
12419 return ((a
->pspace
->num
> b
->pspace
->num
)
12420 - (a
->pspace
->num
< b
->pspace
->num
));
12422 /* Sort permanent breakpoints first. */
12423 if (a
->permanent
!= b
->permanent
)
12424 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12426 /* Make the internal GDB representation stable across GDB runs
12427 where A and B memory inside GDB can differ. Breakpoint locations of
12428 the same type at the same address can be sorted in arbitrary order. */
12430 if (a
->owner
->number
!= b
->owner
->number
)
12431 return ((a
->owner
->number
> b
->owner
->number
)
12432 - (a
->owner
->number
< b
->owner
->number
));
12434 return (a
> b
) - (a
< b
);
12437 /* Set bp_location_placed_address_before_address_max and
12438 bp_location_shadow_len_after_address_max according to the current
12439 content of the bp_location array. */
12442 bp_location_target_extensions_update (void)
12444 struct bp_location
*bl
, **blp_tmp
;
12446 bp_location_placed_address_before_address_max
= 0;
12447 bp_location_shadow_len_after_address_max
= 0;
12449 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12451 CORE_ADDR start
, end
, addr
;
12453 if (!bp_location_has_shadow (bl
))
12456 start
= bl
->target_info
.placed_address
;
12457 end
= start
+ bl
->target_info
.shadow_len
;
12459 gdb_assert (bl
->address
>= start
);
12460 addr
= bl
->address
- start
;
12461 if (addr
> bp_location_placed_address_before_address_max
)
12462 bp_location_placed_address_before_address_max
= addr
;
12464 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12466 gdb_assert (bl
->address
< end
);
12467 addr
= end
- bl
->address
;
12468 if (addr
> bp_location_shadow_len_after_address_max
)
12469 bp_location_shadow_len_after_address_max
= addr
;
12473 /* Download tracepoint locations if they haven't been. */
12476 download_tracepoint_locations (void)
12478 struct breakpoint
*b
;
12479 struct cleanup
*old_chain
;
12481 if (!target_can_download_tracepoint ())
12484 old_chain
= save_current_space_and_thread ();
12486 ALL_TRACEPOINTS (b
)
12488 struct bp_location
*bl
;
12489 struct tracepoint
*t
;
12490 int bp_location_downloaded
= 0;
12492 if ((b
->type
== bp_fast_tracepoint
12493 ? !may_insert_fast_tracepoints
12494 : !may_insert_tracepoints
))
12497 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12499 /* In tracepoint, locations are _never_ duplicated, so
12500 should_be_inserted is equivalent to
12501 unduplicated_should_be_inserted. */
12502 if (!should_be_inserted (bl
) || bl
->inserted
)
12505 switch_to_program_space_and_thread (bl
->pspace
);
12507 target_download_tracepoint (bl
);
12510 bp_location_downloaded
= 1;
12512 t
= (struct tracepoint
*) b
;
12513 t
->number_on_target
= b
->number
;
12514 if (bp_location_downloaded
)
12515 observer_notify_breakpoint_modified (b
);
12518 do_cleanups (old_chain
);
12521 /* Swap the insertion/duplication state between two locations. */
12524 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12526 const int left_inserted
= left
->inserted
;
12527 const int left_duplicate
= left
->duplicate
;
12528 const int left_needs_update
= left
->needs_update
;
12529 const struct bp_target_info left_target_info
= left
->target_info
;
12531 /* Locations of tracepoints can never be duplicated. */
12532 if (is_tracepoint (left
->owner
))
12533 gdb_assert (!left
->duplicate
);
12534 if (is_tracepoint (right
->owner
))
12535 gdb_assert (!right
->duplicate
);
12537 left
->inserted
= right
->inserted
;
12538 left
->duplicate
= right
->duplicate
;
12539 left
->needs_update
= right
->needs_update
;
12540 left
->target_info
= right
->target_info
;
12541 right
->inserted
= left_inserted
;
12542 right
->duplicate
= left_duplicate
;
12543 right
->needs_update
= left_needs_update
;
12544 right
->target_info
= left_target_info
;
12547 /* Force the re-insertion of the locations at ADDRESS. This is called
12548 once a new/deleted/modified duplicate location is found and we are evaluating
12549 conditions on the target's side. Such conditions need to be updated on
12553 force_breakpoint_reinsertion (struct bp_location
*bl
)
12555 struct bp_location
**locp
= NULL
, **loc2p
;
12556 struct bp_location
*loc
;
12557 CORE_ADDR address
= 0;
12560 address
= bl
->address
;
12561 pspace_num
= bl
->pspace
->num
;
12563 /* This is only meaningful if the target is
12564 evaluating conditions and if the user has
12565 opted for condition evaluation on the target's
12567 if (gdb_evaluates_breakpoint_condition_p ()
12568 || !target_supports_evaluation_of_breakpoint_conditions ())
12571 /* Flag all breakpoint locations with this address and
12572 the same program space as the location
12573 as "its condition has changed". We need to
12574 update the conditions on the target's side. */
12575 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12579 if (!is_breakpoint (loc
->owner
)
12580 || pspace_num
!= loc
->pspace
->num
)
12583 /* Flag the location appropriately. We use a different state to
12584 let everyone know that we already updated the set of locations
12585 with addr bl->address and program space bl->pspace. This is so
12586 we don't have to keep calling these functions just to mark locations
12587 that have already been marked. */
12588 loc
->condition_changed
= condition_updated
;
12590 /* Free the agent expression bytecode as well. We will compute
12592 if (loc
->cond_bytecode
)
12594 free_agent_expr (loc
->cond_bytecode
);
12595 loc
->cond_bytecode
= NULL
;
12599 /* Called whether new breakpoints are created, or existing breakpoints
12600 deleted, to update the global location list and recompute which
12601 locations are duplicate of which.
12603 The INSERT_MODE flag determines whether locations may not, may, or
12604 shall be inserted now. See 'enum ugll_insert_mode' for more
12608 update_global_location_list (enum ugll_insert_mode insert_mode
)
12610 struct breakpoint
*b
;
12611 struct bp_location
**locp
, *loc
;
12612 struct cleanup
*cleanups
;
12613 /* Last breakpoint location address that was marked for update. */
12614 CORE_ADDR last_addr
= 0;
12615 /* Last breakpoint location program space that was marked for update. */
12616 int last_pspace_num
= -1;
12618 /* Used in the duplicates detection below. When iterating over all
12619 bp_locations, points to the first bp_location of a given address.
12620 Breakpoints and watchpoints of different types are never
12621 duplicates of each other. Keep one pointer for each type of
12622 breakpoint/watchpoint, so we only need to loop over all locations
12624 struct bp_location
*bp_loc_first
; /* breakpoint */
12625 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12626 struct bp_location
*awp_loc_first
; /* access watchpoint */
12627 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12629 /* Saved former bp_location array which we compare against the newly
12630 built bp_location from the current state of ALL_BREAKPOINTS. */
12631 struct bp_location
**old_location
, **old_locp
;
12632 unsigned old_location_count
;
12634 old_location
= bp_location
;
12635 old_location_count
= bp_location_count
;
12636 bp_location
= NULL
;
12637 bp_location_count
= 0;
12638 cleanups
= make_cleanup (xfree
, old_location
);
12640 ALL_BREAKPOINTS (b
)
12641 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12642 bp_location_count
++;
12644 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12645 locp
= bp_location
;
12646 ALL_BREAKPOINTS (b
)
12647 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12649 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12650 bp_location_compare
);
12652 bp_location_target_extensions_update ();
12654 /* Identify bp_location instances that are no longer present in the
12655 new list, and therefore should be freed. Note that it's not
12656 necessary that those locations should be removed from inferior --
12657 if there's another location at the same address (previously
12658 marked as duplicate), we don't need to remove/insert the
12661 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12662 and former bp_location array state respectively. */
12664 locp
= bp_location
;
12665 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12668 struct bp_location
*old_loc
= *old_locp
;
12669 struct bp_location
**loc2p
;
12671 /* Tells if 'old_loc' is found among the new locations. If
12672 not, we have to free it. */
12673 int found_object
= 0;
12674 /* Tells if the location should remain inserted in the target. */
12675 int keep_in_target
= 0;
12678 /* Skip LOCP entries which will definitely never be needed.
12679 Stop either at or being the one matching OLD_LOC. */
12680 while (locp
< bp_location
+ bp_location_count
12681 && (*locp
)->address
< old_loc
->address
)
12685 (loc2p
< bp_location
+ bp_location_count
12686 && (*loc2p
)->address
== old_loc
->address
);
12689 /* Check if this is a new/duplicated location or a duplicated
12690 location that had its condition modified. If so, we want to send
12691 its condition to the target if evaluation of conditions is taking
12693 if ((*loc2p
)->condition_changed
== condition_modified
12694 && (last_addr
!= old_loc
->address
12695 || last_pspace_num
!= old_loc
->pspace
->num
))
12697 force_breakpoint_reinsertion (*loc2p
);
12698 last_pspace_num
= old_loc
->pspace
->num
;
12701 if (*loc2p
== old_loc
)
12705 /* We have already handled this address, update it so that we don't
12706 have to go through updates again. */
12707 last_addr
= old_loc
->address
;
12709 /* Target-side condition evaluation: Handle deleted locations. */
12711 force_breakpoint_reinsertion (old_loc
);
12713 /* If this location is no longer present, and inserted, look if
12714 there's maybe a new location at the same address. If so,
12715 mark that one inserted, and don't remove this one. This is
12716 needed so that we don't have a time window where a breakpoint
12717 at certain location is not inserted. */
12719 if (old_loc
->inserted
)
12721 /* If the location is inserted now, we might have to remove
12724 if (found_object
&& should_be_inserted (old_loc
))
12726 /* The location is still present in the location list,
12727 and still should be inserted. Don't do anything. */
12728 keep_in_target
= 1;
12732 /* This location still exists, but it won't be kept in the
12733 target since it may have been disabled. We proceed to
12734 remove its target-side condition. */
12736 /* The location is either no longer present, or got
12737 disabled. See if there's another location at the
12738 same address, in which case we don't need to remove
12739 this one from the target. */
12741 /* OLD_LOC comes from existing struct breakpoint. */
12742 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12745 (loc2p
< bp_location
+ bp_location_count
12746 && (*loc2p
)->address
== old_loc
->address
);
12749 struct bp_location
*loc2
= *loc2p
;
12751 if (breakpoint_locations_match (loc2
, old_loc
))
12753 /* Read watchpoint locations are switched to
12754 access watchpoints, if the former are not
12755 supported, but the latter are. */
12756 if (is_hardware_watchpoint (old_loc
->owner
))
12758 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12759 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12762 /* loc2 is a duplicated location. We need to check
12763 if it should be inserted in case it will be
12765 if (loc2
!= old_loc
12766 && unduplicated_should_be_inserted (loc2
))
12768 swap_insertion (old_loc
, loc2
);
12769 keep_in_target
= 1;
12777 if (!keep_in_target
)
12779 if (remove_breakpoint (old_loc
, mark_uninserted
))
12781 /* This is just about all we can do. We could keep
12782 this location on the global list, and try to
12783 remove it next time, but there's no particular
12784 reason why we will succeed next time.
12786 Note that at this point, old_loc->owner is still
12787 valid, as delete_breakpoint frees the breakpoint
12788 only after calling us. */
12789 printf_filtered (_("warning: Error removing "
12790 "breakpoint %d\n"),
12791 old_loc
->owner
->number
);
12799 if (removed
&& non_stop
12800 && breakpoint_address_is_meaningful (old_loc
->owner
)
12801 && !is_hardware_watchpoint (old_loc
->owner
))
12803 /* This location was removed from the target. In
12804 non-stop mode, a race condition is possible where
12805 we've removed a breakpoint, but stop events for that
12806 breakpoint are already queued and will arrive later.
12807 We apply an heuristic to be able to distinguish such
12808 SIGTRAPs from other random SIGTRAPs: we keep this
12809 breakpoint location for a bit, and will retire it
12810 after we see some number of events. The theory here
12811 is that reporting of events should, "on the average",
12812 be fair, so after a while we'll see events from all
12813 threads that have anything of interest, and no longer
12814 need to keep this breakpoint location around. We
12815 don't hold locations forever so to reduce chances of
12816 mistaking a non-breakpoint SIGTRAP for a breakpoint
12819 The heuristic failing can be disastrous on
12820 decr_pc_after_break targets.
12822 On decr_pc_after_break targets, like e.g., x86-linux,
12823 if we fail to recognize a late breakpoint SIGTRAP,
12824 because events_till_retirement has reached 0 too
12825 soon, we'll fail to do the PC adjustment, and report
12826 a random SIGTRAP to the user. When the user resumes
12827 the inferior, it will most likely immediately crash
12828 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12829 corrupted, because of being resumed e.g., in the
12830 middle of a multi-byte instruction, or skipped a
12831 one-byte instruction. This was actually seen happen
12832 on native x86-linux, and should be less rare on
12833 targets that do not support new thread events, like
12834 remote, due to the heuristic depending on
12837 Mistaking a random SIGTRAP for a breakpoint trap
12838 causes similar symptoms (PC adjustment applied when
12839 it shouldn't), but then again, playing with SIGTRAPs
12840 behind the debugger's back is asking for trouble.
12842 Since hardware watchpoint traps are always
12843 distinguishable from other traps, so we don't need to
12844 apply keep hardware watchpoint moribund locations
12845 around. We simply always ignore hardware watchpoint
12846 traps we can no longer explain. */
12848 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12849 old_loc
->owner
= NULL
;
12851 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12855 old_loc
->owner
= NULL
;
12856 decref_bp_location (&old_loc
);
12861 /* Rescan breakpoints at the same address and section, marking the
12862 first one as "first" and any others as "duplicates". This is so
12863 that the bpt instruction is only inserted once. If we have a
12864 permanent breakpoint at the same place as BPT, make that one the
12865 official one, and the rest as duplicates. Permanent breakpoints
12866 are sorted first for the same address.
12868 Do the same for hardware watchpoints, but also considering the
12869 watchpoint's type (regular/access/read) and length. */
12871 bp_loc_first
= NULL
;
12872 wp_loc_first
= NULL
;
12873 awp_loc_first
= NULL
;
12874 rwp_loc_first
= NULL
;
12875 ALL_BP_LOCATIONS (loc
, locp
)
12877 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12879 struct bp_location
**loc_first_p
;
12882 if (!unduplicated_should_be_inserted (loc
)
12883 || !breakpoint_address_is_meaningful (b
)
12884 /* Don't detect duplicate for tracepoint locations because they are
12885 never duplicated. See the comments in field `duplicate' of
12886 `struct bp_location'. */
12887 || is_tracepoint (b
))
12889 /* Clear the condition modification flag. */
12890 loc
->condition_changed
= condition_unchanged
;
12894 /* Permanent breakpoint should always be inserted. */
12895 if (loc
->permanent
&& ! loc
->inserted
)
12896 internal_error (__FILE__
, __LINE__
,
12897 _("allegedly permanent breakpoint is not "
12898 "actually inserted"));
12900 if (b
->type
== bp_hardware_watchpoint
)
12901 loc_first_p
= &wp_loc_first
;
12902 else if (b
->type
== bp_read_watchpoint
)
12903 loc_first_p
= &rwp_loc_first
;
12904 else if (b
->type
== bp_access_watchpoint
)
12905 loc_first_p
= &awp_loc_first
;
12907 loc_first_p
= &bp_loc_first
;
12909 if (*loc_first_p
== NULL
12910 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12911 || !breakpoint_locations_match (loc
, *loc_first_p
))
12913 *loc_first_p
= loc
;
12914 loc
->duplicate
= 0;
12916 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12918 loc
->needs_update
= 1;
12919 /* Clear the condition modification flag. */
12920 loc
->condition_changed
= condition_unchanged
;
12926 /* This and the above ensure the invariant that the first location
12927 is not duplicated, and is the inserted one.
12928 All following are marked as duplicated, and are not inserted. */
12930 swap_insertion (loc
, *loc_first_p
);
12931 loc
->duplicate
= 1;
12933 /* Clear the condition modification flag. */
12934 loc
->condition_changed
= condition_unchanged
;
12936 if (loc
->inserted
&& !loc
->permanent
12937 && (*loc_first_p
)->permanent
)
12938 internal_error (__FILE__
, __LINE__
,
12939 _("another breakpoint was inserted on top of "
12940 "a permanent breakpoint"));
12943 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12945 if (insert_mode
!= UGLL_DONT_INSERT
)
12946 insert_breakpoint_locations ();
12949 /* Even though the caller told us to not insert new
12950 locations, we may still need to update conditions on the
12951 target's side of breakpoints that were already inserted
12952 if the target is evaluating breakpoint conditions. We
12953 only update conditions for locations that are marked
12955 update_inserted_breakpoint_locations ();
12959 if (insert_mode
!= UGLL_DONT_INSERT
)
12960 download_tracepoint_locations ();
12962 do_cleanups (cleanups
);
12966 breakpoint_retire_moribund (void)
12968 struct bp_location
*loc
;
12971 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12972 if (--(loc
->events_till_retirement
) == 0)
12974 decref_bp_location (&loc
);
12975 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12981 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12983 volatile struct gdb_exception e
;
12985 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12986 update_global_location_list (insert_mode
);
12989 /* Clear BKP from a BPS. */
12992 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12996 for (bs
= bps
; bs
; bs
= bs
->next
)
12997 if (bs
->breakpoint_at
== bpt
)
12999 bs
->breakpoint_at
= NULL
;
13000 bs
->old_val
= NULL
;
13001 /* bs->commands will be freed later. */
13005 /* Callback for iterate_over_threads. */
13007 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
13009 struct breakpoint
*bpt
= data
;
13011 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
13015 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
13019 say_where (struct breakpoint
*b
)
13021 struct value_print_options opts
;
13023 get_user_print_options (&opts
);
13025 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13027 if (b
->loc
== NULL
)
13029 printf_filtered (_(" (%s) pending."), b
->addr_string
);
13033 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
13035 printf_filtered (" at ");
13036 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
13039 if (b
->loc
->symtab
!= NULL
)
13041 /* If there is a single location, we can print the location
13043 if (b
->loc
->next
== NULL
)
13044 printf_filtered (": file %s, line %d.",
13045 symtab_to_filename_for_display (b
->loc
->symtab
),
13046 b
->loc
->line_number
);
13048 /* This is not ideal, but each location may have a
13049 different file name, and this at least reflects the
13050 real situation somewhat. */
13051 printf_filtered (": %s.", b
->addr_string
);
13056 struct bp_location
*loc
= b
->loc
;
13058 for (; loc
; loc
= loc
->next
)
13060 printf_filtered (" (%d locations)", n
);
13065 /* Default bp_location_ops methods. */
13068 bp_location_dtor (struct bp_location
*self
)
13070 xfree (self
->cond
);
13071 if (self
->cond_bytecode
)
13072 free_agent_expr (self
->cond_bytecode
);
13073 xfree (self
->function_name
);
13075 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
13076 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
13079 static const struct bp_location_ops bp_location_ops
=
13084 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13088 base_breakpoint_dtor (struct breakpoint
*self
)
13090 decref_counted_command_line (&self
->commands
);
13091 xfree (self
->cond_string
);
13092 xfree (self
->extra_string
);
13093 xfree (self
->addr_string
);
13094 xfree (self
->filter
);
13095 xfree (self
->addr_string_range_end
);
13098 static struct bp_location
*
13099 base_breakpoint_allocate_location (struct breakpoint
*self
)
13101 struct bp_location
*loc
;
13103 loc
= XNEW (struct bp_location
);
13104 init_bp_location (loc
, &bp_location_ops
, self
);
13109 base_breakpoint_re_set (struct breakpoint
*b
)
13111 /* Nothing to re-set. */
13114 #define internal_error_pure_virtual_called() \
13115 gdb_assert_not_reached ("pure virtual function called")
13118 base_breakpoint_insert_location (struct bp_location
*bl
)
13120 internal_error_pure_virtual_called ();
13124 base_breakpoint_remove_location (struct bp_location
*bl
)
13126 internal_error_pure_virtual_called ();
13130 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
13131 struct address_space
*aspace
,
13133 const struct target_waitstatus
*ws
)
13135 internal_error_pure_virtual_called ();
13139 base_breakpoint_check_status (bpstat bs
)
13144 /* A "works_in_software_mode" breakpoint_ops method that just internal
13148 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13150 internal_error_pure_virtual_called ();
13153 /* A "resources_needed" breakpoint_ops method that just internal
13157 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13159 internal_error_pure_virtual_called ();
13162 static enum print_stop_action
13163 base_breakpoint_print_it (bpstat bs
)
13165 internal_error_pure_virtual_called ();
13169 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13170 struct ui_out
*uiout
)
13176 base_breakpoint_print_mention (struct breakpoint
*b
)
13178 internal_error_pure_virtual_called ();
13182 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13184 internal_error_pure_virtual_called ();
13188 base_breakpoint_create_sals_from_address (char **arg
,
13189 struct linespec_result
*canonical
,
13190 enum bptype type_wanted
,
13194 internal_error_pure_virtual_called ();
13198 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13199 struct linespec_result
*c
,
13201 char *extra_string
,
13202 enum bptype type_wanted
,
13203 enum bpdisp disposition
,
13205 int task
, int ignore_count
,
13206 const struct breakpoint_ops
*o
,
13207 int from_tty
, int enabled
,
13208 int internal
, unsigned flags
)
13210 internal_error_pure_virtual_called ();
13214 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13215 struct symtabs_and_lines
*sals
)
13217 internal_error_pure_virtual_called ();
13220 /* The default 'explains_signal' method. */
13223 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13228 /* The default "after_condition_true" method. */
13231 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13233 /* Nothing to do. */
13236 struct breakpoint_ops base_breakpoint_ops
=
13238 base_breakpoint_dtor
,
13239 base_breakpoint_allocate_location
,
13240 base_breakpoint_re_set
,
13241 base_breakpoint_insert_location
,
13242 base_breakpoint_remove_location
,
13243 base_breakpoint_breakpoint_hit
,
13244 base_breakpoint_check_status
,
13245 base_breakpoint_resources_needed
,
13246 base_breakpoint_works_in_software_mode
,
13247 base_breakpoint_print_it
,
13249 base_breakpoint_print_one_detail
,
13250 base_breakpoint_print_mention
,
13251 base_breakpoint_print_recreate
,
13252 base_breakpoint_create_sals_from_address
,
13253 base_breakpoint_create_breakpoints_sal
,
13254 base_breakpoint_decode_linespec
,
13255 base_breakpoint_explains_signal
,
13256 base_breakpoint_after_condition_true
,
13259 /* Default breakpoint_ops methods. */
13262 bkpt_re_set (struct breakpoint
*b
)
13264 /* FIXME: is this still reachable? */
13265 if (b
->addr_string
== NULL
)
13267 /* Anything without a string can't be re-set. */
13268 delete_breakpoint (b
);
13272 breakpoint_re_set_default (b
);
13276 bkpt_insert_location (struct bp_location
*bl
)
13278 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13279 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13281 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13285 bkpt_remove_location (struct bp_location
*bl
)
13287 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13288 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13290 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13294 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13295 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13296 const struct target_waitstatus
*ws
)
13298 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13299 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13302 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13306 if (overlay_debugging
/* unmapped overlay section */
13307 && section_is_overlay (bl
->section
)
13308 && !section_is_mapped (bl
->section
))
13315 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13316 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13317 const struct target_waitstatus
*ws
)
13319 if (dprintf_style
== dprintf_style_agent
13320 && target_can_run_breakpoint_commands ())
13322 /* An agent-style dprintf never causes a stop. If we see a trap
13323 for this address it must be for a breakpoint that happens to
13324 be set at the same address. */
13328 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13332 bkpt_resources_needed (const struct bp_location
*bl
)
13334 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13339 static enum print_stop_action
13340 bkpt_print_it (bpstat bs
)
13342 struct breakpoint
*b
;
13343 const struct bp_location
*bl
;
13345 struct ui_out
*uiout
= current_uiout
;
13347 gdb_assert (bs
->bp_location_at
!= NULL
);
13349 bl
= bs
->bp_location_at
;
13350 b
= bs
->breakpoint_at
;
13352 bp_temp
= b
->disposition
== disp_del
;
13353 if (bl
->address
!= bl
->requested_address
)
13354 breakpoint_adjustment_warning (bl
->requested_address
,
13357 annotate_breakpoint (b
->number
);
13359 ui_out_text (uiout
, "\nTemporary breakpoint ");
13361 ui_out_text (uiout
, "\nBreakpoint ");
13362 if (ui_out_is_mi_like_p (uiout
))
13364 ui_out_field_string (uiout
, "reason",
13365 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13366 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13368 ui_out_field_int (uiout
, "bkptno", b
->number
);
13369 ui_out_text (uiout
, ", ");
13371 return PRINT_SRC_AND_LOC
;
13375 bkpt_print_mention (struct breakpoint
*b
)
13377 if (ui_out_is_mi_like_p (current_uiout
))
13382 case bp_breakpoint
:
13383 case bp_gnu_ifunc_resolver
:
13384 if (b
->disposition
== disp_del
)
13385 printf_filtered (_("Temporary breakpoint"));
13387 printf_filtered (_("Breakpoint"));
13388 printf_filtered (_(" %d"), b
->number
);
13389 if (b
->type
== bp_gnu_ifunc_resolver
)
13390 printf_filtered (_(" at gnu-indirect-function resolver"));
13392 case bp_hardware_breakpoint
:
13393 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13396 printf_filtered (_("Dprintf %d"), b
->number
);
13404 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13406 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13407 fprintf_unfiltered (fp
, "tbreak");
13408 else if (tp
->type
== bp_breakpoint
)
13409 fprintf_unfiltered (fp
, "break");
13410 else if (tp
->type
== bp_hardware_breakpoint
13411 && tp
->disposition
== disp_del
)
13412 fprintf_unfiltered (fp
, "thbreak");
13413 else if (tp
->type
== bp_hardware_breakpoint
)
13414 fprintf_unfiltered (fp
, "hbreak");
13416 internal_error (__FILE__
, __LINE__
,
13417 _("unhandled breakpoint type %d"), (int) tp
->type
);
13419 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13420 print_recreate_thread (tp
, fp
);
13424 bkpt_create_sals_from_address (char **arg
,
13425 struct linespec_result
*canonical
,
13426 enum bptype type_wanted
,
13427 char *addr_start
, char **copy_arg
)
13429 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13430 addr_start
, copy_arg
);
13434 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13435 struct linespec_result
*canonical
,
13437 char *extra_string
,
13438 enum bptype type_wanted
,
13439 enum bpdisp disposition
,
13441 int task
, int ignore_count
,
13442 const struct breakpoint_ops
*ops
,
13443 int from_tty
, int enabled
,
13444 int internal
, unsigned flags
)
13446 create_breakpoints_sal_default (gdbarch
, canonical
,
13447 cond_string
, extra_string
,
13449 disposition
, thread
, task
,
13450 ignore_count
, ops
, from_tty
,
13451 enabled
, internal
, flags
);
13455 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13456 struct symtabs_and_lines
*sals
)
13458 decode_linespec_default (b
, s
, sals
);
13461 /* Virtual table for internal breakpoints. */
13464 internal_bkpt_re_set (struct breakpoint
*b
)
13468 /* Delete overlay event and longjmp master breakpoints; they
13469 will be reset later by breakpoint_re_set. */
13470 case bp_overlay_event
:
13471 case bp_longjmp_master
:
13472 case bp_std_terminate_master
:
13473 case bp_exception_master
:
13474 delete_breakpoint (b
);
13477 /* This breakpoint is special, it's set up when the inferior
13478 starts and we really don't want to touch it. */
13479 case bp_shlib_event
:
13481 /* Like bp_shlib_event, this breakpoint type is special. Once
13482 it is set up, we do not want to touch it. */
13483 case bp_thread_event
:
13489 internal_bkpt_check_status (bpstat bs
)
13491 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13493 /* If requested, stop when the dynamic linker notifies GDB of
13494 events. This allows the user to get control and place
13495 breakpoints in initializer routines for dynamically loaded
13496 objects (among other things). */
13497 bs
->stop
= stop_on_solib_events
;
13498 bs
->print
= stop_on_solib_events
;
13504 static enum print_stop_action
13505 internal_bkpt_print_it (bpstat bs
)
13507 struct breakpoint
*b
;
13509 b
= bs
->breakpoint_at
;
13513 case bp_shlib_event
:
13514 /* Did we stop because the user set the stop_on_solib_events
13515 variable? (If so, we report this as a generic, "Stopped due
13516 to shlib event" message.) */
13517 print_solib_event (0);
13520 case bp_thread_event
:
13521 /* Not sure how we will get here.
13522 GDB should not stop for these breakpoints. */
13523 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13526 case bp_overlay_event
:
13527 /* By analogy with the thread event, GDB should not stop for these. */
13528 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13531 case bp_longjmp_master
:
13532 /* These should never be enabled. */
13533 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13536 case bp_std_terminate_master
:
13537 /* These should never be enabled. */
13538 printf_filtered (_("std::terminate Master Breakpoint: "
13539 "gdb should not stop!\n"));
13542 case bp_exception_master
:
13543 /* These should never be enabled. */
13544 printf_filtered (_("Exception Master Breakpoint: "
13545 "gdb should not stop!\n"));
13549 return PRINT_NOTHING
;
13553 internal_bkpt_print_mention (struct breakpoint
*b
)
13555 /* Nothing to mention. These breakpoints are internal. */
13558 /* Virtual table for momentary breakpoints */
13561 momentary_bkpt_re_set (struct breakpoint
*b
)
13563 /* Keep temporary breakpoints, which can be encountered when we step
13564 over a dlopen call and solib_add is resetting the breakpoints.
13565 Otherwise these should have been blown away via the cleanup chain
13566 or by breakpoint_init_inferior when we rerun the executable. */
13570 momentary_bkpt_check_status (bpstat bs
)
13572 /* Nothing. The point of these breakpoints is causing a stop. */
13575 static enum print_stop_action
13576 momentary_bkpt_print_it (bpstat bs
)
13578 struct ui_out
*uiout
= current_uiout
;
13580 if (ui_out_is_mi_like_p (uiout
))
13582 struct breakpoint
*b
= bs
->breakpoint_at
;
13587 ui_out_field_string
13589 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13593 ui_out_field_string
13595 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13600 return PRINT_UNKNOWN
;
13604 momentary_bkpt_print_mention (struct breakpoint
*b
)
13606 /* Nothing to mention. These breakpoints are internal. */
13609 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13611 It gets cleared already on the removal of the first one of such placed
13612 breakpoints. This is OK as they get all removed altogether. */
13615 longjmp_bkpt_dtor (struct breakpoint
*self
)
13617 struct thread_info
*tp
= find_thread_id (self
->thread
);
13620 tp
->initiating_frame
= null_frame_id
;
13622 momentary_breakpoint_ops
.dtor (self
);
13625 /* Specific methods for probe breakpoints. */
13628 bkpt_probe_insert_location (struct bp_location
*bl
)
13630 int v
= bkpt_insert_location (bl
);
13634 /* The insertion was successful, now let's set the probe's semaphore
13636 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13637 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13646 bkpt_probe_remove_location (struct bp_location
*bl
)
13648 /* Let's clear the semaphore before removing the location. */
13649 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13650 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13654 return bkpt_remove_location (bl
);
13658 bkpt_probe_create_sals_from_address (char **arg
,
13659 struct linespec_result
*canonical
,
13660 enum bptype type_wanted
,
13661 char *addr_start
, char **copy_arg
)
13663 struct linespec_sals lsal
;
13665 lsal
.sals
= parse_probes (arg
, canonical
);
13667 *copy_arg
= xstrdup (canonical
->addr_string
);
13668 lsal
.canonical
= xstrdup (*copy_arg
);
13670 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13674 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13675 struct symtabs_and_lines
*sals
)
13677 *sals
= parse_probes (s
, NULL
);
13679 error (_("probe not found"));
13682 /* The breakpoint_ops structure to be used in tracepoints. */
13685 tracepoint_re_set (struct breakpoint
*b
)
13687 breakpoint_re_set_default (b
);
13691 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13692 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13693 const struct target_waitstatus
*ws
)
13695 /* By definition, the inferior does not report stops at
13701 tracepoint_print_one_detail (const struct breakpoint
*self
,
13702 struct ui_out
*uiout
)
13704 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13705 if (tp
->static_trace_marker_id
)
13707 gdb_assert (self
->type
== bp_static_tracepoint
);
13709 ui_out_text (uiout
, "\tmarker id is ");
13710 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13711 tp
->static_trace_marker_id
);
13712 ui_out_text (uiout
, "\n");
13717 tracepoint_print_mention (struct breakpoint
*b
)
13719 if (ui_out_is_mi_like_p (current_uiout
))
13724 case bp_tracepoint
:
13725 printf_filtered (_("Tracepoint"));
13726 printf_filtered (_(" %d"), b
->number
);
13728 case bp_fast_tracepoint
:
13729 printf_filtered (_("Fast tracepoint"));
13730 printf_filtered (_(" %d"), b
->number
);
13732 case bp_static_tracepoint
:
13733 printf_filtered (_("Static tracepoint"));
13734 printf_filtered (_(" %d"), b
->number
);
13737 internal_error (__FILE__
, __LINE__
,
13738 _("unhandled tracepoint type %d"), (int) b
->type
);
13745 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13747 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13749 if (self
->type
== bp_fast_tracepoint
)
13750 fprintf_unfiltered (fp
, "ftrace");
13751 if (self
->type
== bp_static_tracepoint
)
13752 fprintf_unfiltered (fp
, "strace");
13753 else if (self
->type
== bp_tracepoint
)
13754 fprintf_unfiltered (fp
, "trace");
13756 internal_error (__FILE__
, __LINE__
,
13757 _("unhandled tracepoint type %d"), (int) self
->type
);
13759 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13760 print_recreate_thread (self
, fp
);
13762 if (tp
->pass_count
)
13763 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13767 tracepoint_create_sals_from_address (char **arg
,
13768 struct linespec_result
*canonical
,
13769 enum bptype type_wanted
,
13770 char *addr_start
, char **copy_arg
)
13772 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13773 addr_start
, copy_arg
);
13777 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13778 struct linespec_result
*canonical
,
13780 char *extra_string
,
13781 enum bptype type_wanted
,
13782 enum bpdisp disposition
,
13784 int task
, int ignore_count
,
13785 const struct breakpoint_ops
*ops
,
13786 int from_tty
, int enabled
,
13787 int internal
, unsigned flags
)
13789 create_breakpoints_sal_default (gdbarch
, canonical
,
13790 cond_string
, extra_string
,
13792 disposition
, thread
, task
,
13793 ignore_count
, ops
, from_tty
,
13794 enabled
, internal
, flags
);
13798 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13799 struct symtabs_and_lines
*sals
)
13801 decode_linespec_default (b
, s
, sals
);
13804 struct breakpoint_ops tracepoint_breakpoint_ops
;
13806 /* The breakpoint_ops structure to be use on tracepoints placed in a
13810 tracepoint_probe_create_sals_from_address (char **arg
,
13811 struct linespec_result
*canonical
,
13812 enum bptype type_wanted
,
13813 char *addr_start
, char **copy_arg
)
13815 /* We use the same method for breakpoint on probes. */
13816 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13817 addr_start
, copy_arg
);
13821 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13822 struct symtabs_and_lines
*sals
)
13824 /* We use the same method for breakpoint on probes. */
13825 bkpt_probe_decode_linespec (b
, s
, sals
);
13828 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13830 /* Dprintf breakpoint_ops methods. */
13833 dprintf_re_set (struct breakpoint
*b
)
13835 breakpoint_re_set_default (b
);
13837 /* This breakpoint could have been pending, and be resolved now, and
13838 if so, we should now have the extra string. If we don't, the
13839 dprintf was malformed when created, but we couldn't tell because
13840 we can't extract the extra string until the location is
13842 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13843 error (_("Format string required"));
13845 /* 1 - connect to target 1, that can run breakpoint commands.
13846 2 - create a dprintf, which resolves fine.
13847 3 - disconnect from target 1
13848 4 - connect to target 2, that can NOT run breakpoint commands.
13850 After steps #3/#4, you'll want the dprintf command list to
13851 be updated, because target 1 and 2 may well return different
13852 answers for target_can_run_breakpoint_commands().
13853 Given absence of finer grained resetting, we get to do
13854 it all the time. */
13855 if (b
->extra_string
!= NULL
)
13856 update_dprintf_command_list (b
);
13859 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13862 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13864 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13866 print_recreate_thread (tp
, fp
);
13869 /* Implement the "after_condition_true" breakpoint_ops method for
13872 dprintf's are implemented with regular commands in their command
13873 list, but we run the commands here instead of before presenting the
13874 stop to the user, as dprintf's don't actually cause a stop. This
13875 also makes it so that the commands of multiple dprintfs at the same
13876 address are all handled. */
13879 dprintf_after_condition_true (struct bpstats
*bs
)
13881 struct cleanup
*old_chain
;
13882 struct bpstats tmp_bs
= { NULL
};
13883 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13885 /* dprintf's never cause a stop. This wasn't set in the
13886 check_status hook instead because that would make the dprintf's
13887 condition not be evaluated. */
13890 /* Run the command list here. Take ownership of it instead of
13891 copying. We never want these commands to run later in
13892 bpstat_do_actions, if a breakpoint that causes a stop happens to
13893 be set at same address as this dprintf, or even if running the
13894 commands here throws. */
13895 tmp_bs
.commands
= bs
->commands
;
13896 bs
->commands
= NULL
;
13897 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13899 bpstat_do_actions_1 (&tmp_bs_p
);
13901 /* 'tmp_bs.commands' will usually be NULL by now, but
13902 bpstat_do_actions_1 may return early without processing the whole
13904 do_cleanups (old_chain
);
13907 /* The breakpoint_ops structure to be used on static tracepoints with
13911 strace_marker_create_sals_from_address (char **arg
,
13912 struct linespec_result
*canonical
,
13913 enum bptype type_wanted
,
13914 char *addr_start
, char **copy_arg
)
13916 struct linespec_sals lsal
;
13918 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13920 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13922 canonical
->addr_string
= xstrdup (*copy_arg
);
13923 lsal
.canonical
= xstrdup (*copy_arg
);
13924 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13928 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13929 struct linespec_result
*canonical
,
13931 char *extra_string
,
13932 enum bptype type_wanted
,
13933 enum bpdisp disposition
,
13935 int task
, int ignore_count
,
13936 const struct breakpoint_ops
*ops
,
13937 int from_tty
, int enabled
,
13938 int internal
, unsigned flags
)
13941 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13942 canonical
->sals
, 0);
13944 /* If the user is creating a static tracepoint by marker id
13945 (strace -m MARKER_ID), then store the sals index, so that
13946 breakpoint_re_set can try to match up which of the newly
13947 found markers corresponds to this one, and, don't try to
13948 expand multiple locations for each sal, given than SALS
13949 already should contain all sals for MARKER_ID. */
13951 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13953 struct symtabs_and_lines expanded
;
13954 struct tracepoint
*tp
;
13955 struct cleanup
*old_chain
;
13958 expanded
.nelts
= 1;
13959 expanded
.sals
= &lsal
->sals
.sals
[i
];
13961 addr_string
= xstrdup (canonical
->addr_string
);
13962 old_chain
= make_cleanup (xfree
, addr_string
);
13964 tp
= XCNEW (struct tracepoint
);
13965 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13967 cond_string
, extra_string
,
13968 type_wanted
, disposition
,
13969 thread
, task
, ignore_count
, ops
,
13970 from_tty
, enabled
, internal
, flags
,
13971 canonical
->special_display
);
13972 /* Given that its possible to have multiple markers with
13973 the same string id, if the user is creating a static
13974 tracepoint by marker id ("strace -m MARKER_ID"), then
13975 store the sals index, so that breakpoint_re_set can
13976 try to match up which of the newly found markers
13977 corresponds to this one */
13978 tp
->static_trace_marker_id_idx
= i
;
13980 install_breakpoint (internal
, &tp
->base
, 0);
13982 discard_cleanups (old_chain
);
13987 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13988 struct symtabs_and_lines
*sals
)
13990 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13992 *sals
= decode_static_tracepoint_spec (s
);
13993 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13995 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13999 error (_("marker %s not found"), tp
->static_trace_marker_id
);
14002 static struct breakpoint_ops strace_marker_breakpoint_ops
;
14005 strace_marker_p (struct breakpoint
*b
)
14007 return b
->ops
== &strace_marker_breakpoint_ops
;
14010 /* Delete a breakpoint and clean up all traces of it in the data
14014 delete_breakpoint (struct breakpoint
*bpt
)
14016 struct breakpoint
*b
;
14018 gdb_assert (bpt
!= NULL
);
14020 /* Has this bp already been deleted? This can happen because
14021 multiple lists can hold pointers to bp's. bpstat lists are
14024 One example of this happening is a watchpoint's scope bp. When
14025 the scope bp triggers, we notice that the watchpoint is out of
14026 scope, and delete it. We also delete its scope bp. But the
14027 scope bp is marked "auto-deleting", and is already on a bpstat.
14028 That bpstat is then checked for auto-deleting bp's, which are
14031 A real solution to this problem might involve reference counts in
14032 bp's, and/or giving them pointers back to their referencing
14033 bpstat's, and teaching delete_breakpoint to only free a bp's
14034 storage when no more references were extent. A cheaper bandaid
14036 if (bpt
->type
== bp_none
)
14039 /* At least avoid this stale reference until the reference counting
14040 of breakpoints gets resolved. */
14041 if (bpt
->related_breakpoint
!= bpt
)
14043 struct breakpoint
*related
;
14044 struct watchpoint
*w
;
14046 if (bpt
->type
== bp_watchpoint_scope
)
14047 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
14048 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
14049 w
= (struct watchpoint
*) bpt
;
14053 watchpoint_del_at_next_stop (w
);
14055 /* Unlink bpt from the bpt->related_breakpoint ring. */
14056 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
14057 related
= related
->related_breakpoint
);
14058 related
->related_breakpoint
= bpt
->related_breakpoint
;
14059 bpt
->related_breakpoint
= bpt
;
14062 /* watch_command_1 creates a watchpoint but only sets its number if
14063 update_watchpoint succeeds in creating its bp_locations. If there's
14064 a problem in that process, we'll be asked to delete the half-created
14065 watchpoint. In that case, don't announce the deletion. */
14067 observer_notify_breakpoint_deleted (bpt
);
14069 if (breakpoint_chain
== bpt
)
14070 breakpoint_chain
= bpt
->next
;
14072 ALL_BREAKPOINTS (b
)
14073 if (b
->next
== bpt
)
14075 b
->next
= bpt
->next
;
14079 /* Be sure no bpstat's are pointing at the breakpoint after it's
14081 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14082 in all threads for now. Note that we cannot just remove bpstats
14083 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14084 commands are associated with the bpstat; if we remove it here,
14085 then the later call to bpstat_do_actions (&stop_bpstat); in
14086 event-top.c won't do anything, and temporary breakpoints with
14087 commands won't work. */
14089 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
14091 /* Now that breakpoint is removed from breakpoint list, update the
14092 global location list. This will remove locations that used to
14093 belong to this breakpoint. Do this before freeing the breakpoint
14094 itself, since remove_breakpoint looks at location's owner. It
14095 might be better design to have location completely
14096 self-contained, but it's not the case now. */
14097 update_global_location_list (UGLL_DONT_INSERT
);
14099 bpt
->ops
->dtor (bpt
);
14100 /* On the chance that someone will soon try again to delete this
14101 same bp, we mark it as deleted before freeing its storage. */
14102 bpt
->type
= bp_none
;
14107 do_delete_breakpoint_cleanup (void *b
)
14109 delete_breakpoint (b
);
14113 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
14115 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
14118 /* Iterator function to call a user-provided callback function once
14119 for each of B and its related breakpoints. */
14122 iterate_over_related_breakpoints (struct breakpoint
*b
,
14123 void (*function
) (struct breakpoint
*,
14127 struct breakpoint
*related
;
14132 struct breakpoint
*next
;
14134 /* FUNCTION may delete RELATED. */
14135 next
= related
->related_breakpoint
;
14137 if (next
== related
)
14139 /* RELATED is the last ring entry. */
14140 function (related
, data
);
14142 /* FUNCTION may have deleted it, so we'd never reach back to
14143 B. There's nothing left to do anyway, so just break
14148 function (related
, data
);
14152 while (related
!= b
);
14156 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14158 delete_breakpoint (b
);
14161 /* A callback for map_breakpoint_numbers that calls
14162 delete_breakpoint. */
14165 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14167 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14171 delete_command (char *arg
, int from_tty
)
14173 struct breakpoint
*b
, *b_tmp
;
14179 int breaks_to_delete
= 0;
14181 /* Delete all breakpoints if no argument. Do not delete
14182 internal breakpoints, these have to be deleted with an
14183 explicit breakpoint number argument. */
14184 ALL_BREAKPOINTS (b
)
14185 if (user_breakpoint_p (b
))
14187 breaks_to_delete
= 1;
14191 /* Ask user only if there are some breakpoints to delete. */
14193 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14195 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14196 if (user_breakpoint_p (b
))
14197 delete_breakpoint (b
);
14201 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14205 all_locations_are_pending (struct bp_location
*loc
)
14207 for (; loc
; loc
= loc
->next
)
14208 if (!loc
->shlib_disabled
14209 && !loc
->pspace
->executing_startup
)
14214 /* Subroutine of update_breakpoint_locations to simplify it.
14215 Return non-zero if multiple fns in list LOC have the same name.
14216 Null names are ignored. */
14219 ambiguous_names_p (struct bp_location
*loc
)
14221 struct bp_location
*l
;
14222 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14223 (int (*) (const void *,
14224 const void *)) streq
,
14225 NULL
, xcalloc
, xfree
);
14227 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14230 const char *name
= l
->function_name
;
14232 /* Allow for some names to be NULL, ignore them. */
14236 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14238 /* NOTE: We can assume slot != NULL here because xcalloc never
14242 htab_delete (htab
);
14248 htab_delete (htab
);
14252 /* When symbols change, it probably means the sources changed as well,
14253 and it might mean the static tracepoint markers are no longer at
14254 the same address or line numbers they used to be at last we
14255 checked. Losing your static tracepoints whenever you rebuild is
14256 undesirable. This function tries to resync/rematch gdb static
14257 tracepoints with the markers on the target, for static tracepoints
14258 that have not been set by marker id. Static tracepoint that have
14259 been set by marker id are reset by marker id in breakpoint_re_set.
14262 1) For a tracepoint set at a specific address, look for a marker at
14263 the old PC. If one is found there, assume to be the same marker.
14264 If the name / string id of the marker found is different from the
14265 previous known name, assume that means the user renamed the marker
14266 in the sources, and output a warning.
14268 2) For a tracepoint set at a given line number, look for a marker
14269 at the new address of the old line number. If one is found there,
14270 assume to be the same marker. If the name / string id of the
14271 marker found is different from the previous known name, assume that
14272 means the user renamed the marker in the sources, and output a
14275 3) If a marker is no longer found at the same address or line, it
14276 may mean the marker no longer exists. But it may also just mean
14277 the code changed a bit. Maybe the user added a few lines of code
14278 that made the marker move up or down (in line number terms). Ask
14279 the target for info about the marker with the string id as we knew
14280 it. If found, update line number and address in the matching
14281 static tracepoint. This will get confused if there's more than one
14282 marker with the same ID (possible in UST, although unadvised
14283 precisely because it confuses tools). */
14285 static struct symtab_and_line
14286 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14288 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14289 struct static_tracepoint_marker marker
;
14294 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14296 if (target_static_tracepoint_marker_at (pc
, &marker
))
14298 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14299 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14301 tp
->static_trace_marker_id
, marker
.str_id
);
14303 xfree (tp
->static_trace_marker_id
);
14304 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14305 release_static_tracepoint_marker (&marker
);
14310 /* Old marker wasn't found on target at lineno. Try looking it up
14312 if (!sal
.explicit_pc
14314 && sal
.symtab
!= NULL
14315 && tp
->static_trace_marker_id
!= NULL
)
14317 VEC(static_tracepoint_marker_p
) *markers
;
14320 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14322 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14324 struct symtab_and_line sal2
;
14325 struct symbol
*sym
;
14326 struct static_tracepoint_marker
*tpmarker
;
14327 struct ui_out
*uiout
= current_uiout
;
14329 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14331 xfree (tp
->static_trace_marker_id
);
14332 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14334 warning (_("marker for static tracepoint %d (%s) not "
14335 "found at previous line number"),
14336 b
->number
, tp
->static_trace_marker_id
);
14340 sal2
.pc
= tpmarker
->address
;
14342 sal2
= find_pc_line (tpmarker
->address
, 0);
14343 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14344 ui_out_text (uiout
, "Now in ");
14347 ui_out_field_string (uiout
, "func",
14348 SYMBOL_PRINT_NAME (sym
));
14349 ui_out_text (uiout
, " at ");
14351 ui_out_field_string (uiout
, "file",
14352 symtab_to_filename_for_display (sal2
.symtab
));
14353 ui_out_text (uiout
, ":");
14355 if (ui_out_is_mi_like_p (uiout
))
14357 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14359 ui_out_field_string (uiout
, "fullname", fullname
);
14362 ui_out_field_int (uiout
, "line", sal2
.line
);
14363 ui_out_text (uiout
, "\n");
14365 b
->loc
->line_number
= sal2
.line
;
14366 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14368 xfree (b
->addr_string
);
14369 b
->addr_string
= xstrprintf ("%s:%d",
14370 symtab_to_filename_for_display (sal2
.symtab
),
14371 b
->loc
->line_number
);
14373 /* Might be nice to check if function changed, and warn if
14376 release_static_tracepoint_marker (tpmarker
);
14382 /* Returns 1 iff locations A and B are sufficiently same that
14383 we don't need to report breakpoint as changed. */
14386 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14390 if (a
->address
!= b
->address
)
14393 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14396 if (a
->enabled
!= b
->enabled
)
14403 if ((a
== NULL
) != (b
== NULL
))
14409 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14410 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14411 a ranged breakpoint. */
14414 update_breakpoint_locations (struct breakpoint
*b
,
14415 struct symtabs_and_lines sals
,
14416 struct symtabs_and_lines sals_end
)
14419 struct bp_location
*existing_locations
= b
->loc
;
14421 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14423 /* Ranged breakpoints have only one start location and one end
14425 b
->enable_state
= bp_disabled
;
14426 update_global_location_list (UGLL_MAY_INSERT
);
14427 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14428 "multiple locations found\n"),
14433 /* If there's no new locations, and all existing locations are
14434 pending, don't do anything. This optimizes the common case where
14435 all locations are in the same shared library, that was unloaded.
14436 We'd like to retain the location, so that when the library is
14437 loaded again, we don't loose the enabled/disabled status of the
14438 individual locations. */
14439 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14444 for (i
= 0; i
< sals
.nelts
; ++i
)
14446 struct bp_location
*new_loc
;
14448 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14450 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14452 /* Reparse conditions, they might contain references to the
14454 if (b
->cond_string
!= NULL
)
14457 volatile struct gdb_exception e
;
14459 s
= b
->cond_string
;
14460 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14462 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14463 block_for_pc (sals
.sals
[i
].pc
),
14468 warning (_("failed to reevaluate condition "
14469 "for breakpoint %d: %s"),
14470 b
->number
, e
.message
);
14471 new_loc
->enabled
= 0;
14475 if (sals_end
.nelts
)
14477 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14479 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14483 /* If possible, carry over 'disable' status from existing
14486 struct bp_location
*e
= existing_locations
;
14487 /* If there are multiple breakpoints with the same function name,
14488 e.g. for inline functions, comparing function names won't work.
14489 Instead compare pc addresses; this is just a heuristic as things
14490 may have moved, but in practice it gives the correct answer
14491 often enough until a better solution is found. */
14492 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14494 for (; e
; e
= e
->next
)
14496 if (!e
->enabled
&& e
->function_name
)
14498 struct bp_location
*l
= b
->loc
;
14499 if (have_ambiguous_names
)
14501 for (; l
; l
= l
->next
)
14502 if (breakpoint_locations_match (e
, l
))
14510 for (; l
; l
= l
->next
)
14511 if (l
->function_name
14512 && strcmp (e
->function_name
, l
->function_name
) == 0)
14522 if (!locations_are_equal (existing_locations
, b
->loc
))
14523 observer_notify_breakpoint_modified (b
);
14525 update_global_location_list (UGLL_MAY_INSERT
);
14528 /* Find the SaL locations corresponding to the given ADDR_STRING.
14529 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14531 static struct symtabs_and_lines
14532 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14535 struct symtabs_and_lines sals
= {0};
14536 volatile struct gdb_exception e
;
14538 gdb_assert (b
->ops
!= NULL
);
14541 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14543 b
->ops
->decode_linespec (b
, &s
, &sals
);
14547 int not_found_and_ok
= 0;
14548 /* For pending breakpoints, it's expected that parsing will
14549 fail until the right shared library is loaded. User has
14550 already told to create pending breakpoints and don't need
14551 extra messages. If breakpoint is in bp_shlib_disabled
14552 state, then user already saw the message about that
14553 breakpoint being disabled, and don't want to see more
14555 if (e
.error
== NOT_FOUND_ERROR
14556 && (b
->condition_not_parsed
14557 || (b
->loc
&& b
->loc
->shlib_disabled
)
14558 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14559 || b
->enable_state
== bp_disabled
))
14560 not_found_and_ok
= 1;
14562 if (!not_found_and_ok
)
14564 /* We surely don't want to warn about the same breakpoint
14565 10 times. One solution, implemented here, is disable
14566 the breakpoint on error. Another solution would be to
14567 have separate 'warning emitted' flag. Since this
14568 happens only when a binary has changed, I don't know
14569 which approach is better. */
14570 b
->enable_state
= bp_disabled
;
14571 throw_exception (e
);
14575 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14579 for (i
= 0; i
< sals
.nelts
; ++i
)
14580 resolve_sal_pc (&sals
.sals
[i
]);
14581 if (b
->condition_not_parsed
&& s
&& s
[0])
14583 char *cond_string
, *extra_string
;
14586 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14587 &cond_string
, &thread
, &task
,
14590 b
->cond_string
= cond_string
;
14591 b
->thread
= thread
;
14594 b
->extra_string
= extra_string
;
14595 b
->condition_not_parsed
= 0;
14598 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14599 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14609 /* The default re_set method, for typical hardware or software
14610 breakpoints. Reevaluate the breakpoint and recreate its
14614 breakpoint_re_set_default (struct breakpoint
*b
)
14617 struct symtabs_and_lines sals
, sals_end
;
14618 struct symtabs_and_lines expanded
= {0};
14619 struct symtabs_and_lines expanded_end
= {0};
14621 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14624 make_cleanup (xfree
, sals
.sals
);
14628 if (b
->addr_string_range_end
)
14630 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14633 make_cleanup (xfree
, sals_end
.sals
);
14634 expanded_end
= sals_end
;
14638 update_breakpoint_locations (b
, expanded
, expanded_end
);
14641 /* Default method for creating SALs from an address string. It basically
14642 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14645 create_sals_from_address_default (char **arg
,
14646 struct linespec_result
*canonical
,
14647 enum bptype type_wanted
,
14648 char *addr_start
, char **copy_arg
)
14650 parse_breakpoint_sals (arg
, canonical
);
14653 /* Call create_breakpoints_sal for the given arguments. This is the default
14654 function for the `create_breakpoints_sal' method of
14658 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14659 struct linespec_result
*canonical
,
14661 char *extra_string
,
14662 enum bptype type_wanted
,
14663 enum bpdisp disposition
,
14665 int task
, int ignore_count
,
14666 const struct breakpoint_ops
*ops
,
14667 int from_tty
, int enabled
,
14668 int internal
, unsigned flags
)
14670 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14672 type_wanted
, disposition
,
14673 thread
, task
, ignore_count
, ops
, from_tty
,
14674 enabled
, internal
, flags
);
14677 /* Decode the line represented by S by calling decode_line_full. This is the
14678 default function for the `decode_linespec' method of breakpoint_ops. */
14681 decode_linespec_default (struct breakpoint
*b
, char **s
,
14682 struct symtabs_and_lines
*sals
)
14684 struct linespec_result canonical
;
14686 init_linespec_result (&canonical
);
14687 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14688 (struct symtab
*) NULL
, 0,
14689 &canonical
, multiple_symbols_all
,
14692 /* We should get 0 or 1 resulting SALs. */
14693 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14695 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14697 struct linespec_sals
*lsal
;
14699 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14700 *sals
= lsal
->sals
;
14701 /* Arrange it so the destructor does not free the
14703 lsal
->sals
.sals
= NULL
;
14706 destroy_linespec_result (&canonical
);
14709 /* Prepare the global context for a re-set of breakpoint B. */
14711 static struct cleanup
*
14712 prepare_re_set_context (struct breakpoint
*b
)
14714 struct cleanup
*cleanups
;
14716 input_radix
= b
->input_radix
;
14717 cleanups
= save_current_space_and_thread ();
14718 if (b
->pspace
!= NULL
)
14719 switch_to_program_space_and_thread (b
->pspace
);
14720 set_language (b
->language
);
14725 /* Reset a breakpoint given it's struct breakpoint * BINT.
14726 The value we return ends up being the return value from catch_errors.
14727 Unused in this case. */
14730 breakpoint_re_set_one (void *bint
)
14732 /* Get past catch_errs. */
14733 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14734 struct cleanup
*cleanups
;
14736 cleanups
= prepare_re_set_context (b
);
14737 b
->ops
->re_set (b
);
14738 do_cleanups (cleanups
);
14742 /* Re-set all breakpoints after symbols have been re-loaded. */
14744 breakpoint_re_set (void)
14746 struct breakpoint
*b
, *b_tmp
;
14747 enum language save_language
;
14748 int save_input_radix
;
14749 struct cleanup
*old_chain
;
14751 save_language
= current_language
->la_language
;
14752 save_input_radix
= input_radix
;
14753 old_chain
= save_current_program_space ();
14755 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14757 /* Format possible error msg. */
14758 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14760 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14761 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14762 do_cleanups (cleanups
);
14764 set_language (save_language
);
14765 input_radix
= save_input_radix
;
14767 jit_breakpoint_re_set ();
14769 do_cleanups (old_chain
);
14771 create_overlay_event_breakpoint ();
14772 create_longjmp_master_breakpoint ();
14773 create_std_terminate_master_breakpoint ();
14774 create_exception_master_breakpoint ();
14777 /* Reset the thread number of this breakpoint:
14779 - If the breakpoint is for all threads, leave it as-is.
14780 - Else, reset it to the current thread for inferior_ptid. */
14782 breakpoint_re_set_thread (struct breakpoint
*b
)
14784 if (b
->thread
!= -1)
14786 if (in_thread_list (inferior_ptid
))
14787 b
->thread
= pid_to_thread_id (inferior_ptid
);
14789 /* We're being called after following a fork. The new fork is
14790 selected as current, and unless this was a vfork will have a
14791 different program space from the original thread. Reset that
14793 b
->loc
->pspace
= current_program_space
;
14797 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14798 If from_tty is nonzero, it prints a message to that effect,
14799 which ends with a period (no newline). */
14802 set_ignore_count (int bptnum
, int count
, int from_tty
)
14804 struct breakpoint
*b
;
14809 ALL_BREAKPOINTS (b
)
14810 if (b
->number
== bptnum
)
14812 if (is_tracepoint (b
))
14814 if (from_tty
&& count
!= 0)
14815 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14820 b
->ignore_count
= count
;
14824 printf_filtered (_("Will stop next time "
14825 "breakpoint %d is reached."),
14827 else if (count
== 1)
14828 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14831 printf_filtered (_("Will ignore next %d "
14832 "crossings of breakpoint %d."),
14835 observer_notify_breakpoint_modified (b
);
14839 error (_("No breakpoint number %d."), bptnum
);
14842 /* Command to set ignore-count of breakpoint N to COUNT. */
14845 ignore_command (char *args
, int from_tty
)
14851 error_no_arg (_("a breakpoint number"));
14853 num
= get_number (&p
);
14855 error (_("bad breakpoint number: '%s'"), args
);
14857 error (_("Second argument (specified ignore-count) is missing."));
14859 set_ignore_count (num
,
14860 longest_to_int (value_as_long (parse_and_eval (p
))),
14863 printf_filtered ("\n");
14866 /* Call FUNCTION on each of the breakpoints
14867 whose numbers are given in ARGS. */
14870 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14875 struct breakpoint
*b
, *tmp
;
14877 struct get_number_or_range_state state
;
14879 if (args
== 0 || *args
== '\0')
14880 error_no_arg (_("one or more breakpoint numbers"));
14882 init_number_or_range (&state
, args
);
14884 while (!state
.finished
)
14886 const char *p
= state
.string
;
14890 num
= get_number_or_range (&state
);
14893 warning (_("bad breakpoint number at or near '%s'"), p
);
14897 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14898 if (b
->number
== num
)
14901 function (b
, data
);
14905 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14910 static struct bp_location
*
14911 find_location_by_number (char *number
)
14913 char *dot
= strchr (number
, '.');
14917 struct breakpoint
*b
;
14918 struct bp_location
*loc
;
14923 bp_num
= get_number (&p1
);
14925 error (_("Bad breakpoint number '%s'"), number
);
14927 ALL_BREAKPOINTS (b
)
14928 if (b
->number
== bp_num
)
14933 if (!b
|| b
->number
!= bp_num
)
14934 error (_("Bad breakpoint number '%s'"), number
);
14937 loc_num
= get_number (&p1
);
14939 error (_("Bad breakpoint location number '%s'"), number
);
14943 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14946 error (_("Bad breakpoint location number '%s'"), dot
+1);
14952 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14953 If from_tty is nonzero, it prints a message to that effect,
14954 which ends with a period (no newline). */
14957 disable_breakpoint (struct breakpoint
*bpt
)
14959 /* Never disable a watchpoint scope breakpoint; we want to
14960 hit them when we leave scope so we can delete both the
14961 watchpoint and its scope breakpoint at that time. */
14962 if (bpt
->type
== bp_watchpoint_scope
)
14965 bpt
->enable_state
= bp_disabled
;
14967 /* Mark breakpoint locations modified. */
14968 mark_breakpoint_modified (bpt
);
14970 if (target_supports_enable_disable_tracepoint ()
14971 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14973 struct bp_location
*location
;
14975 for (location
= bpt
->loc
; location
; location
= location
->next
)
14976 target_disable_tracepoint (location
);
14979 update_global_location_list (UGLL_DONT_INSERT
);
14981 observer_notify_breakpoint_modified (bpt
);
14984 /* A callback for iterate_over_related_breakpoints. */
14987 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14989 disable_breakpoint (b
);
14992 /* A callback for map_breakpoint_numbers that calls
14993 disable_breakpoint. */
14996 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14998 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
15002 disable_command (char *args
, int from_tty
)
15006 struct breakpoint
*bpt
;
15008 ALL_BREAKPOINTS (bpt
)
15009 if (user_breakpoint_p (bpt
))
15010 disable_breakpoint (bpt
);
15014 char *num
= extract_arg (&args
);
15018 if (strchr (num
, '.'))
15020 struct bp_location
*loc
= find_location_by_number (num
);
15027 mark_breakpoint_location_modified (loc
);
15029 if (target_supports_enable_disable_tracepoint ()
15030 && current_trace_status ()->running
&& loc
->owner
15031 && is_tracepoint (loc
->owner
))
15032 target_disable_tracepoint (loc
);
15034 update_global_location_list (UGLL_DONT_INSERT
);
15037 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
15038 num
= extract_arg (&args
);
15044 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
15047 int target_resources_ok
;
15049 if (bpt
->type
== bp_hardware_breakpoint
)
15052 i
= hw_breakpoint_used_count ();
15053 target_resources_ok
=
15054 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
15056 if (target_resources_ok
== 0)
15057 error (_("No hardware breakpoint support in the target."));
15058 else if (target_resources_ok
< 0)
15059 error (_("Hardware breakpoints used exceeds limit."));
15062 if (is_watchpoint (bpt
))
15064 /* Initialize it just to avoid a GCC false warning. */
15065 enum enable_state orig_enable_state
= 0;
15066 volatile struct gdb_exception e
;
15068 TRY_CATCH (e
, RETURN_MASK_ALL
)
15070 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
15072 orig_enable_state
= bpt
->enable_state
;
15073 bpt
->enable_state
= bp_enabled
;
15074 update_watchpoint (w
, 1 /* reparse */);
15078 bpt
->enable_state
= orig_enable_state
;
15079 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15085 bpt
->enable_state
= bp_enabled
;
15087 /* Mark breakpoint locations modified. */
15088 mark_breakpoint_modified (bpt
);
15090 if (target_supports_enable_disable_tracepoint ()
15091 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15093 struct bp_location
*location
;
15095 for (location
= bpt
->loc
; location
; location
= location
->next
)
15096 target_enable_tracepoint (location
);
15099 bpt
->disposition
= disposition
;
15100 bpt
->enable_count
= count
;
15101 update_global_location_list (UGLL_MAY_INSERT
);
15103 observer_notify_breakpoint_modified (bpt
);
15108 enable_breakpoint (struct breakpoint
*bpt
)
15110 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15114 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15116 enable_breakpoint (bpt
);
15119 /* A callback for map_breakpoint_numbers that calls
15120 enable_breakpoint. */
15123 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15125 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15128 /* The enable command enables the specified breakpoints (or all defined
15129 breakpoints) so they once again become (or continue to be) effective
15130 in stopping the inferior. */
15133 enable_command (char *args
, int from_tty
)
15137 struct breakpoint
*bpt
;
15139 ALL_BREAKPOINTS (bpt
)
15140 if (user_breakpoint_p (bpt
))
15141 enable_breakpoint (bpt
);
15145 char *num
= extract_arg (&args
);
15149 if (strchr (num
, '.'))
15151 struct bp_location
*loc
= find_location_by_number (num
);
15158 mark_breakpoint_location_modified (loc
);
15160 if (target_supports_enable_disable_tracepoint ()
15161 && current_trace_status ()->running
&& loc
->owner
15162 && is_tracepoint (loc
->owner
))
15163 target_enable_tracepoint (loc
);
15165 update_global_location_list (UGLL_MAY_INSERT
);
15168 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15169 num
= extract_arg (&args
);
15174 /* This struct packages up disposition data for application to multiple
15184 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15186 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15188 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15192 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15194 struct disp_data disp
= { disp_disable
, 1 };
15196 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15200 enable_once_command (char *args
, int from_tty
)
15202 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15206 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15208 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15210 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15214 enable_count_command (char *args
, int from_tty
)
15219 error_no_arg (_("hit count"));
15221 count
= get_number (&args
);
15223 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15227 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15229 struct disp_data disp
= { disp_del
, 1 };
15231 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15235 enable_delete_command (char *args
, int from_tty
)
15237 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15241 set_breakpoint_cmd (char *args
, int from_tty
)
15246 show_breakpoint_cmd (char *args
, int from_tty
)
15250 /* Invalidate last known value of any hardware watchpoint if
15251 the memory which that value represents has been written to by
15255 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15256 CORE_ADDR addr
, ssize_t len
,
15257 const bfd_byte
*data
)
15259 struct breakpoint
*bp
;
15261 ALL_BREAKPOINTS (bp
)
15262 if (bp
->enable_state
== bp_enabled
15263 && bp
->type
== bp_hardware_watchpoint
)
15265 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15267 if (wp
->val_valid
&& wp
->val
)
15269 struct bp_location
*loc
;
15271 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15272 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15273 && loc
->address
+ loc
->length
> addr
15274 && addr
+ len
> loc
->address
)
15276 value_free (wp
->val
);
15284 /* Create and insert a breakpoint for software single step. */
15287 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15288 struct address_space
*aspace
,
15291 struct thread_info
*tp
= inferior_thread ();
15292 struct symtab_and_line sal
;
15293 CORE_ADDR pc
= next_pc
;
15295 if (tp
->control
.single_step_breakpoints
== NULL
)
15297 tp
->control
.single_step_breakpoints
15298 = new_single_step_breakpoint (tp
->num
, gdbarch
);
15301 sal
= find_pc_line (pc
, 0);
15303 sal
.section
= find_pc_overlay (pc
);
15304 sal
.explicit_pc
= 1;
15305 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15307 update_global_location_list (UGLL_INSERT
);
15310 /* See breakpoint.h. */
15313 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15314 struct address_space
*aspace
,
15317 struct bp_location
*loc
;
15319 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15321 && breakpoint_location_address_match (loc
, aspace
, pc
))
15327 /* Check whether a software single-step breakpoint is inserted at
15331 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15334 struct breakpoint
*bpt
;
15336 ALL_BREAKPOINTS (bpt
)
15338 if (bpt
->type
== bp_single_step
15339 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15345 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15346 non-zero otherwise. */
15348 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15350 if (syscall_catchpoint_p (bp
)
15351 && bp
->enable_state
!= bp_disabled
15352 && bp
->enable_state
!= bp_call_disabled
)
15359 catch_syscall_enabled (void)
15361 struct catch_syscall_inferior_data
*inf_data
15362 = get_catch_syscall_inferior_data (current_inferior ());
15364 return inf_data
->total_syscalls_count
!= 0;
15368 catching_syscall_number (int syscall_number
)
15370 struct breakpoint
*bp
;
15372 ALL_BREAKPOINTS (bp
)
15373 if (is_syscall_catchpoint_enabled (bp
))
15375 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15377 if (c
->syscalls_to_be_caught
)
15381 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15383 if (syscall_number
== iter
)
15393 /* Complete syscall names. Used by "catch syscall". */
15394 static VEC (char_ptr
) *
15395 catch_syscall_completer (struct cmd_list_element
*cmd
,
15396 const char *text
, const char *word
)
15398 const char **list
= get_syscall_names (get_current_arch ());
15399 VEC (char_ptr
) *retlist
15400 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15406 /* Tracepoint-specific operations. */
15408 /* Set tracepoint count to NUM. */
15410 set_tracepoint_count (int num
)
15412 tracepoint_count
= num
;
15413 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15417 trace_command (char *arg
, int from_tty
)
15419 struct breakpoint_ops
*ops
;
15420 const char *arg_cp
= arg
;
15422 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15423 ops
= &tracepoint_probe_breakpoint_ops
;
15425 ops
= &tracepoint_breakpoint_ops
;
15427 create_breakpoint (get_current_arch (),
15429 NULL
, 0, NULL
, 1 /* parse arg */,
15431 bp_tracepoint
/* type_wanted */,
15432 0 /* Ignore count */,
15433 pending_break_support
,
15437 0 /* internal */, 0);
15441 ftrace_command (char *arg
, int from_tty
)
15443 create_breakpoint (get_current_arch (),
15445 NULL
, 0, NULL
, 1 /* parse arg */,
15447 bp_fast_tracepoint
/* type_wanted */,
15448 0 /* Ignore count */,
15449 pending_break_support
,
15450 &tracepoint_breakpoint_ops
,
15453 0 /* internal */, 0);
15456 /* strace command implementation. Creates a static tracepoint. */
15459 strace_command (char *arg
, int from_tty
)
15461 struct breakpoint_ops
*ops
;
15463 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15464 or with a normal static tracepoint. */
15465 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15466 ops
= &strace_marker_breakpoint_ops
;
15468 ops
= &tracepoint_breakpoint_ops
;
15470 create_breakpoint (get_current_arch (),
15472 NULL
, 0, NULL
, 1 /* parse arg */,
15474 bp_static_tracepoint
/* type_wanted */,
15475 0 /* Ignore count */,
15476 pending_break_support
,
15480 0 /* internal */, 0);
15483 /* Set up a fake reader function that gets command lines from a linked
15484 list that was acquired during tracepoint uploading. */
15486 static struct uploaded_tp
*this_utp
;
15487 static int next_cmd
;
15490 read_uploaded_action (void)
15494 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15501 /* Given information about a tracepoint as recorded on a target (which
15502 can be either a live system or a trace file), attempt to create an
15503 equivalent GDB tracepoint. This is not a reliable process, since
15504 the target does not necessarily have all the information used when
15505 the tracepoint was originally defined. */
15507 struct tracepoint
*
15508 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15510 char *addr_str
, small_buf
[100];
15511 struct tracepoint
*tp
;
15513 if (utp
->at_string
)
15514 addr_str
= utp
->at_string
;
15517 /* In the absence of a source location, fall back to raw
15518 address. Since there is no way to confirm that the address
15519 means the same thing as when the trace was started, warn the
15521 warning (_("Uploaded tracepoint %d has no "
15522 "source location, using raw address"),
15524 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15525 addr_str
= small_buf
;
15528 /* There's not much we can do with a sequence of bytecodes. */
15529 if (utp
->cond
&& !utp
->cond_string
)
15530 warning (_("Uploaded tracepoint %d condition "
15531 "has no source form, ignoring it"),
15534 if (!create_breakpoint (get_current_arch (),
15536 utp
->cond_string
, -1, NULL
,
15537 0 /* parse cond/thread */,
15539 utp
->type
/* type_wanted */,
15540 0 /* Ignore count */,
15541 pending_break_support
,
15542 &tracepoint_breakpoint_ops
,
15544 utp
->enabled
/* enabled */,
15546 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15549 /* Get the tracepoint we just created. */
15550 tp
= get_tracepoint (tracepoint_count
);
15551 gdb_assert (tp
!= NULL
);
15555 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15558 trace_pass_command (small_buf
, 0);
15561 /* If we have uploaded versions of the original commands, set up a
15562 special-purpose "reader" function and call the usual command line
15563 reader, then pass the result to the breakpoint command-setting
15565 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15567 struct command_line
*cmd_list
;
15572 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15574 breakpoint_set_commands (&tp
->base
, cmd_list
);
15576 else if (!VEC_empty (char_ptr
, utp
->actions
)
15577 || !VEC_empty (char_ptr
, utp
->step_actions
))
15578 warning (_("Uploaded tracepoint %d actions "
15579 "have no source form, ignoring them"),
15582 /* Copy any status information that might be available. */
15583 tp
->base
.hit_count
= utp
->hit_count
;
15584 tp
->traceframe_usage
= utp
->traceframe_usage
;
15589 /* Print information on tracepoint number TPNUM_EXP, or all if
15593 tracepoints_info (char *args
, int from_tty
)
15595 struct ui_out
*uiout
= current_uiout
;
15598 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15600 if (num_printed
== 0)
15602 if (args
== NULL
|| *args
== '\0')
15603 ui_out_message (uiout
, 0, "No tracepoints.\n");
15605 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15608 default_collect_info ();
15611 /* The 'enable trace' command enables tracepoints.
15612 Not supported by all targets. */
15614 enable_trace_command (char *args
, int from_tty
)
15616 enable_command (args
, from_tty
);
15619 /* The 'disable trace' command disables tracepoints.
15620 Not supported by all targets. */
15622 disable_trace_command (char *args
, int from_tty
)
15624 disable_command (args
, from_tty
);
15627 /* Remove a tracepoint (or all if no argument). */
15629 delete_trace_command (char *arg
, int from_tty
)
15631 struct breakpoint
*b
, *b_tmp
;
15637 int breaks_to_delete
= 0;
15639 /* Delete all breakpoints if no argument.
15640 Do not delete internal or call-dummy breakpoints, these
15641 have to be deleted with an explicit breakpoint number
15643 ALL_TRACEPOINTS (b
)
15644 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15646 breaks_to_delete
= 1;
15650 /* Ask user only if there are some breakpoints to delete. */
15652 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15654 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15655 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15656 delete_breakpoint (b
);
15660 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15663 /* Helper function for trace_pass_command. */
15666 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15668 tp
->pass_count
= count
;
15669 observer_notify_breakpoint_modified (&tp
->base
);
15671 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15672 tp
->base
.number
, count
);
15675 /* Set passcount for tracepoint.
15677 First command argument is passcount, second is tracepoint number.
15678 If tracepoint number omitted, apply to most recently defined.
15679 Also accepts special argument "all". */
15682 trace_pass_command (char *args
, int from_tty
)
15684 struct tracepoint
*t1
;
15685 unsigned int count
;
15687 if (args
== 0 || *args
== 0)
15688 error (_("passcount command requires an "
15689 "argument (count + optional TP num)"));
15691 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15693 args
= skip_spaces (args
);
15694 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15696 struct breakpoint
*b
;
15698 args
+= 3; /* Skip special argument "all". */
15700 error (_("Junk at end of arguments."));
15702 ALL_TRACEPOINTS (b
)
15704 t1
= (struct tracepoint
*) b
;
15705 trace_pass_set_count (t1
, count
, from_tty
);
15708 else if (*args
== '\0')
15710 t1
= get_tracepoint_by_number (&args
, NULL
);
15712 trace_pass_set_count (t1
, count
, from_tty
);
15716 struct get_number_or_range_state state
;
15718 init_number_or_range (&state
, args
);
15719 while (!state
.finished
)
15721 t1
= get_tracepoint_by_number (&args
, &state
);
15723 trace_pass_set_count (t1
, count
, from_tty
);
15728 struct tracepoint
*
15729 get_tracepoint (int num
)
15731 struct breakpoint
*t
;
15733 ALL_TRACEPOINTS (t
)
15734 if (t
->number
== num
)
15735 return (struct tracepoint
*) t
;
15740 /* Find the tracepoint with the given target-side number (which may be
15741 different from the tracepoint number after disconnecting and
15744 struct tracepoint
*
15745 get_tracepoint_by_number_on_target (int num
)
15747 struct breakpoint
*b
;
15749 ALL_TRACEPOINTS (b
)
15751 struct tracepoint
*t
= (struct tracepoint
*) b
;
15753 if (t
->number_on_target
== num
)
15760 /* Utility: parse a tracepoint number and look it up in the list.
15761 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15762 If the argument is missing, the most recent tracepoint
15763 (tracepoint_count) is returned. */
15765 struct tracepoint
*
15766 get_tracepoint_by_number (char **arg
,
15767 struct get_number_or_range_state
*state
)
15769 struct breakpoint
*t
;
15771 char *instring
= arg
== NULL
? NULL
: *arg
;
15775 gdb_assert (!state
->finished
);
15776 tpnum
= get_number_or_range (state
);
15778 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15779 tpnum
= tracepoint_count
;
15781 tpnum
= get_number (arg
);
15785 if (instring
&& *instring
)
15786 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15789 printf_filtered (_("No previous tracepoint\n"));
15793 ALL_TRACEPOINTS (t
)
15794 if (t
->number
== tpnum
)
15796 return (struct tracepoint
*) t
;
15799 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15804 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15806 if (b
->thread
!= -1)
15807 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15810 fprintf_unfiltered (fp
, " task %d", b
->task
);
15812 fprintf_unfiltered (fp
, "\n");
15815 /* Save information on user settable breakpoints (watchpoints, etc) to
15816 a new script file named FILENAME. If FILTER is non-NULL, call it
15817 on each breakpoint and only include the ones for which it returns
15821 save_breakpoints (char *filename
, int from_tty
,
15822 int (*filter
) (const struct breakpoint
*))
15824 struct breakpoint
*tp
;
15826 struct cleanup
*cleanup
;
15827 struct ui_file
*fp
;
15828 int extra_trace_bits
= 0;
15830 if (filename
== 0 || *filename
== 0)
15831 error (_("Argument required (file name in which to save)"));
15833 /* See if we have anything to save. */
15834 ALL_BREAKPOINTS (tp
)
15836 /* Skip internal and momentary breakpoints. */
15837 if (!user_breakpoint_p (tp
))
15840 /* If we have a filter, only save the breakpoints it accepts. */
15841 if (filter
&& !filter (tp
))
15846 if (is_tracepoint (tp
))
15848 extra_trace_bits
= 1;
15850 /* We can stop searching. */
15857 warning (_("Nothing to save."));
15861 filename
= tilde_expand (filename
);
15862 cleanup
= make_cleanup (xfree
, filename
);
15863 fp
= gdb_fopen (filename
, "w");
15865 error (_("Unable to open file '%s' for saving (%s)"),
15866 filename
, safe_strerror (errno
));
15867 make_cleanup_ui_file_delete (fp
);
15869 if (extra_trace_bits
)
15870 save_trace_state_variables (fp
);
15872 ALL_BREAKPOINTS (tp
)
15874 /* Skip internal and momentary breakpoints. */
15875 if (!user_breakpoint_p (tp
))
15878 /* If we have a filter, only save the breakpoints it accepts. */
15879 if (filter
&& !filter (tp
))
15882 tp
->ops
->print_recreate (tp
, fp
);
15884 /* Note, we can't rely on tp->number for anything, as we can't
15885 assume the recreated breakpoint numbers will match. Use $bpnum
15888 if (tp
->cond_string
)
15889 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15891 if (tp
->ignore_count
)
15892 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15894 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15896 volatile struct gdb_exception ex
;
15898 fprintf_unfiltered (fp
, " commands\n");
15900 ui_out_redirect (current_uiout
, fp
);
15901 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15903 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15905 ui_out_redirect (current_uiout
, NULL
);
15908 throw_exception (ex
);
15910 fprintf_unfiltered (fp
, " end\n");
15913 if (tp
->enable_state
== bp_disabled
)
15914 fprintf_unfiltered (fp
, "disable $bpnum\n");
15916 /* If this is a multi-location breakpoint, check if the locations
15917 should be individually disabled. Watchpoint locations are
15918 special, and not user visible. */
15919 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15921 struct bp_location
*loc
;
15924 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15926 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15930 if (extra_trace_bits
&& *default_collect
)
15931 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15934 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15935 do_cleanups (cleanup
);
15938 /* The `save breakpoints' command. */
15941 save_breakpoints_command (char *args
, int from_tty
)
15943 save_breakpoints (args
, from_tty
, NULL
);
15946 /* The `save tracepoints' command. */
15949 save_tracepoints_command (char *args
, int from_tty
)
15951 save_breakpoints (args
, from_tty
, is_tracepoint
);
15954 /* Create a vector of all tracepoints. */
15956 VEC(breakpoint_p
) *
15957 all_tracepoints (void)
15959 VEC(breakpoint_p
) *tp_vec
= 0;
15960 struct breakpoint
*tp
;
15962 ALL_TRACEPOINTS (tp
)
15964 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15971 /* This help string is used for the break, hbreak, tbreak and thbreak
15972 commands. It is defined as a macro to prevent duplication.
15973 COMMAND should be a string constant containing the name of the
15975 #define BREAK_ARGS_HELP(command) \
15976 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15977 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15978 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15979 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15980 `-probe-dtrace' (for a DTrace probe).\n\
15981 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15982 If a line number is specified, break at start of code for that line.\n\
15983 If a function is specified, break at start of code for that function.\n\
15984 If an address is specified, break at that exact address.\n\
15985 With no LOCATION, uses current execution address of the selected\n\
15986 stack frame. This is useful for breaking on return to a stack frame.\n\
15988 THREADNUM is the number from \"info threads\".\n\
15989 CONDITION is a boolean expression.\n\
15991 Multiple breakpoints at one place are permitted, and useful if their\n\
15992 conditions are different.\n\
15994 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15996 /* List of subcommands for "catch". */
15997 static struct cmd_list_element
*catch_cmdlist
;
15999 /* List of subcommands for "tcatch". */
16000 static struct cmd_list_element
*tcatch_cmdlist
;
16003 add_catch_command (char *name
, char *docstring
,
16004 cmd_sfunc_ftype
*sfunc
,
16005 completer_ftype
*completer
,
16006 void *user_data_catch
,
16007 void *user_data_tcatch
)
16009 struct cmd_list_element
*command
;
16011 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16013 set_cmd_sfunc (command
, sfunc
);
16014 set_cmd_context (command
, user_data_catch
);
16015 set_cmd_completer (command
, completer
);
16017 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16019 set_cmd_sfunc (command
, sfunc
);
16020 set_cmd_context (command
, user_data_tcatch
);
16021 set_cmd_completer (command
, completer
);
16025 clear_syscall_counts (struct inferior
*inf
)
16027 struct catch_syscall_inferior_data
*inf_data
16028 = get_catch_syscall_inferior_data (inf
);
16030 inf_data
->total_syscalls_count
= 0;
16031 inf_data
->any_syscall_count
= 0;
16032 VEC_free (int, inf_data
->syscalls_counts
);
16036 save_command (char *arg
, int from_tty
)
16038 printf_unfiltered (_("\"save\" must be followed by "
16039 "the name of a save subcommand.\n"));
16040 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
16043 struct breakpoint
*
16044 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
16047 struct breakpoint
*b
, *b_tmp
;
16049 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
16051 if ((*callback
) (b
, data
))
16058 /* Zero if any of the breakpoint's locations could be a location where
16059 functions have been inlined, nonzero otherwise. */
16062 is_non_inline_function (struct breakpoint
*b
)
16064 /* The shared library event breakpoint is set on the address of a
16065 non-inline function. */
16066 if (b
->type
== bp_shlib_event
)
16072 /* Nonzero if the specified PC cannot be a location where functions
16073 have been inlined. */
16076 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
16077 const struct target_waitstatus
*ws
)
16079 struct breakpoint
*b
;
16080 struct bp_location
*bl
;
16082 ALL_BREAKPOINTS (b
)
16084 if (!is_non_inline_function (b
))
16087 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16089 if (!bl
->shlib_disabled
16090 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16098 /* Remove any references to OBJFILE which is going to be freed. */
16101 breakpoint_free_objfile (struct objfile
*objfile
)
16103 struct bp_location
**locp
, *loc
;
16105 ALL_BP_LOCATIONS (loc
, locp
)
16106 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
16107 loc
->symtab
= NULL
;
16111 initialize_breakpoint_ops (void)
16113 static int initialized
= 0;
16115 struct breakpoint_ops
*ops
;
16121 /* The breakpoint_ops structure to be inherit by all kinds of
16122 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16123 internal and momentary breakpoints, etc.). */
16124 ops
= &bkpt_base_breakpoint_ops
;
16125 *ops
= base_breakpoint_ops
;
16126 ops
->re_set
= bkpt_re_set
;
16127 ops
->insert_location
= bkpt_insert_location
;
16128 ops
->remove_location
= bkpt_remove_location
;
16129 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16130 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16131 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16132 ops
->decode_linespec
= bkpt_decode_linespec
;
16134 /* The breakpoint_ops structure to be used in regular breakpoints. */
16135 ops
= &bkpt_breakpoint_ops
;
16136 *ops
= bkpt_base_breakpoint_ops
;
16137 ops
->re_set
= bkpt_re_set
;
16138 ops
->resources_needed
= bkpt_resources_needed
;
16139 ops
->print_it
= bkpt_print_it
;
16140 ops
->print_mention
= bkpt_print_mention
;
16141 ops
->print_recreate
= bkpt_print_recreate
;
16143 /* Ranged breakpoints. */
16144 ops
= &ranged_breakpoint_ops
;
16145 *ops
= bkpt_breakpoint_ops
;
16146 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16147 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16148 ops
->print_it
= print_it_ranged_breakpoint
;
16149 ops
->print_one
= print_one_ranged_breakpoint
;
16150 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16151 ops
->print_mention
= print_mention_ranged_breakpoint
;
16152 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16154 /* Internal breakpoints. */
16155 ops
= &internal_breakpoint_ops
;
16156 *ops
= bkpt_base_breakpoint_ops
;
16157 ops
->re_set
= internal_bkpt_re_set
;
16158 ops
->check_status
= internal_bkpt_check_status
;
16159 ops
->print_it
= internal_bkpt_print_it
;
16160 ops
->print_mention
= internal_bkpt_print_mention
;
16162 /* Momentary breakpoints. */
16163 ops
= &momentary_breakpoint_ops
;
16164 *ops
= bkpt_base_breakpoint_ops
;
16165 ops
->re_set
= momentary_bkpt_re_set
;
16166 ops
->check_status
= momentary_bkpt_check_status
;
16167 ops
->print_it
= momentary_bkpt_print_it
;
16168 ops
->print_mention
= momentary_bkpt_print_mention
;
16170 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16171 ops
= &longjmp_breakpoint_ops
;
16172 *ops
= momentary_breakpoint_ops
;
16173 ops
->dtor
= longjmp_bkpt_dtor
;
16175 /* Probe breakpoints. */
16176 ops
= &bkpt_probe_breakpoint_ops
;
16177 *ops
= bkpt_breakpoint_ops
;
16178 ops
->insert_location
= bkpt_probe_insert_location
;
16179 ops
->remove_location
= bkpt_probe_remove_location
;
16180 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16181 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16184 ops
= &watchpoint_breakpoint_ops
;
16185 *ops
= base_breakpoint_ops
;
16186 ops
->dtor
= dtor_watchpoint
;
16187 ops
->re_set
= re_set_watchpoint
;
16188 ops
->insert_location
= insert_watchpoint
;
16189 ops
->remove_location
= remove_watchpoint
;
16190 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16191 ops
->check_status
= check_status_watchpoint
;
16192 ops
->resources_needed
= resources_needed_watchpoint
;
16193 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16194 ops
->print_it
= print_it_watchpoint
;
16195 ops
->print_mention
= print_mention_watchpoint
;
16196 ops
->print_recreate
= print_recreate_watchpoint
;
16197 ops
->explains_signal
= explains_signal_watchpoint
;
16199 /* Masked watchpoints. */
16200 ops
= &masked_watchpoint_breakpoint_ops
;
16201 *ops
= watchpoint_breakpoint_ops
;
16202 ops
->insert_location
= insert_masked_watchpoint
;
16203 ops
->remove_location
= remove_masked_watchpoint
;
16204 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16205 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16206 ops
->print_it
= print_it_masked_watchpoint
;
16207 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16208 ops
->print_mention
= print_mention_masked_watchpoint
;
16209 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16212 ops
= &tracepoint_breakpoint_ops
;
16213 *ops
= base_breakpoint_ops
;
16214 ops
->re_set
= tracepoint_re_set
;
16215 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16216 ops
->print_one_detail
= tracepoint_print_one_detail
;
16217 ops
->print_mention
= tracepoint_print_mention
;
16218 ops
->print_recreate
= tracepoint_print_recreate
;
16219 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16220 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16221 ops
->decode_linespec
= tracepoint_decode_linespec
;
16223 /* Probe tracepoints. */
16224 ops
= &tracepoint_probe_breakpoint_ops
;
16225 *ops
= tracepoint_breakpoint_ops
;
16226 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16227 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16229 /* Static tracepoints with marker (`-m'). */
16230 ops
= &strace_marker_breakpoint_ops
;
16231 *ops
= tracepoint_breakpoint_ops
;
16232 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16233 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16234 ops
->decode_linespec
= strace_marker_decode_linespec
;
16236 /* Fork catchpoints. */
16237 ops
= &catch_fork_breakpoint_ops
;
16238 *ops
= base_breakpoint_ops
;
16239 ops
->insert_location
= insert_catch_fork
;
16240 ops
->remove_location
= remove_catch_fork
;
16241 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16242 ops
->print_it
= print_it_catch_fork
;
16243 ops
->print_one
= print_one_catch_fork
;
16244 ops
->print_mention
= print_mention_catch_fork
;
16245 ops
->print_recreate
= print_recreate_catch_fork
;
16247 /* Vfork catchpoints. */
16248 ops
= &catch_vfork_breakpoint_ops
;
16249 *ops
= base_breakpoint_ops
;
16250 ops
->insert_location
= insert_catch_vfork
;
16251 ops
->remove_location
= remove_catch_vfork
;
16252 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16253 ops
->print_it
= print_it_catch_vfork
;
16254 ops
->print_one
= print_one_catch_vfork
;
16255 ops
->print_mention
= print_mention_catch_vfork
;
16256 ops
->print_recreate
= print_recreate_catch_vfork
;
16258 /* Exec catchpoints. */
16259 ops
= &catch_exec_breakpoint_ops
;
16260 *ops
= base_breakpoint_ops
;
16261 ops
->dtor
= dtor_catch_exec
;
16262 ops
->insert_location
= insert_catch_exec
;
16263 ops
->remove_location
= remove_catch_exec
;
16264 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16265 ops
->print_it
= print_it_catch_exec
;
16266 ops
->print_one
= print_one_catch_exec
;
16267 ops
->print_mention
= print_mention_catch_exec
;
16268 ops
->print_recreate
= print_recreate_catch_exec
;
16270 /* Syscall catchpoints. */
16271 ops
= &catch_syscall_breakpoint_ops
;
16272 *ops
= base_breakpoint_ops
;
16273 ops
->dtor
= dtor_catch_syscall
;
16274 ops
->insert_location
= insert_catch_syscall
;
16275 ops
->remove_location
= remove_catch_syscall
;
16276 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16277 ops
->print_it
= print_it_catch_syscall
;
16278 ops
->print_one
= print_one_catch_syscall
;
16279 ops
->print_mention
= print_mention_catch_syscall
;
16280 ops
->print_recreate
= print_recreate_catch_syscall
;
16282 /* Solib-related catchpoints. */
16283 ops
= &catch_solib_breakpoint_ops
;
16284 *ops
= base_breakpoint_ops
;
16285 ops
->dtor
= dtor_catch_solib
;
16286 ops
->insert_location
= insert_catch_solib
;
16287 ops
->remove_location
= remove_catch_solib
;
16288 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16289 ops
->check_status
= check_status_catch_solib
;
16290 ops
->print_it
= print_it_catch_solib
;
16291 ops
->print_one
= print_one_catch_solib
;
16292 ops
->print_mention
= print_mention_catch_solib
;
16293 ops
->print_recreate
= print_recreate_catch_solib
;
16295 ops
= &dprintf_breakpoint_ops
;
16296 *ops
= bkpt_base_breakpoint_ops
;
16297 ops
->re_set
= dprintf_re_set
;
16298 ops
->resources_needed
= bkpt_resources_needed
;
16299 ops
->print_it
= bkpt_print_it
;
16300 ops
->print_mention
= bkpt_print_mention
;
16301 ops
->print_recreate
= dprintf_print_recreate
;
16302 ops
->after_condition_true
= dprintf_after_condition_true
;
16303 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16306 /* Chain containing all defined "enable breakpoint" subcommands. */
16308 static struct cmd_list_element
*enablebreaklist
= NULL
;
16311 _initialize_breakpoint (void)
16313 struct cmd_list_element
*c
;
16315 initialize_breakpoint_ops ();
16317 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16318 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16319 observer_attach_inferior_exit (clear_syscall_counts
);
16320 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16322 breakpoint_objfile_key
16323 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16325 catch_syscall_inferior_data
16326 = register_inferior_data_with_cleanup (NULL
,
16327 catch_syscall_inferior_data_cleanup
);
16329 breakpoint_chain
= 0;
16330 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16331 before a breakpoint is set. */
16332 breakpoint_count
= 0;
16334 tracepoint_count
= 0;
16336 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16337 Set ignore-count of breakpoint number N to COUNT.\n\
16338 Usage is `ignore N COUNT'."));
16340 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16342 add_com ("commands", class_breakpoint
, commands_command
, _("\
16343 Set commands to be executed when a breakpoint is hit.\n\
16344 Give breakpoint number as argument after \"commands\".\n\
16345 With no argument, the targeted breakpoint is the last one set.\n\
16346 The commands themselves follow starting on the next line.\n\
16347 Type a line containing \"end\" to indicate the end of them.\n\
16348 Give \"silent\" as the first line to make the breakpoint silent;\n\
16349 then no output is printed when it is hit, except what the commands print."));
16351 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16352 Specify breakpoint number N to break only if COND is true.\n\
16353 Usage is `condition N COND', where N is an integer and COND is an\n\
16354 expression to be evaluated whenever breakpoint N is reached."));
16355 set_cmd_completer (c
, condition_completer
);
16357 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16358 Set a temporary breakpoint.\n\
16359 Like \"break\" except the breakpoint is only temporary,\n\
16360 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16361 by using \"enable delete\" on the breakpoint number.\n\
16363 BREAK_ARGS_HELP ("tbreak")));
16364 set_cmd_completer (c
, location_completer
);
16366 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16367 Set a hardware assisted breakpoint.\n\
16368 Like \"break\" except the breakpoint requires hardware support,\n\
16369 some target hardware may not have this support.\n\
16371 BREAK_ARGS_HELP ("hbreak")));
16372 set_cmd_completer (c
, location_completer
);
16374 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16375 Set a temporary hardware assisted breakpoint.\n\
16376 Like \"hbreak\" except the breakpoint is only temporary,\n\
16377 so it will be deleted when hit.\n\
16379 BREAK_ARGS_HELP ("thbreak")));
16380 set_cmd_completer (c
, location_completer
);
16382 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16383 Enable some breakpoints.\n\
16384 Give breakpoint numbers (separated by spaces) as arguments.\n\
16385 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16386 This is used to cancel the effect of the \"disable\" command.\n\
16387 With a subcommand you can enable temporarily."),
16388 &enablelist
, "enable ", 1, &cmdlist
);
16390 add_com ("ab", class_breakpoint
, enable_command
, _("\
16391 Enable some breakpoints.\n\
16392 Give breakpoint numbers (separated by spaces) as arguments.\n\
16393 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16394 This is used to cancel the effect of the \"disable\" command.\n\
16395 With a subcommand you can enable temporarily."));
16397 add_com_alias ("en", "enable", class_breakpoint
, 1);
16399 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16400 Enable some breakpoints.\n\
16401 Give breakpoint numbers (separated by spaces) as arguments.\n\
16402 This is used to cancel the effect of the \"disable\" command.\n\
16403 May be abbreviated to simply \"enable\".\n"),
16404 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16406 add_cmd ("once", no_class
, enable_once_command
, _("\
16407 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16408 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16411 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16412 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16413 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16416 add_cmd ("count", no_class
, enable_count_command
, _("\
16417 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16418 If a breakpoint is hit while enabled in this fashion,\n\
16419 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16422 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16423 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16424 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16427 add_cmd ("once", no_class
, enable_once_command
, _("\
16428 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16429 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16432 add_cmd ("count", no_class
, enable_count_command
, _("\
16433 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16434 If a breakpoint is hit while enabled in this fashion,\n\
16435 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16438 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16439 Disable some breakpoints.\n\
16440 Arguments are breakpoint numbers with spaces in between.\n\
16441 To disable all breakpoints, give no argument.\n\
16442 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16443 &disablelist
, "disable ", 1, &cmdlist
);
16444 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16445 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16447 add_com ("sb", class_breakpoint
, disable_command
, _("\
16448 Disable some breakpoints.\n\
16449 Arguments are breakpoint numbers with spaces in between.\n\
16450 To disable all breakpoints, give no argument.\n\
16451 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16453 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16454 Disable some breakpoints.\n\
16455 Arguments are breakpoint numbers with spaces in between.\n\
16456 To disable all breakpoints, give no argument.\n\
16457 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16458 This command may be abbreviated \"disable\"."),
16461 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16462 Delete some breakpoints or auto-display expressions.\n\
16463 Arguments are breakpoint numbers with spaces in between.\n\
16464 To delete all breakpoints, give no argument.\n\
16466 Also a prefix command for deletion of other GDB objects.\n\
16467 The \"unset\" command is also an alias for \"delete\"."),
16468 &deletelist
, "delete ", 1, &cmdlist
);
16469 add_com_alias ("d", "delete", class_breakpoint
, 1);
16470 add_com_alias ("del", "delete", class_breakpoint
, 1);
16472 add_com ("db", class_breakpoint
, delete_command
, _("\
16473 Delete some breakpoints.\n\
16474 Arguments are breakpoint numbers with spaces in between.\n\
16475 To delete all breakpoints, give no argument.\n"));
16477 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16478 Delete some breakpoints or auto-display expressions.\n\
16479 Arguments are breakpoint numbers with spaces in between.\n\
16480 To delete all breakpoints, give no argument.\n\
16481 This command may be abbreviated \"delete\"."),
16484 add_com ("clear", class_breakpoint
, clear_command
, _("\
16485 Clear breakpoint at specified line or function.\n\
16486 Argument may be line number, function name, or \"*\" and an address.\n\
16487 If line number is specified, all breakpoints in that line are cleared.\n\
16488 If function is specified, breakpoints at beginning of function are cleared.\n\
16489 If an address is specified, breakpoints at that address are cleared.\n\
16491 With no argument, clears all breakpoints in the line that the selected frame\n\
16492 is executing in.\n\
16494 See also the \"delete\" command which clears breakpoints by number."));
16495 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16497 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16498 Set breakpoint at specified line or function.\n"
16499 BREAK_ARGS_HELP ("break")));
16500 set_cmd_completer (c
, location_completer
);
16502 add_com_alias ("b", "break", class_run
, 1);
16503 add_com_alias ("br", "break", class_run
, 1);
16504 add_com_alias ("bre", "break", class_run
, 1);
16505 add_com_alias ("brea", "break", class_run
, 1);
16508 add_com_alias ("ba", "break", class_breakpoint
, 1);
16512 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16513 Break in function/address or break at a line in the current file."),
16514 &stoplist
, "stop ", 1, &cmdlist
);
16515 add_cmd ("in", class_breakpoint
, stopin_command
,
16516 _("Break in function or address."), &stoplist
);
16517 add_cmd ("at", class_breakpoint
, stopat_command
,
16518 _("Break at a line in the current file."), &stoplist
);
16519 add_com ("status", class_info
, breakpoints_info
, _("\
16520 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16521 The \"Type\" column indicates one of:\n\
16522 \tbreakpoint - normal breakpoint\n\
16523 \twatchpoint - watchpoint\n\
16524 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16525 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16526 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16527 address and file/line number respectively.\n\
16529 Convenience variable \"$_\" and default examine address for \"x\"\n\
16530 are set to the address of the last breakpoint listed unless the command\n\
16531 is prefixed with \"server \".\n\n\
16532 Convenience variable \"$bpnum\" contains the number of the last\n\
16533 breakpoint set."));
16536 add_info ("breakpoints", breakpoints_info
, _("\
16537 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16538 The \"Type\" column indicates one of:\n\
16539 \tbreakpoint - normal breakpoint\n\
16540 \twatchpoint - watchpoint\n\
16541 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16542 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16543 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16544 address and file/line number respectively.\n\
16546 Convenience variable \"$_\" and default examine address for \"x\"\n\
16547 are set to the address of the last breakpoint listed unless the command\n\
16548 is prefixed with \"server \".\n\n\
16549 Convenience variable \"$bpnum\" contains the number of the last\n\
16550 breakpoint set."));
16552 add_info_alias ("b", "breakpoints", 1);
16555 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16556 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16557 The \"Type\" column indicates one of:\n\
16558 \tbreakpoint - normal breakpoint\n\
16559 \twatchpoint - watchpoint\n\
16560 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16561 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16562 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16563 address and file/line number respectively.\n\
16565 Convenience variable \"$_\" and default examine address for \"x\"\n\
16566 are set to the address of the last breakpoint listed unless the command\n\
16567 is prefixed with \"server \".\n\n\
16568 Convenience variable \"$bpnum\" contains the number of the last\n\
16569 breakpoint set."));
16571 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16572 Status of all breakpoints, or breakpoint number NUMBER.\n\
16573 The \"Type\" column indicates one of:\n\
16574 \tbreakpoint - normal breakpoint\n\
16575 \twatchpoint - watchpoint\n\
16576 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16577 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16578 \tuntil - internal breakpoint used by the \"until\" command\n\
16579 \tfinish - internal breakpoint used by the \"finish\" command\n\
16580 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16581 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16582 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16583 address and file/line number respectively.\n\
16585 Convenience variable \"$_\" and default examine address for \"x\"\n\
16586 are set to the address of the last breakpoint listed unless the command\n\
16587 is prefixed with \"server \".\n\n\
16588 Convenience variable \"$bpnum\" contains the number of the last\n\
16590 &maintenanceinfolist
);
16592 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16593 Set catchpoints to catch events."),
16594 &catch_cmdlist
, "catch ",
16595 0/*allow-unknown*/, &cmdlist
);
16597 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16598 Set temporary catchpoints to catch events."),
16599 &tcatch_cmdlist
, "tcatch ",
16600 0/*allow-unknown*/, &cmdlist
);
16602 add_catch_command ("fork", _("Catch calls to fork."),
16603 catch_fork_command_1
,
16605 (void *) (uintptr_t) catch_fork_permanent
,
16606 (void *) (uintptr_t) catch_fork_temporary
);
16607 add_catch_command ("vfork", _("Catch calls to vfork."),
16608 catch_fork_command_1
,
16610 (void *) (uintptr_t) catch_vfork_permanent
,
16611 (void *) (uintptr_t) catch_vfork_temporary
);
16612 add_catch_command ("exec", _("Catch calls to exec."),
16613 catch_exec_command_1
,
16617 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16618 Usage: catch load [REGEX]\n\
16619 If REGEX is given, only stop for libraries matching the regular expression."),
16620 catch_load_command_1
,
16624 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16625 Usage: catch unload [REGEX]\n\
16626 If REGEX is given, only stop for libraries matching the regular expression."),
16627 catch_unload_command_1
,
16631 add_catch_command ("syscall", _("\
16632 Catch system calls by their names and/or numbers.\n\
16633 Arguments say which system calls to catch. If no arguments\n\
16634 are given, every system call will be caught.\n\
16635 Arguments, if given, should be one or more system call names\n\
16636 (if your system supports that), or system call numbers."),
16637 catch_syscall_command_1
,
16638 catch_syscall_completer
,
16642 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16643 Set a watchpoint for an expression.\n\
16644 Usage: watch [-l|-location] EXPRESSION\n\
16645 A watchpoint stops execution of your program whenever the value of\n\
16646 an expression changes.\n\
16647 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16648 the memory to which it refers."));
16649 set_cmd_completer (c
, expression_completer
);
16651 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16652 Set a read watchpoint for an expression.\n\
16653 Usage: rwatch [-l|-location] EXPRESSION\n\
16654 A watchpoint stops execution of your program whenever the value of\n\
16655 an expression is read.\n\
16656 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16657 the memory to which it refers."));
16658 set_cmd_completer (c
, expression_completer
);
16660 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16661 Set a watchpoint for an expression.\n\
16662 Usage: awatch [-l|-location] EXPRESSION\n\
16663 A watchpoint stops execution of your program whenever the value of\n\
16664 an expression is either read or written.\n\
16665 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16666 the memory to which it refers."));
16667 set_cmd_completer (c
, expression_completer
);
16669 add_info ("watchpoints", watchpoints_info
, _("\
16670 Status of specified watchpoints (all watchpoints if no argument)."));
16672 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16673 respond to changes - contrary to the description. */
16674 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16675 &can_use_hw_watchpoints
, _("\
16676 Set debugger's willingness to use watchpoint hardware."), _("\
16677 Show debugger's willingness to use watchpoint hardware."), _("\
16678 If zero, gdb will not use hardware for new watchpoints, even if\n\
16679 such is available. (However, any hardware watchpoints that were\n\
16680 created before setting this to nonzero, will continue to use watchpoint\n\
16683 show_can_use_hw_watchpoints
,
16684 &setlist
, &showlist
);
16686 can_use_hw_watchpoints
= 1;
16688 /* Tracepoint manipulation commands. */
16690 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16691 Set a tracepoint at specified line or function.\n\
16693 BREAK_ARGS_HELP ("trace") "\n\
16694 Do \"help tracepoints\" for info on other tracepoint commands."));
16695 set_cmd_completer (c
, location_completer
);
16697 add_com_alias ("tp", "trace", class_alias
, 0);
16698 add_com_alias ("tr", "trace", class_alias
, 1);
16699 add_com_alias ("tra", "trace", class_alias
, 1);
16700 add_com_alias ("trac", "trace", class_alias
, 1);
16702 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16703 Set a fast tracepoint at specified line or function.\n\
16705 BREAK_ARGS_HELP ("ftrace") "\n\
16706 Do \"help tracepoints\" for info on other tracepoint commands."));
16707 set_cmd_completer (c
, location_completer
);
16709 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16710 Set a static tracepoint at specified line, function or marker.\n\
16712 strace [LOCATION] [if CONDITION]\n\
16713 LOCATION may be a line number, function name, \"*\" and an address,\n\
16714 or -m MARKER_ID.\n\
16715 If a line number is specified, probe the marker at start of code\n\
16716 for that line. If a function is specified, probe the marker at start\n\
16717 of code for that function. If an address is specified, probe the marker\n\
16718 at that exact address. If a marker id is specified, probe the marker\n\
16719 with that name. With no LOCATION, uses current execution address of\n\
16720 the selected stack frame.\n\
16721 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16722 This collects arbitrary user data passed in the probe point call to the\n\
16723 tracing library. You can inspect it when analyzing the trace buffer,\n\
16724 by printing the $_sdata variable like any other convenience variable.\n\
16726 CONDITION is a boolean expression.\n\
16728 Multiple tracepoints at one place are permitted, and useful if their\n\
16729 conditions are different.\n\
16731 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16732 Do \"help tracepoints\" for info on other tracepoint commands."));
16733 set_cmd_completer (c
, location_completer
);
16735 add_info ("tracepoints", tracepoints_info
, _("\
16736 Status of specified tracepoints (all tracepoints if no argument).\n\
16737 Convenience variable \"$tpnum\" contains the number of the\n\
16738 last tracepoint set."));
16740 add_info_alias ("tp", "tracepoints", 1);
16742 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16743 Delete specified tracepoints.\n\
16744 Arguments are tracepoint numbers, separated by spaces.\n\
16745 No argument means delete all tracepoints."),
16747 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16749 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16750 Disable specified tracepoints.\n\
16751 Arguments are tracepoint numbers, separated by spaces.\n\
16752 No argument means disable all tracepoints."),
16754 deprecate_cmd (c
, "disable");
16756 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16757 Enable specified tracepoints.\n\
16758 Arguments are tracepoint numbers, separated by spaces.\n\
16759 No argument means enable all tracepoints."),
16761 deprecate_cmd (c
, "enable");
16763 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16764 Set the passcount for a tracepoint.\n\
16765 The trace will end when the tracepoint has been passed 'count' times.\n\
16766 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16767 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16769 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16770 _("Save breakpoint definitions as a script."),
16771 &save_cmdlist
, "save ",
16772 0/*allow-unknown*/, &cmdlist
);
16774 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16775 Save current breakpoint definitions as a script.\n\
16776 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16777 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16778 session to restore them."),
16780 set_cmd_completer (c
, filename_completer
);
16782 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16783 Save current tracepoint definitions as a script.\n\
16784 Use the 'source' command in another debug session to restore them."),
16786 set_cmd_completer (c
, filename_completer
);
16788 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16789 deprecate_cmd (c
, "save tracepoints");
16791 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16792 Breakpoint specific settings\n\
16793 Configure various breakpoint-specific variables such as\n\
16794 pending breakpoint behavior"),
16795 &breakpoint_set_cmdlist
, "set breakpoint ",
16796 0/*allow-unknown*/, &setlist
);
16797 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16798 Breakpoint specific settings\n\
16799 Configure various breakpoint-specific variables such as\n\
16800 pending breakpoint behavior"),
16801 &breakpoint_show_cmdlist
, "show breakpoint ",
16802 0/*allow-unknown*/, &showlist
);
16804 add_setshow_auto_boolean_cmd ("pending", no_class
,
16805 &pending_break_support
, _("\
16806 Set debugger's behavior regarding pending breakpoints."), _("\
16807 Show debugger's behavior regarding pending breakpoints."), _("\
16808 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16809 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16810 an error. If auto, an unrecognized breakpoint location results in a\n\
16811 user-query to see if a pending breakpoint should be created."),
16813 show_pending_break_support
,
16814 &breakpoint_set_cmdlist
,
16815 &breakpoint_show_cmdlist
);
16817 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16819 add_setshow_boolean_cmd ("auto-hw", no_class
,
16820 &automatic_hardware_breakpoints
, _("\
16821 Set automatic usage of hardware breakpoints."), _("\
16822 Show automatic usage of hardware breakpoints."), _("\
16823 If set, the debugger will automatically use hardware breakpoints for\n\
16824 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16825 a warning will be emitted for such breakpoints."),
16827 show_automatic_hardware_breakpoints
,
16828 &breakpoint_set_cmdlist
,
16829 &breakpoint_show_cmdlist
);
16831 add_setshow_boolean_cmd ("always-inserted", class_support
,
16832 &always_inserted_mode
, _("\
16833 Set mode for inserting breakpoints."), _("\
16834 Show mode for inserting breakpoints."), _("\
16835 When this mode is on, breakpoints are inserted immediately as soon as\n\
16836 they're created, kept inserted even when execution stops, and removed\n\
16837 only when the user deletes them. When this mode is off (the default),\n\
16838 breakpoints are inserted only when execution continues, and removed\n\
16839 when execution stops."),
16841 &show_always_inserted_mode
,
16842 &breakpoint_set_cmdlist
,
16843 &breakpoint_show_cmdlist
);
16845 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16846 condition_evaluation_enums
,
16847 &condition_evaluation_mode_1
, _("\
16848 Set mode of breakpoint condition evaluation."), _("\
16849 Show mode of breakpoint condition evaluation."), _("\
16850 When this is set to \"host\", breakpoint conditions will be\n\
16851 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16852 breakpoint conditions will be downloaded to the target (if the target\n\
16853 supports such feature) and conditions will be evaluated on the target's side.\n\
16854 If this is set to \"auto\" (default), this will be automatically set to\n\
16855 \"target\" if it supports condition evaluation, otherwise it will\n\
16856 be set to \"gdb\""),
16857 &set_condition_evaluation_mode
,
16858 &show_condition_evaluation_mode
,
16859 &breakpoint_set_cmdlist
,
16860 &breakpoint_show_cmdlist
);
16862 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16863 Set a breakpoint for an address range.\n\
16864 break-range START-LOCATION, END-LOCATION\n\
16865 where START-LOCATION and END-LOCATION can be one of the following:\n\
16866 LINENUM, for that line in the current file,\n\
16867 FILE:LINENUM, for that line in that file,\n\
16868 +OFFSET, for that number of lines after the current line\n\
16869 or the start of the range\n\
16870 FUNCTION, for the first line in that function,\n\
16871 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16872 *ADDRESS, for the instruction at that address.\n\
16874 The breakpoint will stop execution of the inferior whenever it executes\n\
16875 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16876 range (including START-LOCATION and END-LOCATION)."));
16878 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16879 Set a dynamic printf at specified line or function.\n\
16880 dprintf location,format string,arg1,arg2,...\n\
16881 location may be a line number, function name, or \"*\" and an address.\n\
16882 If a line number is specified, break at start of code for that line.\n\
16883 If a function is specified, break at start of code for that function."));
16884 set_cmd_completer (c
, location_completer
);
16886 add_setshow_enum_cmd ("dprintf-style", class_support
,
16887 dprintf_style_enums
, &dprintf_style
, _("\
16888 Set the style of usage for dynamic printf."), _("\
16889 Show the style of usage for dynamic printf."), _("\
16890 This setting chooses how GDB will do a dynamic printf.\n\
16891 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16892 console, as with the \"printf\" command.\n\
16893 If the value is \"call\", the print is done by calling a function in your\n\
16894 program; by default printf(), but you can choose a different function or\n\
16895 output stream by setting dprintf-function and dprintf-channel."),
16896 update_dprintf_commands
, NULL
,
16897 &setlist
, &showlist
);
16899 dprintf_function
= xstrdup ("printf");
16900 add_setshow_string_cmd ("dprintf-function", class_support
,
16901 &dprintf_function
, _("\
16902 Set the function to use for dynamic printf"), _("\
16903 Show the function to use for dynamic printf"), NULL
,
16904 update_dprintf_commands
, NULL
,
16905 &setlist
, &showlist
);
16907 dprintf_channel
= xstrdup ("");
16908 add_setshow_string_cmd ("dprintf-channel", class_support
,
16909 &dprintf_channel
, _("\
16910 Set the channel to use for dynamic printf"), _("\
16911 Show the channel to use for dynamic printf"), NULL
,
16912 update_dprintf_commands
, NULL
,
16913 &setlist
, &showlist
);
16915 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16916 &disconnected_dprintf
, _("\
16917 Set whether dprintf continues after GDB disconnects."), _("\
16918 Show whether dprintf continues after GDB disconnects."), _("\
16919 Use this to let dprintf commands continue to hit and produce output\n\
16920 even if GDB disconnects or detaches from the target."),
16923 &setlist
, &showlist
);
16925 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16926 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16927 (target agent only) This is useful for formatted output in user-defined commands."));
16929 automatic_hardware_breakpoints
= 1;
16931 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16932 observer_attach_thread_exit (remove_threaded_breakpoints
);