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
;
2228 /* We don't want to stop processing, so catch any errors
2229 that may show up. */
2232 aexpr
= gen_eval_for_expr (scope
, cond
);
2235 CATCH (ex
, RETURN_MASK_ERROR
)
2237 /* If we got here, it means the condition could not be parsed to a valid
2238 bytecode expression and thus can't be evaluated on the target's side.
2239 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 const char *cmdrest
;
2365 const char *format_start
, *format_end
;
2366 struct format_piece
*fpieces
;
2368 struct gdbarch
*gdbarch
= get_current_arch ();
2375 if (*cmdrest
== ',')
2377 cmdrest
= skip_spaces_const (cmdrest
);
2379 if (*cmdrest
++ != '"')
2380 error (_("No format string following the location"));
2382 format_start
= cmdrest
;
2384 fpieces
= parse_format_string (&cmdrest
);
2386 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2388 format_end
= cmdrest
;
2390 if (*cmdrest
++ != '"')
2391 error (_("Bad format string, non-terminated '\"'."));
2393 cmdrest
= skip_spaces_const (cmdrest
);
2395 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2396 error (_("Invalid argument syntax"));
2398 if (*cmdrest
== ',')
2400 cmdrest
= skip_spaces_const (cmdrest
);
2402 /* For each argument, make an expression. */
2404 argvec
= (struct expression
**) alloca (strlen (cmd
)
2405 * sizeof (struct expression
*));
2408 while (*cmdrest
!= '\0')
2413 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2414 argvec
[nargs
++] = expr
;
2416 if (*cmdrest
== ',')
2420 /* We don't want to stop processing, so catch any errors
2421 that may show up. */
2424 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2425 format_start
, format_end
- format_start
,
2426 fpieces
, nargs
, argvec
);
2428 CATCH (ex
, RETURN_MASK_ERROR
)
2430 /* If we got here, it means the command could not be parsed to a valid
2431 bytecode expression and thus can't be evaluated on the target's side.
2432 It's no use iterating through the other commands. */
2437 do_cleanups (old_cleanups
);
2439 /* We have a valid agent expression, return it. */
2443 /* Based on location BL, create a list of breakpoint commands to be
2444 passed on to the target. If we have duplicated locations with
2445 different commands, we will add any such to the list. */
2448 build_target_command_list (struct bp_location
*bl
)
2450 struct bp_location
**locp
= NULL
, **loc2p
;
2451 int null_command_or_parse_error
= 0;
2452 int modified
= bl
->needs_update
;
2453 struct bp_location
*loc
;
2455 /* Release commands left over from a previous insert. */
2456 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2458 if (!target_can_run_breakpoint_commands ())
2461 /* For now, limit to agent-style dprintf breakpoints. */
2462 if (dprintf_style
!= dprintf_style_agent
)
2465 /* For now, if we have any duplicate location that isn't a dprintf,
2466 don't install the target-side commands, as that would make the
2467 breakpoint not be reported to the core, and we'd lose
2469 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2472 if (is_breakpoint (loc
->owner
)
2473 && loc
->pspace
->num
== bl
->pspace
->num
2474 && loc
->owner
->type
!= bp_dprintf
)
2478 /* Do a first pass to check for locations with no assigned
2479 conditions or conditions that fail to parse to a valid agent expression
2480 bytecode. If any of these happen, then it's no use to send conditions
2481 to the target since this location will always trigger and generate a
2482 response back to GDB. */
2483 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2486 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2490 struct agent_expr
*aexpr
;
2492 /* Re-parse the commands since something changed. In that
2493 case we already freed the command bytecodes (see
2494 force_breakpoint_reinsertion). We just
2495 need to parse the command to bytecodes again. */
2496 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2497 loc
->owner
->extra_string
);
2498 loc
->cmd_bytecode
= aexpr
;
2504 /* If we have a NULL bytecode expression, it means something
2505 went wrong or we have a null command expression. */
2506 if (!loc
->cmd_bytecode
)
2508 null_command_or_parse_error
= 1;
2514 /* If anything failed, then we're not doing target-side commands,
2516 if (null_command_or_parse_error
)
2518 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2521 if (is_breakpoint (loc
->owner
)
2522 && loc
->pspace
->num
== bl
->pspace
->num
)
2524 /* Only go as far as the first NULL bytecode is
2526 if (loc
->cmd_bytecode
== NULL
)
2529 free_agent_expr (loc
->cmd_bytecode
);
2530 loc
->cmd_bytecode
= NULL
;
2535 /* No NULL commands or failed bytecode generation. Build a command list
2536 for this location's address. */
2537 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2540 if (loc
->owner
->extra_string
2541 && is_breakpoint (loc
->owner
)
2542 && loc
->pspace
->num
== bl
->pspace
->num
2543 && loc
->owner
->enable_state
== bp_enabled
2545 /* Add the command to the vector. This will be used later
2546 to send the commands to the target. */
2547 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2551 bl
->target_info
.persist
= 0;
2552 /* Maybe flag this location as persistent. */
2553 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2554 bl
->target_info
.persist
= 1;
2557 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2558 location. Any error messages are printed to TMP_ERROR_STREAM; and
2559 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2560 Returns 0 for success, 1 if the bp_location type is not supported or
2563 NOTE drow/2003-09-09: This routine could be broken down to an
2564 object-style method for each breakpoint or catchpoint type. */
2566 insert_bp_location (struct bp_location
*bl
,
2567 struct ui_file
*tmp_error_stream
,
2568 int *disabled_breaks
,
2569 int *hw_breakpoint_error
,
2570 int *hw_bp_error_explained_already
)
2572 enum errors bp_err
= GDB_NO_ERROR
;
2573 const char *bp_err_message
= NULL
;
2575 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2578 /* Note we don't initialize bl->target_info, as that wipes out
2579 the breakpoint location's shadow_contents if the breakpoint
2580 is still inserted at that location. This in turn breaks
2581 target_read_memory which depends on these buffers when
2582 a memory read is requested at the breakpoint location:
2583 Once the target_info has been wiped, we fail to see that
2584 we have a breakpoint inserted at that address and thus
2585 read the breakpoint instead of returning the data saved in
2586 the breakpoint location's shadow contents. */
2587 bl
->target_info
.reqstd_address
= bl
->address
;
2588 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2589 bl
->target_info
.length
= bl
->length
;
2591 /* When working with target-side conditions, we must pass all the conditions
2592 for the same breakpoint address down to the target since GDB will not
2593 insert those locations. With a list of breakpoint conditions, the target
2594 can decide when to stop and notify GDB. */
2596 if (is_breakpoint (bl
->owner
))
2598 build_target_condition_list (bl
);
2599 build_target_command_list (bl
);
2600 /* Reset the modification marker. */
2601 bl
->needs_update
= 0;
2604 if (bl
->loc_type
== bp_loc_software_breakpoint
2605 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2607 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2609 /* If the explicitly specified breakpoint type
2610 is not hardware breakpoint, check the memory map to see
2611 if the breakpoint address is in read only memory or not.
2613 Two important cases are:
2614 - location type is not hardware breakpoint, memory
2615 is readonly. We change the type of the location to
2616 hardware breakpoint.
2617 - location type is hardware breakpoint, memory is
2618 read-write. This means we've previously made the
2619 location hardware one, but then the memory map changed,
2622 When breakpoints are removed, remove_breakpoints will use
2623 location types we've just set here, the only possible
2624 problem is that memory map has changed during running
2625 program, but it's not going to work anyway with current
2627 struct mem_region
*mr
2628 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2632 if (automatic_hardware_breakpoints
)
2634 enum bp_loc_type new_type
;
2636 if (mr
->attrib
.mode
!= MEM_RW
)
2637 new_type
= bp_loc_hardware_breakpoint
;
2639 new_type
= bp_loc_software_breakpoint
;
2641 if (new_type
!= bl
->loc_type
)
2643 static int said
= 0;
2645 bl
->loc_type
= new_type
;
2648 fprintf_filtered (gdb_stdout
,
2649 _("Note: automatically using "
2650 "hardware breakpoints for "
2651 "read-only addresses.\n"));
2656 else if (bl
->loc_type
== bp_loc_software_breakpoint
2657 && mr
->attrib
.mode
!= MEM_RW
)
2659 fprintf_unfiltered (tmp_error_stream
,
2660 _("Cannot insert breakpoint %d.\n"
2661 "Cannot set software breakpoint "
2662 "at read-only address %s\n"),
2664 paddress (bl
->gdbarch
, bl
->address
));
2670 /* First check to see if we have to handle an overlay. */
2671 if (overlay_debugging
== ovly_off
2672 || bl
->section
== NULL
2673 || !(section_is_overlay (bl
->section
)))
2675 /* No overlay handling: just set the breakpoint. */
2680 val
= bl
->owner
->ops
->insert_location (bl
);
2682 bp_err
= GENERIC_ERROR
;
2684 CATCH (e
, RETURN_MASK_ALL
)
2687 bp_err_message
= e
.message
;
2693 /* This breakpoint is in an overlay section.
2694 Shall we set a breakpoint at the LMA? */
2695 if (!overlay_events_enabled
)
2697 /* Yes -- overlay event support is not active,
2698 so we must try to set a breakpoint at the LMA.
2699 This will not work for a hardware breakpoint. */
2700 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2701 warning (_("hardware breakpoint %d not supported in overlay!"),
2705 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2707 /* Set a software (trap) breakpoint at the LMA. */
2708 bl
->overlay_target_info
= bl
->target_info
;
2709 bl
->overlay_target_info
.reqstd_address
= addr
;
2711 /* No overlay handling: just set the breakpoint. */
2716 val
= target_insert_breakpoint (bl
->gdbarch
,
2717 &bl
->overlay_target_info
);
2719 bp_err
= GENERIC_ERROR
;
2721 CATCH (e
, RETURN_MASK_ALL
)
2724 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. */
2743 val
= bl
->owner
->ops
->insert_location (bl
);
2745 bp_err
= GENERIC_ERROR
;
2747 CATCH (e
, RETURN_MASK_ALL
)
2750 bp_err_message
= e
.message
;
2756 /* No. This breakpoint will not be inserted.
2757 No error, but do not mark the bp as 'inserted'. */
2762 if (bp_err
!= GDB_NO_ERROR
)
2764 /* Can't set the breakpoint. */
2766 /* In some cases, we might not be able to insert a
2767 breakpoint in a shared library that has already been
2768 removed, but we have not yet processed the shlib unload
2769 event. Unfortunately, some targets that implement
2770 breakpoint insertion themselves can't tell why the
2771 breakpoint insertion failed (e.g., the remote target
2772 doesn't define error codes), so we must treat generic
2773 errors as memory errors. */
2774 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2775 && bl
->loc_type
== bp_loc_software_breakpoint
2776 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2777 || shared_objfile_contains_address_p (bl
->pspace
,
2780 /* See also: disable_breakpoints_in_shlibs. */
2781 bl
->shlib_disabled
= 1;
2782 observer_notify_breakpoint_modified (bl
->owner
);
2783 if (!*disabled_breaks
)
2785 fprintf_unfiltered (tmp_error_stream
,
2786 "Cannot insert breakpoint %d.\n",
2788 fprintf_unfiltered (tmp_error_stream
,
2789 "Temporarily disabling shared "
2790 "library breakpoints:\n");
2792 *disabled_breaks
= 1;
2793 fprintf_unfiltered (tmp_error_stream
,
2794 "breakpoint #%d\n", bl
->owner
->number
);
2799 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2801 *hw_breakpoint_error
= 1;
2802 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2803 fprintf_unfiltered (tmp_error_stream
,
2804 "Cannot insert hardware breakpoint %d%s",
2805 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2806 if (bp_err_message
!= NULL
)
2807 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2811 if (bp_err_message
== NULL
)
2814 = memory_error_message (TARGET_XFER_E_IO
,
2815 bl
->gdbarch
, bl
->address
);
2816 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2818 fprintf_unfiltered (tmp_error_stream
,
2819 "Cannot insert breakpoint %d.\n"
2821 bl
->owner
->number
, message
);
2822 do_cleanups (old_chain
);
2826 fprintf_unfiltered (tmp_error_stream
,
2827 "Cannot insert breakpoint %d: %s\n",
2842 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2843 /* NOTE drow/2003-09-08: This state only exists for removing
2844 watchpoints. It's not clear that it's necessary... */
2845 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2849 gdb_assert (bl
->owner
->ops
!= NULL
2850 && bl
->owner
->ops
->insert_location
!= NULL
);
2852 val
= bl
->owner
->ops
->insert_location (bl
);
2854 /* If trying to set a read-watchpoint, and it turns out it's not
2855 supported, try emulating one with an access watchpoint. */
2856 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2858 struct bp_location
*loc
, **loc_temp
;
2860 /* But don't try to insert it, if there's already another
2861 hw_access location that would be considered a duplicate
2863 ALL_BP_LOCATIONS (loc
, loc_temp
)
2865 && loc
->watchpoint_type
== hw_access
2866 && watchpoint_locations_match (bl
, loc
))
2870 bl
->target_info
= loc
->target_info
;
2871 bl
->watchpoint_type
= hw_access
;
2878 bl
->watchpoint_type
= hw_access
;
2879 val
= bl
->owner
->ops
->insert_location (bl
);
2882 /* Back to the original value. */
2883 bl
->watchpoint_type
= hw_read
;
2887 bl
->inserted
= (val
== 0);
2890 else if (bl
->owner
->type
== bp_catchpoint
)
2894 gdb_assert (bl
->owner
->ops
!= NULL
2895 && bl
->owner
->ops
->insert_location
!= NULL
);
2897 val
= bl
->owner
->ops
->insert_location (bl
);
2900 bl
->owner
->enable_state
= bp_disabled
;
2904 Error inserting catchpoint %d: Your system does not support this type\n\
2905 of catchpoint."), bl
->owner
->number
);
2907 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2910 bl
->inserted
= (val
== 0);
2912 /* We've already printed an error message if there was a problem
2913 inserting this catchpoint, and we've disabled the catchpoint,
2914 so just return success. */
2921 /* This function is called when program space PSPACE is about to be
2922 deleted. It takes care of updating breakpoints to not reference
2926 breakpoint_program_space_exit (struct program_space
*pspace
)
2928 struct breakpoint
*b
, *b_temp
;
2929 struct bp_location
*loc
, **loc_temp
;
2931 /* Remove any breakpoint that was set through this program space. */
2932 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2934 if (b
->pspace
== pspace
)
2935 delete_breakpoint (b
);
2938 /* Breakpoints set through other program spaces could have locations
2939 bound to PSPACE as well. Remove those. */
2940 ALL_BP_LOCATIONS (loc
, loc_temp
)
2942 struct bp_location
*tmp
;
2944 if (loc
->pspace
== pspace
)
2946 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2947 if (loc
->owner
->loc
== loc
)
2948 loc
->owner
->loc
= loc
->next
;
2950 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2951 if (tmp
->next
== loc
)
2953 tmp
->next
= loc
->next
;
2959 /* Now update the global location list to permanently delete the
2960 removed locations above. */
2961 update_global_location_list (UGLL_DONT_INSERT
);
2964 /* Make sure all breakpoints are inserted in inferior.
2965 Throws exception on any error.
2966 A breakpoint that is already inserted won't be inserted
2967 again, so calling this function twice is safe. */
2969 insert_breakpoints (void)
2971 struct breakpoint
*bpt
;
2973 ALL_BREAKPOINTS (bpt
)
2974 if (is_hardware_watchpoint (bpt
))
2976 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2978 update_watchpoint (w
, 0 /* don't reparse. */);
2981 /* Updating watchpoints creates new locations, so update the global
2982 location list. Explicitly tell ugll to insert locations and
2983 ignore breakpoints_always_inserted_mode. */
2984 update_global_location_list (UGLL_INSERT
);
2987 /* Invoke CALLBACK for each of bp_location. */
2990 iterate_over_bp_locations (walk_bp_location_callback callback
)
2992 struct bp_location
*loc
, **loc_tmp
;
2994 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2996 callback (loc
, NULL
);
3000 /* This is used when we need to synch breakpoint conditions between GDB and the
3001 target. It is the case with deleting and disabling of breakpoints when using
3002 always-inserted mode. */
3005 update_inserted_breakpoint_locations (void)
3007 struct bp_location
*bl
, **blp_tmp
;
3010 int disabled_breaks
= 0;
3011 int hw_breakpoint_error
= 0;
3012 int hw_bp_details_reported
= 0;
3014 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3015 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3017 /* Explicitly mark the warning -- this will only be printed if
3018 there was an error. */
3019 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3021 save_current_space_and_thread ();
3023 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3025 /* We only want to update software breakpoints and hardware
3027 if (!is_breakpoint (bl
->owner
))
3030 /* We only want to update locations that are already inserted
3031 and need updating. This is to avoid unwanted insertion during
3032 deletion of breakpoints. */
3033 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3036 switch_to_program_space_and_thread (bl
->pspace
);
3038 /* For targets that support global breakpoints, there's no need
3039 to select an inferior to insert breakpoint to. In fact, even
3040 if we aren't attached to any process yet, we should still
3041 insert breakpoints. */
3042 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3043 && ptid_equal (inferior_ptid
, null_ptid
))
3046 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3047 &hw_breakpoint_error
, &hw_bp_details_reported
);
3054 target_terminal_ours_for_output ();
3055 error_stream (tmp_error_stream
);
3058 do_cleanups (cleanups
);
3061 /* Used when starting or continuing the program. */
3064 insert_breakpoint_locations (void)
3066 struct breakpoint
*bpt
;
3067 struct bp_location
*bl
, **blp_tmp
;
3070 int disabled_breaks
= 0;
3071 int hw_breakpoint_error
= 0;
3072 int hw_bp_error_explained_already
= 0;
3074 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3075 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3077 /* Explicitly mark the warning -- this will only be printed if
3078 there was an error. */
3079 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3081 save_current_space_and_thread ();
3083 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3085 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3088 /* There is no point inserting thread-specific breakpoints if
3089 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3090 has BL->OWNER always non-NULL. */
3091 if (bl
->owner
->thread
!= -1
3092 && !valid_thread_id (bl
->owner
->thread
))
3095 switch_to_program_space_and_thread (bl
->pspace
);
3097 /* For targets that support global breakpoints, there's no need
3098 to select an inferior to insert breakpoint to. In fact, even
3099 if we aren't attached to any process yet, we should still
3100 insert breakpoints. */
3101 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3102 && ptid_equal (inferior_ptid
, null_ptid
))
3105 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3106 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3111 /* If we failed to insert all locations of a watchpoint, remove
3112 them, as half-inserted watchpoint is of limited use. */
3113 ALL_BREAKPOINTS (bpt
)
3115 int some_failed
= 0;
3116 struct bp_location
*loc
;
3118 if (!is_hardware_watchpoint (bpt
))
3121 if (!breakpoint_enabled (bpt
))
3124 if (bpt
->disposition
== disp_del_at_next_stop
)
3127 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3128 if (!loc
->inserted
&& should_be_inserted (loc
))
3135 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3137 remove_breakpoint (loc
, mark_uninserted
);
3139 hw_breakpoint_error
= 1;
3140 fprintf_unfiltered (tmp_error_stream
,
3141 "Could not insert hardware watchpoint %d.\n",
3149 /* If a hardware breakpoint or watchpoint was inserted, add a
3150 message about possibly exhausted resources. */
3151 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3153 fprintf_unfiltered (tmp_error_stream
,
3154 "Could not insert hardware breakpoints:\n\
3155 You may have requested too many hardware breakpoints/watchpoints.\n");
3157 target_terminal_ours_for_output ();
3158 error_stream (tmp_error_stream
);
3161 do_cleanups (cleanups
);
3164 /* Used when the program stops.
3165 Returns zero if successful, or non-zero if there was a problem
3166 removing a breakpoint location. */
3169 remove_breakpoints (void)
3171 struct bp_location
*bl
, **blp_tmp
;
3174 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3176 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3177 val
|= remove_breakpoint (bl
, mark_uninserted
);
3182 /* When a thread exits, remove breakpoints that are related to
3186 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3188 struct breakpoint
*b
, *b_tmp
;
3190 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3192 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3194 b
->disposition
= disp_del_at_next_stop
;
3196 printf_filtered (_("\
3197 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3198 b
->number
, tp
->num
);
3200 /* Hide it from the user. */
3206 /* Remove breakpoints of process PID. */
3209 remove_breakpoints_pid (int pid
)
3211 struct bp_location
*bl
, **blp_tmp
;
3213 struct inferior
*inf
= find_inferior_pid (pid
);
3215 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3217 if (bl
->pspace
!= inf
->pspace
)
3220 if (bl
->inserted
&& !bl
->target_info
.persist
)
3222 val
= remove_breakpoint (bl
, mark_uninserted
);
3231 reattach_breakpoints (int pid
)
3233 struct cleanup
*old_chain
;
3234 struct bp_location
*bl
, **blp_tmp
;
3236 struct ui_file
*tmp_error_stream
;
3237 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3238 struct inferior
*inf
;
3239 struct thread_info
*tp
;
3241 tp
= any_live_thread_of_process (pid
);
3245 inf
= find_inferior_pid (pid
);
3246 old_chain
= save_inferior_ptid ();
3248 inferior_ptid
= tp
->ptid
;
3250 tmp_error_stream
= mem_fileopen ();
3251 make_cleanup_ui_file_delete (tmp_error_stream
);
3253 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3255 if (bl
->pspace
!= inf
->pspace
)
3261 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3264 do_cleanups (old_chain
);
3269 do_cleanups (old_chain
);
3273 static int internal_breakpoint_number
= -1;
3275 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3276 If INTERNAL is non-zero, the breakpoint number will be populated
3277 from internal_breakpoint_number and that variable decremented.
3278 Otherwise the breakpoint number will be populated from
3279 breakpoint_count and that value incremented. Internal breakpoints
3280 do not set the internal var bpnum. */
3282 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3285 b
->number
= internal_breakpoint_number
--;
3288 set_breakpoint_count (breakpoint_count
+ 1);
3289 b
->number
= breakpoint_count
;
3293 static struct breakpoint
*
3294 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3295 CORE_ADDR address
, enum bptype type
,
3296 const struct breakpoint_ops
*ops
)
3298 struct symtab_and_line sal
;
3299 struct breakpoint
*b
;
3301 init_sal (&sal
); /* Initialize to zeroes. */
3304 sal
.section
= find_pc_overlay (sal
.pc
);
3305 sal
.pspace
= current_program_space
;
3307 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3308 b
->number
= internal_breakpoint_number
--;
3309 b
->disposition
= disp_donttouch
;
3314 static const char *const longjmp_names
[] =
3316 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3318 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3320 /* Per-objfile data private to breakpoint.c. */
3321 struct breakpoint_objfile_data
3323 /* Minimal symbol for "_ovly_debug_event" (if any). */
3324 struct bound_minimal_symbol overlay_msym
;
3326 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3327 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3329 /* True if we have looked for longjmp probes. */
3330 int longjmp_searched
;
3332 /* SystemTap probe points for longjmp (if any). */
3333 VEC (probe_p
) *longjmp_probes
;
3335 /* Minimal symbol for "std::terminate()" (if any). */
3336 struct bound_minimal_symbol terminate_msym
;
3338 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3339 struct bound_minimal_symbol exception_msym
;
3341 /* True if we have looked for exception probes. */
3342 int exception_searched
;
3344 /* SystemTap probe points for unwinding (if any). */
3345 VEC (probe_p
) *exception_probes
;
3348 static const struct objfile_data
*breakpoint_objfile_key
;
3350 /* Minimal symbol not found sentinel. */
3351 static struct minimal_symbol msym_not_found
;
3353 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3356 msym_not_found_p (const struct minimal_symbol
*msym
)
3358 return msym
== &msym_not_found
;
3361 /* Return per-objfile data needed by breakpoint.c.
3362 Allocate the data if necessary. */
3364 static struct breakpoint_objfile_data
*
3365 get_breakpoint_objfile_data (struct objfile
*objfile
)
3367 struct breakpoint_objfile_data
*bp_objfile_data
;
3369 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3370 if (bp_objfile_data
== NULL
)
3372 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3373 sizeof (*bp_objfile_data
));
3375 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3376 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3378 return bp_objfile_data
;
3382 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3384 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3386 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3387 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3391 create_overlay_event_breakpoint (void)
3393 struct objfile
*objfile
;
3394 const char *const func_name
= "_ovly_debug_event";
3396 ALL_OBJFILES (objfile
)
3398 struct breakpoint
*b
;
3399 struct breakpoint_objfile_data
*bp_objfile_data
;
3402 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3404 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3407 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3409 struct bound_minimal_symbol m
;
3411 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3412 if (m
.minsym
== NULL
)
3414 /* Avoid future lookups in this objfile. */
3415 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3418 bp_objfile_data
->overlay_msym
= m
;
3421 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3422 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3424 &internal_breakpoint_ops
);
3425 b
->addr_string
= xstrdup (func_name
);
3427 if (overlay_debugging
== ovly_auto
)
3429 b
->enable_state
= bp_enabled
;
3430 overlay_events_enabled
= 1;
3434 b
->enable_state
= bp_disabled
;
3435 overlay_events_enabled
= 0;
3438 update_global_location_list (UGLL_MAY_INSERT
);
3442 create_longjmp_master_breakpoint (void)
3444 struct program_space
*pspace
;
3445 struct cleanup
*old_chain
;
3447 old_chain
= save_current_program_space ();
3449 ALL_PSPACES (pspace
)
3451 struct objfile
*objfile
;
3453 set_current_program_space (pspace
);
3455 ALL_OBJFILES (objfile
)
3458 struct gdbarch
*gdbarch
;
3459 struct breakpoint_objfile_data
*bp_objfile_data
;
3461 gdbarch
= get_objfile_arch (objfile
);
3463 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3465 if (!bp_objfile_data
->longjmp_searched
)
3469 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3472 /* We are only interested in checking one element. */
3473 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3475 if (!can_evaluate_probe_arguments (p
))
3477 /* We cannot use the probe interface here, because it does
3478 not know how to evaluate arguments. */
3479 VEC_free (probe_p
, ret
);
3483 bp_objfile_data
->longjmp_probes
= ret
;
3484 bp_objfile_data
->longjmp_searched
= 1;
3487 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3490 struct probe
*probe
;
3491 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3494 VEC_iterate (probe_p
,
3495 bp_objfile_data
->longjmp_probes
,
3499 struct breakpoint
*b
;
3501 b
= create_internal_breakpoint (gdbarch
,
3502 get_probe_address (probe
,
3505 &internal_breakpoint_ops
);
3506 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3507 b
->enable_state
= bp_disabled
;
3513 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3516 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3518 struct breakpoint
*b
;
3519 const char *func_name
;
3522 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3525 func_name
= longjmp_names
[i
];
3526 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3528 struct bound_minimal_symbol m
;
3530 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3531 if (m
.minsym
== NULL
)
3533 /* Prevent future lookups in this objfile. */
3534 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3537 bp_objfile_data
->longjmp_msym
[i
] = m
;
3540 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3541 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3542 &internal_breakpoint_ops
);
3543 b
->addr_string
= xstrdup (func_name
);
3544 b
->enable_state
= bp_disabled
;
3548 update_global_location_list (UGLL_MAY_INSERT
);
3550 do_cleanups (old_chain
);
3553 /* Create a master std::terminate breakpoint. */
3555 create_std_terminate_master_breakpoint (void)
3557 struct program_space
*pspace
;
3558 struct cleanup
*old_chain
;
3559 const char *const func_name
= "std::terminate()";
3561 old_chain
= save_current_program_space ();
3563 ALL_PSPACES (pspace
)
3565 struct objfile
*objfile
;
3568 set_current_program_space (pspace
);
3570 ALL_OBJFILES (objfile
)
3572 struct breakpoint
*b
;
3573 struct breakpoint_objfile_data
*bp_objfile_data
;
3575 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3577 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3580 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3582 struct bound_minimal_symbol m
;
3584 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3585 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3586 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3588 /* Prevent future lookups in this objfile. */
3589 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3592 bp_objfile_data
->terminate_msym
= m
;
3595 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3596 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3597 bp_std_terminate_master
,
3598 &internal_breakpoint_ops
);
3599 b
->addr_string
= xstrdup (func_name
);
3600 b
->enable_state
= bp_disabled
;
3604 update_global_location_list (UGLL_MAY_INSERT
);
3606 do_cleanups (old_chain
);
3609 /* Install a master breakpoint on the unwinder's debug hook. */
3612 create_exception_master_breakpoint (void)
3614 struct objfile
*objfile
;
3615 const char *const func_name
= "_Unwind_DebugHook";
3617 ALL_OBJFILES (objfile
)
3619 struct breakpoint
*b
;
3620 struct gdbarch
*gdbarch
;
3621 struct breakpoint_objfile_data
*bp_objfile_data
;
3624 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3626 /* We prefer the SystemTap probe point if it exists. */
3627 if (!bp_objfile_data
->exception_searched
)
3631 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3635 /* We are only interested in checking one element. */
3636 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3638 if (!can_evaluate_probe_arguments (p
))
3640 /* We cannot use the probe interface here, because it does
3641 not know how to evaluate arguments. */
3642 VEC_free (probe_p
, ret
);
3646 bp_objfile_data
->exception_probes
= ret
;
3647 bp_objfile_data
->exception_searched
= 1;
3650 if (bp_objfile_data
->exception_probes
!= NULL
)
3652 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3654 struct probe
*probe
;
3657 VEC_iterate (probe_p
,
3658 bp_objfile_data
->exception_probes
,
3662 struct breakpoint
*b
;
3664 b
= create_internal_breakpoint (gdbarch
,
3665 get_probe_address (probe
,
3667 bp_exception_master
,
3668 &internal_breakpoint_ops
);
3669 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3670 b
->enable_state
= bp_disabled
;
3676 /* Otherwise, try the hook function. */
3678 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3681 gdbarch
= get_objfile_arch (objfile
);
3683 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3685 struct bound_minimal_symbol debug_hook
;
3687 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3688 if (debug_hook
.minsym
== NULL
)
3690 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3694 bp_objfile_data
->exception_msym
= debug_hook
;
3697 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3698 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3700 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3701 &internal_breakpoint_ops
);
3702 b
->addr_string
= xstrdup (func_name
);
3703 b
->enable_state
= bp_disabled
;
3706 update_global_location_list (UGLL_MAY_INSERT
);
3710 update_breakpoints_after_exec (void)
3712 struct breakpoint
*b
, *b_tmp
;
3713 struct bp_location
*bploc
, **bplocp_tmp
;
3715 /* We're about to delete breakpoints from GDB's lists. If the
3716 INSERTED flag is true, GDB will try to lift the breakpoints by
3717 writing the breakpoints' "shadow contents" back into memory. The
3718 "shadow contents" are NOT valid after an exec, so GDB should not
3719 do that. Instead, the target is responsible from marking
3720 breakpoints out as soon as it detects an exec. We don't do that
3721 here instead, because there may be other attempts to delete
3722 breakpoints after detecting an exec and before reaching here. */
3723 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3724 if (bploc
->pspace
== current_program_space
)
3725 gdb_assert (!bploc
->inserted
);
3727 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3729 if (b
->pspace
!= current_program_space
)
3732 /* Solib breakpoints must be explicitly reset after an exec(). */
3733 if (b
->type
== bp_shlib_event
)
3735 delete_breakpoint (b
);
3739 /* JIT breakpoints must be explicitly reset after an exec(). */
3740 if (b
->type
== bp_jit_event
)
3742 delete_breakpoint (b
);
3746 /* Thread event breakpoints must be set anew after an exec(),
3747 as must overlay event and longjmp master breakpoints. */
3748 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3749 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3750 || b
->type
== bp_exception_master
)
3752 delete_breakpoint (b
);
3756 /* Step-resume breakpoints are meaningless after an exec(). */
3757 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3759 delete_breakpoint (b
);
3763 /* Just like single-step breakpoints. */
3764 if (b
->type
== bp_single_step
)
3766 delete_breakpoint (b
);
3770 /* Longjmp and longjmp-resume breakpoints are also meaningless
3772 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3773 || b
->type
== bp_longjmp_call_dummy
3774 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3776 delete_breakpoint (b
);
3780 if (b
->type
== bp_catchpoint
)
3782 /* For now, none of the bp_catchpoint breakpoints need to
3783 do anything at this point. In the future, if some of
3784 the catchpoints need to something, we will need to add
3785 a new method, and call this method from here. */
3789 /* bp_finish is a special case. The only way we ought to be able
3790 to see one of these when an exec() has happened, is if the user
3791 caught a vfork, and then said "finish". Ordinarily a finish just
3792 carries them to the call-site of the current callee, by setting
3793 a temporary bp there and resuming. But in this case, the finish
3794 will carry them entirely through the vfork & exec.
3796 We don't want to allow a bp_finish to remain inserted now. But
3797 we can't safely delete it, 'cause finish_command has a handle to
3798 the bp on a bpstat, and will later want to delete it. There's a
3799 chance (and I've seen it happen) that if we delete the bp_finish
3800 here, that its storage will get reused by the time finish_command
3801 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3802 We really must allow finish_command to delete a bp_finish.
3804 In the absence of a general solution for the "how do we know
3805 it's safe to delete something others may have handles to?"
3806 problem, what we'll do here is just uninsert the bp_finish, and
3807 let finish_command delete it.
3809 (We know the bp_finish is "doomed" in the sense that it's
3810 momentary, and will be deleted as soon as finish_command sees
3811 the inferior stopped. So it doesn't matter that the bp's
3812 address is probably bogus in the new a.out, unlike e.g., the
3813 solib breakpoints.) */
3815 if (b
->type
== bp_finish
)
3820 /* Without a symbolic address, we have little hope of the
3821 pre-exec() address meaning the same thing in the post-exec()
3823 if (b
->addr_string
== NULL
)
3825 delete_breakpoint (b
);
3832 detach_breakpoints (ptid_t ptid
)
3834 struct bp_location
*bl
, **blp_tmp
;
3836 struct cleanup
*old_chain
= save_inferior_ptid ();
3837 struct inferior
*inf
= current_inferior ();
3839 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3840 error (_("Cannot detach breakpoints of inferior_ptid"));
3842 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3843 inferior_ptid
= ptid
;
3844 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3846 if (bl
->pspace
!= inf
->pspace
)
3849 /* This function must physically remove breakpoints locations
3850 from the specified ptid, without modifying the breakpoint
3851 package's state. Locations of type bp_loc_other are only
3852 maintained at GDB side. So, there is no need to remove
3853 these bp_loc_other locations. Moreover, removing these
3854 would modify the breakpoint package's state. */
3855 if (bl
->loc_type
== bp_loc_other
)
3859 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3862 do_cleanups (old_chain
);
3866 /* Remove the breakpoint location BL from the current address space.
3867 Note that this is used to detach breakpoints from a child fork.
3868 When we get here, the child isn't in the inferior list, and neither
3869 do we have objects to represent its address space --- we should
3870 *not* look at bl->pspace->aspace here. */
3873 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3877 /* BL is never in moribund_locations by our callers. */
3878 gdb_assert (bl
->owner
!= NULL
);
3881 /* Permanent breakpoints cannot be inserted or removed. */
3884 /* The type of none suggests that owner is actually deleted.
3885 This should not ever happen. */
3886 gdb_assert (bl
->owner
->type
!= bp_none
);
3888 if (bl
->loc_type
== bp_loc_software_breakpoint
3889 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3891 /* "Normal" instruction breakpoint: either the standard
3892 trap-instruction bp (bp_breakpoint), or a
3893 bp_hardware_breakpoint. */
3895 /* First check to see if we have to handle an overlay. */
3896 if (overlay_debugging
== ovly_off
3897 || bl
->section
== NULL
3898 || !(section_is_overlay (bl
->section
)))
3900 /* No overlay handling: just remove the breakpoint. */
3902 /* If we're trying to uninsert a memory breakpoint that we
3903 know is set in a dynamic object that is marked
3904 shlib_disabled, then either the dynamic object was
3905 removed with "remove-symbol-file" or with
3906 "nosharedlibrary". In the former case, we don't know
3907 whether another dynamic object might have loaded over the
3908 breakpoint's address -- the user might well let us know
3909 about it next with add-symbol-file (the whole point of
3910 add-symbol-file is letting the user manually maintain a
3911 list of dynamically loaded objects). If we have the
3912 breakpoint's shadow memory, that is, this is a software
3913 breakpoint managed by GDB, check whether the breakpoint
3914 is still inserted in memory, to avoid overwriting wrong
3915 code with stale saved shadow contents. Note that HW
3916 breakpoints don't have shadow memory, as they're
3917 implemented using a mechanism that is not dependent on
3918 being able to modify the target's memory, and as such
3919 they should always be removed. */
3920 if (bl
->shlib_disabled
3921 && bl
->target_info
.shadow_len
!= 0
3922 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3925 val
= bl
->owner
->ops
->remove_location (bl
);
3929 /* This breakpoint is in an overlay section.
3930 Did we set a breakpoint at the LMA? */
3931 if (!overlay_events_enabled
)
3933 /* Yes -- overlay event support is not active, so we
3934 should have set a breakpoint at the LMA. Remove it.
3936 /* Ignore any failures: if the LMA is in ROM, we will
3937 have already warned when we failed to insert it. */
3938 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3939 target_remove_hw_breakpoint (bl
->gdbarch
,
3940 &bl
->overlay_target_info
);
3942 target_remove_breakpoint (bl
->gdbarch
,
3943 &bl
->overlay_target_info
);
3945 /* Did we set a breakpoint at the VMA?
3946 If so, we will have marked the breakpoint 'inserted'. */
3949 /* Yes -- remove it. Previously we did not bother to
3950 remove the breakpoint if the section had been
3951 unmapped, but let's not rely on that being safe. We
3952 don't know what the overlay manager might do. */
3954 /* However, we should remove *software* breakpoints only
3955 if the section is still mapped, or else we overwrite
3956 wrong code with the saved shadow contents. */
3957 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3958 || section_is_mapped (bl
->section
))
3959 val
= bl
->owner
->ops
->remove_location (bl
);
3965 /* No -- not inserted, so no need to remove. No error. */
3970 /* In some cases, we might not be able to remove a breakpoint in
3971 a shared library that has already been removed, but we have
3972 not yet processed the shlib unload event. Similarly for an
3973 unloaded add-symbol-file object - the user might not yet have
3974 had the chance to remove-symbol-file it. shlib_disabled will
3975 be set if the library/object has already been removed, but
3976 the breakpoint hasn't been uninserted yet, e.g., after
3977 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3978 always-inserted mode. */
3980 && (bl
->loc_type
== bp_loc_software_breakpoint
3981 && (bl
->shlib_disabled
3982 || solib_name_from_address (bl
->pspace
, bl
->address
)
3983 || shared_objfile_contains_address_p (bl
->pspace
,
3989 bl
->inserted
= (is
== mark_inserted
);
3991 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3993 gdb_assert (bl
->owner
->ops
!= NULL
3994 && bl
->owner
->ops
->remove_location
!= NULL
);
3996 bl
->inserted
= (is
== mark_inserted
);
3997 bl
->owner
->ops
->remove_location (bl
);
3999 /* Failure to remove any of the hardware watchpoints comes here. */
4000 if ((is
== mark_uninserted
) && (bl
->inserted
))
4001 warning (_("Could not remove hardware watchpoint %d."),
4004 else if (bl
->owner
->type
== bp_catchpoint
4005 && breakpoint_enabled (bl
->owner
)
4008 gdb_assert (bl
->owner
->ops
!= NULL
4009 && bl
->owner
->ops
->remove_location
!= NULL
);
4011 val
= bl
->owner
->ops
->remove_location (bl
);
4015 bl
->inserted
= (is
== mark_inserted
);
4022 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4025 struct cleanup
*old_chain
;
4027 /* BL is never in moribund_locations by our callers. */
4028 gdb_assert (bl
->owner
!= NULL
);
4031 /* Permanent breakpoints cannot be inserted or removed. */
4034 /* The type of none suggests that owner is actually deleted.
4035 This should not ever happen. */
4036 gdb_assert (bl
->owner
->type
!= bp_none
);
4038 old_chain
= save_current_space_and_thread ();
4040 switch_to_program_space_and_thread (bl
->pspace
);
4042 ret
= remove_breakpoint_1 (bl
, is
);
4044 do_cleanups (old_chain
);
4048 /* Clear the "inserted" flag in all breakpoints. */
4051 mark_breakpoints_out (void)
4053 struct bp_location
*bl
, **blp_tmp
;
4055 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4056 if (bl
->pspace
== current_program_space
4061 /* Clear the "inserted" flag in all breakpoints and delete any
4062 breakpoints which should go away between runs of the program.
4064 Plus other such housekeeping that has to be done for breakpoints
4067 Note: this function gets called at the end of a run (by
4068 generic_mourn_inferior) and when a run begins (by
4069 init_wait_for_inferior). */
4074 breakpoint_init_inferior (enum inf_context context
)
4076 struct breakpoint
*b
, *b_tmp
;
4077 struct bp_location
*bl
, **blp_tmp
;
4079 struct program_space
*pspace
= current_program_space
;
4081 /* If breakpoint locations are shared across processes, then there's
4083 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4086 mark_breakpoints_out ();
4088 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4090 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4096 case bp_longjmp_call_dummy
:
4098 /* If the call dummy breakpoint is at the entry point it will
4099 cause problems when the inferior is rerun, so we better get
4102 case bp_watchpoint_scope
:
4104 /* Also get rid of scope breakpoints. */
4106 case bp_shlib_event
:
4108 /* Also remove solib event breakpoints. Their addresses may
4109 have changed since the last time we ran the program.
4110 Actually we may now be debugging against different target;
4111 and so the solib backend that installed this breakpoint may
4112 not be used in by the target. E.g.,
4114 (gdb) file prog-linux
4115 (gdb) run # native linux target
4118 (gdb) file prog-win.exe
4119 (gdb) tar rem :9999 # remote Windows gdbserver.
4122 case bp_step_resume
:
4124 /* Also remove step-resume breakpoints. */
4126 case bp_single_step
:
4128 /* Also remove single-step breakpoints. */
4130 delete_breakpoint (b
);
4134 case bp_hardware_watchpoint
:
4135 case bp_read_watchpoint
:
4136 case bp_access_watchpoint
:
4138 struct watchpoint
*w
= (struct watchpoint
*) b
;
4140 /* Likewise for watchpoints on local expressions. */
4141 if (w
->exp_valid_block
!= NULL
)
4142 delete_breakpoint (b
);
4143 else if (context
== inf_starting
)
4145 /* Reset val field to force reread of starting value in
4146 insert_breakpoints. */
4148 value_free (w
->val
);
4159 /* Get rid of the moribund locations. */
4160 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4161 decref_bp_location (&bl
);
4162 VEC_free (bp_location_p
, moribund_locations
);
4165 /* These functions concern about actual breakpoints inserted in the
4166 target --- to e.g. check if we need to do decr_pc adjustment or if
4167 we need to hop over the bkpt --- so we check for address space
4168 match, not program space. */
4170 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4171 exists at PC. It returns ordinary_breakpoint_here if it's an
4172 ordinary breakpoint, or permanent_breakpoint_here if it's a
4173 permanent breakpoint.
4174 - When continuing from a location with an ordinary breakpoint, we
4175 actually single step once before calling insert_breakpoints.
4176 - When continuing from a location with a permanent breakpoint, we
4177 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4178 the target, to advance the PC past the breakpoint. */
4180 enum breakpoint_here
4181 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4183 struct bp_location
*bl
, **blp_tmp
;
4184 int any_breakpoint_here
= 0;
4186 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4188 if (bl
->loc_type
!= bp_loc_software_breakpoint
4189 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4192 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4193 if ((breakpoint_enabled (bl
->owner
)
4195 && breakpoint_location_address_match (bl
, aspace
, pc
))
4197 if (overlay_debugging
4198 && section_is_overlay (bl
->section
)
4199 && !section_is_mapped (bl
->section
))
4200 continue; /* unmapped overlay -- can't be a match */
4201 else if (bl
->permanent
)
4202 return permanent_breakpoint_here
;
4204 any_breakpoint_here
= 1;
4208 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4211 /* Return true if there's a moribund breakpoint at PC. */
4214 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4216 struct bp_location
*loc
;
4219 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4220 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4226 /* Returns non-zero iff BL is inserted at PC, in address space
4230 bp_location_inserted_here_p (struct bp_location
*bl
,
4231 struct address_space
*aspace
, CORE_ADDR pc
)
4234 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4237 if (overlay_debugging
4238 && section_is_overlay (bl
->section
)
4239 && !section_is_mapped (bl
->section
))
4240 return 0; /* unmapped overlay -- can't be a match */
4247 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4250 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4252 struct bp_location
**blp
, **blp_tmp
= NULL
;
4253 struct bp_location
*bl
;
4255 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4257 struct bp_location
*bl
= *blp
;
4259 if (bl
->loc_type
!= bp_loc_software_breakpoint
4260 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4263 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4269 /* This function returns non-zero iff there is a software breakpoint
4273 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4276 struct bp_location
**blp
, **blp_tmp
= NULL
;
4277 struct bp_location
*bl
;
4279 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4281 struct bp_location
*bl
= *blp
;
4283 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4286 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4293 /* See breakpoint.h. */
4296 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4299 struct bp_location
**blp
, **blp_tmp
= NULL
;
4300 struct bp_location
*bl
;
4302 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4304 struct bp_location
*bl
= *blp
;
4306 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4309 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4317 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4318 CORE_ADDR addr
, ULONGEST len
)
4320 struct breakpoint
*bpt
;
4322 ALL_BREAKPOINTS (bpt
)
4324 struct bp_location
*loc
;
4326 if (bpt
->type
!= bp_hardware_watchpoint
4327 && bpt
->type
!= bp_access_watchpoint
)
4330 if (!breakpoint_enabled (bpt
))
4333 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4334 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4338 /* Check for intersection. */
4339 l
= max (loc
->address
, addr
);
4340 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4349 /* bpstat stuff. External routines' interfaces are documented
4353 is_catchpoint (struct breakpoint
*ep
)
4355 return (ep
->type
== bp_catchpoint
);
4358 /* Frees any storage that is part of a bpstat. Does not walk the
4362 bpstat_free (bpstat bs
)
4364 if (bs
->old_val
!= NULL
)
4365 value_free (bs
->old_val
);
4366 decref_counted_command_line (&bs
->commands
);
4367 decref_bp_location (&bs
->bp_location_at
);
4371 /* Clear a bpstat so that it says we are not at any breakpoint.
4372 Also free any storage that is part of a bpstat. */
4375 bpstat_clear (bpstat
*bsp
)
4392 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4393 is part of the bpstat is copied as well. */
4396 bpstat_copy (bpstat bs
)
4400 bpstat retval
= NULL
;
4405 for (; bs
!= NULL
; bs
= bs
->next
)
4407 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4408 memcpy (tmp
, bs
, sizeof (*tmp
));
4409 incref_counted_command_line (tmp
->commands
);
4410 incref_bp_location (tmp
->bp_location_at
);
4411 if (bs
->old_val
!= NULL
)
4413 tmp
->old_val
= value_copy (bs
->old_val
);
4414 release_value (tmp
->old_val
);
4418 /* This is the first thing in the chain. */
4428 /* Find the bpstat associated with this breakpoint. */
4431 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4436 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4438 if (bsp
->breakpoint_at
== breakpoint
)
4444 /* See breakpoint.h. */
4447 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4449 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4451 if (bsp
->breakpoint_at
== NULL
)
4453 /* A moribund location can never explain a signal other than
4455 if (sig
== GDB_SIGNAL_TRAP
)
4460 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4469 /* Put in *NUM the breakpoint number of the first breakpoint we are
4470 stopped at. *BSP upon return is a bpstat which points to the
4471 remaining breakpoints stopped at (but which is not guaranteed to be
4472 good for anything but further calls to bpstat_num).
4474 Return 0 if passed a bpstat which does not indicate any breakpoints.
4475 Return -1 if stopped at a breakpoint that has been deleted since
4477 Return 1 otherwise. */
4480 bpstat_num (bpstat
*bsp
, int *num
)
4482 struct breakpoint
*b
;
4485 return 0; /* No more breakpoint values */
4487 /* We assume we'll never have several bpstats that correspond to a
4488 single breakpoint -- otherwise, this function might return the
4489 same number more than once and this will look ugly. */
4490 b
= (*bsp
)->breakpoint_at
;
4491 *bsp
= (*bsp
)->next
;
4493 return -1; /* breakpoint that's been deleted since */
4495 *num
= b
->number
; /* We have its number */
4499 /* See breakpoint.h. */
4502 bpstat_clear_actions (void)
4504 struct thread_info
*tp
;
4507 if (ptid_equal (inferior_ptid
, null_ptid
))
4510 tp
= find_thread_ptid (inferior_ptid
);
4514 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4516 decref_counted_command_line (&bs
->commands
);
4518 if (bs
->old_val
!= NULL
)
4520 value_free (bs
->old_val
);
4526 /* Called when a command is about to proceed the inferior. */
4529 breakpoint_about_to_proceed (void)
4531 if (!ptid_equal (inferior_ptid
, null_ptid
))
4533 struct thread_info
*tp
= inferior_thread ();
4535 /* Allow inferior function calls in breakpoint commands to not
4536 interrupt the command list. When the call finishes
4537 successfully, the inferior will be standing at the same
4538 breakpoint as if nothing happened. */
4539 if (tp
->control
.in_infcall
)
4543 breakpoint_proceeded
= 1;
4546 /* Stub for cleaning up our state if we error-out of a breakpoint
4549 cleanup_executing_breakpoints (void *ignore
)
4551 executing_breakpoint_commands
= 0;
4554 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4555 or its equivalent. */
4558 command_line_is_silent (struct command_line
*cmd
)
4560 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4561 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4564 /* Execute all the commands associated with all the breakpoints at
4565 this location. Any of these commands could cause the process to
4566 proceed beyond this point, etc. We look out for such changes by
4567 checking the global "breakpoint_proceeded" after each command.
4569 Returns true if a breakpoint command resumed the inferior. In that
4570 case, it is the caller's responsibility to recall it again with the
4571 bpstat of the current thread. */
4574 bpstat_do_actions_1 (bpstat
*bsp
)
4577 struct cleanup
*old_chain
;
4580 /* Avoid endless recursion if a `source' command is contained
4582 if (executing_breakpoint_commands
)
4585 executing_breakpoint_commands
= 1;
4586 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4588 prevent_dont_repeat ();
4590 /* This pointer will iterate over the list of bpstat's. */
4593 breakpoint_proceeded
= 0;
4594 for (; bs
!= NULL
; bs
= bs
->next
)
4596 struct counted_command_line
*ccmd
;
4597 struct command_line
*cmd
;
4598 struct cleanup
*this_cmd_tree_chain
;
4600 /* Take ownership of the BSP's command tree, if it has one.
4602 The command tree could legitimately contain commands like
4603 'step' and 'next', which call clear_proceed_status, which
4604 frees stop_bpstat's command tree. To make sure this doesn't
4605 free the tree we're executing out from under us, we need to
4606 take ownership of the tree ourselves. Since a given bpstat's
4607 commands are only executed once, we don't need to copy it; we
4608 can clear the pointer in the bpstat, and make sure we free
4609 the tree when we're done. */
4610 ccmd
= bs
->commands
;
4611 bs
->commands
= NULL
;
4612 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4613 cmd
= ccmd
? ccmd
->commands
: NULL
;
4614 if (command_line_is_silent (cmd
))
4616 /* The action has been already done by bpstat_stop_status. */
4622 execute_control_command (cmd
);
4624 if (breakpoint_proceeded
)
4630 /* We can free this command tree now. */
4631 do_cleanups (this_cmd_tree_chain
);
4633 if (breakpoint_proceeded
)
4635 if (interpreter_async
&& target_can_async_p ())
4636 /* If we are in async mode, then the target might be still
4637 running, not stopped at any breakpoint, so nothing for
4638 us to do here -- just return to the event loop. */
4641 /* In sync mode, when execute_control_command returns
4642 we're already standing on the next breakpoint.
4643 Breakpoint commands for that stop were not run, since
4644 execute_command does not run breakpoint commands --
4645 only command_line_handler does, but that one is not
4646 involved in execution of breakpoint commands. So, we
4647 can now execute breakpoint commands. It should be
4648 noted that making execute_command do bpstat actions is
4649 not an option -- in this case we'll have recursive
4650 invocation of bpstat for each breakpoint with a
4651 command, and can easily blow up GDB stack. Instead, we
4652 return true, which will trigger the caller to recall us
4653 with the new stop_bpstat. */
4658 do_cleanups (old_chain
);
4663 bpstat_do_actions (void)
4665 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4667 /* Do any commands attached to breakpoint we are stopped at. */
4668 while (!ptid_equal (inferior_ptid
, null_ptid
)
4669 && target_has_execution
4670 && !is_exited (inferior_ptid
)
4671 && !is_executing (inferior_ptid
))
4672 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4673 and only return when it is stopped at the next breakpoint, we
4674 keep doing breakpoint actions until it returns false to
4675 indicate the inferior was not resumed. */
4676 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4679 discard_cleanups (cleanup_if_error
);
4682 /* Print out the (old or new) value associated with a watchpoint. */
4685 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4688 fprintf_unfiltered (stream
, _("<unreadable>"));
4691 struct value_print_options opts
;
4692 get_user_print_options (&opts
);
4693 value_print (val
, stream
, &opts
);
4697 /* Generic routine for printing messages indicating why we
4698 stopped. The behavior of this function depends on the value
4699 'print_it' in the bpstat structure. Under some circumstances we
4700 may decide not to print anything here and delegate the task to
4703 static enum print_stop_action
4704 print_bp_stop_message (bpstat bs
)
4706 switch (bs
->print_it
)
4709 /* Nothing should be printed for this bpstat entry. */
4710 return PRINT_UNKNOWN
;
4714 /* We still want to print the frame, but we already printed the
4715 relevant messages. */
4716 return PRINT_SRC_AND_LOC
;
4719 case print_it_normal
:
4721 struct breakpoint
*b
= bs
->breakpoint_at
;
4723 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4724 which has since been deleted. */
4726 return PRINT_UNKNOWN
;
4728 /* Normal case. Call the breakpoint's print_it method. */
4729 return b
->ops
->print_it (bs
);
4734 internal_error (__FILE__
, __LINE__
,
4735 _("print_bp_stop_message: unrecognized enum value"));
4740 /* A helper function that prints a shared library stopped event. */
4743 print_solib_event (int is_catchpoint
)
4746 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4748 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4752 if (any_added
|| any_deleted
)
4753 ui_out_text (current_uiout
,
4754 _("Stopped due to shared library event:\n"));
4756 ui_out_text (current_uiout
,
4757 _("Stopped due to shared library event (no "
4758 "libraries added or removed)\n"));
4761 if (ui_out_is_mi_like_p (current_uiout
))
4762 ui_out_field_string (current_uiout
, "reason",
4763 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4767 struct cleanup
*cleanup
;
4771 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4772 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4775 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4780 ui_out_text (current_uiout
, " ");
4781 ui_out_field_string (current_uiout
, "library", name
);
4782 ui_out_text (current_uiout
, "\n");
4785 do_cleanups (cleanup
);
4790 struct so_list
*iter
;
4792 struct cleanup
*cleanup
;
4794 ui_out_text (current_uiout
, _(" Inferior loaded "));
4795 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4798 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4803 ui_out_text (current_uiout
, " ");
4804 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4805 ui_out_text (current_uiout
, "\n");
4808 do_cleanups (cleanup
);
4812 /* Print a message indicating what happened. This is called from
4813 normal_stop(). The input to this routine is the head of the bpstat
4814 list - a list of the eventpoints that caused this stop. KIND is
4815 the target_waitkind for the stopping event. This
4816 routine calls the generic print routine for printing a message
4817 about reasons for stopping. This will print (for example) the
4818 "Breakpoint n," part of the output. The return value of this
4821 PRINT_UNKNOWN: Means we printed nothing.
4822 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4823 code to print the location. An example is
4824 "Breakpoint 1, " which should be followed by
4826 PRINT_SRC_ONLY: Means we printed something, but there is no need
4827 to also print the location part of the message.
4828 An example is the catch/throw messages, which
4829 don't require a location appended to the end.
4830 PRINT_NOTHING: We have done some printing and we don't need any
4831 further info to be printed. */
4833 enum print_stop_action
4834 bpstat_print (bpstat bs
, int kind
)
4838 /* Maybe another breakpoint in the chain caused us to stop.
4839 (Currently all watchpoints go on the bpstat whether hit or not.
4840 That probably could (should) be changed, provided care is taken
4841 with respect to bpstat_explains_signal). */
4842 for (; bs
; bs
= bs
->next
)
4844 val
= print_bp_stop_message (bs
);
4845 if (val
== PRINT_SRC_ONLY
4846 || val
== PRINT_SRC_AND_LOC
4847 || val
== PRINT_NOTHING
)
4851 /* If we had hit a shared library event breakpoint,
4852 print_bp_stop_message would print out this message. If we hit an
4853 OS-level shared library event, do the same thing. */
4854 if (kind
== TARGET_WAITKIND_LOADED
)
4856 print_solib_event (0);
4857 return PRINT_NOTHING
;
4860 /* We reached the end of the chain, or we got a null BS to start
4861 with and nothing was printed. */
4862 return PRINT_UNKNOWN
;
4865 /* Evaluate the expression EXP and return 1 if value is zero.
4866 This returns the inverse of the condition because it is called
4867 from catch_errors which returns 0 if an exception happened, and if an
4868 exception happens we want execution to stop.
4869 The argument is a "struct expression *" that has been cast to a
4870 "void *" to make it pass through catch_errors. */
4873 breakpoint_cond_eval (void *exp
)
4875 struct value
*mark
= value_mark ();
4876 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4878 value_free_to_mark (mark
);
4882 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4885 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4889 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4891 **bs_link_pointer
= bs
;
4892 *bs_link_pointer
= &bs
->next
;
4893 bs
->breakpoint_at
= bl
->owner
;
4894 bs
->bp_location_at
= bl
;
4895 incref_bp_location (bl
);
4896 /* If the condition is false, etc., don't do the commands. */
4897 bs
->commands
= NULL
;
4899 bs
->print_it
= print_it_normal
;
4903 /* The target has stopped with waitstatus WS. Check if any hardware
4904 watchpoints have triggered, according to the target. */
4907 watchpoints_triggered (struct target_waitstatus
*ws
)
4909 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4911 struct breakpoint
*b
;
4913 if (!stopped_by_watchpoint
)
4915 /* We were not stopped by a watchpoint. Mark all watchpoints
4916 as not triggered. */
4918 if (is_hardware_watchpoint (b
))
4920 struct watchpoint
*w
= (struct watchpoint
*) b
;
4922 w
->watchpoint_triggered
= watch_triggered_no
;
4928 if (!target_stopped_data_address (¤t_target
, &addr
))
4930 /* We were stopped by a watchpoint, but we don't know where.
4931 Mark all watchpoints as unknown. */
4933 if (is_hardware_watchpoint (b
))
4935 struct watchpoint
*w
= (struct watchpoint
*) b
;
4937 w
->watchpoint_triggered
= watch_triggered_unknown
;
4943 /* The target could report the data address. Mark watchpoints
4944 affected by this data address as triggered, and all others as not
4948 if (is_hardware_watchpoint (b
))
4950 struct watchpoint
*w
= (struct watchpoint
*) b
;
4951 struct bp_location
*loc
;
4953 w
->watchpoint_triggered
= watch_triggered_no
;
4954 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4956 if (is_masked_watchpoint (b
))
4958 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4959 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4961 if (newaddr
== start
)
4963 w
->watchpoint_triggered
= watch_triggered_yes
;
4967 /* Exact match not required. Within range is sufficient. */
4968 else if (target_watchpoint_addr_within_range (¤t_target
,
4972 w
->watchpoint_triggered
= watch_triggered_yes
;
4981 /* Possible return values for watchpoint_check (this can't be an enum
4982 because of check_errors). */
4983 /* The watchpoint has been deleted. */
4984 #define WP_DELETED 1
4985 /* The value has changed. */
4986 #define WP_VALUE_CHANGED 2
4987 /* The value has not changed. */
4988 #define WP_VALUE_NOT_CHANGED 3
4989 /* Ignore this watchpoint, no matter if the value changed or not. */
4992 #define BP_TEMPFLAG 1
4993 #define BP_HARDWAREFLAG 2
4995 /* Evaluate watchpoint condition expression and check if its value
4998 P should be a pointer to struct bpstat, but is defined as a void *
4999 in order for this function to be usable with catch_errors. */
5002 watchpoint_check (void *p
)
5004 bpstat bs
= (bpstat
) p
;
5005 struct watchpoint
*b
;
5006 struct frame_info
*fr
;
5007 int within_current_scope
;
5009 /* BS is built from an existing struct breakpoint. */
5010 gdb_assert (bs
->breakpoint_at
!= NULL
);
5011 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5013 /* If this is a local watchpoint, we only want to check if the
5014 watchpoint frame is in scope if the current thread is the thread
5015 that was used to create the watchpoint. */
5016 if (!watchpoint_in_thread_scope (b
))
5019 if (b
->exp_valid_block
== NULL
)
5020 within_current_scope
= 1;
5023 struct frame_info
*frame
= get_current_frame ();
5024 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5025 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5027 /* in_function_epilogue_p() returns a non-zero value if we're
5028 still in the function but the stack frame has already been
5029 invalidated. Since we can't rely on the values of local
5030 variables after the stack has been destroyed, we are treating
5031 the watchpoint in that state as `not changed' without further
5032 checking. Don't mark watchpoints as changed if the current
5033 frame is in an epilogue - even if they are in some other
5034 frame, our view of the stack is likely to be wrong and
5035 frame_find_by_id could error out. */
5036 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
5039 fr
= frame_find_by_id (b
->watchpoint_frame
);
5040 within_current_scope
= (fr
!= NULL
);
5042 /* If we've gotten confused in the unwinder, we might have
5043 returned a frame that can't describe this variable. */
5044 if (within_current_scope
)
5046 struct symbol
*function
;
5048 function
= get_frame_function (fr
);
5049 if (function
== NULL
5050 || !contained_in (b
->exp_valid_block
,
5051 SYMBOL_BLOCK_VALUE (function
)))
5052 within_current_scope
= 0;
5055 if (within_current_scope
)
5056 /* If we end up stopping, the current frame will get selected
5057 in normal_stop. So this call to select_frame won't affect
5062 if (within_current_scope
)
5064 /* We use value_{,free_to_}mark because it could be a *long*
5065 time before we return to the command level and call
5066 free_all_values. We can't call free_all_values because we
5067 might be in the middle of evaluating a function call. */
5071 struct value
*new_val
;
5073 if (is_masked_watchpoint (&b
->base
))
5074 /* Since we don't know the exact trigger address (from
5075 stopped_data_address), just tell the user we've triggered
5076 a mask watchpoint. */
5077 return WP_VALUE_CHANGED
;
5079 mark
= value_mark ();
5080 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5082 if (b
->val_bitsize
!= 0)
5083 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5085 /* We use value_equal_contents instead of value_equal because
5086 the latter coerces an array to a pointer, thus comparing just
5087 the address of the array instead of its contents. This is
5088 not what we want. */
5089 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5090 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5092 if (new_val
!= NULL
)
5094 release_value (new_val
);
5095 value_free_to_mark (mark
);
5097 bs
->old_val
= b
->val
;
5100 return WP_VALUE_CHANGED
;
5104 /* Nothing changed. */
5105 value_free_to_mark (mark
);
5106 return WP_VALUE_NOT_CHANGED
;
5111 struct ui_out
*uiout
= current_uiout
;
5113 /* This seems like the only logical thing to do because
5114 if we temporarily ignored the watchpoint, then when
5115 we reenter the block in which it is valid it contains
5116 garbage (in the case of a function, it may have two
5117 garbage values, one before and one after the prologue).
5118 So we can't even detect the first assignment to it and
5119 watch after that (since the garbage may or may not equal
5120 the first value assigned). */
5121 /* We print all the stop information in
5122 breakpoint_ops->print_it, but in this case, by the time we
5123 call breakpoint_ops->print_it this bp will be deleted
5124 already. So we have no choice but print the information
5126 if (ui_out_is_mi_like_p (uiout
))
5128 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5129 ui_out_text (uiout
, "\nWatchpoint ");
5130 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5132 " deleted because the program has left the block in\n\
5133 which its expression is valid.\n");
5135 /* Make sure the watchpoint's commands aren't executed. */
5136 decref_counted_command_line (&b
->base
.commands
);
5137 watchpoint_del_at_next_stop (b
);
5143 /* Return true if it looks like target has stopped due to hitting
5144 breakpoint location BL. This function does not check if we should
5145 stop, only if BL explains the stop. */
5148 bpstat_check_location (const struct bp_location
*bl
,
5149 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5150 const struct target_waitstatus
*ws
)
5152 struct breakpoint
*b
= bl
->owner
;
5154 /* BL is from an existing breakpoint. */
5155 gdb_assert (b
!= NULL
);
5157 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5160 /* Determine if the watched values have actually changed, and we
5161 should stop. If not, set BS->stop to 0. */
5164 bpstat_check_watchpoint (bpstat bs
)
5166 const struct bp_location
*bl
;
5167 struct watchpoint
*b
;
5169 /* BS is built for existing struct breakpoint. */
5170 bl
= bs
->bp_location_at
;
5171 gdb_assert (bl
!= NULL
);
5172 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5173 gdb_assert (b
!= NULL
);
5176 int must_check_value
= 0;
5178 if (b
->base
.type
== bp_watchpoint
)
5179 /* For a software watchpoint, we must always check the
5181 must_check_value
= 1;
5182 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5183 /* We have a hardware watchpoint (read, write, or access)
5184 and the target earlier reported an address watched by
5186 must_check_value
= 1;
5187 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5188 && b
->base
.type
== bp_hardware_watchpoint
)
5189 /* We were stopped by a hardware watchpoint, but the target could
5190 not report the data address. We must check the watchpoint's
5191 value. Access and read watchpoints are out of luck; without
5192 a data address, we can't figure it out. */
5193 must_check_value
= 1;
5195 if (must_check_value
)
5198 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5200 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5201 int e
= catch_errors (watchpoint_check
, bs
, message
,
5203 do_cleanups (cleanups
);
5207 /* We've already printed what needs to be printed. */
5208 bs
->print_it
= print_it_done
;
5212 bs
->print_it
= print_it_noop
;
5215 case WP_VALUE_CHANGED
:
5216 if (b
->base
.type
== bp_read_watchpoint
)
5218 /* There are two cases to consider here:
5220 1. We're watching the triggered memory for reads.
5221 In that case, trust the target, and always report
5222 the watchpoint hit to the user. Even though
5223 reads don't cause value changes, the value may
5224 have changed since the last time it was read, and
5225 since we're not trapping writes, we will not see
5226 those, and as such we should ignore our notion of
5229 2. We're watching the triggered memory for both
5230 reads and writes. There are two ways this may
5233 2.1. This is a target that can't break on data
5234 reads only, but can break on accesses (reads or
5235 writes), such as e.g., x86. We detect this case
5236 at the time we try to insert read watchpoints.
5238 2.2. Otherwise, the target supports read
5239 watchpoints, but, the user set an access or write
5240 watchpoint watching the same memory as this read
5243 If we're watching memory writes as well as reads,
5244 ignore watchpoint hits when we find that the
5245 value hasn't changed, as reads don't cause
5246 changes. This still gives false positives when
5247 the program writes the same value to memory as
5248 what there was already in memory (we will confuse
5249 it for a read), but it's much better than
5252 int other_write_watchpoint
= 0;
5254 if (bl
->watchpoint_type
== hw_read
)
5256 struct breakpoint
*other_b
;
5258 ALL_BREAKPOINTS (other_b
)
5259 if (other_b
->type
== bp_hardware_watchpoint
5260 || other_b
->type
== bp_access_watchpoint
)
5262 struct watchpoint
*other_w
=
5263 (struct watchpoint
*) other_b
;
5265 if (other_w
->watchpoint_triggered
5266 == watch_triggered_yes
)
5268 other_write_watchpoint
= 1;
5274 if (other_write_watchpoint
5275 || bl
->watchpoint_type
== hw_access
)
5277 /* We're watching the same memory for writes,
5278 and the value changed since the last time we
5279 updated it, so this trap must be for a write.
5281 bs
->print_it
= print_it_noop
;
5286 case WP_VALUE_NOT_CHANGED
:
5287 if (b
->base
.type
== bp_hardware_watchpoint
5288 || b
->base
.type
== bp_watchpoint
)
5290 /* Don't stop: write watchpoints shouldn't fire if
5291 the value hasn't changed. */
5292 bs
->print_it
= print_it_noop
;
5300 /* Error from catch_errors. */
5301 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5302 watchpoint_del_at_next_stop (b
);
5303 /* We've already printed what needs to be printed. */
5304 bs
->print_it
= print_it_done
;
5308 else /* must_check_value == 0 */
5310 /* This is a case where some watchpoint(s) triggered, but
5311 not at the address of this watchpoint, or else no
5312 watchpoint triggered after all. So don't print
5313 anything for this watchpoint. */
5314 bs
->print_it
= print_it_noop
;
5320 /* For breakpoints that are currently marked as telling gdb to stop,
5321 check conditions (condition proper, frame, thread and ignore count)
5322 of breakpoint referred to by BS. If we should not stop for this
5323 breakpoint, set BS->stop to 0. */
5326 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5328 const struct bp_location
*bl
;
5329 struct breakpoint
*b
;
5330 int value_is_zero
= 0;
5331 struct expression
*cond
;
5333 gdb_assert (bs
->stop
);
5335 /* BS is built for existing struct breakpoint. */
5336 bl
= bs
->bp_location_at
;
5337 gdb_assert (bl
!= NULL
);
5338 b
= bs
->breakpoint_at
;
5339 gdb_assert (b
!= NULL
);
5341 /* Even if the target evaluated the condition on its end and notified GDB, we
5342 need to do so again since GDB does not know if we stopped due to a
5343 breakpoint or a single step breakpoint. */
5345 if (frame_id_p (b
->frame_id
)
5346 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5352 /* If this is a thread/task-specific breakpoint, don't waste cpu
5353 evaluating the condition if this isn't the specified
5355 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5356 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5363 /* Evaluate extension language breakpoints that have a "stop" method
5365 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5367 if (is_watchpoint (b
))
5369 struct watchpoint
*w
= (struct watchpoint
*) b
;
5376 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5378 int within_current_scope
= 1;
5379 struct watchpoint
* w
;
5381 /* We use value_mark and value_free_to_mark because it could
5382 be a long time before we return to the command level and
5383 call free_all_values. We can't call free_all_values
5384 because we might be in the middle of evaluating a
5386 struct value
*mark
= value_mark ();
5388 if (is_watchpoint (b
))
5389 w
= (struct watchpoint
*) b
;
5393 /* Need to select the frame, with all that implies so that
5394 the conditions will have the right context. Because we
5395 use the frame, we will not see an inlined function's
5396 variables when we arrive at a breakpoint at the start
5397 of the inlined function; the current frame will be the
5399 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5400 select_frame (get_current_frame ());
5403 struct frame_info
*frame
;
5405 /* For local watchpoint expressions, which particular
5406 instance of a local is being watched matters, so we
5407 keep track of the frame to evaluate the expression
5408 in. To evaluate the condition however, it doesn't
5409 really matter which instantiation of the function
5410 where the condition makes sense triggers the
5411 watchpoint. This allows an expression like "watch
5412 global if q > 10" set in `func', catch writes to
5413 global on all threads that call `func', or catch
5414 writes on all recursive calls of `func' by a single
5415 thread. We simply always evaluate the condition in
5416 the innermost frame that's executing where it makes
5417 sense to evaluate the condition. It seems
5419 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5421 select_frame (frame
);
5423 within_current_scope
= 0;
5425 if (within_current_scope
)
5427 = catch_errors (breakpoint_cond_eval
, cond
,
5428 "Error in testing breakpoint condition:\n",
5432 warning (_("Watchpoint condition cannot be tested "
5433 "in the current scope"));
5434 /* If we failed to set the right context for this
5435 watchpoint, unconditionally report it. */
5438 /* FIXME-someday, should give breakpoint #. */
5439 value_free_to_mark (mark
);
5442 if (cond
&& value_is_zero
)
5446 else if (b
->ignore_count
> 0)
5450 /* Increase the hit count even though we don't stop. */
5452 observer_notify_breakpoint_modified (b
);
5456 /* Returns true if we need to track moribund locations of LOC's type
5457 on the current target. */
5460 need_moribund_for_location_type (struct bp_location
*loc
)
5462 return ((loc
->loc_type
== bp_loc_software_breakpoint
5463 && !target_supports_stopped_by_sw_breakpoint ())
5464 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5465 && !target_supports_stopped_by_hw_breakpoint ()));
5469 /* Get a bpstat associated with having just stopped at address
5470 BP_ADDR in thread PTID.
5472 Determine whether we stopped at a breakpoint, etc, or whether we
5473 don't understand this stop. Result is a chain of bpstat's such
5476 if we don't understand the stop, the result is a null pointer.
5478 if we understand why we stopped, the result is not null.
5480 Each element of the chain refers to a particular breakpoint or
5481 watchpoint at which we have stopped. (We may have stopped for
5482 several reasons concurrently.)
5484 Each element of the chain has valid next, breakpoint_at,
5485 commands, FIXME??? fields. */
5488 bpstat_stop_status (struct address_space
*aspace
,
5489 CORE_ADDR bp_addr
, ptid_t ptid
,
5490 const struct target_waitstatus
*ws
)
5492 struct breakpoint
*b
= NULL
;
5493 struct bp_location
*bl
;
5494 struct bp_location
*loc
;
5495 /* First item of allocated bpstat's. */
5496 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5497 /* Pointer to the last thing in the chain currently. */
5500 int need_remove_insert
;
5503 /* First, build the bpstat chain with locations that explain a
5504 target stop, while being careful to not set the target running,
5505 as that may invalidate locations (in particular watchpoint
5506 locations are recreated). Resuming will happen here with
5507 breakpoint conditions or watchpoint expressions that include
5508 inferior function calls. */
5512 if (!breakpoint_enabled (b
))
5515 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5517 /* For hardware watchpoints, we look only at the first
5518 location. The watchpoint_check function will work on the
5519 entire expression, not the individual locations. For
5520 read watchpoints, the watchpoints_triggered function has
5521 checked all locations already. */
5522 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5525 if (!bl
->enabled
|| bl
->shlib_disabled
)
5528 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5531 /* Come here if it's a watchpoint, or if the break address
5534 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5537 /* Assume we stop. Should we find a watchpoint that is not
5538 actually triggered, or if the condition of the breakpoint
5539 evaluates as false, we'll reset 'stop' to 0. */
5543 /* If this is a scope breakpoint, mark the associated
5544 watchpoint as triggered so that we will handle the
5545 out-of-scope event. We'll get to the watchpoint next
5547 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5549 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5551 w
->watchpoint_triggered
= watch_triggered_yes
;
5556 /* Check if a moribund breakpoint explains the stop. */
5557 if (!target_supports_stopped_by_sw_breakpoint ()
5558 || !target_supports_stopped_by_hw_breakpoint ())
5560 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5562 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5563 && need_moribund_for_location_type (loc
))
5565 bs
= bpstat_alloc (loc
, &bs_link
);
5566 /* For hits of moribund locations, we should just proceed. */
5569 bs
->print_it
= print_it_noop
;
5574 /* A bit of special processing for shlib breakpoints. We need to
5575 process solib loading here, so that the lists of loaded and
5576 unloaded libraries are correct before we handle "catch load" and
5578 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5580 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5582 handle_solib_event ();
5587 /* Now go through the locations that caused the target to stop, and
5588 check whether we're interested in reporting this stop to higher
5589 layers, or whether we should resume the target transparently. */
5593 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5598 b
= bs
->breakpoint_at
;
5599 b
->ops
->check_status (bs
);
5602 bpstat_check_breakpoint_conditions (bs
, ptid
);
5607 observer_notify_breakpoint_modified (b
);
5609 /* We will stop here. */
5610 if (b
->disposition
== disp_disable
)
5612 --(b
->enable_count
);
5613 if (b
->enable_count
<= 0)
5614 b
->enable_state
= bp_disabled
;
5619 bs
->commands
= b
->commands
;
5620 incref_counted_command_line (bs
->commands
);
5621 if (command_line_is_silent (bs
->commands
5622 ? bs
->commands
->commands
: NULL
))
5625 b
->ops
->after_condition_true (bs
);
5630 /* Print nothing for this entry if we don't stop or don't
5632 if (!bs
->stop
|| !bs
->print
)
5633 bs
->print_it
= print_it_noop
;
5636 /* If we aren't stopping, the value of some hardware watchpoint may
5637 not have changed, but the intermediate memory locations we are
5638 watching may have. Don't bother if we're stopping; this will get
5640 need_remove_insert
= 0;
5641 if (! bpstat_causes_stop (bs_head
))
5642 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5644 && bs
->breakpoint_at
5645 && is_hardware_watchpoint (bs
->breakpoint_at
))
5647 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5649 update_watchpoint (w
, 0 /* don't reparse. */);
5650 need_remove_insert
= 1;
5653 if (need_remove_insert
)
5654 update_global_location_list (UGLL_MAY_INSERT
);
5655 else if (removed_any
)
5656 update_global_location_list (UGLL_DONT_INSERT
);
5662 handle_jit_event (void)
5664 struct frame_info
*frame
;
5665 struct gdbarch
*gdbarch
;
5667 /* Switch terminal for any messages produced by
5668 breakpoint_re_set. */
5669 target_terminal_ours_for_output ();
5671 frame
= get_current_frame ();
5672 gdbarch
= get_frame_arch (frame
);
5674 jit_event_handler (gdbarch
);
5676 target_terminal_inferior ();
5679 /* Prepare WHAT final decision for infrun. */
5681 /* Decide what infrun needs to do with this bpstat. */
5684 bpstat_what (bpstat bs_head
)
5686 struct bpstat_what retval
;
5690 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5691 retval
.call_dummy
= STOP_NONE
;
5692 retval
.is_longjmp
= 0;
5694 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5696 /* Extract this BS's action. After processing each BS, we check
5697 if its action overrides all we've seem so far. */
5698 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5701 if (bs
->breakpoint_at
== NULL
)
5703 /* I suspect this can happen if it was a momentary
5704 breakpoint which has since been deleted. */
5708 bptype
= bs
->breakpoint_at
->type
;
5715 case bp_hardware_breakpoint
:
5716 case bp_single_step
:
5719 case bp_shlib_event
:
5723 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5725 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5728 this_action
= BPSTAT_WHAT_SINGLE
;
5731 case bp_hardware_watchpoint
:
5732 case bp_read_watchpoint
:
5733 case bp_access_watchpoint
:
5737 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5739 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5743 /* There was a watchpoint, but we're not stopping.
5744 This requires no further action. */
5748 case bp_longjmp_call_dummy
:
5750 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5751 retval
.is_longjmp
= bptype
!= bp_exception
;
5753 case bp_longjmp_resume
:
5754 case bp_exception_resume
:
5755 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5756 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5758 case bp_step_resume
:
5760 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5763 /* It is for the wrong frame. */
5764 this_action
= BPSTAT_WHAT_SINGLE
;
5767 case bp_hp_step_resume
:
5769 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5772 /* It is for the wrong frame. */
5773 this_action
= BPSTAT_WHAT_SINGLE
;
5776 case bp_watchpoint_scope
:
5777 case bp_thread_event
:
5778 case bp_overlay_event
:
5779 case bp_longjmp_master
:
5780 case bp_std_terminate_master
:
5781 case bp_exception_master
:
5782 this_action
= BPSTAT_WHAT_SINGLE
;
5788 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5790 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5794 /* There was a catchpoint, but we're not stopping.
5795 This requires no further action. */
5800 this_action
= BPSTAT_WHAT_SINGLE
;
5803 /* Make sure the action is stop (silent or noisy),
5804 so infrun.c pops the dummy frame. */
5805 retval
.call_dummy
= STOP_STACK_DUMMY
;
5806 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5808 case bp_std_terminate
:
5809 /* Make sure the action is stop (silent or noisy),
5810 so infrun.c pops the dummy frame. */
5811 retval
.call_dummy
= STOP_STD_TERMINATE
;
5812 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5815 case bp_fast_tracepoint
:
5816 case bp_static_tracepoint
:
5817 /* Tracepoint hits should not be reported back to GDB, and
5818 if one got through somehow, it should have been filtered
5820 internal_error (__FILE__
, __LINE__
,
5821 _("bpstat_what: tracepoint encountered"));
5823 case bp_gnu_ifunc_resolver
:
5824 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5825 this_action
= BPSTAT_WHAT_SINGLE
;
5827 case bp_gnu_ifunc_resolver_return
:
5828 /* The breakpoint will be removed, execution will restart from the
5829 PC of the former breakpoint. */
5830 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5835 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5837 this_action
= BPSTAT_WHAT_SINGLE
;
5841 internal_error (__FILE__
, __LINE__
,
5842 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5845 retval
.main_action
= max (retval
.main_action
, this_action
);
5848 /* These operations may affect the bs->breakpoint_at state so they are
5849 delayed after MAIN_ACTION is decided above. */
5854 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5856 handle_jit_event ();
5859 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5861 struct breakpoint
*b
= bs
->breakpoint_at
;
5867 case bp_gnu_ifunc_resolver
:
5868 gnu_ifunc_resolver_stop (b
);
5870 case bp_gnu_ifunc_resolver_return
:
5871 gnu_ifunc_resolver_return_stop (b
);
5879 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5880 without hardware support). This isn't related to a specific bpstat,
5881 just to things like whether watchpoints are set. */
5884 bpstat_should_step (void)
5886 struct breakpoint
*b
;
5889 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5895 bpstat_causes_stop (bpstat bs
)
5897 for (; bs
!= NULL
; bs
= bs
->next
)
5906 /* Compute a string of spaces suitable to indent the next line
5907 so it starts at the position corresponding to the table column
5908 named COL_NAME in the currently active table of UIOUT. */
5911 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5913 static char wrap_indent
[80];
5914 int i
, total_width
, width
, align
;
5918 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5920 if (strcmp (text
, col_name
) == 0)
5922 gdb_assert (total_width
< sizeof wrap_indent
);
5923 memset (wrap_indent
, ' ', total_width
);
5924 wrap_indent
[total_width
] = 0;
5929 total_width
+= width
+ 1;
5935 /* Determine if the locations of this breakpoint will have their conditions
5936 evaluated by the target, host or a mix of both. Returns the following:
5938 "host": Host evals condition.
5939 "host or target": Host or Target evals condition.
5940 "target": Target evals condition.
5944 bp_condition_evaluator (struct breakpoint
*b
)
5946 struct bp_location
*bl
;
5947 char host_evals
= 0;
5948 char target_evals
= 0;
5953 if (!is_breakpoint (b
))
5956 if (gdb_evaluates_breakpoint_condition_p ()
5957 || !target_supports_evaluation_of_breakpoint_conditions ())
5958 return condition_evaluation_host
;
5960 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5962 if (bl
->cond_bytecode
)
5968 if (host_evals
&& target_evals
)
5969 return condition_evaluation_both
;
5970 else if (target_evals
)
5971 return condition_evaluation_target
;
5973 return condition_evaluation_host
;
5976 /* Determine the breakpoint location's condition evaluator. This is
5977 similar to bp_condition_evaluator, but for locations. */
5980 bp_location_condition_evaluator (struct bp_location
*bl
)
5982 if (bl
&& !is_breakpoint (bl
->owner
))
5985 if (gdb_evaluates_breakpoint_condition_p ()
5986 || !target_supports_evaluation_of_breakpoint_conditions ())
5987 return condition_evaluation_host
;
5989 if (bl
&& bl
->cond_bytecode
)
5990 return condition_evaluation_target
;
5992 return condition_evaluation_host
;
5995 /* Print the LOC location out of the list of B->LOC locations. */
5998 print_breakpoint_location (struct breakpoint
*b
,
5999 struct bp_location
*loc
)
6001 struct ui_out
*uiout
= current_uiout
;
6002 struct cleanup
*old_chain
= save_current_program_space ();
6004 if (loc
!= NULL
&& loc
->shlib_disabled
)
6008 set_current_program_space (loc
->pspace
);
6010 if (b
->display_canonical
)
6011 ui_out_field_string (uiout
, "what", b
->addr_string
);
6012 else if (loc
&& loc
->symtab
)
6015 = find_pc_sect_function (loc
->address
, loc
->section
);
6018 ui_out_text (uiout
, "in ");
6019 ui_out_field_string (uiout
, "func",
6020 SYMBOL_PRINT_NAME (sym
));
6021 ui_out_text (uiout
, " ");
6022 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6023 ui_out_text (uiout
, "at ");
6025 ui_out_field_string (uiout
, "file",
6026 symtab_to_filename_for_display (loc
->symtab
));
6027 ui_out_text (uiout
, ":");
6029 if (ui_out_is_mi_like_p (uiout
))
6030 ui_out_field_string (uiout
, "fullname",
6031 symtab_to_fullname (loc
->symtab
));
6033 ui_out_field_int (uiout
, "line", loc
->line_number
);
6037 struct ui_file
*stb
= mem_fileopen ();
6038 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6040 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6042 ui_out_field_stream (uiout
, "at", stb
);
6044 do_cleanups (stb_chain
);
6047 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6049 if (loc
&& is_breakpoint (b
)
6050 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6051 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6053 ui_out_text (uiout
, " (");
6054 ui_out_field_string (uiout
, "evaluated-by",
6055 bp_location_condition_evaluator (loc
));
6056 ui_out_text (uiout
, ")");
6059 do_cleanups (old_chain
);
6063 bptype_string (enum bptype type
)
6065 struct ep_type_description
6070 static struct ep_type_description bptypes
[] =
6072 {bp_none
, "?deleted?"},
6073 {bp_breakpoint
, "breakpoint"},
6074 {bp_hardware_breakpoint
, "hw breakpoint"},
6075 {bp_single_step
, "sw single-step"},
6076 {bp_until
, "until"},
6077 {bp_finish
, "finish"},
6078 {bp_watchpoint
, "watchpoint"},
6079 {bp_hardware_watchpoint
, "hw watchpoint"},
6080 {bp_read_watchpoint
, "read watchpoint"},
6081 {bp_access_watchpoint
, "acc watchpoint"},
6082 {bp_longjmp
, "longjmp"},
6083 {bp_longjmp_resume
, "longjmp resume"},
6084 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6085 {bp_exception
, "exception"},
6086 {bp_exception_resume
, "exception resume"},
6087 {bp_step_resume
, "step resume"},
6088 {bp_hp_step_resume
, "high-priority step resume"},
6089 {bp_watchpoint_scope
, "watchpoint scope"},
6090 {bp_call_dummy
, "call dummy"},
6091 {bp_std_terminate
, "std::terminate"},
6092 {bp_shlib_event
, "shlib events"},
6093 {bp_thread_event
, "thread events"},
6094 {bp_overlay_event
, "overlay events"},
6095 {bp_longjmp_master
, "longjmp master"},
6096 {bp_std_terminate_master
, "std::terminate master"},
6097 {bp_exception_master
, "exception master"},
6098 {bp_catchpoint
, "catchpoint"},
6099 {bp_tracepoint
, "tracepoint"},
6100 {bp_fast_tracepoint
, "fast tracepoint"},
6101 {bp_static_tracepoint
, "static tracepoint"},
6102 {bp_dprintf
, "dprintf"},
6103 {bp_jit_event
, "jit events"},
6104 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6105 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6108 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6109 || ((int) type
!= bptypes
[(int) type
].type
))
6110 internal_error (__FILE__
, __LINE__
,
6111 _("bptypes table does not describe type #%d."),
6114 return bptypes
[(int) type
].description
;
6117 /* For MI, output a field named 'thread-groups' with a list as the value.
6118 For CLI, prefix the list with the string 'inf'. */
6121 output_thread_groups (struct ui_out
*uiout
,
6122 const char *field_name
,
6126 struct cleanup
*back_to
;
6127 int is_mi
= ui_out_is_mi_like_p (uiout
);
6131 /* For backward compatibility, don't display inferiors in CLI unless
6132 there are several. Always display them for MI. */
6133 if (!is_mi
&& mi_only
)
6136 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6138 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6144 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6145 ui_out_field_string (uiout
, NULL
, mi_group
);
6150 ui_out_text (uiout
, " inf ");
6152 ui_out_text (uiout
, ", ");
6154 ui_out_text (uiout
, plongest (inf
));
6158 do_cleanups (back_to
);
6161 /* Print B to gdb_stdout. */
6164 print_one_breakpoint_location (struct breakpoint
*b
,
6165 struct bp_location
*loc
,
6167 struct bp_location
**last_loc
,
6170 struct command_line
*l
;
6171 static char bpenables
[] = "nynny";
6173 struct ui_out
*uiout
= current_uiout
;
6174 int header_of_multiple
= 0;
6175 int part_of_multiple
= (loc
!= NULL
);
6176 struct value_print_options opts
;
6178 get_user_print_options (&opts
);
6180 gdb_assert (!loc
|| loc_number
!= 0);
6181 /* See comment in print_one_breakpoint concerning treatment of
6182 breakpoints with single disabled location. */
6185 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6186 header_of_multiple
= 1;
6194 if (part_of_multiple
)
6197 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6198 ui_out_field_string (uiout
, "number", formatted
);
6203 ui_out_field_int (uiout
, "number", b
->number
);
6208 if (part_of_multiple
)
6209 ui_out_field_skip (uiout
, "type");
6211 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6215 if (part_of_multiple
)
6216 ui_out_field_skip (uiout
, "disp");
6218 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6223 if (part_of_multiple
)
6224 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6226 ui_out_field_fmt (uiout
, "enabled", "%c",
6227 bpenables
[(int) b
->enable_state
]);
6228 ui_out_spaces (uiout
, 2);
6232 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6234 /* Although the print_one can possibly print all locations,
6235 calling it here is not likely to get any nice result. So,
6236 make sure there's just one location. */
6237 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6238 b
->ops
->print_one (b
, last_loc
);
6244 internal_error (__FILE__
, __LINE__
,
6245 _("print_one_breakpoint: bp_none encountered\n"));
6249 case bp_hardware_watchpoint
:
6250 case bp_read_watchpoint
:
6251 case bp_access_watchpoint
:
6253 struct watchpoint
*w
= (struct watchpoint
*) b
;
6255 /* Field 4, the address, is omitted (which makes the columns
6256 not line up too nicely with the headers, but the effect
6257 is relatively readable). */
6258 if (opts
.addressprint
)
6259 ui_out_field_skip (uiout
, "addr");
6261 ui_out_field_string (uiout
, "what", w
->exp_string
);
6266 case bp_hardware_breakpoint
:
6267 case bp_single_step
:
6271 case bp_longjmp_resume
:
6272 case bp_longjmp_call_dummy
:
6274 case bp_exception_resume
:
6275 case bp_step_resume
:
6276 case bp_hp_step_resume
:
6277 case bp_watchpoint_scope
:
6279 case bp_std_terminate
:
6280 case bp_shlib_event
:
6281 case bp_thread_event
:
6282 case bp_overlay_event
:
6283 case bp_longjmp_master
:
6284 case bp_std_terminate_master
:
6285 case bp_exception_master
:
6287 case bp_fast_tracepoint
:
6288 case bp_static_tracepoint
:
6291 case bp_gnu_ifunc_resolver
:
6292 case bp_gnu_ifunc_resolver_return
:
6293 if (opts
.addressprint
)
6296 if (header_of_multiple
)
6297 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6298 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6299 ui_out_field_string (uiout
, "addr", "<PENDING>");
6301 ui_out_field_core_addr (uiout
, "addr",
6302 loc
->gdbarch
, loc
->address
);
6305 if (!header_of_multiple
)
6306 print_breakpoint_location (b
, loc
);
6313 if (loc
!= NULL
&& !header_of_multiple
)
6315 struct inferior
*inf
;
6316 VEC(int) *inf_num
= NULL
;
6321 if (inf
->pspace
== loc
->pspace
)
6322 VEC_safe_push (int, inf_num
, inf
->num
);
6325 /* For backward compatibility, don't display inferiors in CLI unless
6326 there are several. Always display for MI. */
6328 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6329 && (number_of_program_spaces () > 1
6330 || number_of_inferiors () > 1)
6331 /* LOC is for existing B, it cannot be in
6332 moribund_locations and thus having NULL OWNER. */
6333 && loc
->owner
->type
!= bp_catchpoint
))
6335 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6336 VEC_free (int, inf_num
);
6339 if (!part_of_multiple
)
6341 if (b
->thread
!= -1)
6343 /* FIXME: This seems to be redundant and lost here; see the
6344 "stop only in" line a little further down. */
6345 ui_out_text (uiout
, " thread ");
6346 ui_out_field_int (uiout
, "thread", b
->thread
);
6348 else if (b
->task
!= 0)
6350 ui_out_text (uiout
, " task ");
6351 ui_out_field_int (uiout
, "task", b
->task
);
6355 ui_out_text (uiout
, "\n");
6357 if (!part_of_multiple
)
6358 b
->ops
->print_one_detail (b
, uiout
);
6360 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6363 ui_out_text (uiout
, "\tstop only in stack frame at ");
6364 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6366 ui_out_field_core_addr (uiout
, "frame",
6367 b
->gdbarch
, b
->frame_id
.stack_addr
);
6368 ui_out_text (uiout
, "\n");
6371 if (!part_of_multiple
&& b
->cond_string
)
6374 if (is_tracepoint (b
))
6375 ui_out_text (uiout
, "\ttrace only if ");
6377 ui_out_text (uiout
, "\tstop only if ");
6378 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6380 /* Print whether the target is doing the breakpoint's condition
6381 evaluation. If GDB is doing the evaluation, don't print anything. */
6382 if (is_breakpoint (b
)
6383 && breakpoint_condition_evaluation_mode ()
6384 == condition_evaluation_target
)
6386 ui_out_text (uiout
, " (");
6387 ui_out_field_string (uiout
, "evaluated-by",
6388 bp_condition_evaluator (b
));
6389 ui_out_text (uiout
, " evals)");
6391 ui_out_text (uiout
, "\n");
6394 if (!part_of_multiple
&& b
->thread
!= -1)
6396 /* FIXME should make an annotation for this. */
6397 ui_out_text (uiout
, "\tstop only in thread ");
6398 ui_out_field_int (uiout
, "thread", b
->thread
);
6399 ui_out_text (uiout
, "\n");
6402 if (!part_of_multiple
)
6406 /* FIXME should make an annotation for this. */
6407 if (is_catchpoint (b
))
6408 ui_out_text (uiout
, "\tcatchpoint");
6409 else if (is_tracepoint (b
))
6410 ui_out_text (uiout
, "\ttracepoint");
6412 ui_out_text (uiout
, "\tbreakpoint");
6413 ui_out_text (uiout
, " already hit ");
6414 ui_out_field_int (uiout
, "times", b
->hit_count
);
6415 if (b
->hit_count
== 1)
6416 ui_out_text (uiout
, " time\n");
6418 ui_out_text (uiout
, " times\n");
6422 /* Output the count also if it is zero, but only if this is mi. */
6423 if (ui_out_is_mi_like_p (uiout
))
6424 ui_out_field_int (uiout
, "times", b
->hit_count
);
6428 if (!part_of_multiple
&& b
->ignore_count
)
6431 ui_out_text (uiout
, "\tignore next ");
6432 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6433 ui_out_text (uiout
, " hits\n");
6436 /* Note that an enable count of 1 corresponds to "enable once"
6437 behavior, which is reported by the combination of enablement and
6438 disposition, so we don't need to mention it here. */
6439 if (!part_of_multiple
&& b
->enable_count
> 1)
6442 ui_out_text (uiout
, "\tdisable after ");
6443 /* Tweak the wording to clarify that ignore and enable counts
6444 are distinct, and have additive effect. */
6445 if (b
->ignore_count
)
6446 ui_out_text (uiout
, "additional ");
6448 ui_out_text (uiout
, "next ");
6449 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6450 ui_out_text (uiout
, " hits\n");
6453 if (!part_of_multiple
&& is_tracepoint (b
))
6455 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6457 if (tp
->traceframe_usage
)
6459 ui_out_text (uiout
, "\ttrace buffer usage ");
6460 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6461 ui_out_text (uiout
, " bytes\n");
6465 l
= b
->commands
? b
->commands
->commands
: NULL
;
6466 if (!part_of_multiple
&& l
)
6468 struct cleanup
*script_chain
;
6471 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6472 print_command_lines (uiout
, l
, 4);
6473 do_cleanups (script_chain
);
6476 if (is_tracepoint (b
))
6478 struct tracepoint
*t
= (struct tracepoint
*) b
;
6480 if (!part_of_multiple
&& t
->pass_count
)
6482 annotate_field (10);
6483 ui_out_text (uiout
, "\tpass count ");
6484 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6485 ui_out_text (uiout
, " \n");
6488 /* Don't display it when tracepoint or tracepoint location is
6490 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6492 annotate_field (11);
6494 if (ui_out_is_mi_like_p (uiout
))
6495 ui_out_field_string (uiout
, "installed",
6496 loc
->inserted
? "y" : "n");
6500 ui_out_text (uiout
, "\t");
6502 ui_out_text (uiout
, "\tnot ");
6503 ui_out_text (uiout
, "installed on target\n");
6508 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6510 if (is_watchpoint (b
))
6512 struct watchpoint
*w
= (struct watchpoint
*) b
;
6514 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6516 else if (b
->addr_string
)
6517 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6522 print_one_breakpoint (struct breakpoint
*b
,
6523 struct bp_location
**last_loc
,
6526 struct cleanup
*bkpt_chain
;
6527 struct ui_out
*uiout
= current_uiout
;
6529 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6531 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6532 do_cleanups (bkpt_chain
);
6534 /* If this breakpoint has custom print function,
6535 it's already printed. Otherwise, print individual
6536 locations, if any. */
6537 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6539 /* If breakpoint has a single location that is disabled, we
6540 print it as if it had several locations, since otherwise it's
6541 hard to represent "breakpoint enabled, location disabled"
6544 Note that while hardware watchpoints have several locations
6545 internally, that's not a property exposed to user. */
6547 && !is_hardware_watchpoint (b
)
6548 && (b
->loc
->next
|| !b
->loc
->enabled
))
6550 struct bp_location
*loc
;
6553 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6555 struct cleanup
*inner2
=
6556 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6557 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6558 do_cleanups (inner2
);
6565 breakpoint_address_bits (struct breakpoint
*b
)
6567 int print_address_bits
= 0;
6568 struct bp_location
*loc
;
6570 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6574 /* Software watchpoints that aren't watching memory don't have
6575 an address to print. */
6576 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6579 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6580 if (addr_bit
> print_address_bits
)
6581 print_address_bits
= addr_bit
;
6584 return print_address_bits
;
6587 struct captured_breakpoint_query_args
6593 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6595 struct captured_breakpoint_query_args
*args
= data
;
6596 struct breakpoint
*b
;
6597 struct bp_location
*dummy_loc
= NULL
;
6601 if (args
->bnum
== b
->number
)
6603 print_one_breakpoint (b
, &dummy_loc
, 0);
6611 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6612 char **error_message
)
6614 struct captured_breakpoint_query_args args
;
6617 /* For the moment we don't trust print_one_breakpoint() to not throw
6619 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6620 error_message
, RETURN_MASK_ALL
) < 0)
6626 /* Return true if this breakpoint was set by the user, false if it is
6627 internal or momentary. */
6630 user_breakpoint_p (struct breakpoint
*b
)
6632 return b
->number
> 0;
6635 /* Print information on user settable breakpoint (watchpoint, etc)
6636 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6637 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6638 FILTER is non-NULL, call it on each breakpoint and only include the
6639 ones for which it returns non-zero. Return the total number of
6640 breakpoints listed. */
6643 breakpoint_1 (char *args
, int allflag
,
6644 int (*filter
) (const struct breakpoint
*))
6646 struct breakpoint
*b
;
6647 struct bp_location
*last_loc
= NULL
;
6648 int nr_printable_breakpoints
;
6649 struct cleanup
*bkpttbl_chain
;
6650 struct value_print_options opts
;
6651 int print_address_bits
= 0;
6652 int print_type_col_width
= 14;
6653 struct ui_out
*uiout
= current_uiout
;
6655 get_user_print_options (&opts
);
6657 /* Compute the number of rows in the table, as well as the size
6658 required for address fields. */
6659 nr_printable_breakpoints
= 0;
6662 /* If we have a filter, only list the breakpoints it accepts. */
6663 if (filter
&& !filter (b
))
6666 /* If we have an "args" string, it is a list of breakpoints to
6667 accept. Skip the others. */
6668 if (args
!= NULL
&& *args
!= '\0')
6670 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6672 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6676 if (allflag
|| user_breakpoint_p (b
))
6678 int addr_bit
, type_len
;
6680 addr_bit
= breakpoint_address_bits (b
);
6681 if (addr_bit
> print_address_bits
)
6682 print_address_bits
= addr_bit
;
6684 type_len
= strlen (bptype_string (b
->type
));
6685 if (type_len
> print_type_col_width
)
6686 print_type_col_width
= type_len
;
6688 nr_printable_breakpoints
++;
6692 if (opts
.addressprint
)
6694 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6695 nr_printable_breakpoints
,
6699 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6700 nr_printable_breakpoints
,
6703 if (nr_printable_breakpoints
> 0)
6704 annotate_breakpoints_headers ();
6705 if (nr_printable_breakpoints
> 0)
6707 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6708 if (nr_printable_breakpoints
> 0)
6710 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6711 "type", "Type"); /* 2 */
6712 if (nr_printable_breakpoints
> 0)
6714 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6715 if (nr_printable_breakpoints
> 0)
6717 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6718 if (opts
.addressprint
)
6720 if (nr_printable_breakpoints
> 0)
6722 if (print_address_bits
<= 32)
6723 ui_out_table_header (uiout
, 10, ui_left
,
6724 "addr", "Address"); /* 5 */
6726 ui_out_table_header (uiout
, 18, ui_left
,
6727 "addr", "Address"); /* 5 */
6729 if (nr_printable_breakpoints
> 0)
6731 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6732 ui_out_table_body (uiout
);
6733 if (nr_printable_breakpoints
> 0)
6734 annotate_breakpoints_table ();
6739 /* If we have a filter, only list the breakpoints it accepts. */
6740 if (filter
&& !filter (b
))
6743 /* If we have an "args" string, it is a list of breakpoints to
6744 accept. Skip the others. */
6746 if (args
!= NULL
&& *args
!= '\0')
6748 if (allflag
) /* maintenance info breakpoint */
6750 if (parse_and_eval_long (args
) != b
->number
)
6753 else /* all others */
6755 if (!number_is_in_list (args
, b
->number
))
6759 /* We only print out user settable breakpoints unless the
6761 if (allflag
|| user_breakpoint_p (b
))
6762 print_one_breakpoint (b
, &last_loc
, allflag
);
6765 do_cleanups (bkpttbl_chain
);
6767 if (nr_printable_breakpoints
== 0)
6769 /* If there's a filter, let the caller decide how to report
6773 if (args
== NULL
|| *args
== '\0')
6774 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6776 ui_out_message (uiout
, 0,
6777 "No breakpoint or watchpoint matching '%s'.\n",
6783 if (last_loc
&& !server_command
)
6784 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6787 /* FIXME? Should this be moved up so that it is only called when
6788 there have been breakpoints? */
6789 annotate_breakpoints_table_end ();
6791 return nr_printable_breakpoints
;
6794 /* Display the value of default-collect in a way that is generally
6795 compatible with the breakpoint list. */
6798 default_collect_info (void)
6800 struct ui_out
*uiout
= current_uiout
;
6802 /* If it has no value (which is frequently the case), say nothing; a
6803 message like "No default-collect." gets in user's face when it's
6805 if (!*default_collect
)
6808 /* The following phrase lines up nicely with per-tracepoint collect
6810 ui_out_text (uiout
, "default collect ");
6811 ui_out_field_string (uiout
, "default-collect", default_collect
);
6812 ui_out_text (uiout
, " \n");
6816 breakpoints_info (char *args
, int from_tty
)
6818 breakpoint_1 (args
, 0, NULL
);
6820 default_collect_info ();
6824 watchpoints_info (char *args
, int from_tty
)
6826 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6827 struct ui_out
*uiout
= current_uiout
;
6829 if (num_printed
== 0)
6831 if (args
== NULL
|| *args
== '\0')
6832 ui_out_message (uiout
, 0, "No watchpoints.\n");
6834 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6839 maintenance_info_breakpoints (char *args
, int from_tty
)
6841 breakpoint_1 (args
, 1, NULL
);
6843 default_collect_info ();
6847 breakpoint_has_pc (struct breakpoint
*b
,
6848 struct program_space
*pspace
,
6849 CORE_ADDR pc
, struct obj_section
*section
)
6851 struct bp_location
*bl
= b
->loc
;
6853 for (; bl
; bl
= bl
->next
)
6855 if (bl
->pspace
== pspace
6856 && bl
->address
== pc
6857 && (!overlay_debugging
|| bl
->section
== section
))
6863 /* Print a message describing any user-breakpoints set at PC. This
6864 concerns with logical breakpoints, so we match program spaces, not
6868 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6869 struct program_space
*pspace
, CORE_ADDR pc
,
6870 struct obj_section
*section
, int thread
)
6873 struct breakpoint
*b
;
6876 others
+= (user_breakpoint_p (b
)
6877 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6881 printf_filtered (_("Note: breakpoint "));
6882 else /* if (others == ???) */
6883 printf_filtered (_("Note: breakpoints "));
6885 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6888 printf_filtered ("%d", b
->number
);
6889 if (b
->thread
== -1 && thread
!= -1)
6890 printf_filtered (" (all threads)");
6891 else if (b
->thread
!= -1)
6892 printf_filtered (" (thread %d)", b
->thread
);
6893 printf_filtered ("%s%s ",
6894 ((b
->enable_state
== bp_disabled
6895 || b
->enable_state
== bp_call_disabled
)
6899 : ((others
== 1) ? " and" : ""));
6901 printf_filtered (_("also set at pc "));
6902 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6903 printf_filtered (".\n");
6908 /* Return true iff it is meaningful to use the address member of
6909 BPT. For some breakpoint types, the address member is irrelevant
6910 and it makes no sense to attempt to compare it to other addresses
6911 (or use it for any other purpose either).
6913 More specifically, each of the following breakpoint types will
6914 always have a zero valued address and we don't want to mark
6915 breakpoints of any of these types to be a duplicate of an actual
6916 breakpoint at address zero:
6924 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6926 enum bptype type
= bpt
->type
;
6928 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6931 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6932 true if LOC1 and LOC2 represent the same watchpoint location. */
6935 watchpoint_locations_match (struct bp_location
*loc1
,
6936 struct bp_location
*loc2
)
6938 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6939 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6941 /* Both of them must exist. */
6942 gdb_assert (w1
!= NULL
);
6943 gdb_assert (w2
!= NULL
);
6945 /* If the target can evaluate the condition expression in hardware,
6946 then we we need to insert both watchpoints even if they are at
6947 the same place. Otherwise the watchpoint will only trigger when
6948 the condition of whichever watchpoint was inserted evaluates to
6949 true, not giving a chance for GDB to check the condition of the
6950 other watchpoint. */
6952 && target_can_accel_watchpoint_condition (loc1
->address
,
6954 loc1
->watchpoint_type
,
6957 && target_can_accel_watchpoint_condition (loc2
->address
,
6959 loc2
->watchpoint_type
,
6963 /* Note that this checks the owner's type, not the location's. In
6964 case the target does not support read watchpoints, but does
6965 support access watchpoints, we'll have bp_read_watchpoint
6966 watchpoints with hw_access locations. Those should be considered
6967 duplicates of hw_read locations. The hw_read locations will
6968 become hw_access locations later. */
6969 return (loc1
->owner
->type
== loc2
->owner
->type
6970 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6971 && loc1
->address
== loc2
->address
6972 && loc1
->length
== loc2
->length
);
6975 /* See breakpoint.h. */
6978 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6979 struct address_space
*aspace2
, CORE_ADDR addr2
)
6981 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6982 || aspace1
== aspace2
)
6986 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6987 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6988 matches ASPACE2. On targets that have global breakpoints, the address
6989 space doesn't really matter. */
6992 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6993 int len1
, struct address_space
*aspace2
,
6996 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6997 || aspace1
== aspace2
)
6998 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7001 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7002 a ranged breakpoint. In most targets, a match happens only if ASPACE
7003 matches the breakpoint's address space. On targets that have global
7004 breakpoints, the address space doesn't really matter. */
7007 breakpoint_location_address_match (struct bp_location
*bl
,
7008 struct address_space
*aspace
,
7011 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7014 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7015 bl
->address
, bl
->length
,
7019 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7020 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7021 true, otherwise returns false. */
7024 tracepoint_locations_match (struct bp_location
*loc1
,
7025 struct bp_location
*loc2
)
7027 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7028 /* Since tracepoint locations are never duplicated with others', tracepoint
7029 locations at the same address of different tracepoints are regarded as
7030 different locations. */
7031 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7036 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7037 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7038 represent the same location. */
7041 breakpoint_locations_match (struct bp_location
*loc1
,
7042 struct bp_location
*loc2
)
7044 int hw_point1
, hw_point2
;
7046 /* Both of them must not be in moribund_locations. */
7047 gdb_assert (loc1
->owner
!= NULL
);
7048 gdb_assert (loc2
->owner
!= NULL
);
7050 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7051 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7053 if (hw_point1
!= hw_point2
)
7056 return watchpoint_locations_match (loc1
, loc2
);
7057 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7058 return tracepoint_locations_match (loc1
, loc2
);
7060 /* We compare bp_location.length in order to cover ranged breakpoints. */
7061 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7062 loc2
->pspace
->aspace
, loc2
->address
)
7063 && loc1
->length
== loc2
->length
);
7067 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7068 int bnum
, int have_bnum
)
7070 /* The longest string possibly returned by hex_string_custom
7071 is 50 chars. These must be at least that big for safety. */
7075 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7076 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7078 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7079 bnum
, astr1
, astr2
);
7081 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7084 /* Adjust a breakpoint's address to account for architectural
7085 constraints on breakpoint placement. Return the adjusted address.
7086 Note: Very few targets require this kind of adjustment. For most
7087 targets, this function is simply the identity function. */
7090 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7091 CORE_ADDR bpaddr
, enum bptype bptype
)
7093 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7095 /* Very few targets need any kind of breakpoint adjustment. */
7098 else if (bptype
== bp_watchpoint
7099 || bptype
== bp_hardware_watchpoint
7100 || bptype
== bp_read_watchpoint
7101 || bptype
== bp_access_watchpoint
7102 || bptype
== bp_catchpoint
)
7104 /* Watchpoints and the various bp_catch_* eventpoints should not
7105 have their addresses modified. */
7108 else if (bptype
== bp_single_step
)
7110 /* Single-step breakpoints should not have their addresses
7111 modified. If there's any architectural constrain that
7112 applies to this address, then it should have already been
7113 taken into account when the breakpoint was created in the
7114 first place. If we didn't do this, stepping through e.g.,
7115 Thumb-2 IT blocks would break. */
7120 CORE_ADDR adjusted_bpaddr
;
7122 /* Some targets have architectural constraints on the placement
7123 of breakpoint instructions. Obtain the adjusted address. */
7124 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7126 /* An adjusted breakpoint address can significantly alter
7127 a user's expectations. Print a warning if an adjustment
7129 if (adjusted_bpaddr
!= bpaddr
)
7130 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7132 return adjusted_bpaddr
;
7137 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7138 struct breakpoint
*owner
)
7140 memset (loc
, 0, sizeof (*loc
));
7142 gdb_assert (ops
!= NULL
);
7147 loc
->cond_bytecode
= NULL
;
7148 loc
->shlib_disabled
= 0;
7151 switch (owner
->type
)
7154 case bp_single_step
:
7158 case bp_longjmp_resume
:
7159 case bp_longjmp_call_dummy
:
7161 case bp_exception_resume
:
7162 case bp_step_resume
:
7163 case bp_hp_step_resume
:
7164 case bp_watchpoint_scope
:
7166 case bp_std_terminate
:
7167 case bp_shlib_event
:
7168 case bp_thread_event
:
7169 case bp_overlay_event
:
7171 case bp_longjmp_master
:
7172 case bp_std_terminate_master
:
7173 case bp_exception_master
:
7174 case bp_gnu_ifunc_resolver
:
7175 case bp_gnu_ifunc_resolver_return
:
7177 loc
->loc_type
= bp_loc_software_breakpoint
;
7178 mark_breakpoint_location_modified (loc
);
7180 case bp_hardware_breakpoint
:
7181 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7182 mark_breakpoint_location_modified (loc
);
7184 case bp_hardware_watchpoint
:
7185 case bp_read_watchpoint
:
7186 case bp_access_watchpoint
:
7187 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7192 case bp_fast_tracepoint
:
7193 case bp_static_tracepoint
:
7194 loc
->loc_type
= bp_loc_other
;
7197 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7203 /* Allocate a struct bp_location. */
7205 static struct bp_location
*
7206 allocate_bp_location (struct breakpoint
*bpt
)
7208 return bpt
->ops
->allocate_location (bpt
);
7212 free_bp_location (struct bp_location
*loc
)
7214 loc
->ops
->dtor (loc
);
7218 /* Increment reference count. */
7221 incref_bp_location (struct bp_location
*bl
)
7226 /* Decrement reference count. If the reference count reaches 0,
7227 destroy the bp_location. Sets *BLP to NULL. */
7230 decref_bp_location (struct bp_location
**blp
)
7232 gdb_assert ((*blp
)->refc
> 0);
7234 if (--(*blp
)->refc
== 0)
7235 free_bp_location (*blp
);
7239 /* Add breakpoint B at the end of the global breakpoint chain. */
7242 add_to_breakpoint_chain (struct breakpoint
*b
)
7244 struct breakpoint
*b1
;
7246 /* Add this breakpoint to the end of the chain so that a list of
7247 breakpoints will come out in order of increasing numbers. */
7249 b1
= breakpoint_chain
;
7251 breakpoint_chain
= b
;
7260 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7263 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7264 struct gdbarch
*gdbarch
,
7266 const struct breakpoint_ops
*ops
)
7268 memset (b
, 0, sizeof (*b
));
7270 gdb_assert (ops
!= NULL
);
7274 b
->gdbarch
= gdbarch
;
7275 b
->language
= current_language
->la_language
;
7276 b
->input_radix
= input_radix
;
7278 b
->enable_state
= bp_enabled
;
7281 b
->ignore_count
= 0;
7283 b
->frame_id
= null_frame_id
;
7284 b
->condition_not_parsed
= 0;
7285 b
->py_bp_object
= NULL
;
7286 b
->related_breakpoint
= b
;
7289 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7290 that has type BPTYPE and has no locations as yet. */
7292 static struct breakpoint
*
7293 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7295 const struct breakpoint_ops
*ops
)
7297 struct breakpoint
*b
= XNEW (struct breakpoint
);
7299 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7300 add_to_breakpoint_chain (b
);
7304 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7305 resolutions should be made as the user specified the location explicitly
7309 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7311 gdb_assert (loc
->owner
!= NULL
);
7313 if (loc
->owner
->type
== bp_breakpoint
7314 || loc
->owner
->type
== bp_hardware_breakpoint
7315 || is_tracepoint (loc
->owner
))
7318 const char *function_name
;
7319 CORE_ADDR func_addr
;
7321 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7322 &func_addr
, NULL
, &is_gnu_ifunc
);
7324 if (is_gnu_ifunc
&& !explicit_loc
)
7326 struct breakpoint
*b
= loc
->owner
;
7328 gdb_assert (loc
->pspace
== current_program_space
);
7329 if (gnu_ifunc_resolve_name (function_name
,
7330 &loc
->requested_address
))
7332 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7333 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7334 loc
->requested_address
,
7337 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7338 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7340 /* Create only the whole new breakpoint of this type but do not
7341 mess more complicated breakpoints with multiple locations. */
7342 b
->type
= bp_gnu_ifunc_resolver
;
7343 /* Remember the resolver's address for use by the return
7345 loc
->related_address
= func_addr
;
7350 loc
->function_name
= xstrdup (function_name
);
7354 /* Attempt to determine architecture of location identified by SAL. */
7356 get_sal_arch (struct symtab_and_line sal
)
7359 return get_objfile_arch (sal
.section
->objfile
);
7361 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7366 /* Low level routine for partially initializing a breakpoint of type
7367 BPTYPE. The newly created breakpoint's address, section, source
7368 file name, and line number are provided by SAL.
7370 It is expected that the caller will complete the initialization of
7371 the newly created breakpoint struct as well as output any status
7372 information regarding the creation of a new breakpoint. */
7375 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7376 struct symtab_and_line sal
, enum bptype bptype
,
7377 const struct breakpoint_ops
*ops
)
7379 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7381 add_location_to_breakpoint (b
, &sal
);
7383 if (bptype
!= bp_catchpoint
)
7384 gdb_assert (sal
.pspace
!= NULL
);
7386 /* Store the program space that was used to set the breakpoint,
7387 except for ordinary breakpoints, which are independent of the
7389 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7390 b
->pspace
= sal
.pspace
;
7393 /* set_raw_breakpoint is a low level routine for allocating and
7394 partially initializing a breakpoint of type BPTYPE. The newly
7395 created breakpoint's address, section, source file name, and line
7396 number are provided by SAL. The newly created and partially
7397 initialized breakpoint is added to the breakpoint chain and
7398 is also returned as the value of this function.
7400 It is expected that the caller will complete the initialization of
7401 the newly created breakpoint struct as well as output any status
7402 information regarding the creation of a new breakpoint. In
7403 particular, set_raw_breakpoint does NOT set the breakpoint
7404 number! Care should be taken to not allow an error to occur
7405 prior to completing the initialization of the breakpoint. If this
7406 should happen, a bogus breakpoint will be left on the chain. */
7409 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7410 struct symtab_and_line sal
, enum bptype bptype
,
7411 const struct breakpoint_ops
*ops
)
7413 struct breakpoint
*b
= XNEW (struct breakpoint
);
7415 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7416 add_to_breakpoint_chain (b
);
7421 /* Note that the breakpoint object B describes a permanent breakpoint
7422 instruction, hard-wired into the inferior's code. */
7424 make_breakpoint_permanent (struct breakpoint
*b
)
7426 struct bp_location
*bl
;
7428 /* By definition, permanent breakpoints are already present in the
7429 code. Mark all locations as inserted. For now,
7430 make_breakpoint_permanent is called in just one place, so it's
7431 hard to say if it's reasonable to have permanent breakpoint with
7432 multiple locations or not, but it's easy to implement. */
7433 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7440 /* Call this routine when stepping and nexting to enable a breakpoint
7441 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7442 initiated the operation. */
7445 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7447 struct breakpoint
*b
, *b_tmp
;
7448 int thread
= tp
->num
;
7450 /* To avoid having to rescan all objfile symbols at every step,
7451 we maintain a list of continually-inserted but always disabled
7452 longjmp "master" breakpoints. Here, we simply create momentary
7453 clones of those and enable them for the requested thread. */
7454 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7455 if (b
->pspace
== current_program_space
7456 && (b
->type
== bp_longjmp_master
7457 || b
->type
== bp_exception_master
))
7459 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7460 struct breakpoint
*clone
;
7462 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7463 after their removal. */
7464 clone
= momentary_breakpoint_from_master (b
, type
,
7465 &longjmp_breakpoint_ops
, 1);
7466 clone
->thread
= thread
;
7469 tp
->initiating_frame
= frame
;
7472 /* Delete all longjmp breakpoints from THREAD. */
7474 delete_longjmp_breakpoint (int thread
)
7476 struct breakpoint
*b
, *b_tmp
;
7478 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7479 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7481 if (b
->thread
== thread
)
7482 delete_breakpoint (b
);
7487 delete_longjmp_breakpoint_at_next_stop (int thread
)
7489 struct breakpoint
*b
, *b_tmp
;
7491 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7492 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7494 if (b
->thread
== thread
)
7495 b
->disposition
= disp_del_at_next_stop
;
7499 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7500 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7501 pointer to any of them. Return NULL if this system cannot place longjmp
7505 set_longjmp_breakpoint_for_call_dummy (void)
7507 struct breakpoint
*b
, *retval
= NULL
;
7510 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7512 struct breakpoint
*new_b
;
7514 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7515 &momentary_breakpoint_ops
,
7517 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7519 /* Link NEW_B into the chain of RETVAL breakpoints. */
7521 gdb_assert (new_b
->related_breakpoint
== new_b
);
7524 new_b
->related_breakpoint
= retval
;
7525 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7526 retval
= retval
->related_breakpoint
;
7527 retval
->related_breakpoint
= new_b
;
7533 /* Verify all existing dummy frames and their associated breakpoints for
7534 TP. Remove those which can no longer be found in the current frame
7537 You should call this function only at places where it is safe to currently
7538 unwind the whole stack. Failed stack unwind would discard live dummy
7542 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7544 struct breakpoint
*b
, *b_tmp
;
7546 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7547 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7549 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7551 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7552 dummy_b
= dummy_b
->related_breakpoint
;
7553 if (dummy_b
->type
!= bp_call_dummy
7554 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7557 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7559 while (b
->related_breakpoint
!= b
)
7561 if (b_tmp
== b
->related_breakpoint
)
7562 b_tmp
= b
->related_breakpoint
->next
;
7563 delete_breakpoint (b
->related_breakpoint
);
7565 delete_breakpoint (b
);
7570 enable_overlay_breakpoints (void)
7572 struct breakpoint
*b
;
7575 if (b
->type
== bp_overlay_event
)
7577 b
->enable_state
= bp_enabled
;
7578 update_global_location_list (UGLL_MAY_INSERT
);
7579 overlay_events_enabled
= 1;
7584 disable_overlay_breakpoints (void)
7586 struct breakpoint
*b
;
7589 if (b
->type
== bp_overlay_event
)
7591 b
->enable_state
= bp_disabled
;
7592 update_global_location_list (UGLL_DONT_INSERT
);
7593 overlay_events_enabled
= 0;
7597 /* Set an active std::terminate breakpoint for each std::terminate
7598 master breakpoint. */
7600 set_std_terminate_breakpoint (void)
7602 struct breakpoint
*b
, *b_tmp
;
7604 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7605 if (b
->pspace
== current_program_space
7606 && b
->type
== bp_std_terminate_master
)
7608 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7609 &momentary_breakpoint_ops
, 1);
7613 /* Delete all the std::terminate breakpoints. */
7615 delete_std_terminate_breakpoint (void)
7617 struct breakpoint
*b
, *b_tmp
;
7619 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7620 if (b
->type
== bp_std_terminate
)
7621 delete_breakpoint (b
);
7625 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7627 struct breakpoint
*b
;
7629 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7630 &internal_breakpoint_ops
);
7632 b
->enable_state
= bp_enabled
;
7633 /* addr_string has to be used or breakpoint_re_set will delete me. */
7635 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7637 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7643 remove_thread_event_breakpoints (void)
7645 struct breakpoint
*b
, *b_tmp
;
7647 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7648 if (b
->type
== bp_thread_event
7649 && b
->loc
->pspace
== current_program_space
)
7650 delete_breakpoint (b
);
7653 struct lang_and_radix
7659 /* Create a breakpoint for JIT code registration and unregistration. */
7662 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7664 struct breakpoint
*b
;
7666 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7667 &internal_breakpoint_ops
);
7668 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7672 /* Remove JIT code registration and unregistration breakpoint(s). */
7675 remove_jit_event_breakpoints (void)
7677 struct breakpoint
*b
, *b_tmp
;
7679 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7680 if (b
->type
== bp_jit_event
7681 && b
->loc
->pspace
== current_program_space
)
7682 delete_breakpoint (b
);
7686 remove_solib_event_breakpoints (void)
7688 struct breakpoint
*b
, *b_tmp
;
7690 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7691 if (b
->type
== bp_shlib_event
7692 && b
->loc
->pspace
== current_program_space
)
7693 delete_breakpoint (b
);
7696 /* See breakpoint.h. */
7699 remove_solib_event_breakpoints_at_next_stop (void)
7701 struct breakpoint
*b
, *b_tmp
;
7703 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7704 if (b
->type
== bp_shlib_event
7705 && b
->loc
->pspace
== current_program_space
)
7706 b
->disposition
= disp_del_at_next_stop
;
7709 /* Helper for create_solib_event_breakpoint /
7710 create_and_insert_solib_event_breakpoint. Allows specifying which
7711 INSERT_MODE to pass through to update_global_location_list. */
7713 static struct breakpoint
*
7714 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7715 enum ugll_insert_mode insert_mode
)
7717 struct breakpoint
*b
;
7719 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7720 &internal_breakpoint_ops
);
7721 update_global_location_list_nothrow (insert_mode
);
7726 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7728 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7731 /* See breakpoint.h. */
7734 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7736 struct breakpoint
*b
;
7738 /* Explicitly tell update_global_location_list to insert
7740 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7741 if (!b
->loc
->inserted
)
7743 delete_breakpoint (b
);
7749 /* Disable any breakpoints that are on code in shared libraries. Only
7750 apply to enabled breakpoints, disabled ones can just stay disabled. */
7753 disable_breakpoints_in_shlibs (void)
7755 struct bp_location
*loc
, **locp_tmp
;
7757 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7759 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7760 struct breakpoint
*b
= loc
->owner
;
7762 /* We apply the check to all breakpoints, including disabled for
7763 those with loc->duplicate set. This is so that when breakpoint
7764 becomes enabled, or the duplicate is removed, gdb will try to
7765 insert all breakpoints. If we don't set shlib_disabled here,
7766 we'll try to insert those breakpoints and fail. */
7767 if (((b
->type
== bp_breakpoint
)
7768 || (b
->type
== bp_jit_event
)
7769 || (b
->type
== bp_hardware_breakpoint
)
7770 || (is_tracepoint (b
)))
7771 && loc
->pspace
== current_program_space
7772 && !loc
->shlib_disabled
7773 && solib_name_from_address (loc
->pspace
, loc
->address
)
7776 loc
->shlib_disabled
= 1;
7781 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7782 notification of unloaded_shlib. Only apply to enabled breakpoints,
7783 disabled ones can just stay disabled. */
7786 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7788 struct bp_location
*loc
, **locp_tmp
;
7789 int disabled_shlib_breaks
= 0;
7791 /* SunOS a.out shared libraries are always mapped, so do not
7792 disable breakpoints; they will only be reported as unloaded
7793 through clear_solib when GDB discards its shared library
7794 list. See clear_solib for more information. */
7795 if (exec_bfd
!= NULL
7796 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7799 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7801 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7802 struct breakpoint
*b
= loc
->owner
;
7804 if (solib
->pspace
== loc
->pspace
7805 && !loc
->shlib_disabled
7806 && (((b
->type
== bp_breakpoint
7807 || b
->type
== bp_jit_event
7808 || b
->type
== bp_hardware_breakpoint
)
7809 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7810 || loc
->loc_type
== bp_loc_software_breakpoint
))
7811 || is_tracepoint (b
))
7812 && solib_contains_address_p (solib
, loc
->address
))
7814 loc
->shlib_disabled
= 1;
7815 /* At this point, we cannot rely on remove_breakpoint
7816 succeeding so we must mark the breakpoint as not inserted
7817 to prevent future errors occurring in remove_breakpoints. */
7820 /* This may cause duplicate notifications for the same breakpoint. */
7821 observer_notify_breakpoint_modified (b
);
7823 if (!disabled_shlib_breaks
)
7825 target_terminal_ours_for_output ();
7826 warning (_("Temporarily disabling breakpoints "
7827 "for unloaded shared library \"%s\""),
7830 disabled_shlib_breaks
= 1;
7835 /* Disable any breakpoints and tracepoints in OBJFILE upon
7836 notification of free_objfile. Only apply to enabled breakpoints,
7837 disabled ones can just stay disabled. */
7840 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7842 struct breakpoint
*b
;
7844 if (objfile
== NULL
)
7847 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7848 managed by the user with add-symbol-file/remove-symbol-file.
7849 Similarly to how breakpoints in shared libraries are handled in
7850 response to "nosharedlibrary", mark breakpoints in such modules
7851 shlib_disabled so they end up uninserted on the next global
7852 location list update. Shared libraries not loaded by the user
7853 aren't handled here -- they're already handled in
7854 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7855 solib_unloaded observer. We skip objfiles that are not
7856 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7858 if ((objfile
->flags
& OBJF_SHARED
) == 0
7859 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7864 struct bp_location
*loc
;
7865 int bp_modified
= 0;
7867 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7870 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7872 CORE_ADDR loc_addr
= loc
->address
;
7874 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7875 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7878 if (loc
->shlib_disabled
!= 0)
7881 if (objfile
->pspace
!= loc
->pspace
)
7884 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7885 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7888 if (is_addr_in_objfile (loc_addr
, objfile
))
7890 loc
->shlib_disabled
= 1;
7891 /* At this point, we don't know whether the object was
7892 unmapped from the inferior or not, so leave the
7893 inserted flag alone. We'll handle failure to
7894 uninsert quietly, in case the object was indeed
7897 mark_breakpoint_location_modified (loc
);
7904 observer_notify_breakpoint_modified (b
);
7908 /* FORK & VFORK catchpoints. */
7910 /* An instance of this type is used to represent a fork or vfork
7911 catchpoint. It includes a "struct breakpoint" as a kind of base
7912 class; users downcast to "struct breakpoint *" when needed. A
7913 breakpoint is really of this type iff its ops pointer points to
7914 CATCH_FORK_BREAKPOINT_OPS. */
7916 struct fork_catchpoint
7918 /* The base class. */
7919 struct breakpoint base
;
7921 /* Process id of a child process whose forking triggered this
7922 catchpoint. This field is only valid immediately after this
7923 catchpoint has triggered. */
7924 ptid_t forked_inferior_pid
;
7927 /* Implement the "insert" breakpoint_ops method for fork
7931 insert_catch_fork (struct bp_location
*bl
)
7933 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7936 /* Implement the "remove" breakpoint_ops method for fork
7940 remove_catch_fork (struct bp_location
*bl
)
7942 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7945 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7949 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7950 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7951 const struct target_waitstatus
*ws
)
7953 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7955 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7958 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7962 /* Implement the "print_it" breakpoint_ops method for fork
7965 static enum print_stop_action
7966 print_it_catch_fork (bpstat bs
)
7968 struct ui_out
*uiout
= current_uiout
;
7969 struct breakpoint
*b
= bs
->breakpoint_at
;
7970 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7972 annotate_catchpoint (b
->number
);
7973 if (b
->disposition
== disp_del
)
7974 ui_out_text (uiout
, "\nTemporary catchpoint ");
7976 ui_out_text (uiout
, "\nCatchpoint ");
7977 if (ui_out_is_mi_like_p (uiout
))
7979 ui_out_field_string (uiout
, "reason",
7980 async_reason_lookup (EXEC_ASYNC_FORK
));
7981 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7983 ui_out_field_int (uiout
, "bkptno", b
->number
);
7984 ui_out_text (uiout
, " (forked process ");
7985 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7986 ui_out_text (uiout
, "), ");
7987 return PRINT_SRC_AND_LOC
;
7990 /* Implement the "print_one" breakpoint_ops method for fork
7994 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7996 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7997 struct value_print_options opts
;
7998 struct ui_out
*uiout
= current_uiout
;
8000 get_user_print_options (&opts
);
8002 /* Field 4, the address, is omitted (which makes the columns not
8003 line up too nicely with the headers, but the effect is relatively
8005 if (opts
.addressprint
)
8006 ui_out_field_skip (uiout
, "addr");
8008 ui_out_text (uiout
, "fork");
8009 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8011 ui_out_text (uiout
, ", process ");
8012 ui_out_field_int (uiout
, "what",
8013 ptid_get_pid (c
->forked_inferior_pid
));
8014 ui_out_spaces (uiout
, 1);
8017 if (ui_out_is_mi_like_p (uiout
))
8018 ui_out_field_string (uiout
, "catch-type", "fork");
8021 /* Implement the "print_mention" breakpoint_ops method for fork
8025 print_mention_catch_fork (struct breakpoint
*b
)
8027 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8030 /* Implement the "print_recreate" breakpoint_ops method for fork
8034 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8036 fprintf_unfiltered (fp
, "catch fork");
8037 print_recreate_thread (b
, fp
);
8040 /* The breakpoint_ops structure to be used in fork catchpoints. */
8042 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8044 /* Implement the "insert" breakpoint_ops method for vfork
8048 insert_catch_vfork (struct bp_location
*bl
)
8050 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8053 /* Implement the "remove" breakpoint_ops method for vfork
8057 remove_catch_vfork (struct bp_location
*bl
)
8059 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8062 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8066 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8067 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8068 const struct target_waitstatus
*ws
)
8070 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8072 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8075 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8079 /* Implement the "print_it" breakpoint_ops method for vfork
8082 static enum print_stop_action
8083 print_it_catch_vfork (bpstat bs
)
8085 struct ui_out
*uiout
= current_uiout
;
8086 struct breakpoint
*b
= bs
->breakpoint_at
;
8087 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8089 annotate_catchpoint (b
->number
);
8090 if (b
->disposition
== disp_del
)
8091 ui_out_text (uiout
, "\nTemporary catchpoint ");
8093 ui_out_text (uiout
, "\nCatchpoint ");
8094 if (ui_out_is_mi_like_p (uiout
))
8096 ui_out_field_string (uiout
, "reason",
8097 async_reason_lookup (EXEC_ASYNC_VFORK
));
8098 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8100 ui_out_field_int (uiout
, "bkptno", b
->number
);
8101 ui_out_text (uiout
, " (vforked process ");
8102 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8103 ui_out_text (uiout
, "), ");
8104 return PRINT_SRC_AND_LOC
;
8107 /* Implement the "print_one" breakpoint_ops method for vfork
8111 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8113 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8114 struct value_print_options opts
;
8115 struct ui_out
*uiout
= current_uiout
;
8117 get_user_print_options (&opts
);
8118 /* Field 4, the address, is omitted (which makes the columns not
8119 line up too nicely with the headers, but the effect is relatively
8121 if (opts
.addressprint
)
8122 ui_out_field_skip (uiout
, "addr");
8124 ui_out_text (uiout
, "vfork");
8125 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8127 ui_out_text (uiout
, ", process ");
8128 ui_out_field_int (uiout
, "what",
8129 ptid_get_pid (c
->forked_inferior_pid
));
8130 ui_out_spaces (uiout
, 1);
8133 if (ui_out_is_mi_like_p (uiout
))
8134 ui_out_field_string (uiout
, "catch-type", "vfork");
8137 /* Implement the "print_mention" breakpoint_ops method for vfork
8141 print_mention_catch_vfork (struct breakpoint
*b
)
8143 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8146 /* Implement the "print_recreate" breakpoint_ops method for vfork
8150 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8152 fprintf_unfiltered (fp
, "catch vfork");
8153 print_recreate_thread (b
, fp
);
8156 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8158 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8160 /* An instance of this type is used to represent an solib catchpoint.
8161 It includes a "struct breakpoint" as a kind of base class; users
8162 downcast to "struct breakpoint *" when needed. A breakpoint is
8163 really of this type iff its ops pointer points to
8164 CATCH_SOLIB_BREAKPOINT_OPS. */
8166 struct solib_catchpoint
8168 /* The base class. */
8169 struct breakpoint base
;
8171 /* True for "catch load", false for "catch unload". */
8172 unsigned char is_load
;
8174 /* Regular expression to match, if any. COMPILED is only valid when
8175 REGEX is non-NULL. */
8181 dtor_catch_solib (struct breakpoint
*b
)
8183 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8186 regfree (&self
->compiled
);
8187 xfree (self
->regex
);
8189 base_breakpoint_ops
.dtor (b
);
8193 insert_catch_solib (struct bp_location
*ignore
)
8199 remove_catch_solib (struct bp_location
*ignore
)
8205 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8206 struct address_space
*aspace
,
8208 const struct target_waitstatus
*ws
)
8210 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8211 struct breakpoint
*other
;
8213 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8216 ALL_BREAKPOINTS (other
)
8218 struct bp_location
*other_bl
;
8220 if (other
== bl
->owner
)
8223 if (other
->type
!= bp_shlib_event
)
8226 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8229 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8231 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8240 check_status_catch_solib (struct bpstats
*bs
)
8242 struct solib_catchpoint
*self
8243 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8248 struct so_list
*iter
;
8251 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8256 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8265 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8270 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8276 bs
->print_it
= print_it_noop
;
8279 static enum print_stop_action
8280 print_it_catch_solib (bpstat bs
)
8282 struct breakpoint
*b
= bs
->breakpoint_at
;
8283 struct ui_out
*uiout
= current_uiout
;
8285 annotate_catchpoint (b
->number
);
8286 if (b
->disposition
== disp_del
)
8287 ui_out_text (uiout
, "\nTemporary catchpoint ");
8289 ui_out_text (uiout
, "\nCatchpoint ");
8290 ui_out_field_int (uiout
, "bkptno", b
->number
);
8291 ui_out_text (uiout
, "\n");
8292 if (ui_out_is_mi_like_p (uiout
))
8293 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8294 print_solib_event (1);
8295 return PRINT_SRC_AND_LOC
;
8299 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8301 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8302 struct value_print_options opts
;
8303 struct ui_out
*uiout
= current_uiout
;
8306 get_user_print_options (&opts
);
8307 /* Field 4, the address, is omitted (which makes the columns not
8308 line up too nicely with the headers, but the effect is relatively
8310 if (opts
.addressprint
)
8313 ui_out_field_skip (uiout
, "addr");
8320 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8322 msg
= xstrdup (_("load of library"));
8327 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8329 msg
= xstrdup (_("unload of library"));
8331 ui_out_field_string (uiout
, "what", msg
);
8334 if (ui_out_is_mi_like_p (uiout
))
8335 ui_out_field_string (uiout
, "catch-type",
8336 self
->is_load
? "load" : "unload");
8340 print_mention_catch_solib (struct breakpoint
*b
)
8342 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8344 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8345 self
->is_load
? "load" : "unload");
8349 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8351 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8353 fprintf_unfiltered (fp
, "%s %s",
8354 b
->disposition
== disp_del
? "tcatch" : "catch",
8355 self
->is_load
? "load" : "unload");
8357 fprintf_unfiltered (fp
, " %s", self
->regex
);
8358 fprintf_unfiltered (fp
, "\n");
8361 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8363 /* Shared helper function (MI and CLI) for creating and installing
8364 a shared object event catchpoint. If IS_LOAD is non-zero then
8365 the events to be caught are load events, otherwise they are
8366 unload events. If IS_TEMP is non-zero the catchpoint is a
8367 temporary one. If ENABLED is non-zero the catchpoint is
8368 created in an enabled state. */
8371 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8373 struct solib_catchpoint
*c
;
8374 struct gdbarch
*gdbarch
= get_current_arch ();
8375 struct cleanup
*cleanup
;
8379 arg
= skip_spaces (arg
);
8381 c
= XCNEW (struct solib_catchpoint
);
8382 cleanup
= make_cleanup (xfree
, c
);
8388 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8391 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8393 make_cleanup (xfree
, err
);
8394 error (_("Invalid regexp (%s): %s"), err
, arg
);
8396 c
->regex
= xstrdup (arg
);
8399 c
->is_load
= is_load
;
8400 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8401 &catch_solib_breakpoint_ops
);
8403 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8405 discard_cleanups (cleanup
);
8406 install_breakpoint (0, &c
->base
, 1);
8409 /* A helper function that does all the work for "catch load" and
8413 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8414 struct cmd_list_element
*command
)
8417 const int enabled
= 1;
8419 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8421 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8425 catch_load_command_1 (char *arg
, int from_tty
,
8426 struct cmd_list_element
*command
)
8428 catch_load_or_unload (arg
, from_tty
, 1, command
);
8432 catch_unload_command_1 (char *arg
, int from_tty
,
8433 struct cmd_list_element
*command
)
8435 catch_load_or_unload (arg
, from_tty
, 0, command
);
8438 /* An instance of this type is used to represent a syscall catchpoint.
8439 It includes a "struct breakpoint" as a kind of base class; users
8440 downcast to "struct breakpoint *" when needed. A breakpoint is
8441 really of this type iff its ops pointer points to
8442 CATCH_SYSCALL_BREAKPOINT_OPS. */
8444 struct syscall_catchpoint
8446 /* The base class. */
8447 struct breakpoint base
;
8449 /* Syscall numbers used for the 'catch syscall' feature. If no
8450 syscall has been specified for filtering, its value is NULL.
8451 Otherwise, it holds a list of all syscalls to be caught. The
8452 list elements are allocated with xmalloc. */
8453 VEC(int) *syscalls_to_be_caught
;
8456 /* Implement the "dtor" breakpoint_ops method for syscall
8460 dtor_catch_syscall (struct breakpoint
*b
)
8462 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8464 VEC_free (int, c
->syscalls_to_be_caught
);
8466 base_breakpoint_ops
.dtor (b
);
8469 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8471 struct catch_syscall_inferior_data
8473 /* We keep a count of the number of times the user has requested a
8474 particular syscall to be tracked, and pass this information to the
8475 target. This lets capable targets implement filtering directly. */
8477 /* Number of times that "any" syscall is requested. */
8478 int any_syscall_count
;
8480 /* Count of each system call. */
8481 VEC(int) *syscalls_counts
;
8483 /* This counts all syscall catch requests, so we can readily determine
8484 if any catching is necessary. */
8485 int total_syscalls_count
;
8488 static struct catch_syscall_inferior_data
*
8489 get_catch_syscall_inferior_data (struct inferior
*inf
)
8491 struct catch_syscall_inferior_data
*inf_data
;
8493 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8494 if (inf_data
== NULL
)
8496 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8497 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8504 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8510 /* Implement the "insert" breakpoint_ops method for syscall
8514 insert_catch_syscall (struct bp_location
*bl
)
8516 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8517 struct inferior
*inf
= current_inferior ();
8518 struct catch_syscall_inferior_data
*inf_data
8519 = get_catch_syscall_inferior_data (inf
);
8521 ++inf_data
->total_syscalls_count
;
8522 if (!c
->syscalls_to_be_caught
)
8523 ++inf_data
->any_syscall_count
;
8529 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8534 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8536 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8537 uintptr_t vec_addr_offset
8538 = old_size
* ((uintptr_t) sizeof (int));
8540 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8541 vec_addr
= ((uintptr_t) VEC_address (int,
8542 inf_data
->syscalls_counts
)
8544 memset ((void *) vec_addr
, 0,
8545 (iter
+ 1 - old_size
) * sizeof (int));
8547 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8548 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8552 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8553 inf_data
->total_syscalls_count
!= 0,
8554 inf_data
->any_syscall_count
,
8556 inf_data
->syscalls_counts
),
8558 inf_data
->syscalls_counts
));
8561 /* Implement the "remove" breakpoint_ops method for syscall
8565 remove_catch_syscall (struct bp_location
*bl
)
8567 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8568 struct inferior
*inf
= current_inferior ();
8569 struct catch_syscall_inferior_data
*inf_data
8570 = get_catch_syscall_inferior_data (inf
);
8572 --inf_data
->total_syscalls_count
;
8573 if (!c
->syscalls_to_be_caught
)
8574 --inf_data
->any_syscall_count
;
8580 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8584 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8585 /* Shouldn't happen. */
8587 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8588 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8592 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8593 inf_data
->total_syscalls_count
!= 0,
8594 inf_data
->any_syscall_count
,
8596 inf_data
->syscalls_counts
),
8598 inf_data
->syscalls_counts
));
8601 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8605 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8606 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8607 const struct target_waitstatus
*ws
)
8609 /* We must check if we are catching specific syscalls in this
8610 breakpoint. If we are, then we must guarantee that the called
8611 syscall is the same syscall we are catching. */
8612 int syscall_number
= 0;
8613 const struct syscall_catchpoint
*c
8614 = (const struct syscall_catchpoint
*) bl
->owner
;
8616 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8617 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8620 syscall_number
= ws
->value
.syscall_number
;
8622 /* Now, checking if the syscall is the same. */
8623 if (c
->syscalls_to_be_caught
)
8628 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8630 if (syscall_number
== iter
)
8639 /* Implement the "print_it" breakpoint_ops method for syscall
8642 static enum print_stop_action
8643 print_it_catch_syscall (bpstat bs
)
8645 struct ui_out
*uiout
= current_uiout
;
8646 struct breakpoint
*b
= bs
->breakpoint_at
;
8647 /* These are needed because we want to know in which state a
8648 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8649 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8650 must print "called syscall" or "returned from syscall". */
8652 struct target_waitstatus last
;
8654 struct gdbarch
*gdbarch
= bs
->bp_location_at
->gdbarch
;
8656 get_last_target_status (&ptid
, &last
);
8658 get_syscall_by_number (gdbarch
, last
.value
.syscall_number
, &s
);
8660 annotate_catchpoint (b
->number
);
8662 if (b
->disposition
== disp_del
)
8663 ui_out_text (uiout
, "\nTemporary catchpoint ");
8665 ui_out_text (uiout
, "\nCatchpoint ");
8666 if (ui_out_is_mi_like_p (uiout
))
8668 ui_out_field_string (uiout
, "reason",
8669 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8670 ? EXEC_ASYNC_SYSCALL_ENTRY
8671 : EXEC_ASYNC_SYSCALL_RETURN
));
8672 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8674 ui_out_field_int (uiout
, "bkptno", b
->number
);
8676 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8677 ui_out_text (uiout
, " (call to syscall ");
8679 ui_out_text (uiout
, " (returned from syscall ");
8681 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8682 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8684 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8686 ui_out_text (uiout
, "), ");
8688 return PRINT_SRC_AND_LOC
;
8691 /* Implement the "print_one" breakpoint_ops method for syscall
8695 print_one_catch_syscall (struct breakpoint
*b
,
8696 struct bp_location
**last_loc
)
8698 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8699 struct value_print_options opts
;
8700 struct ui_out
*uiout
= current_uiout
;
8701 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8703 get_user_print_options (&opts
);
8704 /* Field 4, the address, is omitted (which makes the columns not
8705 line up too nicely with the headers, but the effect is relatively
8707 if (opts
.addressprint
)
8708 ui_out_field_skip (uiout
, "addr");
8711 if (c
->syscalls_to_be_caught
8712 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8713 ui_out_text (uiout
, "syscalls \"");
8715 ui_out_text (uiout
, "syscall \"");
8717 if (c
->syscalls_to_be_caught
)
8720 char *text
= xstrprintf ("%s", "");
8723 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8728 get_syscall_by_number (gdbarch
, iter
, &s
);
8731 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8733 text
= xstrprintf ("%s%d, ", text
, iter
);
8735 /* We have to xfree the last 'text' (now stored at 'x')
8736 because xstrprintf dynamically allocates new space for it
8740 /* Remove the last comma. */
8741 text
[strlen (text
) - 2] = '\0';
8742 ui_out_field_string (uiout
, "what", text
);
8745 ui_out_field_string (uiout
, "what", "<any syscall>");
8746 ui_out_text (uiout
, "\" ");
8748 if (ui_out_is_mi_like_p (uiout
))
8749 ui_out_field_string (uiout
, "catch-type", "syscall");
8752 /* Implement the "print_mention" breakpoint_ops method for syscall
8756 print_mention_catch_syscall (struct breakpoint
*b
)
8758 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8759 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8761 if (c
->syscalls_to_be_caught
)
8765 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8766 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8768 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8771 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8775 get_syscall_by_number (gdbarch
, iter
, &s
);
8778 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8780 printf_filtered (" %d", s
.number
);
8782 printf_filtered (")");
8785 printf_filtered (_("Catchpoint %d (any syscall)"),
8789 /* Implement the "print_recreate" breakpoint_ops method for syscall
8793 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8795 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8796 struct gdbarch
*gdbarch
= b
->loc
->gdbarch
;
8798 fprintf_unfiltered (fp
, "catch syscall");
8800 if (c
->syscalls_to_be_caught
)
8805 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8810 get_syscall_by_number (gdbarch
, iter
, &s
);
8812 fprintf_unfiltered (fp
, " %s", s
.name
);
8814 fprintf_unfiltered (fp
, " %d", s
.number
);
8817 print_recreate_thread (b
, fp
);
8820 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8822 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8824 /* Returns non-zero if 'b' is a syscall catchpoint. */
8827 syscall_catchpoint_p (struct breakpoint
*b
)
8829 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8832 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8833 is non-zero, then make the breakpoint temporary. If COND_STRING is
8834 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8835 the breakpoint_ops structure associated to the catchpoint. */
8838 init_catchpoint (struct breakpoint
*b
,
8839 struct gdbarch
*gdbarch
, int tempflag
,
8841 const struct breakpoint_ops
*ops
)
8843 struct symtab_and_line sal
;
8846 sal
.pspace
= current_program_space
;
8848 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8850 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8851 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8855 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8857 add_to_breakpoint_chain (b
);
8858 set_breakpoint_number (internal
, b
);
8859 if (is_tracepoint (b
))
8860 set_tracepoint_count (breakpoint_count
);
8863 observer_notify_breakpoint_created (b
);
8866 update_global_location_list (UGLL_MAY_INSERT
);
8870 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8871 int tempflag
, char *cond_string
,
8872 const struct breakpoint_ops
*ops
)
8874 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8876 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8878 c
->forked_inferior_pid
= null_ptid
;
8880 install_breakpoint (0, &c
->base
, 1);
8883 /* Exec catchpoints. */
8885 /* An instance of this type is used to represent an exec catchpoint.
8886 It includes a "struct breakpoint" as a kind of base class; users
8887 downcast to "struct breakpoint *" when needed. A breakpoint is
8888 really of this type iff its ops pointer points to
8889 CATCH_EXEC_BREAKPOINT_OPS. */
8891 struct exec_catchpoint
8893 /* The base class. */
8894 struct breakpoint base
;
8896 /* Filename of a program whose exec triggered this catchpoint.
8897 This field is only valid immediately after this catchpoint has
8899 char *exec_pathname
;
8902 /* Implement the "dtor" breakpoint_ops method for exec
8906 dtor_catch_exec (struct breakpoint
*b
)
8908 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8910 xfree (c
->exec_pathname
);
8912 base_breakpoint_ops
.dtor (b
);
8916 insert_catch_exec (struct bp_location
*bl
)
8918 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8922 remove_catch_exec (struct bp_location
*bl
)
8924 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8928 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8929 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8930 const struct target_waitstatus
*ws
)
8932 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8934 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8937 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8941 static enum print_stop_action
8942 print_it_catch_exec (bpstat bs
)
8944 struct ui_out
*uiout
= current_uiout
;
8945 struct breakpoint
*b
= bs
->breakpoint_at
;
8946 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8948 annotate_catchpoint (b
->number
);
8949 if (b
->disposition
== disp_del
)
8950 ui_out_text (uiout
, "\nTemporary catchpoint ");
8952 ui_out_text (uiout
, "\nCatchpoint ");
8953 if (ui_out_is_mi_like_p (uiout
))
8955 ui_out_field_string (uiout
, "reason",
8956 async_reason_lookup (EXEC_ASYNC_EXEC
));
8957 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8959 ui_out_field_int (uiout
, "bkptno", b
->number
);
8960 ui_out_text (uiout
, " (exec'd ");
8961 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8962 ui_out_text (uiout
, "), ");
8964 return PRINT_SRC_AND_LOC
;
8968 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8970 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8971 struct value_print_options opts
;
8972 struct ui_out
*uiout
= current_uiout
;
8974 get_user_print_options (&opts
);
8976 /* Field 4, the address, is omitted (which makes the columns
8977 not line up too nicely with the headers, but the effect
8978 is relatively readable). */
8979 if (opts
.addressprint
)
8980 ui_out_field_skip (uiout
, "addr");
8982 ui_out_text (uiout
, "exec");
8983 if (c
->exec_pathname
!= NULL
)
8985 ui_out_text (uiout
, ", program \"");
8986 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8987 ui_out_text (uiout
, "\" ");
8990 if (ui_out_is_mi_like_p (uiout
))
8991 ui_out_field_string (uiout
, "catch-type", "exec");
8995 print_mention_catch_exec (struct breakpoint
*b
)
8997 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
9000 /* Implement the "print_recreate" breakpoint_ops method for exec
9004 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
9006 fprintf_unfiltered (fp
, "catch exec");
9007 print_recreate_thread (b
, fp
);
9010 static struct breakpoint_ops catch_exec_breakpoint_ops
;
9013 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
9014 const struct breakpoint_ops
*ops
)
9016 struct syscall_catchpoint
*c
;
9017 struct gdbarch
*gdbarch
= get_current_arch ();
9019 c
= XNEW (struct syscall_catchpoint
);
9020 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
9021 c
->syscalls_to_be_caught
= filter
;
9023 install_breakpoint (0, &c
->base
, 1);
9027 hw_breakpoint_used_count (void)
9030 struct breakpoint
*b
;
9031 struct bp_location
*bl
;
9035 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
9036 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9038 /* Special types of hardware breakpoints may use more than
9040 i
+= b
->ops
->resources_needed (bl
);
9047 /* Returns the resources B would use if it were a hardware
9051 hw_watchpoint_use_count (struct breakpoint
*b
)
9054 struct bp_location
*bl
;
9056 if (!breakpoint_enabled (b
))
9059 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9061 /* Special types of hardware watchpoints may use more than
9063 i
+= b
->ops
->resources_needed (bl
);
9069 /* Returns the sum the used resources of all hardware watchpoints of
9070 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9071 the sum of the used resources of all hardware watchpoints of other
9072 types _not_ TYPE. */
9075 hw_watchpoint_used_count_others (struct breakpoint
*except
,
9076 enum bptype type
, int *other_type_used
)
9079 struct breakpoint
*b
;
9081 *other_type_used
= 0;
9086 if (!breakpoint_enabled (b
))
9089 if (b
->type
== type
)
9090 i
+= hw_watchpoint_use_count (b
);
9091 else if (is_hardware_watchpoint (b
))
9092 *other_type_used
= 1;
9099 disable_watchpoints_before_interactive_call_start (void)
9101 struct breakpoint
*b
;
9105 if (is_watchpoint (b
) && breakpoint_enabled (b
))
9107 b
->enable_state
= bp_call_disabled
;
9108 update_global_location_list (UGLL_DONT_INSERT
);
9114 enable_watchpoints_after_interactive_call_stop (void)
9116 struct breakpoint
*b
;
9120 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
9122 b
->enable_state
= bp_enabled
;
9123 update_global_location_list (UGLL_MAY_INSERT
);
9129 disable_breakpoints_before_startup (void)
9131 current_program_space
->executing_startup
= 1;
9132 update_global_location_list (UGLL_DONT_INSERT
);
9136 enable_breakpoints_after_startup (void)
9138 current_program_space
->executing_startup
= 0;
9139 breakpoint_re_set ();
9142 /* Create a new single-step breakpoint for thread THREAD, with no
9145 static struct breakpoint
*
9146 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
9148 struct breakpoint
*b
= XNEW (struct breakpoint
);
9150 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
9151 &momentary_breakpoint_ops
);
9153 b
->disposition
= disp_donttouch
;
9154 b
->frame_id
= null_frame_id
;
9157 gdb_assert (b
->thread
!= 0);
9159 add_to_breakpoint_chain (b
);
9164 /* Set a momentary breakpoint of type TYPE at address specified by
9165 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
9169 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9170 struct frame_id frame_id
, enum bptype type
)
9172 struct breakpoint
*b
;
9174 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9176 gdb_assert (!frame_id_artificial_p (frame_id
));
9178 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9179 b
->enable_state
= bp_enabled
;
9180 b
->disposition
= disp_donttouch
;
9181 b
->frame_id
= frame_id
;
9183 /* If we're debugging a multi-threaded program, then we want
9184 momentary breakpoints to be active in only a single thread of
9186 if (in_thread_list (inferior_ptid
))
9187 b
->thread
= pid_to_thread_id (inferior_ptid
);
9189 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
9194 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9195 The new breakpoint will have type TYPE, use OPS as its
9196 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9198 static struct breakpoint
*
9199 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9201 const struct breakpoint_ops
*ops
,
9204 struct breakpoint
*copy
;
9206 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9207 copy
->loc
= allocate_bp_location (copy
);
9208 set_breakpoint_location_function (copy
->loc
, 1);
9210 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9211 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9212 copy
->loc
->address
= orig
->loc
->address
;
9213 copy
->loc
->section
= orig
->loc
->section
;
9214 copy
->loc
->pspace
= orig
->loc
->pspace
;
9215 copy
->loc
->probe
= orig
->loc
->probe
;
9216 copy
->loc
->line_number
= orig
->loc
->line_number
;
9217 copy
->loc
->symtab
= orig
->loc
->symtab
;
9218 copy
->loc
->enabled
= loc_enabled
;
9219 copy
->frame_id
= orig
->frame_id
;
9220 copy
->thread
= orig
->thread
;
9221 copy
->pspace
= orig
->pspace
;
9223 copy
->enable_state
= bp_enabled
;
9224 copy
->disposition
= disp_donttouch
;
9225 copy
->number
= internal_breakpoint_number
--;
9227 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9231 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9235 clone_momentary_breakpoint (struct breakpoint
*orig
)
9237 /* If there's nothing to clone, then return nothing. */
9241 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9245 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9248 struct symtab_and_line sal
;
9250 sal
= find_pc_line (pc
, 0);
9252 sal
.section
= find_pc_overlay (pc
);
9253 sal
.explicit_pc
= 1;
9255 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9259 /* Tell the user we have just set a breakpoint B. */
9262 mention (struct breakpoint
*b
)
9264 b
->ops
->print_mention (b
);
9265 if (ui_out_is_mi_like_p (current_uiout
))
9267 printf_filtered ("\n");
9271 static int bp_loc_is_permanent (struct bp_location
*loc
);
9273 static struct bp_location
*
9274 add_location_to_breakpoint (struct breakpoint
*b
,
9275 const struct symtab_and_line
*sal
)
9277 struct bp_location
*loc
, **tmp
;
9278 CORE_ADDR adjusted_address
;
9279 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9281 if (loc_gdbarch
== NULL
)
9282 loc_gdbarch
= b
->gdbarch
;
9284 /* Adjust the breakpoint's address prior to allocating a location.
9285 Once we call allocate_bp_location(), that mostly uninitialized
9286 location will be placed on the location chain. Adjustment of the
9287 breakpoint may cause target_read_memory() to be called and we do
9288 not want its scan of the location chain to find a breakpoint and
9289 location that's only been partially initialized. */
9290 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9293 /* Sort the locations by their ADDRESS. */
9294 loc
= allocate_bp_location (b
);
9295 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9296 tmp
= &((*tmp
)->next
))
9301 loc
->requested_address
= sal
->pc
;
9302 loc
->address
= adjusted_address
;
9303 loc
->pspace
= sal
->pspace
;
9304 loc
->probe
.probe
= sal
->probe
;
9305 loc
->probe
.objfile
= sal
->objfile
;
9306 gdb_assert (loc
->pspace
!= NULL
);
9307 loc
->section
= sal
->section
;
9308 loc
->gdbarch
= loc_gdbarch
;
9309 loc
->line_number
= sal
->line
;
9310 loc
->symtab
= sal
->symtab
;
9312 set_breakpoint_location_function (loc
,
9313 sal
->explicit_pc
|| sal
->explicit_line
);
9315 if (bp_loc_is_permanent (loc
))
9325 /* See breakpoint.h. */
9328 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9332 const gdb_byte
*bpoint
;
9333 gdb_byte
*target_mem
;
9334 struct cleanup
*cleanup
;
9338 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9340 /* Software breakpoints unsupported? */
9344 target_mem
= alloca (len
);
9346 /* Enable the automatic memory restoration from breakpoints while
9347 we read the memory. Otherwise we could say about our temporary
9348 breakpoints they are permanent. */
9349 cleanup
= make_show_memory_breakpoints_cleanup (0);
9351 if (target_read_memory (address
, target_mem
, len
) == 0
9352 && memcmp (target_mem
, bpoint
, len
) == 0)
9355 do_cleanups (cleanup
);
9360 /* Return 1 if LOC is pointing to a permanent breakpoint,
9361 return 0 otherwise. */
9364 bp_loc_is_permanent (struct bp_location
*loc
)
9366 struct cleanup
*cleanup
;
9369 gdb_assert (loc
!= NULL
);
9371 /* bp_call_dummy breakpoint locations are usually memory locations
9372 where GDB just wrote a breakpoint instruction, making it look
9373 as if there is a permanent breakpoint at that location. Considering
9374 it permanent makes GDB rely on that breakpoint instruction to stop
9375 the program, thus removing the need to insert its own breakpoint
9376 there. This is normally expected to work, except that some versions
9377 of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap
9378 0x02 while interrupts disabled, Error state) instead of reporting
9379 a SIGTRAP. QEMU should probably be fixed, but in the interest of
9380 compatibility with versions that behave this way, we always consider
9381 bp_call_dummy breakpoint locations as non-permanent. */
9382 if (loc
->owner
->type
== bp_call_dummy
)
9385 cleanup
= save_current_space_and_thread ();
9386 switch_to_program_space_and_thread (loc
->pspace
);
9388 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9390 do_cleanups (cleanup
);
9395 /* Build a command list for the dprintf corresponding to the current
9396 settings of the dprintf style options. */
9399 update_dprintf_command_list (struct breakpoint
*b
)
9401 char *dprintf_args
= b
->extra_string
;
9402 char *printf_line
= NULL
;
9407 dprintf_args
= skip_spaces (dprintf_args
);
9409 /* Allow a comma, as it may have terminated a location, but don't
9411 if (*dprintf_args
== ',')
9413 dprintf_args
= skip_spaces (dprintf_args
);
9415 if (*dprintf_args
!= '"')
9416 error (_("Bad format string, missing '\"'."));
9418 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9419 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9420 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9422 if (!dprintf_function
)
9423 error (_("No function supplied for dprintf call"));
9425 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9426 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9431 printf_line
= xstrprintf ("call (void) %s (%s)",
9435 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9437 if (target_can_run_breakpoint_commands ())
9438 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9441 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9442 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9446 internal_error (__FILE__
, __LINE__
,
9447 _("Invalid dprintf style."));
9449 gdb_assert (printf_line
!= NULL
);
9450 /* Manufacture a printf sequence. */
9452 struct command_line
*printf_cmd_line
9453 = xmalloc (sizeof (struct command_line
));
9455 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9456 printf_cmd_line
->control_type
= simple_control
;
9457 printf_cmd_line
->body_count
= 0;
9458 printf_cmd_line
->body_list
= NULL
;
9459 printf_cmd_line
->next
= NULL
;
9460 printf_cmd_line
->line
= printf_line
;
9462 breakpoint_set_commands (b
, printf_cmd_line
);
9466 /* Update all dprintf commands, making their command lists reflect
9467 current style settings. */
9470 update_dprintf_commands (char *args
, int from_tty
,
9471 struct cmd_list_element
*c
)
9473 struct breakpoint
*b
;
9477 if (b
->type
== bp_dprintf
)
9478 update_dprintf_command_list (b
);
9482 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9483 as textual description of the location, and COND_STRING
9484 as condition expression. */
9487 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9488 struct symtabs_and_lines sals
, char *addr_string
,
9489 char *filter
, char *cond_string
,
9491 enum bptype type
, enum bpdisp disposition
,
9492 int thread
, int task
, int ignore_count
,
9493 const struct breakpoint_ops
*ops
, int from_tty
,
9494 int enabled
, int internal
, unsigned flags
,
9495 int display_canonical
)
9499 if (type
== bp_hardware_breakpoint
)
9501 int target_resources_ok
;
9503 i
= hw_breakpoint_used_count ();
9504 target_resources_ok
=
9505 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9507 if (target_resources_ok
== 0)
9508 error (_("No hardware breakpoint support in the target."));
9509 else if (target_resources_ok
< 0)
9510 error (_("Hardware breakpoints used exceeds limit."));
9513 gdb_assert (sals
.nelts
> 0);
9515 for (i
= 0; i
< sals
.nelts
; ++i
)
9517 struct symtab_and_line sal
= sals
.sals
[i
];
9518 struct bp_location
*loc
;
9522 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9524 loc_gdbarch
= gdbarch
;
9526 describe_other_breakpoints (loc_gdbarch
,
9527 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9532 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9536 b
->cond_string
= cond_string
;
9537 b
->extra_string
= extra_string
;
9538 b
->ignore_count
= ignore_count
;
9539 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9540 b
->disposition
= disposition
;
9542 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9543 b
->loc
->inserted
= 1;
9545 if (type
== bp_static_tracepoint
)
9547 struct tracepoint
*t
= (struct tracepoint
*) b
;
9548 struct static_tracepoint_marker marker
;
9550 if (strace_marker_p (b
))
9552 /* We already know the marker exists, otherwise, we
9553 wouldn't see a sal for it. */
9554 char *p
= &addr_string
[3];
9558 p
= skip_spaces (p
);
9560 endp
= skip_to_space (p
);
9562 marker_str
= savestring (p
, endp
- p
);
9563 t
->static_trace_marker_id
= marker_str
;
9565 printf_filtered (_("Probed static tracepoint "
9567 t
->static_trace_marker_id
);
9569 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9571 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9572 release_static_tracepoint_marker (&marker
);
9574 printf_filtered (_("Probed static tracepoint "
9576 t
->static_trace_marker_id
);
9579 warning (_("Couldn't determine the static "
9580 "tracepoint marker to probe"));
9587 loc
= add_location_to_breakpoint (b
, &sal
);
9588 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9594 const char *arg
= b
->cond_string
;
9596 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9597 block_for_pc (loc
->address
), 0);
9599 error (_("Garbage '%s' follows condition"), arg
);
9602 /* Dynamic printf requires and uses additional arguments on the
9603 command line, otherwise it's an error. */
9604 if (type
== bp_dprintf
)
9606 if (b
->extra_string
)
9607 update_dprintf_command_list (b
);
9609 error (_("Format string required"));
9611 else if (b
->extra_string
)
9612 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9615 b
->display_canonical
= display_canonical
;
9617 b
->addr_string
= addr_string
;
9619 /* addr_string has to be used or breakpoint_re_set will delete
9622 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9627 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9628 struct symtabs_and_lines sals
, char *addr_string
,
9629 char *filter
, char *cond_string
,
9631 enum bptype type
, enum bpdisp disposition
,
9632 int thread
, int task
, int ignore_count
,
9633 const struct breakpoint_ops
*ops
, int from_tty
,
9634 int enabled
, int internal
, unsigned flags
,
9635 int display_canonical
)
9637 struct breakpoint
*b
;
9638 struct cleanup
*old_chain
;
9640 if (is_tracepoint_type (type
))
9642 struct tracepoint
*t
;
9644 t
= XCNEW (struct tracepoint
);
9648 b
= XNEW (struct breakpoint
);
9650 old_chain
= make_cleanup (xfree
, b
);
9652 init_breakpoint_sal (b
, gdbarch
,
9654 filter
, cond_string
, extra_string
,
9656 thread
, task
, ignore_count
,
9658 enabled
, internal
, flags
,
9660 discard_cleanups (old_chain
);
9662 install_breakpoint (internal
, b
, 0);
9665 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9666 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9667 value. COND_STRING, if not NULL, specified the condition to be
9668 used for all breakpoints. Essentially the only case where
9669 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9670 function. In that case, it's still not possible to specify
9671 separate conditions for different overloaded functions, so
9672 we take just a single condition string.
9674 NOTE: If the function succeeds, the caller is expected to cleanup
9675 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9676 array contents). If the function fails (error() is called), the
9677 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9678 COND and SALS arrays and each of those arrays contents. */
9681 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9682 struct linespec_result
*canonical
,
9683 char *cond_string
, char *extra_string
,
9684 enum bptype type
, enum bpdisp disposition
,
9685 int thread
, int task
, int ignore_count
,
9686 const struct breakpoint_ops
*ops
, int from_tty
,
9687 int enabled
, int internal
, unsigned flags
)
9690 struct linespec_sals
*lsal
;
9692 if (canonical
->pre_expanded
)
9693 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9695 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9697 /* Note that 'addr_string' can be NULL in the case of a plain
9698 'break', without arguments. */
9699 char *addr_string
= (canonical
->addr_string
9700 ? xstrdup (canonical
->addr_string
)
9702 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9703 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9705 make_cleanup (xfree
, filter_string
);
9706 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9709 cond_string
, extra_string
,
9711 thread
, task
, ignore_count
, ops
,
9712 from_tty
, enabled
, internal
, flags
,
9713 canonical
->special_display
);
9714 discard_cleanups (inner
);
9718 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9719 followed by conditionals. On return, SALS contains an array of SAL
9720 addresses found. ADDR_STRING contains a vector of (canonical)
9721 address strings. ADDRESS points to the end of the SAL.
9723 The array and the line spec strings are allocated on the heap, it is
9724 the caller's responsibility to free them. */
9727 parse_breakpoint_sals (char **address
,
9728 struct linespec_result
*canonical
)
9730 /* If no arg given, or if first arg is 'if ', use the default
9732 if ((*address
) == NULL
9733 || (startswith ((*address
), "if") && isspace ((*address
)[2])))
9735 /* The last displayed codepoint, if it's valid, is our default breakpoint
9737 if (last_displayed_sal_is_valid ())
9739 struct linespec_sals lsal
;
9740 struct symtab_and_line sal
;
9743 init_sal (&sal
); /* Initialize to zeroes. */
9744 lsal
.sals
.sals
= (struct symtab_and_line
*)
9745 xmalloc (sizeof (struct symtab_and_line
));
9747 /* Set sal's pspace, pc, symtab, and line to the values
9748 corresponding to the last call to print_frame_info.
9749 Be sure to reinitialize LINE with NOTCURRENT == 0
9750 as the breakpoint line number is inappropriate otherwise.
9751 find_pc_line would adjust PC, re-set it back. */
9752 get_last_displayed_sal (&sal
);
9754 sal
= find_pc_line (pc
, 0);
9756 /* "break" without arguments is equivalent to "break *PC"
9757 where PC is the last displayed codepoint's address. So
9758 make sure to set sal.explicit_pc to prevent GDB from
9759 trying to expand the list of sals to include all other
9760 instances with the same symtab and line. */
9762 sal
.explicit_pc
= 1;
9764 lsal
.sals
.sals
[0] = sal
;
9765 lsal
.sals
.nelts
= 1;
9766 lsal
.canonical
= NULL
;
9768 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9771 error (_("No default breakpoint address now."));
9775 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9777 /* Force almost all breakpoints to be in terms of the
9778 current_source_symtab (which is decode_line_1's default).
9779 This should produce the results we want almost all of the
9780 time while leaving default_breakpoint_* alone.
9782 ObjC: However, don't match an Objective-C method name which
9783 may have a '+' or '-' succeeded by a '['. */
9784 if (last_displayed_sal_is_valid ()
9786 || ((strchr ("+-", (*address
)[0]) != NULL
)
9787 && ((*address
)[1] != '['))))
9788 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9789 get_last_displayed_symtab (),
9790 get_last_displayed_line (),
9791 canonical
, NULL
, NULL
);
9793 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9794 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9799 /* Convert each SAL into a real PC. Verify that the PC can be
9800 inserted as a breakpoint. If it can't throw an error. */
9803 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9807 for (i
= 0; i
< sals
->nelts
; i
++)
9808 resolve_sal_pc (&sals
->sals
[i
]);
9811 /* Fast tracepoints may have restrictions on valid locations. For
9812 instance, a fast tracepoint using a jump instead of a trap will
9813 likely have to overwrite more bytes than a trap would, and so can
9814 only be placed where the instruction is longer than the jump, or a
9815 multi-instruction sequence does not have a jump into the middle of
9819 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9820 struct symtabs_and_lines
*sals
)
9823 struct symtab_and_line
*sal
;
9825 struct cleanup
*old_chain
;
9827 for (i
= 0; i
< sals
->nelts
; i
++)
9829 struct gdbarch
*sarch
;
9831 sal
= &sals
->sals
[i
];
9833 sarch
= get_sal_arch (*sal
);
9834 /* We fall back to GDBARCH if there is no architecture
9835 associated with SAL. */
9838 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9840 old_chain
= make_cleanup (xfree
, msg
);
9843 error (_("May not have a fast tracepoint at 0x%s%s"),
9844 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9846 do_cleanups (old_chain
);
9850 /* Issue an invalid thread ID error. */
9852 static void ATTRIBUTE_NORETURN
9853 invalid_thread_id_error (int id
)
9855 error (_("Unknown thread %d."), id
);
9858 /* Given TOK, a string specification of condition and thread, as
9859 accepted by the 'break' command, extract the condition
9860 string and thread number and set *COND_STRING and *THREAD.
9861 PC identifies the context at which the condition should be parsed.
9862 If no condition is found, *COND_STRING is set to NULL.
9863 If no thread is found, *THREAD is set to -1. */
9866 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9867 char **cond_string
, int *thread
, int *task
,
9870 *cond_string
= NULL
;
9877 const char *end_tok
;
9879 const char *cond_start
= NULL
;
9880 const char *cond_end
= NULL
;
9882 tok
= skip_spaces_const (tok
);
9884 if ((*tok
== '"' || *tok
== ',') && rest
)
9886 *rest
= savestring (tok
, strlen (tok
));
9890 end_tok
= skip_to_space_const (tok
);
9892 toklen
= end_tok
- tok
;
9894 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9896 struct expression
*expr
;
9898 tok
= cond_start
= end_tok
+ 1;
9899 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9902 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9904 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9909 *thread
= strtol (tok
, &tmptok
, 0);
9911 error (_("Junk after thread keyword."));
9912 if (!valid_thread_id (*thread
))
9913 invalid_thread_id_error (*thread
);
9916 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9921 *task
= strtol (tok
, &tmptok
, 0);
9923 error (_("Junk after task keyword."));
9924 if (!valid_task_id (*task
))
9925 error (_("Unknown task %d."), *task
);
9930 *rest
= savestring (tok
, strlen (tok
));
9934 error (_("Junk at end of arguments."));
9938 /* Decode a static tracepoint marker spec. */
9940 static struct symtabs_and_lines
9941 decode_static_tracepoint_spec (char **arg_p
)
9943 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9944 struct symtabs_and_lines sals
;
9945 struct cleanup
*old_chain
;
9946 char *p
= &(*arg_p
)[3];
9951 p
= skip_spaces (p
);
9953 endp
= skip_to_space (p
);
9955 marker_str
= savestring (p
, endp
- p
);
9956 old_chain
= make_cleanup (xfree
, marker_str
);
9958 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9959 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9960 error (_("No known static tracepoint marker named %s"), marker_str
);
9962 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9963 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9965 for (i
= 0; i
< sals
.nelts
; i
++)
9967 struct static_tracepoint_marker
*marker
;
9969 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9971 init_sal (&sals
.sals
[i
]);
9973 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9974 sals
.sals
[i
].pc
= marker
->address
;
9976 release_static_tracepoint_marker (marker
);
9979 do_cleanups (old_chain
);
9985 /* Set a breakpoint. This function is shared between CLI and MI
9986 functions for setting a breakpoint. This function has two major
9987 modes of operations, selected by the PARSE_ARG parameter. If
9988 non-zero, the function will parse ARG, extracting location,
9989 condition, thread and extra string. Otherwise, ARG is just the
9990 breakpoint's location, with condition, thread, and extra string
9991 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9992 If INTERNAL is non-zero, the breakpoint number will be allocated
9993 from the internal breakpoint count. Returns true if any breakpoint
9994 was created; false otherwise. */
9997 create_breakpoint (struct gdbarch
*gdbarch
,
9998 char *arg
, char *cond_string
,
9999 int thread
, char *extra_string
,
10001 int tempflag
, enum bptype type_wanted
,
10003 enum auto_boolean pending_break_support
,
10004 const struct breakpoint_ops
*ops
,
10005 int from_tty
, int enabled
, int internal
,
10008 char *copy_arg
= NULL
;
10009 char *addr_start
= arg
;
10010 struct linespec_result canonical
;
10011 struct cleanup
*old_chain
;
10012 struct cleanup
*bkpt_chain
= NULL
;
10015 int prev_bkpt_count
= breakpoint_count
;
10017 gdb_assert (ops
!= NULL
);
10019 init_linespec_result (&canonical
);
10023 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
10024 addr_start
, ©_arg
);
10026 CATCH (e
, RETURN_MASK_ERROR
)
10028 /* If caller is interested in rc value from parse, set
10030 if (e
.error
== NOT_FOUND_ERROR
)
10032 /* If pending breakpoint support is turned off, throw
10035 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
10036 throw_exception (e
);
10038 exception_print (gdb_stderr
, e
);
10040 /* If pending breakpoint support is auto query and the user
10041 selects no, then simply return the error code. */
10042 if (pending_break_support
== AUTO_BOOLEAN_AUTO
10043 && !nquery (_("Make %s pending on future shared library load? "),
10044 bptype_string (type_wanted
)))
10047 /* At this point, either the user was queried about setting
10048 a pending breakpoint and selected yes, or pending
10049 breakpoint behavior is on and thus a pending breakpoint
10050 is defaulted on behalf of the user. */
10052 struct linespec_sals lsal
;
10054 copy_arg
= xstrdup (addr_start
);
10055 lsal
.canonical
= xstrdup (copy_arg
);
10056 lsal
.sals
.nelts
= 1;
10057 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
10058 init_sal (&lsal
.sals
.sals
[0]);
10060 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
10064 throw_exception (e
);
10068 if (VEC_empty (linespec_sals
, canonical
.sals
))
10071 /* Create a chain of things that always need to be cleaned up. */
10072 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
10074 /* ----------------------------- SNIP -----------------------------
10075 Anything added to the cleanup chain beyond this point is assumed
10076 to be part of a breakpoint. If the breakpoint create succeeds
10077 then the memory is not reclaimed. */
10078 bkpt_chain
= make_cleanup (null_cleanup
, 0);
10080 /* Resolve all line numbers to PC's and verify that the addresses
10081 are ok for the target. */
10085 struct linespec_sals
*iter
;
10087 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10088 breakpoint_sals_to_pc (&iter
->sals
);
10091 /* Fast tracepoints may have additional restrictions on location. */
10092 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
10095 struct linespec_sals
*iter
;
10097 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10098 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
10101 /* Verify that condition can be parsed, before setting any
10102 breakpoints. Allocate a separate condition expression for each
10109 struct linespec_sals
*lsal
;
10111 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
10113 /* Here we only parse 'arg' to separate condition
10114 from thread number, so parsing in context of first
10115 sal is OK. When setting the breakpoint we'll
10116 re-parse it in context of each sal. */
10118 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
10119 &thread
, &task
, &rest
);
10121 make_cleanup (xfree
, cond_string
);
10123 make_cleanup (xfree
, rest
);
10125 extra_string
= rest
;
10130 error (_("Garbage '%s' at end of location"), arg
);
10132 /* Create a private copy of condition string. */
10135 cond_string
= xstrdup (cond_string
);
10136 make_cleanup (xfree
, cond_string
);
10138 /* Create a private copy of any extra string. */
10141 extra_string
= xstrdup (extra_string
);
10142 make_cleanup (xfree
, extra_string
);
10146 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
10147 cond_string
, extra_string
, type_wanted
,
10148 tempflag
? disp_del
: disp_donttouch
,
10149 thread
, task
, ignore_count
, ops
,
10150 from_tty
, enabled
, internal
, flags
);
10154 struct breakpoint
*b
;
10156 make_cleanup (xfree
, copy_arg
);
10158 if (is_tracepoint_type (type_wanted
))
10160 struct tracepoint
*t
;
10162 t
= XCNEW (struct tracepoint
);
10166 b
= XNEW (struct breakpoint
);
10168 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
10170 b
->addr_string
= copy_arg
;
10172 b
->cond_string
= NULL
;
10175 /* Create a private copy of condition string. */
10178 cond_string
= xstrdup (cond_string
);
10179 make_cleanup (xfree
, cond_string
);
10181 b
->cond_string
= cond_string
;
10183 b
->extra_string
= NULL
;
10184 b
->ignore_count
= ignore_count
;
10185 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10186 b
->condition_not_parsed
= 1;
10187 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10188 if ((type_wanted
!= bp_breakpoint
10189 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
10190 b
->pspace
= current_program_space
;
10192 install_breakpoint (internal
, b
, 0);
10195 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
10197 warning (_("Multiple breakpoints were set.\nUse the "
10198 "\"delete\" command to delete unwanted breakpoints."));
10199 prev_breakpoint_count
= prev_bkpt_count
;
10202 /* That's it. Discard the cleanups for data inserted into the
10204 discard_cleanups (bkpt_chain
);
10205 /* But cleanup everything else. */
10206 do_cleanups (old_chain
);
10208 /* error call may happen here - have BKPT_CHAIN already discarded. */
10209 update_global_location_list (UGLL_MAY_INSERT
);
10214 /* Set a breakpoint.
10215 ARG is a string describing breakpoint address,
10216 condition, and thread.
10217 FLAG specifies if a breakpoint is hardware on,
10218 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10219 and BP_TEMPFLAG. */
10222 break_command_1 (char *arg
, int flag
, int from_tty
)
10224 int tempflag
= flag
& BP_TEMPFLAG
;
10225 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10226 ? bp_hardware_breakpoint
10228 struct breakpoint_ops
*ops
;
10229 const char *arg_cp
= arg
;
10231 /* Matching breakpoints on probes. */
10232 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10233 ops
= &bkpt_probe_breakpoint_ops
;
10235 ops
= &bkpt_breakpoint_ops
;
10237 create_breakpoint (get_current_arch (),
10239 NULL
, 0, NULL
, 1 /* parse arg */,
10240 tempflag
, type_wanted
,
10241 0 /* Ignore count */,
10242 pending_break_support
,
10250 /* Helper function for break_command_1 and disassemble_command. */
10253 resolve_sal_pc (struct symtab_and_line
*sal
)
10257 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10259 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10260 error (_("No line %d in file \"%s\"."),
10261 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10264 /* If this SAL corresponds to a breakpoint inserted using a line
10265 number, then skip the function prologue if necessary. */
10266 if (sal
->explicit_line
)
10267 skip_prologue_sal (sal
);
10270 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10272 const struct blockvector
*bv
;
10273 const struct block
*b
;
10274 struct symbol
*sym
;
10276 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10277 SYMTAB_COMPUNIT (sal
->symtab
));
10280 sym
= block_linkage_function (b
);
10283 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10284 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10289 /* It really is worthwhile to have the section, so we'll
10290 just have to look harder. This case can be executed
10291 if we have line numbers but no functions (as can
10292 happen in assembly source). */
10294 struct bound_minimal_symbol msym
;
10295 struct cleanup
*old_chain
= save_current_space_and_thread ();
10297 switch_to_program_space_and_thread (sal
->pspace
);
10299 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10301 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10303 do_cleanups (old_chain
);
10310 break_command (char *arg
, int from_tty
)
10312 break_command_1 (arg
, 0, from_tty
);
10316 tbreak_command (char *arg
, int from_tty
)
10318 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10322 hbreak_command (char *arg
, int from_tty
)
10324 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10328 thbreak_command (char *arg
, int from_tty
)
10330 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10334 stop_command (char *arg
, int from_tty
)
10336 printf_filtered (_("Specify the type of breakpoint to set.\n\
10337 Usage: stop in <function | address>\n\
10338 stop at <line>\n"));
10342 stopin_command (char *arg
, int from_tty
)
10346 if (arg
== (char *) NULL
)
10348 else if (*arg
!= '*')
10350 char *argptr
= arg
;
10353 /* Look for a ':'. If this is a line number specification, then
10354 say it is bad, otherwise, it should be an address or
10355 function/method name. */
10356 while (*argptr
&& !hasColon
)
10358 hasColon
= (*argptr
== ':');
10363 badInput
= (*argptr
!= ':'); /* Not a class::method */
10365 badInput
= isdigit (*arg
); /* a simple line number */
10369 printf_filtered (_("Usage: stop in <function | address>\n"));
10371 break_command_1 (arg
, 0, from_tty
);
10375 stopat_command (char *arg
, int from_tty
)
10379 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10383 char *argptr
= arg
;
10386 /* Look for a ':'. If there is a '::' then get out, otherwise
10387 it is probably a line number. */
10388 while (*argptr
&& !hasColon
)
10390 hasColon
= (*argptr
== ':');
10395 badInput
= (*argptr
== ':'); /* we have class::method */
10397 badInput
= !isdigit (*arg
); /* not a line number */
10401 printf_filtered (_("Usage: stop at <line>\n"));
10403 break_command_1 (arg
, 0, from_tty
);
10406 /* The dynamic printf command is mostly like a regular breakpoint, but
10407 with a prewired command list consisting of a single output command,
10408 built from extra arguments supplied on the dprintf command
10412 dprintf_command (char *arg
, int from_tty
)
10414 create_breakpoint (get_current_arch (),
10416 NULL
, 0, NULL
, 1 /* parse arg */,
10418 0 /* Ignore count */,
10419 pending_break_support
,
10420 &dprintf_breakpoint_ops
,
10428 agent_printf_command (char *arg
, int from_tty
)
10430 error (_("May only run agent-printf on the target"));
10433 /* Implement the "breakpoint_hit" breakpoint_ops method for
10434 ranged breakpoints. */
10437 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10438 struct address_space
*aspace
,
10440 const struct target_waitstatus
*ws
)
10442 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10443 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10446 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10447 bl
->length
, aspace
, bp_addr
);
10450 /* Implement the "resources_needed" breakpoint_ops method for
10451 ranged breakpoints. */
10454 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10456 return target_ranged_break_num_registers ();
10459 /* Implement the "print_it" breakpoint_ops method for
10460 ranged breakpoints. */
10462 static enum print_stop_action
10463 print_it_ranged_breakpoint (bpstat bs
)
10465 struct breakpoint
*b
= bs
->breakpoint_at
;
10466 struct bp_location
*bl
= b
->loc
;
10467 struct ui_out
*uiout
= current_uiout
;
10469 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10471 /* Ranged breakpoints have only one location. */
10472 gdb_assert (bl
&& bl
->next
== NULL
);
10474 annotate_breakpoint (b
->number
);
10475 if (b
->disposition
== disp_del
)
10476 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10478 ui_out_text (uiout
, "\nRanged breakpoint ");
10479 if (ui_out_is_mi_like_p (uiout
))
10481 ui_out_field_string (uiout
, "reason",
10482 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10483 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10485 ui_out_field_int (uiout
, "bkptno", b
->number
);
10486 ui_out_text (uiout
, ", ");
10488 return PRINT_SRC_AND_LOC
;
10491 /* Implement the "print_one" breakpoint_ops method for
10492 ranged breakpoints. */
10495 print_one_ranged_breakpoint (struct breakpoint
*b
,
10496 struct bp_location
**last_loc
)
10498 struct bp_location
*bl
= b
->loc
;
10499 struct value_print_options opts
;
10500 struct ui_out
*uiout
= current_uiout
;
10502 /* Ranged breakpoints have only one location. */
10503 gdb_assert (bl
&& bl
->next
== NULL
);
10505 get_user_print_options (&opts
);
10507 if (opts
.addressprint
)
10508 /* We don't print the address range here, it will be printed later
10509 by print_one_detail_ranged_breakpoint. */
10510 ui_out_field_skip (uiout
, "addr");
10511 annotate_field (5);
10512 print_breakpoint_location (b
, bl
);
10516 /* Implement the "print_one_detail" breakpoint_ops method for
10517 ranged breakpoints. */
10520 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10521 struct ui_out
*uiout
)
10523 CORE_ADDR address_start
, address_end
;
10524 struct bp_location
*bl
= b
->loc
;
10525 struct ui_file
*stb
= mem_fileopen ();
10526 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10530 address_start
= bl
->address
;
10531 address_end
= address_start
+ bl
->length
- 1;
10533 ui_out_text (uiout
, "\taddress range: ");
10534 fprintf_unfiltered (stb
, "[%s, %s]",
10535 print_core_address (bl
->gdbarch
, address_start
),
10536 print_core_address (bl
->gdbarch
, address_end
));
10537 ui_out_field_stream (uiout
, "addr", stb
);
10538 ui_out_text (uiout
, "\n");
10540 do_cleanups (cleanup
);
10543 /* Implement the "print_mention" breakpoint_ops method for
10544 ranged breakpoints. */
10547 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10549 struct bp_location
*bl
= b
->loc
;
10550 struct ui_out
*uiout
= current_uiout
;
10553 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10555 if (ui_out_is_mi_like_p (uiout
))
10558 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10559 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10560 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10563 /* Implement the "print_recreate" breakpoint_ops method for
10564 ranged breakpoints. */
10567 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10569 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10570 b
->addr_string_range_end
);
10571 print_recreate_thread (b
, fp
);
10574 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10576 static struct breakpoint_ops ranged_breakpoint_ops
;
10578 /* Find the address where the end of the breakpoint range should be
10579 placed, given the SAL of the end of the range. This is so that if
10580 the user provides a line number, the end of the range is set to the
10581 last instruction of the given line. */
10584 find_breakpoint_range_end (struct symtab_and_line sal
)
10588 /* If the user provided a PC value, use it. Otherwise,
10589 find the address of the end of the given location. */
10590 if (sal
.explicit_pc
)
10597 ret
= find_line_pc_range (sal
, &start
, &end
);
10599 error (_("Could not find location of the end of the range."));
10601 /* find_line_pc_range returns the start of the next line. */
10608 /* Implement the "break-range" CLI command. */
10611 break_range_command (char *arg
, int from_tty
)
10613 char *arg_start
, *addr_string_start
, *addr_string_end
;
10614 struct linespec_result canonical_start
, canonical_end
;
10615 int bp_count
, can_use_bp
, length
;
10617 struct breakpoint
*b
;
10618 struct symtab_and_line sal_start
, sal_end
;
10619 struct cleanup
*cleanup_bkpt
;
10620 struct linespec_sals
*lsal_start
, *lsal_end
;
10622 /* We don't support software ranged breakpoints. */
10623 if (target_ranged_break_num_registers () < 0)
10624 error (_("This target does not support hardware ranged breakpoints."));
10626 bp_count
= hw_breakpoint_used_count ();
10627 bp_count
+= target_ranged_break_num_registers ();
10628 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10630 if (can_use_bp
< 0)
10631 error (_("Hardware breakpoints used exceeds limit."));
10633 arg
= skip_spaces (arg
);
10634 if (arg
== NULL
|| arg
[0] == '\0')
10635 error(_("No address range specified."));
10637 init_linespec_result (&canonical_start
);
10640 parse_breakpoint_sals (&arg
, &canonical_start
);
10642 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10645 error (_("Too few arguments."));
10646 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10647 error (_("Could not find location of the beginning of the range."));
10649 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10651 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10652 || lsal_start
->sals
.nelts
!= 1)
10653 error (_("Cannot create a ranged breakpoint with multiple locations."));
10655 sal_start
= lsal_start
->sals
.sals
[0];
10656 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10657 make_cleanup (xfree
, addr_string_start
);
10659 arg
++; /* Skip the comma. */
10660 arg
= skip_spaces (arg
);
10662 /* Parse the end location. */
10664 init_linespec_result (&canonical_end
);
10667 /* We call decode_line_full directly here instead of using
10668 parse_breakpoint_sals because we need to specify the start location's
10669 symtab and line as the default symtab and line for the end of the
10670 range. This makes it possible to have ranges like "foo.c:27, +14",
10671 where +14 means 14 lines from the start location. */
10672 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10673 sal_start
.symtab
, sal_start
.line
,
10674 &canonical_end
, NULL
, NULL
);
10676 make_cleanup_destroy_linespec_result (&canonical_end
);
10678 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10679 error (_("Could not find location of the end of the range."));
10681 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10682 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10683 || lsal_end
->sals
.nelts
!= 1)
10684 error (_("Cannot create a ranged breakpoint with multiple locations."));
10686 sal_end
= lsal_end
->sals
.sals
[0];
10687 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10688 make_cleanup (xfree
, addr_string_end
);
10690 end
= find_breakpoint_range_end (sal_end
);
10691 if (sal_start
.pc
> end
)
10692 error (_("Invalid address range, end precedes start."));
10694 length
= end
- sal_start
.pc
+ 1;
10696 /* Length overflowed. */
10697 error (_("Address range too large."));
10698 else if (length
== 1)
10700 /* This range is simple enough to be handled by
10701 the `hbreak' command. */
10702 hbreak_command (addr_string_start
, 1);
10704 do_cleanups (cleanup_bkpt
);
10709 /* Now set up the breakpoint. */
10710 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10711 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10712 set_breakpoint_count (breakpoint_count
+ 1);
10713 b
->number
= breakpoint_count
;
10714 b
->disposition
= disp_donttouch
;
10715 b
->addr_string
= xstrdup (addr_string_start
);
10716 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10717 b
->loc
->length
= length
;
10719 do_cleanups (cleanup_bkpt
);
10722 observer_notify_breakpoint_created (b
);
10723 update_global_location_list (UGLL_MAY_INSERT
);
10726 /* Return non-zero if EXP is verified as constant. Returned zero
10727 means EXP is variable. Also the constant detection may fail for
10728 some constant expressions and in such case still falsely return
10732 watchpoint_exp_is_const (const struct expression
*exp
)
10734 int i
= exp
->nelts
;
10740 /* We are only interested in the descriptor of each element. */
10741 operator_length (exp
, i
, &oplenp
, &argsp
);
10744 switch (exp
->elts
[i
].opcode
)
10754 case BINOP_LOGICAL_AND
:
10755 case BINOP_LOGICAL_OR
:
10756 case BINOP_BITWISE_AND
:
10757 case BINOP_BITWISE_IOR
:
10758 case BINOP_BITWISE_XOR
:
10760 case BINOP_NOTEQUAL
:
10787 case OP_OBJC_NSSTRING
:
10790 case UNOP_LOGICAL_NOT
:
10791 case UNOP_COMPLEMENT
:
10796 case UNOP_CAST_TYPE
:
10797 case UNOP_REINTERPRET_CAST
:
10798 case UNOP_DYNAMIC_CAST
:
10799 /* Unary, binary and ternary operators: We have to check
10800 their operands. If they are constant, then so is the
10801 result of that operation. For instance, if A and B are
10802 determined to be constants, then so is "A + B".
10804 UNOP_IND is one exception to the rule above, because the
10805 value of *ADDR is not necessarily a constant, even when
10810 /* Check whether the associated symbol is a constant.
10812 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10813 possible that a buggy compiler could mark a variable as
10814 constant even when it is not, and TYPE_CONST would return
10815 true in this case, while SYMBOL_CLASS wouldn't.
10817 We also have to check for function symbols because they
10818 are always constant. */
10820 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10822 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10823 && SYMBOL_CLASS (s
) != LOC_CONST
10824 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10829 /* The default action is to return 0 because we are using
10830 the optimistic approach here: If we don't know something,
10831 then it is not a constant. */
10840 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10843 dtor_watchpoint (struct breakpoint
*self
)
10845 struct watchpoint
*w
= (struct watchpoint
*) self
;
10847 xfree (w
->cond_exp
);
10849 xfree (w
->exp_string
);
10850 xfree (w
->exp_string_reparse
);
10851 value_free (w
->val
);
10853 base_breakpoint_ops
.dtor (self
);
10856 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10859 re_set_watchpoint (struct breakpoint
*b
)
10861 struct watchpoint
*w
= (struct watchpoint
*) b
;
10863 /* Watchpoint can be either on expression using entirely global
10864 variables, or it can be on local variables.
10866 Watchpoints of the first kind are never auto-deleted, and even
10867 persist across program restarts. Since they can use variables
10868 from shared libraries, we need to reparse expression as libraries
10869 are loaded and unloaded.
10871 Watchpoints on local variables can also change meaning as result
10872 of solib event. For example, if a watchpoint uses both a local
10873 and a global variables in expression, it's a local watchpoint,
10874 but unloading of a shared library will make the expression
10875 invalid. This is not a very common use case, but we still
10876 re-evaluate expression, to avoid surprises to the user.
10878 Note that for local watchpoints, we re-evaluate it only if
10879 watchpoints frame id is still valid. If it's not, it means the
10880 watchpoint is out of scope and will be deleted soon. In fact,
10881 I'm not sure we'll ever be called in this case.
10883 If a local watchpoint's frame id is still valid, then
10884 w->exp_valid_block is likewise valid, and we can safely use it.
10886 Don't do anything about disabled watchpoints, since they will be
10887 reevaluated again when enabled. */
10888 update_watchpoint (w
, 1 /* reparse */);
10891 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10894 insert_watchpoint (struct bp_location
*bl
)
10896 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10897 int length
= w
->exact
? 1 : bl
->length
;
10899 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10903 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10906 remove_watchpoint (struct bp_location
*bl
)
10908 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10909 int length
= w
->exact
? 1 : bl
->length
;
10911 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10916 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10917 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10918 const struct target_waitstatus
*ws
)
10920 struct breakpoint
*b
= bl
->owner
;
10921 struct watchpoint
*w
= (struct watchpoint
*) b
;
10923 /* Continuable hardware watchpoints are treated as non-existent if the
10924 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10925 some data address). Otherwise gdb won't stop on a break instruction
10926 in the code (not from a breakpoint) when a hardware watchpoint has
10927 been defined. Also skip watchpoints which we know did not trigger
10928 (did not match the data address). */
10929 if (is_hardware_watchpoint (b
)
10930 && w
->watchpoint_triggered
== watch_triggered_no
)
10937 check_status_watchpoint (bpstat bs
)
10939 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10941 bpstat_check_watchpoint (bs
);
10944 /* Implement the "resources_needed" breakpoint_ops method for
10945 hardware watchpoints. */
10948 resources_needed_watchpoint (const struct bp_location
*bl
)
10950 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10951 int length
= w
->exact
? 1 : bl
->length
;
10953 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10956 /* Implement the "works_in_software_mode" breakpoint_ops method for
10957 hardware watchpoints. */
10960 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10962 /* Read and access watchpoints only work with hardware support. */
10963 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10966 static enum print_stop_action
10967 print_it_watchpoint (bpstat bs
)
10969 struct cleanup
*old_chain
;
10970 struct breakpoint
*b
;
10971 struct ui_file
*stb
;
10972 enum print_stop_action result
;
10973 struct watchpoint
*w
;
10974 struct ui_out
*uiout
= current_uiout
;
10976 gdb_assert (bs
->bp_location_at
!= NULL
);
10978 b
= bs
->breakpoint_at
;
10979 w
= (struct watchpoint
*) b
;
10981 stb
= mem_fileopen ();
10982 old_chain
= make_cleanup_ui_file_delete (stb
);
10986 case bp_watchpoint
:
10987 case bp_hardware_watchpoint
:
10988 annotate_watchpoint (b
->number
);
10989 if (ui_out_is_mi_like_p (uiout
))
10990 ui_out_field_string
10992 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10994 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10995 ui_out_text (uiout
, "\nOld value = ");
10996 watchpoint_value_print (bs
->old_val
, stb
);
10997 ui_out_field_stream (uiout
, "old", stb
);
10998 ui_out_text (uiout
, "\nNew value = ");
10999 watchpoint_value_print (w
->val
, stb
);
11000 ui_out_field_stream (uiout
, "new", stb
);
11001 ui_out_text (uiout
, "\n");
11002 /* More than one watchpoint may have been triggered. */
11003 result
= PRINT_UNKNOWN
;
11006 case bp_read_watchpoint
:
11007 if (ui_out_is_mi_like_p (uiout
))
11008 ui_out_field_string
11010 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11012 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11013 ui_out_text (uiout
, "\nValue = ");
11014 watchpoint_value_print (w
->val
, stb
);
11015 ui_out_field_stream (uiout
, "value", stb
);
11016 ui_out_text (uiout
, "\n");
11017 result
= PRINT_UNKNOWN
;
11020 case bp_access_watchpoint
:
11021 if (bs
->old_val
!= NULL
)
11023 annotate_watchpoint (b
->number
);
11024 if (ui_out_is_mi_like_p (uiout
))
11025 ui_out_field_string
11027 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11029 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11030 ui_out_text (uiout
, "\nOld value = ");
11031 watchpoint_value_print (bs
->old_val
, stb
);
11032 ui_out_field_stream (uiout
, "old", stb
);
11033 ui_out_text (uiout
, "\nNew value = ");
11038 if (ui_out_is_mi_like_p (uiout
))
11039 ui_out_field_string
11041 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11042 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11043 ui_out_text (uiout
, "\nValue = ");
11045 watchpoint_value_print (w
->val
, stb
);
11046 ui_out_field_stream (uiout
, "new", stb
);
11047 ui_out_text (uiout
, "\n");
11048 result
= PRINT_UNKNOWN
;
11051 result
= PRINT_UNKNOWN
;
11054 do_cleanups (old_chain
);
11058 /* Implement the "print_mention" breakpoint_ops method for hardware
11062 print_mention_watchpoint (struct breakpoint
*b
)
11064 struct cleanup
*ui_out_chain
;
11065 struct watchpoint
*w
= (struct watchpoint
*) b
;
11066 struct ui_out
*uiout
= current_uiout
;
11070 case bp_watchpoint
:
11071 ui_out_text (uiout
, "Watchpoint ");
11072 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11074 case bp_hardware_watchpoint
:
11075 ui_out_text (uiout
, "Hardware watchpoint ");
11076 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11078 case bp_read_watchpoint
:
11079 ui_out_text (uiout
, "Hardware read watchpoint ");
11080 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11082 case bp_access_watchpoint
:
11083 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
11084 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11087 internal_error (__FILE__
, __LINE__
,
11088 _("Invalid hardware watchpoint type."));
11091 ui_out_field_int (uiout
, "number", b
->number
);
11092 ui_out_text (uiout
, ": ");
11093 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11094 do_cleanups (ui_out_chain
);
11097 /* Implement the "print_recreate" breakpoint_ops method for
11101 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11103 struct watchpoint
*w
= (struct watchpoint
*) b
;
11107 case bp_watchpoint
:
11108 case bp_hardware_watchpoint
:
11109 fprintf_unfiltered (fp
, "watch");
11111 case bp_read_watchpoint
:
11112 fprintf_unfiltered (fp
, "rwatch");
11114 case bp_access_watchpoint
:
11115 fprintf_unfiltered (fp
, "awatch");
11118 internal_error (__FILE__
, __LINE__
,
11119 _("Invalid watchpoint type."));
11122 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
11123 print_recreate_thread (b
, fp
);
11126 /* Implement the "explains_signal" breakpoint_ops method for
11130 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
11132 /* A software watchpoint cannot cause a signal other than
11133 GDB_SIGNAL_TRAP. */
11134 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
11140 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11142 static struct breakpoint_ops watchpoint_breakpoint_ops
;
11144 /* Implement the "insert" breakpoint_ops method for
11145 masked hardware watchpoints. */
11148 insert_masked_watchpoint (struct bp_location
*bl
)
11150 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11152 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11153 bl
->watchpoint_type
);
11156 /* Implement the "remove" breakpoint_ops method for
11157 masked hardware watchpoints. */
11160 remove_masked_watchpoint (struct bp_location
*bl
)
11162 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11164 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11165 bl
->watchpoint_type
);
11168 /* Implement the "resources_needed" breakpoint_ops method for
11169 masked hardware watchpoints. */
11172 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11174 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11176 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11179 /* Implement the "works_in_software_mode" breakpoint_ops method for
11180 masked hardware watchpoints. */
11183 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11188 /* Implement the "print_it" breakpoint_ops method for
11189 masked hardware watchpoints. */
11191 static enum print_stop_action
11192 print_it_masked_watchpoint (bpstat bs
)
11194 struct breakpoint
*b
= bs
->breakpoint_at
;
11195 struct ui_out
*uiout
= current_uiout
;
11197 /* Masked watchpoints have only one location. */
11198 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11202 case bp_hardware_watchpoint
:
11203 annotate_watchpoint (b
->number
);
11204 if (ui_out_is_mi_like_p (uiout
))
11205 ui_out_field_string
11207 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11210 case bp_read_watchpoint
:
11211 if (ui_out_is_mi_like_p (uiout
))
11212 ui_out_field_string
11214 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11217 case bp_access_watchpoint
:
11218 if (ui_out_is_mi_like_p (uiout
))
11219 ui_out_field_string
11221 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11224 internal_error (__FILE__
, __LINE__
,
11225 _("Invalid hardware watchpoint type."));
11229 ui_out_text (uiout
, _("\n\
11230 Check the underlying instruction at PC for the memory\n\
11231 address and value which triggered this watchpoint.\n"));
11232 ui_out_text (uiout
, "\n");
11234 /* More than one watchpoint may have been triggered. */
11235 return PRINT_UNKNOWN
;
11238 /* Implement the "print_one_detail" breakpoint_ops method for
11239 masked hardware watchpoints. */
11242 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11243 struct ui_out
*uiout
)
11245 struct watchpoint
*w
= (struct watchpoint
*) b
;
11247 /* Masked watchpoints have only one location. */
11248 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11250 ui_out_text (uiout
, "\tmask ");
11251 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11252 ui_out_text (uiout
, "\n");
11255 /* Implement the "print_mention" breakpoint_ops method for
11256 masked hardware watchpoints. */
11259 print_mention_masked_watchpoint (struct breakpoint
*b
)
11261 struct watchpoint
*w
= (struct watchpoint
*) b
;
11262 struct ui_out
*uiout
= current_uiout
;
11263 struct cleanup
*ui_out_chain
;
11267 case bp_hardware_watchpoint
:
11268 ui_out_text (uiout
, "Masked hardware watchpoint ");
11269 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11271 case bp_read_watchpoint
:
11272 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11273 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11275 case bp_access_watchpoint
:
11276 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11277 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11280 internal_error (__FILE__
, __LINE__
,
11281 _("Invalid hardware watchpoint type."));
11284 ui_out_field_int (uiout
, "number", b
->number
);
11285 ui_out_text (uiout
, ": ");
11286 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11287 do_cleanups (ui_out_chain
);
11290 /* Implement the "print_recreate" breakpoint_ops method for
11291 masked hardware watchpoints. */
11294 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11296 struct watchpoint
*w
= (struct watchpoint
*) b
;
11301 case bp_hardware_watchpoint
:
11302 fprintf_unfiltered (fp
, "watch");
11304 case bp_read_watchpoint
:
11305 fprintf_unfiltered (fp
, "rwatch");
11307 case bp_access_watchpoint
:
11308 fprintf_unfiltered (fp
, "awatch");
11311 internal_error (__FILE__
, __LINE__
,
11312 _("Invalid hardware watchpoint type."));
11315 sprintf_vma (tmp
, w
->hw_wp_mask
);
11316 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11317 print_recreate_thread (b
, fp
);
11320 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11322 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11324 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11327 is_masked_watchpoint (const struct breakpoint
*b
)
11329 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11332 /* accessflag: hw_write: watch write,
11333 hw_read: watch read,
11334 hw_access: watch access (read or write) */
11336 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11337 int just_location
, int internal
)
11339 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11340 struct expression
*exp
;
11341 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11342 struct value
*val
, *mark
, *result
;
11343 int saved_bitpos
= 0, saved_bitsize
= 0;
11344 struct frame_info
*frame
;
11345 const char *exp_start
= NULL
;
11346 const char *exp_end
= NULL
;
11347 const char *tok
, *end_tok
;
11349 const char *cond_start
= NULL
;
11350 const char *cond_end
= NULL
;
11351 enum bptype bp_type
;
11354 /* Flag to indicate whether we are going to use masks for
11355 the hardware watchpoint. */
11357 CORE_ADDR mask
= 0;
11358 struct watchpoint
*w
;
11360 struct cleanup
*back_to
;
11362 /* Make sure that we actually have parameters to parse. */
11363 if (arg
!= NULL
&& arg
[0] != '\0')
11365 const char *value_start
;
11367 exp_end
= arg
+ strlen (arg
);
11369 /* Look for "parameter value" pairs at the end
11370 of the arguments string. */
11371 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11373 /* Skip whitespace at the end of the argument list. */
11374 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11377 /* Find the beginning of the last token.
11378 This is the value of the parameter. */
11379 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11381 value_start
= tok
+ 1;
11383 /* Skip whitespace. */
11384 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11389 /* Find the beginning of the second to last token.
11390 This is the parameter itself. */
11391 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11394 toklen
= end_tok
- tok
+ 1;
11396 if (toklen
== 6 && startswith (tok
, "thread"))
11398 /* At this point we've found a "thread" token, which means
11399 the user is trying to set a watchpoint that triggers
11400 only in a specific thread. */
11404 error(_("You can specify only one thread."));
11406 /* Extract the thread ID from the next token. */
11407 thread
= strtol (value_start
, &endp
, 0);
11409 /* Check if the user provided a valid numeric value for the
11411 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11412 error (_("Invalid thread ID specification %s."), value_start
);
11414 /* Check if the thread actually exists. */
11415 if (!valid_thread_id (thread
))
11416 invalid_thread_id_error (thread
);
11418 else if (toklen
== 4 && startswith (tok
, "mask"))
11420 /* We've found a "mask" token, which means the user wants to
11421 create a hardware watchpoint that is going to have the mask
11423 struct value
*mask_value
, *mark
;
11426 error(_("You can specify only one mask."));
11428 use_mask
= just_location
= 1;
11430 mark
= value_mark ();
11431 mask_value
= parse_to_comma_and_eval (&value_start
);
11432 mask
= value_as_address (mask_value
);
11433 value_free_to_mark (mark
);
11436 /* We didn't recognize what we found. We should stop here. */
11439 /* Truncate the string and get rid of the "parameter value" pair before
11440 the arguments string is parsed by the parse_exp_1 function. */
11447 /* Parse the rest of the arguments. From here on out, everything
11448 is in terms of a newly allocated string instead of the original
11450 innermost_block
= NULL
;
11451 expression
= savestring (arg
, exp_end
- arg
);
11452 back_to
= make_cleanup (xfree
, expression
);
11453 exp_start
= arg
= expression
;
11454 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11456 /* Remove trailing whitespace from the expression before saving it.
11457 This makes the eventual display of the expression string a bit
11459 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11462 /* Checking if the expression is not constant. */
11463 if (watchpoint_exp_is_const (exp
))
11467 len
= exp_end
- exp_start
;
11468 while (len
> 0 && isspace (exp_start
[len
- 1]))
11470 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11473 exp_valid_block
= innermost_block
;
11474 mark
= value_mark ();
11475 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11477 if (val
!= NULL
&& just_location
)
11479 saved_bitpos
= value_bitpos (val
);
11480 saved_bitsize
= value_bitsize (val
);
11487 exp_valid_block
= NULL
;
11488 val
= value_addr (result
);
11489 release_value (val
);
11490 value_free_to_mark (mark
);
11494 ret
= target_masked_watch_num_registers (value_as_address (val
),
11497 error (_("This target does not support masked watchpoints."));
11498 else if (ret
== -2)
11499 error (_("Invalid mask or memory region."));
11502 else if (val
!= NULL
)
11503 release_value (val
);
11505 tok
= skip_spaces_const (arg
);
11506 end_tok
= skip_to_space_const (tok
);
11508 toklen
= end_tok
- tok
;
11509 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11511 struct expression
*cond
;
11513 innermost_block
= NULL
;
11514 tok
= cond_start
= end_tok
+ 1;
11515 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11517 /* The watchpoint expression may not be local, but the condition
11518 may still be. E.g.: `watch global if local > 0'. */
11519 cond_exp_valid_block
= innermost_block
;
11525 error (_("Junk at end of command."));
11527 frame
= block_innermost_frame (exp_valid_block
);
11529 /* If the expression is "local", then set up a "watchpoint scope"
11530 breakpoint at the point where we've left the scope of the watchpoint
11531 expression. Create the scope breakpoint before the watchpoint, so
11532 that we will encounter it first in bpstat_stop_status. */
11533 if (exp_valid_block
&& frame
)
11535 if (frame_id_p (frame_unwind_caller_id (frame
)))
11538 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11539 frame_unwind_caller_pc (frame
),
11540 bp_watchpoint_scope
,
11541 &momentary_breakpoint_ops
);
11543 scope_breakpoint
->enable_state
= bp_enabled
;
11545 /* Automatically delete the breakpoint when it hits. */
11546 scope_breakpoint
->disposition
= disp_del
;
11548 /* Only break in the proper frame (help with recursion). */
11549 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11551 /* Set the address at which we will stop. */
11552 scope_breakpoint
->loc
->gdbarch
11553 = frame_unwind_caller_arch (frame
);
11554 scope_breakpoint
->loc
->requested_address
11555 = frame_unwind_caller_pc (frame
);
11556 scope_breakpoint
->loc
->address
11557 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11558 scope_breakpoint
->loc
->requested_address
,
11559 scope_breakpoint
->type
);
11563 /* Now set up the breakpoint. We create all watchpoints as hardware
11564 watchpoints here even if hardware watchpoints are turned off, a call
11565 to update_watchpoint later in this function will cause the type to
11566 drop back to bp_watchpoint (software watchpoint) if required. */
11568 if (accessflag
== hw_read
)
11569 bp_type
= bp_read_watchpoint
;
11570 else if (accessflag
== hw_access
)
11571 bp_type
= bp_access_watchpoint
;
11573 bp_type
= bp_hardware_watchpoint
;
11575 w
= XCNEW (struct watchpoint
);
11578 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11579 &masked_watchpoint_breakpoint_ops
);
11581 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11582 &watchpoint_breakpoint_ops
);
11583 b
->thread
= thread
;
11584 b
->disposition
= disp_donttouch
;
11585 b
->pspace
= current_program_space
;
11587 w
->exp_valid_block
= exp_valid_block
;
11588 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11591 struct type
*t
= value_type (val
);
11592 CORE_ADDR addr
= value_as_address (val
);
11595 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11596 name
= type_to_string (t
);
11598 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11599 core_addr_to_string (addr
));
11602 w
->exp_string
= xstrprintf ("-location %.*s",
11603 (int) (exp_end
- exp_start
), exp_start
);
11605 /* The above expression is in C. */
11606 b
->language
= language_c
;
11609 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11613 w
->hw_wp_mask
= mask
;
11618 w
->val_bitpos
= saved_bitpos
;
11619 w
->val_bitsize
= saved_bitsize
;
11624 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11626 b
->cond_string
= 0;
11630 w
->watchpoint_frame
= get_frame_id (frame
);
11631 w
->watchpoint_thread
= inferior_ptid
;
11635 w
->watchpoint_frame
= null_frame_id
;
11636 w
->watchpoint_thread
= null_ptid
;
11639 if (scope_breakpoint
!= NULL
)
11641 /* The scope breakpoint is related to the watchpoint. We will
11642 need to act on them together. */
11643 b
->related_breakpoint
= scope_breakpoint
;
11644 scope_breakpoint
->related_breakpoint
= b
;
11647 if (!just_location
)
11648 value_free_to_mark (mark
);
11652 /* Finally update the new watchpoint. This creates the locations
11653 that should be inserted. */
11654 update_watchpoint (w
, 1);
11656 CATCH (e
, RETURN_MASK_ALL
)
11658 delete_breakpoint (b
);
11659 throw_exception (e
);
11663 install_breakpoint (internal
, b
, 1);
11664 do_cleanups (back_to
);
11667 /* Return count of debug registers needed to watch the given expression.
11668 If the watchpoint cannot be handled in hardware return zero. */
11671 can_use_hardware_watchpoint (struct value
*v
)
11673 int found_memory_cnt
= 0;
11674 struct value
*head
= v
;
11676 /* Did the user specifically forbid us to use hardware watchpoints? */
11677 if (!can_use_hw_watchpoints
)
11680 /* Make sure that the value of the expression depends only upon
11681 memory contents, and values computed from them within GDB. If we
11682 find any register references or function calls, we can't use a
11683 hardware watchpoint.
11685 The idea here is that evaluating an expression generates a series
11686 of values, one holding the value of every subexpression. (The
11687 expression a*b+c has five subexpressions: a, b, a*b, c, and
11688 a*b+c.) GDB's values hold almost enough information to establish
11689 the criteria given above --- they identify memory lvalues,
11690 register lvalues, computed values, etcetera. So we can evaluate
11691 the expression, and then scan the chain of values that leaves
11692 behind to decide whether we can detect any possible change to the
11693 expression's final value using only hardware watchpoints.
11695 However, I don't think that the values returned by inferior
11696 function calls are special in any way. So this function may not
11697 notice that an expression involving an inferior function call
11698 can't be watched with hardware watchpoints. FIXME. */
11699 for (; v
; v
= value_next (v
))
11701 if (VALUE_LVAL (v
) == lval_memory
)
11703 if (v
!= head
&& value_lazy (v
))
11704 /* A lazy memory lvalue in the chain is one that GDB never
11705 needed to fetch; we either just used its address (e.g.,
11706 `a' in `a.b') or we never needed it at all (e.g., `a'
11707 in `a,b'). This doesn't apply to HEAD; if that is
11708 lazy then it was not readable, but watch it anyway. */
11712 /* Ahh, memory we actually used! Check if we can cover
11713 it with hardware watchpoints. */
11714 struct type
*vtype
= check_typedef (value_type (v
));
11716 /* We only watch structs and arrays if user asked for it
11717 explicitly, never if they just happen to appear in a
11718 middle of some value chain. */
11720 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11721 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11723 CORE_ADDR vaddr
= value_address (v
);
11727 len
= (target_exact_watchpoints
11728 && is_scalar_type_recursive (vtype
))?
11729 1 : TYPE_LENGTH (value_type (v
));
11731 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11735 found_memory_cnt
+= num_regs
;
11739 else if (VALUE_LVAL (v
) != not_lval
11740 && deprecated_value_modifiable (v
) == 0)
11741 return 0; /* These are values from the history (e.g., $1). */
11742 else if (VALUE_LVAL (v
) == lval_register
)
11743 return 0; /* Cannot watch a register with a HW watchpoint. */
11746 /* The expression itself looks suitable for using a hardware
11747 watchpoint, but give the target machine a chance to reject it. */
11748 return found_memory_cnt
;
11752 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11754 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11757 /* A helper function that looks for the "-location" argument and then
11758 calls watch_command_1. */
11761 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11763 int just_location
= 0;
11766 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11767 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11769 arg
= skip_spaces (arg
);
11773 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11777 watch_command (char *arg
, int from_tty
)
11779 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11783 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11785 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11789 rwatch_command (char *arg
, int from_tty
)
11791 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11795 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11797 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11801 awatch_command (char *arg
, int from_tty
)
11803 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11807 /* Helper routines for the until_command routine in infcmd.c. Here
11808 because it uses the mechanisms of breakpoints. */
11810 struct until_break_command_continuation_args
11812 struct breakpoint
*breakpoint
;
11813 struct breakpoint
*breakpoint2
;
11817 /* This function is called by fetch_inferior_event via the
11818 cmd_continuation pointer, to complete the until command. It takes
11819 care of cleaning up the temporary breakpoints set up by the until
11822 until_break_command_continuation (void *arg
, int err
)
11824 struct until_break_command_continuation_args
*a
= arg
;
11826 delete_breakpoint (a
->breakpoint
);
11827 if (a
->breakpoint2
)
11828 delete_breakpoint (a
->breakpoint2
);
11829 delete_longjmp_breakpoint (a
->thread_num
);
11833 until_break_command (char *arg
, int from_tty
, int anywhere
)
11835 struct symtabs_and_lines sals
;
11836 struct symtab_and_line sal
;
11837 struct frame_info
*frame
;
11838 struct gdbarch
*frame_gdbarch
;
11839 struct frame_id stack_frame_id
;
11840 struct frame_id caller_frame_id
;
11841 struct breakpoint
*breakpoint
;
11842 struct breakpoint
*breakpoint2
= NULL
;
11843 struct cleanup
*old_chain
;
11845 struct thread_info
*tp
;
11847 clear_proceed_status (0);
11849 /* Set a breakpoint where the user wants it and at return from
11852 if (last_displayed_sal_is_valid ())
11853 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11854 get_last_displayed_symtab (),
11855 get_last_displayed_line ());
11857 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11858 (struct symtab
*) NULL
, 0);
11860 if (sals
.nelts
!= 1)
11861 error (_("Couldn't get information on specified line."));
11863 sal
= sals
.sals
[0];
11864 xfree (sals
.sals
); /* malloc'd, so freed. */
11867 error (_("Junk at end of arguments."));
11869 resolve_sal_pc (&sal
);
11871 tp
= inferior_thread ();
11874 old_chain
= make_cleanup (null_cleanup
, NULL
);
11876 /* Note linespec handling above invalidates the frame chain.
11877 Installing a breakpoint also invalidates the frame chain (as it
11878 may need to switch threads), so do any frame handling before
11881 frame
= get_selected_frame (NULL
);
11882 frame_gdbarch
= get_frame_arch (frame
);
11883 stack_frame_id
= get_stack_frame_id (frame
);
11884 caller_frame_id
= frame_unwind_caller_id (frame
);
11886 /* Keep within the current frame, or in frames called by the current
11889 if (frame_id_p (caller_frame_id
))
11891 struct symtab_and_line sal2
;
11893 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11894 sal2
.pc
= frame_unwind_caller_pc (frame
);
11895 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11899 make_cleanup_delete_breakpoint (breakpoint2
);
11901 set_longjmp_breakpoint (tp
, caller_frame_id
);
11902 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11905 /* set_momentary_breakpoint could invalidate FRAME. */
11909 /* If the user told us to continue until a specified location,
11910 we don't specify a frame at which we need to stop. */
11911 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11912 null_frame_id
, bp_until
);
11914 /* Otherwise, specify the selected frame, because we want to stop
11915 only at the very same frame. */
11916 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11917 stack_frame_id
, bp_until
);
11918 make_cleanup_delete_breakpoint (breakpoint
);
11920 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11922 /* If we are running asynchronously, and proceed call above has
11923 actually managed to start the target, arrange for breakpoints to
11924 be deleted when the target stops. Otherwise, we're already
11925 stopped and delete breakpoints via cleanup chain. */
11927 if (target_can_async_p () && is_running (inferior_ptid
))
11929 struct until_break_command_continuation_args
*args
;
11930 args
= xmalloc (sizeof (*args
));
11932 args
->breakpoint
= breakpoint
;
11933 args
->breakpoint2
= breakpoint2
;
11934 args
->thread_num
= thread
;
11936 discard_cleanups (old_chain
);
11937 add_continuation (inferior_thread (),
11938 until_break_command_continuation
, args
,
11942 do_cleanups (old_chain
);
11945 /* This function attempts to parse an optional "if <cond>" clause
11946 from the arg string. If one is not found, it returns NULL.
11948 Else, it returns a pointer to the condition string. (It does not
11949 attempt to evaluate the string against a particular block.) And,
11950 it updates arg to point to the first character following the parsed
11951 if clause in the arg string. */
11954 ep_parse_optional_if_clause (char **arg
)
11958 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11961 /* Skip the "if" keyword. */
11964 /* Skip any extra leading whitespace, and record the start of the
11965 condition string. */
11966 *arg
= skip_spaces (*arg
);
11967 cond_string
= *arg
;
11969 /* Assume that the condition occupies the remainder of the arg
11971 (*arg
) += strlen (cond_string
);
11973 return cond_string
;
11976 /* Commands to deal with catching events, such as signals, exceptions,
11977 process start/exit, etc. */
11981 catch_fork_temporary
, catch_vfork_temporary
,
11982 catch_fork_permanent
, catch_vfork_permanent
11987 catch_fork_command_1 (char *arg
, int from_tty
,
11988 struct cmd_list_element
*command
)
11990 struct gdbarch
*gdbarch
= get_current_arch ();
11991 char *cond_string
= NULL
;
11992 catch_fork_kind fork_kind
;
11995 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11996 tempflag
= (fork_kind
== catch_fork_temporary
11997 || fork_kind
== catch_vfork_temporary
);
12001 arg
= skip_spaces (arg
);
12003 /* The allowed syntax is:
12005 catch [v]fork if <cond>
12007 First, check if there's an if clause. */
12008 cond_string
= ep_parse_optional_if_clause (&arg
);
12010 if ((*arg
!= '\0') && !isspace (*arg
))
12011 error (_("Junk at end of arguments."));
12013 /* If this target supports it, create a fork or vfork catchpoint
12014 and enable reporting of such events. */
12017 case catch_fork_temporary
:
12018 case catch_fork_permanent
:
12019 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
12020 &catch_fork_breakpoint_ops
);
12022 case catch_vfork_temporary
:
12023 case catch_vfork_permanent
:
12024 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
12025 &catch_vfork_breakpoint_ops
);
12028 error (_("unsupported or unknown fork kind; cannot catch it"));
12034 catch_exec_command_1 (char *arg
, int from_tty
,
12035 struct cmd_list_element
*command
)
12037 struct exec_catchpoint
*c
;
12038 struct gdbarch
*gdbarch
= get_current_arch ();
12040 char *cond_string
= NULL
;
12042 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12046 arg
= skip_spaces (arg
);
12048 /* The allowed syntax is:
12050 catch exec if <cond>
12052 First, check if there's an if clause. */
12053 cond_string
= ep_parse_optional_if_clause (&arg
);
12055 if ((*arg
!= '\0') && !isspace (*arg
))
12056 error (_("Junk at end of arguments."));
12058 c
= XNEW (struct exec_catchpoint
);
12059 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
12060 &catch_exec_breakpoint_ops
);
12061 c
->exec_pathname
= NULL
;
12063 install_breakpoint (0, &c
->base
, 1);
12067 init_ada_exception_breakpoint (struct breakpoint
*b
,
12068 struct gdbarch
*gdbarch
,
12069 struct symtab_and_line sal
,
12071 const struct breakpoint_ops
*ops
,
12078 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
12080 loc_gdbarch
= gdbarch
;
12082 describe_other_breakpoints (loc_gdbarch
,
12083 sal
.pspace
, sal
.pc
, sal
.section
, -1);
12084 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12085 version for exception catchpoints, because two catchpoints
12086 used for different exception names will use the same address.
12087 In this case, a "breakpoint ... also set at..." warning is
12088 unproductive. Besides, the warning phrasing is also a bit
12089 inappropriate, we should use the word catchpoint, and tell
12090 the user what type of catchpoint it is. The above is good
12091 enough for now, though. */
12094 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12096 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12097 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12098 b
->addr_string
= addr_string
;
12099 b
->language
= language_ada
;
12102 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12103 filter list, or NULL if no filtering is required. */
12105 catch_syscall_split_args (char *arg
)
12107 VEC(int) *result
= NULL
;
12108 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
12109 struct gdbarch
*gdbarch
= target_gdbarch ();
12111 while (*arg
!= '\0')
12113 int i
, syscall_number
;
12115 char cur_name
[128];
12118 /* Skip whitespace. */
12119 arg
= skip_spaces (arg
);
12121 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
12122 cur_name
[i
] = arg
[i
];
12123 cur_name
[i
] = '\0';
12126 /* Check if the user provided a syscall name or a number. */
12127 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
12128 if (*endptr
== '\0')
12129 get_syscall_by_number (gdbarch
, syscall_number
, &s
);
12132 /* We have a name. Let's check if it's valid and convert it
12134 get_syscall_by_name (gdbarch
, cur_name
, &s
);
12136 if (s
.number
== UNKNOWN_SYSCALL
)
12137 /* Here we have to issue an error instead of a warning,
12138 because GDB cannot do anything useful if there's no
12139 syscall number to be caught. */
12140 error (_("Unknown syscall name '%s'."), cur_name
);
12143 /* Ok, it's valid. */
12144 VEC_safe_push (int, result
, s
.number
);
12147 discard_cleanups (cleanup
);
12151 /* Implement the "catch syscall" command. */
12154 catch_syscall_command_1 (char *arg
, int from_tty
,
12155 struct cmd_list_element
*command
)
12160 struct gdbarch
*gdbarch
= get_current_arch ();
12162 /* Checking if the feature if supported. */
12163 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
12164 error (_("The feature 'catch syscall' is not supported on \
12165 this architecture yet."));
12167 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12169 arg
= skip_spaces (arg
);
12171 /* We need to do this first "dummy" translation in order
12172 to get the syscall XML file loaded or, most important,
12173 to display a warning to the user if there's no XML file
12174 for his/her architecture. */
12175 get_syscall_by_number (gdbarch
, 0, &s
);
12177 /* The allowed syntax is:
12179 catch syscall <name | number> [<name | number> ... <name | number>]
12181 Let's check if there's a syscall name. */
12184 filter
= catch_syscall_split_args (arg
);
12188 create_syscall_event_catchpoint (tempflag
, filter
,
12189 &catch_syscall_breakpoint_ops
);
12193 catch_command (char *arg
, int from_tty
)
12195 error (_("Catch requires an event name."));
12200 tcatch_command (char *arg
, int from_tty
)
12202 error (_("Catch requires an event name."));
12205 /* A qsort comparison function that sorts breakpoints in order. */
12208 compare_breakpoints (const void *a
, const void *b
)
12210 const breakpoint_p
*ba
= a
;
12211 uintptr_t ua
= (uintptr_t) *ba
;
12212 const breakpoint_p
*bb
= b
;
12213 uintptr_t ub
= (uintptr_t) *bb
;
12215 if ((*ba
)->number
< (*bb
)->number
)
12217 else if ((*ba
)->number
> (*bb
)->number
)
12220 /* Now sort by address, in case we see, e..g, two breakpoints with
12224 return ua
> ub
? 1 : 0;
12227 /* Delete breakpoints by address or line. */
12230 clear_command (char *arg
, int from_tty
)
12232 struct breakpoint
*b
, *prev
;
12233 VEC(breakpoint_p
) *found
= 0;
12236 struct symtabs_and_lines sals
;
12237 struct symtab_and_line sal
;
12239 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12243 sals
= decode_line_with_current_source (arg
,
12244 (DECODE_LINE_FUNFIRSTLINE
12245 | DECODE_LINE_LIST_MODE
));
12246 make_cleanup (xfree
, sals
.sals
);
12251 sals
.sals
= (struct symtab_and_line
*)
12252 xmalloc (sizeof (struct symtab_and_line
));
12253 make_cleanup (xfree
, sals
.sals
);
12254 init_sal (&sal
); /* Initialize to zeroes. */
12256 /* Set sal's line, symtab, pc, and pspace to the values
12257 corresponding to the last call to print_frame_info. If the
12258 codepoint is not valid, this will set all the fields to 0. */
12259 get_last_displayed_sal (&sal
);
12260 if (sal
.symtab
== 0)
12261 error (_("No source file specified."));
12263 sals
.sals
[0] = sal
;
12269 /* We don't call resolve_sal_pc here. That's not as bad as it
12270 seems, because all existing breakpoints typically have both
12271 file/line and pc set. So, if clear is given file/line, we can
12272 match this to existing breakpoint without obtaining pc at all.
12274 We only support clearing given the address explicitly
12275 present in breakpoint table. Say, we've set breakpoint
12276 at file:line. There were several PC values for that file:line,
12277 due to optimization, all in one block.
12279 We've picked one PC value. If "clear" is issued with another
12280 PC corresponding to the same file:line, the breakpoint won't
12281 be cleared. We probably can still clear the breakpoint, but
12282 since the other PC value is never presented to user, user
12283 can only find it by guessing, and it does not seem important
12284 to support that. */
12286 /* For each line spec given, delete bps which correspond to it. Do
12287 it in two passes, solely to preserve the current behavior that
12288 from_tty is forced true if we delete more than one
12292 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12293 for (i
= 0; i
< sals
.nelts
; i
++)
12295 const char *sal_fullname
;
12297 /* If exact pc given, clear bpts at that pc.
12298 If line given (pc == 0), clear all bpts on specified line.
12299 If defaulting, clear all bpts on default line
12302 defaulting sal.pc != 0 tests to do
12307 1 0 <can't happen> */
12309 sal
= sals
.sals
[i
];
12310 sal_fullname
= (sal
.symtab
== NULL
12311 ? NULL
: symtab_to_fullname (sal
.symtab
));
12313 /* Find all matching breakpoints and add them to 'found'. */
12314 ALL_BREAKPOINTS (b
)
12317 /* Are we going to delete b? */
12318 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12320 struct bp_location
*loc
= b
->loc
;
12321 for (; loc
; loc
= loc
->next
)
12323 /* If the user specified file:line, don't allow a PC
12324 match. This matches historical gdb behavior. */
12325 int pc_match
= (!sal
.explicit_line
12327 && (loc
->pspace
== sal
.pspace
)
12328 && (loc
->address
== sal
.pc
)
12329 && (!section_is_overlay (loc
->section
)
12330 || loc
->section
== sal
.section
));
12331 int line_match
= 0;
12333 if ((default_match
|| sal
.explicit_line
)
12334 && loc
->symtab
!= NULL
12335 && sal_fullname
!= NULL
12336 && sal
.pspace
== loc
->pspace
12337 && loc
->line_number
== sal
.line
12338 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12339 sal_fullname
) == 0)
12342 if (pc_match
|| line_match
)
12351 VEC_safe_push(breakpoint_p
, found
, b
);
12355 /* Now go thru the 'found' chain and delete them. */
12356 if (VEC_empty(breakpoint_p
, found
))
12359 error (_("No breakpoint at %s."), arg
);
12361 error (_("No breakpoint at this line."));
12364 /* Remove duplicates from the vec. */
12365 qsort (VEC_address (breakpoint_p
, found
),
12366 VEC_length (breakpoint_p
, found
),
12367 sizeof (breakpoint_p
),
12368 compare_breakpoints
);
12369 prev
= VEC_index (breakpoint_p
, found
, 0);
12370 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12374 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12379 if (VEC_length(breakpoint_p
, found
) > 1)
12380 from_tty
= 1; /* Always report if deleted more than one. */
12383 if (VEC_length(breakpoint_p
, found
) == 1)
12384 printf_unfiltered (_("Deleted breakpoint "));
12386 printf_unfiltered (_("Deleted breakpoints "));
12389 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12392 printf_unfiltered ("%d ", b
->number
);
12393 delete_breakpoint (b
);
12396 putchar_unfiltered ('\n');
12398 do_cleanups (cleanups
);
12401 /* Delete breakpoint in BS if they are `delete' breakpoints and
12402 all breakpoints that are marked for deletion, whether hit or not.
12403 This is called after any breakpoint is hit, or after errors. */
12406 breakpoint_auto_delete (bpstat bs
)
12408 struct breakpoint
*b
, *b_tmp
;
12410 for (; bs
; bs
= bs
->next
)
12411 if (bs
->breakpoint_at
12412 && bs
->breakpoint_at
->disposition
== disp_del
12414 delete_breakpoint (bs
->breakpoint_at
);
12416 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12418 if (b
->disposition
== disp_del_at_next_stop
)
12419 delete_breakpoint (b
);
12423 /* A comparison function for bp_location AP and BP being interfaced to
12424 qsort. Sort elements primarily by their ADDRESS (no matter what
12425 does breakpoint_address_is_meaningful say for its OWNER),
12426 secondarily by ordering first permanent elements and
12427 terciarily just ensuring the array is sorted stable way despite
12428 qsort being an unstable algorithm. */
12431 bp_location_compare (const void *ap
, const void *bp
)
12433 struct bp_location
*a
= *(void **) ap
;
12434 struct bp_location
*b
= *(void **) bp
;
12436 if (a
->address
!= b
->address
)
12437 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12439 /* Sort locations at the same address by their pspace number, keeping
12440 locations of the same inferior (in a multi-inferior environment)
12443 if (a
->pspace
->num
!= b
->pspace
->num
)
12444 return ((a
->pspace
->num
> b
->pspace
->num
)
12445 - (a
->pspace
->num
< b
->pspace
->num
));
12447 /* Sort permanent breakpoints first. */
12448 if (a
->permanent
!= b
->permanent
)
12449 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12451 /* Make the internal GDB representation stable across GDB runs
12452 where A and B memory inside GDB can differ. Breakpoint locations of
12453 the same type at the same address can be sorted in arbitrary order. */
12455 if (a
->owner
->number
!= b
->owner
->number
)
12456 return ((a
->owner
->number
> b
->owner
->number
)
12457 - (a
->owner
->number
< b
->owner
->number
));
12459 return (a
> b
) - (a
< b
);
12462 /* Set bp_location_placed_address_before_address_max and
12463 bp_location_shadow_len_after_address_max according to the current
12464 content of the bp_location array. */
12467 bp_location_target_extensions_update (void)
12469 struct bp_location
*bl
, **blp_tmp
;
12471 bp_location_placed_address_before_address_max
= 0;
12472 bp_location_shadow_len_after_address_max
= 0;
12474 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12476 CORE_ADDR start
, end
, addr
;
12478 if (!bp_location_has_shadow (bl
))
12481 start
= bl
->target_info
.placed_address
;
12482 end
= start
+ bl
->target_info
.shadow_len
;
12484 gdb_assert (bl
->address
>= start
);
12485 addr
= bl
->address
- start
;
12486 if (addr
> bp_location_placed_address_before_address_max
)
12487 bp_location_placed_address_before_address_max
= addr
;
12489 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12491 gdb_assert (bl
->address
< end
);
12492 addr
= end
- bl
->address
;
12493 if (addr
> bp_location_shadow_len_after_address_max
)
12494 bp_location_shadow_len_after_address_max
= addr
;
12498 /* Download tracepoint locations if they haven't been. */
12501 download_tracepoint_locations (void)
12503 struct breakpoint
*b
;
12504 struct cleanup
*old_chain
;
12506 if (!target_can_download_tracepoint ())
12509 old_chain
= save_current_space_and_thread ();
12511 ALL_TRACEPOINTS (b
)
12513 struct bp_location
*bl
;
12514 struct tracepoint
*t
;
12515 int bp_location_downloaded
= 0;
12517 if ((b
->type
== bp_fast_tracepoint
12518 ? !may_insert_fast_tracepoints
12519 : !may_insert_tracepoints
))
12522 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12524 /* In tracepoint, locations are _never_ duplicated, so
12525 should_be_inserted is equivalent to
12526 unduplicated_should_be_inserted. */
12527 if (!should_be_inserted (bl
) || bl
->inserted
)
12530 switch_to_program_space_and_thread (bl
->pspace
);
12532 target_download_tracepoint (bl
);
12535 bp_location_downloaded
= 1;
12537 t
= (struct tracepoint
*) b
;
12538 t
->number_on_target
= b
->number
;
12539 if (bp_location_downloaded
)
12540 observer_notify_breakpoint_modified (b
);
12543 do_cleanups (old_chain
);
12546 /* Swap the insertion/duplication state between two locations. */
12549 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12551 const int left_inserted
= left
->inserted
;
12552 const int left_duplicate
= left
->duplicate
;
12553 const int left_needs_update
= left
->needs_update
;
12554 const struct bp_target_info left_target_info
= left
->target_info
;
12556 /* Locations of tracepoints can never be duplicated. */
12557 if (is_tracepoint (left
->owner
))
12558 gdb_assert (!left
->duplicate
);
12559 if (is_tracepoint (right
->owner
))
12560 gdb_assert (!right
->duplicate
);
12562 left
->inserted
= right
->inserted
;
12563 left
->duplicate
= right
->duplicate
;
12564 left
->needs_update
= right
->needs_update
;
12565 left
->target_info
= right
->target_info
;
12566 right
->inserted
= left_inserted
;
12567 right
->duplicate
= left_duplicate
;
12568 right
->needs_update
= left_needs_update
;
12569 right
->target_info
= left_target_info
;
12572 /* Force the re-insertion of the locations at ADDRESS. This is called
12573 once a new/deleted/modified duplicate location is found and we are evaluating
12574 conditions on the target's side. Such conditions need to be updated on
12578 force_breakpoint_reinsertion (struct bp_location
*bl
)
12580 struct bp_location
**locp
= NULL
, **loc2p
;
12581 struct bp_location
*loc
;
12582 CORE_ADDR address
= 0;
12585 address
= bl
->address
;
12586 pspace_num
= bl
->pspace
->num
;
12588 /* This is only meaningful if the target is
12589 evaluating conditions and if the user has
12590 opted for condition evaluation on the target's
12592 if (gdb_evaluates_breakpoint_condition_p ()
12593 || !target_supports_evaluation_of_breakpoint_conditions ())
12596 /* Flag all breakpoint locations with this address and
12597 the same program space as the location
12598 as "its condition has changed". We need to
12599 update the conditions on the target's side. */
12600 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12604 if (!is_breakpoint (loc
->owner
)
12605 || pspace_num
!= loc
->pspace
->num
)
12608 /* Flag the location appropriately. We use a different state to
12609 let everyone know that we already updated the set of locations
12610 with addr bl->address and program space bl->pspace. This is so
12611 we don't have to keep calling these functions just to mark locations
12612 that have already been marked. */
12613 loc
->condition_changed
= condition_updated
;
12615 /* Free the agent expression bytecode as well. We will compute
12617 if (loc
->cond_bytecode
)
12619 free_agent_expr (loc
->cond_bytecode
);
12620 loc
->cond_bytecode
= NULL
;
12624 /* Called whether new breakpoints are created, or existing breakpoints
12625 deleted, to update the global location list and recompute which
12626 locations are duplicate of which.
12628 The INSERT_MODE flag determines whether locations may not, may, or
12629 shall be inserted now. See 'enum ugll_insert_mode' for more
12633 update_global_location_list (enum ugll_insert_mode insert_mode
)
12635 struct breakpoint
*b
;
12636 struct bp_location
**locp
, *loc
;
12637 struct cleanup
*cleanups
;
12638 /* Last breakpoint location address that was marked for update. */
12639 CORE_ADDR last_addr
= 0;
12640 /* Last breakpoint location program space that was marked for update. */
12641 int last_pspace_num
= -1;
12643 /* Used in the duplicates detection below. When iterating over all
12644 bp_locations, points to the first bp_location of a given address.
12645 Breakpoints and watchpoints of different types are never
12646 duplicates of each other. Keep one pointer for each type of
12647 breakpoint/watchpoint, so we only need to loop over all locations
12649 struct bp_location
*bp_loc_first
; /* breakpoint */
12650 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12651 struct bp_location
*awp_loc_first
; /* access watchpoint */
12652 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12654 /* Saved former bp_location array which we compare against the newly
12655 built bp_location from the current state of ALL_BREAKPOINTS. */
12656 struct bp_location
**old_location
, **old_locp
;
12657 unsigned old_location_count
;
12659 old_location
= bp_location
;
12660 old_location_count
= bp_location_count
;
12661 bp_location
= NULL
;
12662 bp_location_count
= 0;
12663 cleanups
= make_cleanup (xfree
, old_location
);
12665 ALL_BREAKPOINTS (b
)
12666 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12667 bp_location_count
++;
12669 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12670 locp
= bp_location
;
12671 ALL_BREAKPOINTS (b
)
12672 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12674 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12675 bp_location_compare
);
12677 bp_location_target_extensions_update ();
12679 /* Identify bp_location instances that are no longer present in the
12680 new list, and therefore should be freed. Note that it's not
12681 necessary that those locations should be removed from inferior --
12682 if there's another location at the same address (previously
12683 marked as duplicate), we don't need to remove/insert the
12686 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12687 and former bp_location array state respectively. */
12689 locp
= bp_location
;
12690 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12693 struct bp_location
*old_loc
= *old_locp
;
12694 struct bp_location
**loc2p
;
12696 /* Tells if 'old_loc' is found among the new locations. If
12697 not, we have to free it. */
12698 int found_object
= 0;
12699 /* Tells if the location should remain inserted in the target. */
12700 int keep_in_target
= 0;
12703 /* Skip LOCP entries which will definitely never be needed.
12704 Stop either at or being the one matching OLD_LOC. */
12705 while (locp
< bp_location
+ bp_location_count
12706 && (*locp
)->address
< old_loc
->address
)
12710 (loc2p
< bp_location
+ bp_location_count
12711 && (*loc2p
)->address
== old_loc
->address
);
12714 /* Check if this is a new/duplicated location or a duplicated
12715 location that had its condition modified. If so, we want to send
12716 its condition to the target if evaluation of conditions is taking
12718 if ((*loc2p
)->condition_changed
== condition_modified
12719 && (last_addr
!= old_loc
->address
12720 || last_pspace_num
!= old_loc
->pspace
->num
))
12722 force_breakpoint_reinsertion (*loc2p
);
12723 last_pspace_num
= old_loc
->pspace
->num
;
12726 if (*loc2p
== old_loc
)
12730 /* We have already handled this address, update it so that we don't
12731 have to go through updates again. */
12732 last_addr
= old_loc
->address
;
12734 /* Target-side condition evaluation: Handle deleted locations. */
12736 force_breakpoint_reinsertion (old_loc
);
12738 /* If this location is no longer present, and inserted, look if
12739 there's maybe a new location at the same address. If so,
12740 mark that one inserted, and don't remove this one. This is
12741 needed so that we don't have a time window where a breakpoint
12742 at certain location is not inserted. */
12744 if (old_loc
->inserted
)
12746 /* If the location is inserted now, we might have to remove
12749 if (found_object
&& should_be_inserted (old_loc
))
12751 /* The location is still present in the location list,
12752 and still should be inserted. Don't do anything. */
12753 keep_in_target
= 1;
12757 /* This location still exists, but it won't be kept in the
12758 target since it may have been disabled. We proceed to
12759 remove its target-side condition. */
12761 /* The location is either no longer present, or got
12762 disabled. See if there's another location at the
12763 same address, in which case we don't need to remove
12764 this one from the target. */
12766 /* OLD_LOC comes from existing struct breakpoint. */
12767 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12770 (loc2p
< bp_location
+ bp_location_count
12771 && (*loc2p
)->address
== old_loc
->address
);
12774 struct bp_location
*loc2
= *loc2p
;
12776 if (breakpoint_locations_match (loc2
, old_loc
))
12778 /* Read watchpoint locations are switched to
12779 access watchpoints, if the former are not
12780 supported, but the latter are. */
12781 if (is_hardware_watchpoint (old_loc
->owner
))
12783 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12784 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12787 /* loc2 is a duplicated location. We need to check
12788 if it should be inserted in case it will be
12790 if (loc2
!= old_loc
12791 && unduplicated_should_be_inserted (loc2
))
12793 swap_insertion (old_loc
, loc2
);
12794 keep_in_target
= 1;
12802 if (!keep_in_target
)
12804 if (remove_breakpoint (old_loc
, mark_uninserted
))
12806 /* This is just about all we can do. We could keep
12807 this location on the global list, and try to
12808 remove it next time, but there's no particular
12809 reason why we will succeed next time.
12811 Note that at this point, old_loc->owner is still
12812 valid, as delete_breakpoint frees the breakpoint
12813 only after calling us. */
12814 printf_filtered (_("warning: Error removing "
12815 "breakpoint %d\n"),
12816 old_loc
->owner
->number
);
12824 if (removed
&& non_stop
12825 && need_moribund_for_location_type (old_loc
))
12827 /* This location was removed from the target. In
12828 non-stop mode, a race condition is possible where
12829 we've removed a breakpoint, but stop events for that
12830 breakpoint are already queued and will arrive later.
12831 We apply an heuristic to be able to distinguish such
12832 SIGTRAPs from other random SIGTRAPs: we keep this
12833 breakpoint location for a bit, and will retire it
12834 after we see some number of events. The theory here
12835 is that reporting of events should, "on the average",
12836 be fair, so after a while we'll see events from all
12837 threads that have anything of interest, and no longer
12838 need to keep this breakpoint location around. We
12839 don't hold locations forever so to reduce chances of
12840 mistaking a non-breakpoint SIGTRAP for a breakpoint
12843 The heuristic failing can be disastrous on
12844 decr_pc_after_break targets.
12846 On decr_pc_after_break targets, like e.g., x86-linux,
12847 if we fail to recognize a late breakpoint SIGTRAP,
12848 because events_till_retirement has reached 0 too
12849 soon, we'll fail to do the PC adjustment, and report
12850 a random SIGTRAP to the user. When the user resumes
12851 the inferior, it will most likely immediately crash
12852 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12853 corrupted, because of being resumed e.g., in the
12854 middle of a multi-byte instruction, or skipped a
12855 one-byte instruction. This was actually seen happen
12856 on native x86-linux, and should be less rare on
12857 targets that do not support new thread events, like
12858 remote, due to the heuristic depending on
12861 Mistaking a random SIGTRAP for a breakpoint trap
12862 causes similar symptoms (PC adjustment applied when
12863 it shouldn't), but then again, playing with SIGTRAPs
12864 behind the debugger's back is asking for trouble.
12866 Since hardware watchpoint traps are always
12867 distinguishable from other traps, so we don't need to
12868 apply keep hardware watchpoint moribund locations
12869 around. We simply always ignore hardware watchpoint
12870 traps we can no longer explain. */
12872 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12873 old_loc
->owner
= NULL
;
12875 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12879 old_loc
->owner
= NULL
;
12880 decref_bp_location (&old_loc
);
12885 /* Rescan breakpoints at the same address and section, marking the
12886 first one as "first" and any others as "duplicates". This is so
12887 that the bpt instruction is only inserted once. If we have a
12888 permanent breakpoint at the same place as BPT, make that one the
12889 official one, and the rest as duplicates. Permanent breakpoints
12890 are sorted first for the same address.
12892 Do the same for hardware watchpoints, but also considering the
12893 watchpoint's type (regular/access/read) and length. */
12895 bp_loc_first
= NULL
;
12896 wp_loc_first
= NULL
;
12897 awp_loc_first
= NULL
;
12898 rwp_loc_first
= NULL
;
12899 ALL_BP_LOCATIONS (loc
, locp
)
12901 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12903 struct bp_location
**loc_first_p
;
12906 if (!unduplicated_should_be_inserted (loc
)
12907 || !breakpoint_address_is_meaningful (b
)
12908 /* Don't detect duplicate for tracepoint locations because they are
12909 never duplicated. See the comments in field `duplicate' of
12910 `struct bp_location'. */
12911 || is_tracepoint (b
))
12913 /* Clear the condition modification flag. */
12914 loc
->condition_changed
= condition_unchanged
;
12918 /* Permanent breakpoint should always be inserted. */
12919 if (loc
->permanent
&& ! loc
->inserted
)
12920 internal_error (__FILE__
, __LINE__
,
12921 _("allegedly permanent breakpoint is not "
12922 "actually inserted"));
12924 if (b
->type
== bp_hardware_watchpoint
)
12925 loc_first_p
= &wp_loc_first
;
12926 else if (b
->type
== bp_read_watchpoint
)
12927 loc_first_p
= &rwp_loc_first
;
12928 else if (b
->type
== bp_access_watchpoint
)
12929 loc_first_p
= &awp_loc_first
;
12931 loc_first_p
= &bp_loc_first
;
12933 if (*loc_first_p
== NULL
12934 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12935 || !breakpoint_locations_match (loc
, *loc_first_p
))
12937 *loc_first_p
= loc
;
12938 loc
->duplicate
= 0;
12940 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12942 loc
->needs_update
= 1;
12943 /* Clear the condition modification flag. */
12944 loc
->condition_changed
= condition_unchanged
;
12950 /* This and the above ensure the invariant that the first location
12951 is not duplicated, and is the inserted one.
12952 All following are marked as duplicated, and are not inserted. */
12954 swap_insertion (loc
, *loc_first_p
);
12955 loc
->duplicate
= 1;
12957 /* Clear the condition modification flag. */
12958 loc
->condition_changed
= condition_unchanged
;
12960 if (loc
->inserted
&& !loc
->permanent
12961 && (*loc_first_p
)->permanent
)
12962 internal_error (__FILE__
, __LINE__
,
12963 _("another breakpoint was inserted on top of "
12964 "a permanent breakpoint"));
12967 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12969 if (insert_mode
!= UGLL_DONT_INSERT
)
12970 insert_breakpoint_locations ();
12973 /* Even though the caller told us to not insert new
12974 locations, we may still need to update conditions on the
12975 target's side of breakpoints that were already inserted
12976 if the target is evaluating breakpoint conditions. We
12977 only update conditions for locations that are marked
12979 update_inserted_breakpoint_locations ();
12983 if (insert_mode
!= UGLL_DONT_INSERT
)
12984 download_tracepoint_locations ();
12986 do_cleanups (cleanups
);
12990 breakpoint_retire_moribund (void)
12992 struct bp_location
*loc
;
12995 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12996 if (--(loc
->events_till_retirement
) == 0)
12998 decref_bp_location (&loc
);
12999 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
13005 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
13010 update_global_location_list (insert_mode
);
13012 CATCH (e
, RETURN_MASK_ERROR
)
13018 /* Clear BKP from a BPS. */
13021 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
13025 for (bs
= bps
; bs
; bs
= bs
->next
)
13026 if (bs
->breakpoint_at
== bpt
)
13028 bs
->breakpoint_at
= NULL
;
13029 bs
->old_val
= NULL
;
13030 /* bs->commands will be freed later. */
13034 /* Callback for iterate_over_threads. */
13036 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
13038 struct breakpoint
*bpt
= data
;
13040 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
13044 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
13048 say_where (struct breakpoint
*b
)
13050 struct value_print_options opts
;
13052 get_user_print_options (&opts
);
13054 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13056 if (b
->loc
== NULL
)
13058 printf_filtered (_(" (%s) pending."), b
->addr_string
);
13062 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
13064 printf_filtered (" at ");
13065 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
13068 if (b
->loc
->symtab
!= NULL
)
13070 /* If there is a single location, we can print the location
13072 if (b
->loc
->next
== NULL
)
13073 printf_filtered (": file %s, line %d.",
13074 symtab_to_filename_for_display (b
->loc
->symtab
),
13075 b
->loc
->line_number
);
13077 /* This is not ideal, but each location may have a
13078 different file name, and this at least reflects the
13079 real situation somewhat. */
13080 printf_filtered (": %s.", b
->addr_string
);
13085 struct bp_location
*loc
= b
->loc
;
13087 for (; loc
; loc
= loc
->next
)
13089 printf_filtered (" (%d locations)", n
);
13094 /* Default bp_location_ops methods. */
13097 bp_location_dtor (struct bp_location
*self
)
13099 xfree (self
->cond
);
13100 if (self
->cond_bytecode
)
13101 free_agent_expr (self
->cond_bytecode
);
13102 xfree (self
->function_name
);
13104 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
13105 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
13108 static const struct bp_location_ops bp_location_ops
=
13113 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13117 base_breakpoint_dtor (struct breakpoint
*self
)
13119 decref_counted_command_line (&self
->commands
);
13120 xfree (self
->cond_string
);
13121 xfree (self
->extra_string
);
13122 xfree (self
->addr_string
);
13123 xfree (self
->filter
);
13124 xfree (self
->addr_string_range_end
);
13127 static struct bp_location
*
13128 base_breakpoint_allocate_location (struct breakpoint
*self
)
13130 struct bp_location
*loc
;
13132 loc
= XNEW (struct bp_location
);
13133 init_bp_location (loc
, &bp_location_ops
, self
);
13138 base_breakpoint_re_set (struct breakpoint
*b
)
13140 /* Nothing to re-set. */
13143 #define internal_error_pure_virtual_called() \
13144 gdb_assert_not_reached ("pure virtual function called")
13147 base_breakpoint_insert_location (struct bp_location
*bl
)
13149 internal_error_pure_virtual_called ();
13153 base_breakpoint_remove_location (struct bp_location
*bl
)
13155 internal_error_pure_virtual_called ();
13159 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
13160 struct address_space
*aspace
,
13162 const struct target_waitstatus
*ws
)
13164 internal_error_pure_virtual_called ();
13168 base_breakpoint_check_status (bpstat bs
)
13173 /* A "works_in_software_mode" breakpoint_ops method that just internal
13177 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13179 internal_error_pure_virtual_called ();
13182 /* A "resources_needed" breakpoint_ops method that just internal
13186 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13188 internal_error_pure_virtual_called ();
13191 static enum print_stop_action
13192 base_breakpoint_print_it (bpstat bs
)
13194 internal_error_pure_virtual_called ();
13198 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13199 struct ui_out
*uiout
)
13205 base_breakpoint_print_mention (struct breakpoint
*b
)
13207 internal_error_pure_virtual_called ();
13211 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13213 internal_error_pure_virtual_called ();
13217 base_breakpoint_create_sals_from_address (char **arg
,
13218 struct linespec_result
*canonical
,
13219 enum bptype type_wanted
,
13223 internal_error_pure_virtual_called ();
13227 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13228 struct linespec_result
*c
,
13230 char *extra_string
,
13231 enum bptype type_wanted
,
13232 enum bpdisp disposition
,
13234 int task
, int ignore_count
,
13235 const struct breakpoint_ops
*o
,
13236 int from_tty
, int enabled
,
13237 int internal
, unsigned flags
)
13239 internal_error_pure_virtual_called ();
13243 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13244 struct symtabs_and_lines
*sals
)
13246 internal_error_pure_virtual_called ();
13249 /* The default 'explains_signal' method. */
13252 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13257 /* The default "after_condition_true" method. */
13260 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13262 /* Nothing to do. */
13265 struct breakpoint_ops base_breakpoint_ops
=
13267 base_breakpoint_dtor
,
13268 base_breakpoint_allocate_location
,
13269 base_breakpoint_re_set
,
13270 base_breakpoint_insert_location
,
13271 base_breakpoint_remove_location
,
13272 base_breakpoint_breakpoint_hit
,
13273 base_breakpoint_check_status
,
13274 base_breakpoint_resources_needed
,
13275 base_breakpoint_works_in_software_mode
,
13276 base_breakpoint_print_it
,
13278 base_breakpoint_print_one_detail
,
13279 base_breakpoint_print_mention
,
13280 base_breakpoint_print_recreate
,
13281 base_breakpoint_create_sals_from_address
,
13282 base_breakpoint_create_breakpoints_sal
,
13283 base_breakpoint_decode_linespec
,
13284 base_breakpoint_explains_signal
,
13285 base_breakpoint_after_condition_true
,
13288 /* Default breakpoint_ops methods. */
13291 bkpt_re_set (struct breakpoint
*b
)
13293 /* FIXME: is this still reachable? */
13294 if (b
->addr_string
== NULL
)
13296 /* Anything without a string can't be re-set. */
13297 delete_breakpoint (b
);
13301 breakpoint_re_set_default (b
);
13305 bkpt_insert_location (struct bp_location
*bl
)
13307 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13308 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13310 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13314 bkpt_remove_location (struct bp_location
*bl
)
13316 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13317 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13319 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13323 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13324 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13325 const struct target_waitstatus
*ws
)
13327 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13328 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13331 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13335 if (overlay_debugging
/* unmapped overlay section */
13336 && section_is_overlay (bl
->section
)
13337 && !section_is_mapped (bl
->section
))
13344 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13345 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13346 const struct target_waitstatus
*ws
)
13348 if (dprintf_style
== dprintf_style_agent
13349 && target_can_run_breakpoint_commands ())
13351 /* An agent-style dprintf never causes a stop. If we see a trap
13352 for this address it must be for a breakpoint that happens to
13353 be set at the same address. */
13357 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13361 bkpt_resources_needed (const struct bp_location
*bl
)
13363 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13368 static enum print_stop_action
13369 bkpt_print_it (bpstat bs
)
13371 struct breakpoint
*b
;
13372 const struct bp_location
*bl
;
13374 struct ui_out
*uiout
= current_uiout
;
13376 gdb_assert (bs
->bp_location_at
!= NULL
);
13378 bl
= bs
->bp_location_at
;
13379 b
= bs
->breakpoint_at
;
13381 bp_temp
= b
->disposition
== disp_del
;
13382 if (bl
->address
!= bl
->requested_address
)
13383 breakpoint_adjustment_warning (bl
->requested_address
,
13386 annotate_breakpoint (b
->number
);
13388 ui_out_text (uiout
, "\nTemporary breakpoint ");
13390 ui_out_text (uiout
, "\nBreakpoint ");
13391 if (ui_out_is_mi_like_p (uiout
))
13393 ui_out_field_string (uiout
, "reason",
13394 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13395 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13397 ui_out_field_int (uiout
, "bkptno", b
->number
);
13398 ui_out_text (uiout
, ", ");
13400 return PRINT_SRC_AND_LOC
;
13404 bkpt_print_mention (struct breakpoint
*b
)
13406 if (ui_out_is_mi_like_p (current_uiout
))
13411 case bp_breakpoint
:
13412 case bp_gnu_ifunc_resolver
:
13413 if (b
->disposition
== disp_del
)
13414 printf_filtered (_("Temporary breakpoint"));
13416 printf_filtered (_("Breakpoint"));
13417 printf_filtered (_(" %d"), b
->number
);
13418 if (b
->type
== bp_gnu_ifunc_resolver
)
13419 printf_filtered (_(" at gnu-indirect-function resolver"));
13421 case bp_hardware_breakpoint
:
13422 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13425 printf_filtered (_("Dprintf %d"), b
->number
);
13433 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13435 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13436 fprintf_unfiltered (fp
, "tbreak");
13437 else if (tp
->type
== bp_breakpoint
)
13438 fprintf_unfiltered (fp
, "break");
13439 else if (tp
->type
== bp_hardware_breakpoint
13440 && tp
->disposition
== disp_del
)
13441 fprintf_unfiltered (fp
, "thbreak");
13442 else if (tp
->type
== bp_hardware_breakpoint
)
13443 fprintf_unfiltered (fp
, "hbreak");
13445 internal_error (__FILE__
, __LINE__
,
13446 _("unhandled breakpoint type %d"), (int) tp
->type
);
13448 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13449 print_recreate_thread (tp
, fp
);
13453 bkpt_create_sals_from_address (char **arg
,
13454 struct linespec_result
*canonical
,
13455 enum bptype type_wanted
,
13456 char *addr_start
, char **copy_arg
)
13458 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13459 addr_start
, copy_arg
);
13463 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13464 struct linespec_result
*canonical
,
13466 char *extra_string
,
13467 enum bptype type_wanted
,
13468 enum bpdisp disposition
,
13470 int task
, int ignore_count
,
13471 const struct breakpoint_ops
*ops
,
13472 int from_tty
, int enabled
,
13473 int internal
, unsigned flags
)
13475 create_breakpoints_sal_default (gdbarch
, canonical
,
13476 cond_string
, extra_string
,
13478 disposition
, thread
, task
,
13479 ignore_count
, ops
, from_tty
,
13480 enabled
, internal
, flags
);
13484 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13485 struct symtabs_and_lines
*sals
)
13487 decode_linespec_default (b
, s
, sals
);
13490 /* Virtual table for internal breakpoints. */
13493 internal_bkpt_re_set (struct breakpoint
*b
)
13497 /* Delete overlay event and longjmp master breakpoints; they
13498 will be reset later by breakpoint_re_set. */
13499 case bp_overlay_event
:
13500 case bp_longjmp_master
:
13501 case bp_std_terminate_master
:
13502 case bp_exception_master
:
13503 delete_breakpoint (b
);
13506 /* This breakpoint is special, it's set up when the inferior
13507 starts and we really don't want to touch it. */
13508 case bp_shlib_event
:
13510 /* Like bp_shlib_event, this breakpoint type is special. Once
13511 it is set up, we do not want to touch it. */
13512 case bp_thread_event
:
13518 internal_bkpt_check_status (bpstat bs
)
13520 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13522 /* If requested, stop when the dynamic linker notifies GDB of
13523 events. This allows the user to get control and place
13524 breakpoints in initializer routines for dynamically loaded
13525 objects (among other things). */
13526 bs
->stop
= stop_on_solib_events
;
13527 bs
->print
= stop_on_solib_events
;
13533 static enum print_stop_action
13534 internal_bkpt_print_it (bpstat bs
)
13536 struct breakpoint
*b
;
13538 b
= bs
->breakpoint_at
;
13542 case bp_shlib_event
:
13543 /* Did we stop because the user set the stop_on_solib_events
13544 variable? (If so, we report this as a generic, "Stopped due
13545 to shlib event" message.) */
13546 print_solib_event (0);
13549 case bp_thread_event
:
13550 /* Not sure how we will get here.
13551 GDB should not stop for these breakpoints. */
13552 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13555 case bp_overlay_event
:
13556 /* By analogy with the thread event, GDB should not stop for these. */
13557 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13560 case bp_longjmp_master
:
13561 /* These should never be enabled. */
13562 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13565 case bp_std_terminate_master
:
13566 /* These should never be enabled. */
13567 printf_filtered (_("std::terminate Master Breakpoint: "
13568 "gdb should not stop!\n"));
13571 case bp_exception_master
:
13572 /* These should never be enabled. */
13573 printf_filtered (_("Exception Master Breakpoint: "
13574 "gdb should not stop!\n"));
13578 return PRINT_NOTHING
;
13582 internal_bkpt_print_mention (struct breakpoint
*b
)
13584 /* Nothing to mention. These breakpoints are internal. */
13587 /* Virtual table for momentary breakpoints */
13590 momentary_bkpt_re_set (struct breakpoint
*b
)
13592 /* Keep temporary breakpoints, which can be encountered when we step
13593 over a dlopen call and solib_add is resetting the breakpoints.
13594 Otherwise these should have been blown away via the cleanup chain
13595 or by breakpoint_init_inferior when we rerun the executable. */
13599 momentary_bkpt_check_status (bpstat bs
)
13601 /* Nothing. The point of these breakpoints is causing a stop. */
13604 static enum print_stop_action
13605 momentary_bkpt_print_it (bpstat bs
)
13607 struct ui_out
*uiout
= current_uiout
;
13609 if (ui_out_is_mi_like_p (uiout
))
13611 struct breakpoint
*b
= bs
->breakpoint_at
;
13616 ui_out_field_string
13618 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13622 ui_out_field_string
13624 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13629 return PRINT_UNKNOWN
;
13633 momentary_bkpt_print_mention (struct breakpoint
*b
)
13635 /* Nothing to mention. These breakpoints are internal. */
13638 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13640 It gets cleared already on the removal of the first one of such placed
13641 breakpoints. This is OK as they get all removed altogether. */
13644 longjmp_bkpt_dtor (struct breakpoint
*self
)
13646 struct thread_info
*tp
= find_thread_id (self
->thread
);
13649 tp
->initiating_frame
= null_frame_id
;
13651 momentary_breakpoint_ops
.dtor (self
);
13654 /* Specific methods for probe breakpoints. */
13657 bkpt_probe_insert_location (struct bp_location
*bl
)
13659 int v
= bkpt_insert_location (bl
);
13663 /* The insertion was successful, now let's set the probe's semaphore
13665 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13666 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13675 bkpt_probe_remove_location (struct bp_location
*bl
)
13677 /* Let's clear the semaphore before removing the location. */
13678 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13679 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13683 return bkpt_remove_location (bl
);
13687 bkpt_probe_create_sals_from_address (char **arg
,
13688 struct linespec_result
*canonical
,
13689 enum bptype type_wanted
,
13690 char *addr_start
, char **copy_arg
)
13692 struct linespec_sals lsal
;
13694 lsal
.sals
= parse_probes (arg
, canonical
);
13696 *copy_arg
= xstrdup (canonical
->addr_string
);
13697 lsal
.canonical
= xstrdup (*copy_arg
);
13699 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13703 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13704 struct symtabs_and_lines
*sals
)
13706 *sals
= parse_probes (s
, NULL
);
13708 error (_("probe not found"));
13711 /* The breakpoint_ops structure to be used in tracepoints. */
13714 tracepoint_re_set (struct breakpoint
*b
)
13716 breakpoint_re_set_default (b
);
13720 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13721 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13722 const struct target_waitstatus
*ws
)
13724 /* By definition, the inferior does not report stops at
13730 tracepoint_print_one_detail (const struct breakpoint
*self
,
13731 struct ui_out
*uiout
)
13733 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13734 if (tp
->static_trace_marker_id
)
13736 gdb_assert (self
->type
== bp_static_tracepoint
);
13738 ui_out_text (uiout
, "\tmarker id is ");
13739 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13740 tp
->static_trace_marker_id
);
13741 ui_out_text (uiout
, "\n");
13746 tracepoint_print_mention (struct breakpoint
*b
)
13748 if (ui_out_is_mi_like_p (current_uiout
))
13753 case bp_tracepoint
:
13754 printf_filtered (_("Tracepoint"));
13755 printf_filtered (_(" %d"), b
->number
);
13757 case bp_fast_tracepoint
:
13758 printf_filtered (_("Fast tracepoint"));
13759 printf_filtered (_(" %d"), b
->number
);
13761 case bp_static_tracepoint
:
13762 printf_filtered (_("Static tracepoint"));
13763 printf_filtered (_(" %d"), b
->number
);
13766 internal_error (__FILE__
, __LINE__
,
13767 _("unhandled tracepoint type %d"), (int) b
->type
);
13774 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13776 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13778 if (self
->type
== bp_fast_tracepoint
)
13779 fprintf_unfiltered (fp
, "ftrace");
13780 if (self
->type
== bp_static_tracepoint
)
13781 fprintf_unfiltered (fp
, "strace");
13782 else if (self
->type
== bp_tracepoint
)
13783 fprintf_unfiltered (fp
, "trace");
13785 internal_error (__FILE__
, __LINE__
,
13786 _("unhandled tracepoint type %d"), (int) self
->type
);
13788 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13789 print_recreate_thread (self
, fp
);
13791 if (tp
->pass_count
)
13792 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13796 tracepoint_create_sals_from_address (char **arg
,
13797 struct linespec_result
*canonical
,
13798 enum bptype type_wanted
,
13799 char *addr_start
, char **copy_arg
)
13801 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13802 addr_start
, copy_arg
);
13806 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13807 struct linespec_result
*canonical
,
13809 char *extra_string
,
13810 enum bptype type_wanted
,
13811 enum bpdisp disposition
,
13813 int task
, int ignore_count
,
13814 const struct breakpoint_ops
*ops
,
13815 int from_tty
, int enabled
,
13816 int internal
, unsigned flags
)
13818 create_breakpoints_sal_default (gdbarch
, canonical
,
13819 cond_string
, extra_string
,
13821 disposition
, thread
, task
,
13822 ignore_count
, ops
, from_tty
,
13823 enabled
, internal
, flags
);
13827 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13828 struct symtabs_and_lines
*sals
)
13830 decode_linespec_default (b
, s
, sals
);
13833 struct breakpoint_ops tracepoint_breakpoint_ops
;
13835 /* The breakpoint_ops structure to be use on tracepoints placed in a
13839 tracepoint_probe_create_sals_from_address (char **arg
,
13840 struct linespec_result
*canonical
,
13841 enum bptype type_wanted
,
13842 char *addr_start
, char **copy_arg
)
13844 /* We use the same method for breakpoint on probes. */
13845 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13846 addr_start
, copy_arg
);
13850 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13851 struct symtabs_and_lines
*sals
)
13853 /* We use the same method for breakpoint on probes. */
13854 bkpt_probe_decode_linespec (b
, s
, sals
);
13857 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13859 /* Dprintf breakpoint_ops methods. */
13862 dprintf_re_set (struct breakpoint
*b
)
13864 breakpoint_re_set_default (b
);
13866 /* This breakpoint could have been pending, and be resolved now, and
13867 if so, we should now have the extra string. If we don't, the
13868 dprintf was malformed when created, but we couldn't tell because
13869 we can't extract the extra string until the location is
13871 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13872 error (_("Format string required"));
13874 /* 1 - connect to target 1, that can run breakpoint commands.
13875 2 - create a dprintf, which resolves fine.
13876 3 - disconnect from target 1
13877 4 - connect to target 2, that can NOT run breakpoint commands.
13879 After steps #3/#4, you'll want the dprintf command list to
13880 be updated, because target 1 and 2 may well return different
13881 answers for target_can_run_breakpoint_commands().
13882 Given absence of finer grained resetting, we get to do
13883 it all the time. */
13884 if (b
->extra_string
!= NULL
)
13885 update_dprintf_command_list (b
);
13888 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13891 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13893 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13895 print_recreate_thread (tp
, fp
);
13898 /* Implement the "after_condition_true" breakpoint_ops method for
13901 dprintf's are implemented with regular commands in their command
13902 list, but we run the commands here instead of before presenting the
13903 stop to the user, as dprintf's don't actually cause a stop. This
13904 also makes it so that the commands of multiple dprintfs at the same
13905 address are all handled. */
13908 dprintf_after_condition_true (struct bpstats
*bs
)
13910 struct cleanup
*old_chain
;
13911 struct bpstats tmp_bs
= { NULL
};
13912 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13914 /* dprintf's never cause a stop. This wasn't set in the
13915 check_status hook instead because that would make the dprintf's
13916 condition not be evaluated. */
13919 /* Run the command list here. Take ownership of it instead of
13920 copying. We never want these commands to run later in
13921 bpstat_do_actions, if a breakpoint that causes a stop happens to
13922 be set at same address as this dprintf, or even if running the
13923 commands here throws. */
13924 tmp_bs
.commands
= bs
->commands
;
13925 bs
->commands
= NULL
;
13926 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13928 bpstat_do_actions_1 (&tmp_bs_p
);
13930 /* 'tmp_bs.commands' will usually be NULL by now, but
13931 bpstat_do_actions_1 may return early without processing the whole
13933 do_cleanups (old_chain
);
13936 /* The breakpoint_ops structure to be used on static tracepoints with
13940 strace_marker_create_sals_from_address (char **arg
,
13941 struct linespec_result
*canonical
,
13942 enum bptype type_wanted
,
13943 char *addr_start
, char **copy_arg
)
13945 struct linespec_sals lsal
;
13947 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13949 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13951 canonical
->addr_string
= xstrdup (*copy_arg
);
13952 lsal
.canonical
= xstrdup (*copy_arg
);
13953 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13957 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13958 struct linespec_result
*canonical
,
13960 char *extra_string
,
13961 enum bptype type_wanted
,
13962 enum bpdisp disposition
,
13964 int task
, int ignore_count
,
13965 const struct breakpoint_ops
*ops
,
13966 int from_tty
, int enabled
,
13967 int internal
, unsigned flags
)
13970 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13971 canonical
->sals
, 0);
13973 /* If the user is creating a static tracepoint by marker id
13974 (strace -m MARKER_ID), then store the sals index, so that
13975 breakpoint_re_set can try to match up which of the newly
13976 found markers corresponds to this one, and, don't try to
13977 expand multiple locations for each sal, given than SALS
13978 already should contain all sals for MARKER_ID. */
13980 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13982 struct symtabs_and_lines expanded
;
13983 struct tracepoint
*tp
;
13984 struct cleanup
*old_chain
;
13987 expanded
.nelts
= 1;
13988 expanded
.sals
= &lsal
->sals
.sals
[i
];
13990 addr_string
= xstrdup (canonical
->addr_string
);
13991 old_chain
= make_cleanup (xfree
, addr_string
);
13993 tp
= XCNEW (struct tracepoint
);
13994 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13996 cond_string
, extra_string
,
13997 type_wanted
, disposition
,
13998 thread
, task
, ignore_count
, ops
,
13999 from_tty
, enabled
, internal
, flags
,
14000 canonical
->special_display
);
14001 /* Given that its possible to have multiple markers with
14002 the same string id, if the user is creating a static
14003 tracepoint by marker id ("strace -m MARKER_ID"), then
14004 store the sals index, so that breakpoint_re_set can
14005 try to match up which of the newly found markers
14006 corresponds to this one */
14007 tp
->static_trace_marker_id_idx
= i
;
14009 install_breakpoint (internal
, &tp
->base
, 0);
14011 discard_cleanups (old_chain
);
14016 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
14017 struct symtabs_and_lines
*sals
)
14019 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14021 *sals
= decode_static_tracepoint_spec (s
);
14022 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
14024 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
14028 error (_("marker %s not found"), tp
->static_trace_marker_id
);
14031 static struct breakpoint_ops strace_marker_breakpoint_ops
;
14034 strace_marker_p (struct breakpoint
*b
)
14036 return b
->ops
== &strace_marker_breakpoint_ops
;
14039 /* Delete a breakpoint and clean up all traces of it in the data
14043 delete_breakpoint (struct breakpoint
*bpt
)
14045 struct breakpoint
*b
;
14047 gdb_assert (bpt
!= NULL
);
14049 /* Has this bp already been deleted? This can happen because
14050 multiple lists can hold pointers to bp's. bpstat lists are
14053 One example of this happening is a watchpoint's scope bp. When
14054 the scope bp triggers, we notice that the watchpoint is out of
14055 scope, and delete it. We also delete its scope bp. But the
14056 scope bp is marked "auto-deleting", and is already on a bpstat.
14057 That bpstat is then checked for auto-deleting bp's, which are
14060 A real solution to this problem might involve reference counts in
14061 bp's, and/or giving them pointers back to their referencing
14062 bpstat's, and teaching delete_breakpoint to only free a bp's
14063 storage when no more references were extent. A cheaper bandaid
14065 if (bpt
->type
== bp_none
)
14068 /* At least avoid this stale reference until the reference counting
14069 of breakpoints gets resolved. */
14070 if (bpt
->related_breakpoint
!= bpt
)
14072 struct breakpoint
*related
;
14073 struct watchpoint
*w
;
14075 if (bpt
->type
== bp_watchpoint_scope
)
14076 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
14077 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
14078 w
= (struct watchpoint
*) bpt
;
14082 watchpoint_del_at_next_stop (w
);
14084 /* Unlink bpt from the bpt->related_breakpoint ring. */
14085 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
14086 related
= related
->related_breakpoint
);
14087 related
->related_breakpoint
= bpt
->related_breakpoint
;
14088 bpt
->related_breakpoint
= bpt
;
14091 /* watch_command_1 creates a watchpoint but only sets its number if
14092 update_watchpoint succeeds in creating its bp_locations. If there's
14093 a problem in that process, we'll be asked to delete the half-created
14094 watchpoint. In that case, don't announce the deletion. */
14096 observer_notify_breakpoint_deleted (bpt
);
14098 if (breakpoint_chain
== bpt
)
14099 breakpoint_chain
= bpt
->next
;
14101 ALL_BREAKPOINTS (b
)
14102 if (b
->next
== bpt
)
14104 b
->next
= bpt
->next
;
14108 /* Be sure no bpstat's are pointing at the breakpoint after it's
14110 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14111 in all threads for now. Note that we cannot just remove bpstats
14112 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14113 commands are associated with the bpstat; if we remove it here,
14114 then the later call to bpstat_do_actions (&stop_bpstat); in
14115 event-top.c won't do anything, and temporary breakpoints with
14116 commands won't work. */
14118 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
14120 /* Now that breakpoint is removed from breakpoint list, update the
14121 global location list. This will remove locations that used to
14122 belong to this breakpoint. Do this before freeing the breakpoint
14123 itself, since remove_breakpoint looks at location's owner. It
14124 might be better design to have location completely
14125 self-contained, but it's not the case now. */
14126 update_global_location_list (UGLL_DONT_INSERT
);
14128 bpt
->ops
->dtor (bpt
);
14129 /* On the chance that someone will soon try again to delete this
14130 same bp, we mark it as deleted before freeing its storage. */
14131 bpt
->type
= bp_none
;
14136 do_delete_breakpoint_cleanup (void *b
)
14138 delete_breakpoint (b
);
14142 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
14144 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
14147 /* Iterator function to call a user-provided callback function once
14148 for each of B and its related breakpoints. */
14151 iterate_over_related_breakpoints (struct breakpoint
*b
,
14152 void (*function
) (struct breakpoint
*,
14156 struct breakpoint
*related
;
14161 struct breakpoint
*next
;
14163 /* FUNCTION may delete RELATED. */
14164 next
= related
->related_breakpoint
;
14166 if (next
== related
)
14168 /* RELATED is the last ring entry. */
14169 function (related
, data
);
14171 /* FUNCTION may have deleted it, so we'd never reach back to
14172 B. There's nothing left to do anyway, so just break
14177 function (related
, data
);
14181 while (related
!= b
);
14185 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14187 delete_breakpoint (b
);
14190 /* A callback for map_breakpoint_numbers that calls
14191 delete_breakpoint. */
14194 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14196 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14200 delete_command (char *arg
, int from_tty
)
14202 struct breakpoint
*b
, *b_tmp
;
14208 int breaks_to_delete
= 0;
14210 /* Delete all breakpoints if no argument. Do not delete
14211 internal breakpoints, these have to be deleted with an
14212 explicit breakpoint number argument. */
14213 ALL_BREAKPOINTS (b
)
14214 if (user_breakpoint_p (b
))
14216 breaks_to_delete
= 1;
14220 /* Ask user only if there are some breakpoints to delete. */
14222 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14224 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14225 if (user_breakpoint_p (b
))
14226 delete_breakpoint (b
);
14230 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14234 all_locations_are_pending (struct bp_location
*loc
)
14236 for (; loc
; loc
= loc
->next
)
14237 if (!loc
->shlib_disabled
14238 && !loc
->pspace
->executing_startup
)
14243 /* Subroutine of update_breakpoint_locations to simplify it.
14244 Return non-zero if multiple fns in list LOC have the same name.
14245 Null names are ignored. */
14248 ambiguous_names_p (struct bp_location
*loc
)
14250 struct bp_location
*l
;
14251 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14252 (int (*) (const void *,
14253 const void *)) streq
,
14254 NULL
, xcalloc
, xfree
);
14256 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14259 const char *name
= l
->function_name
;
14261 /* Allow for some names to be NULL, ignore them. */
14265 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14267 /* NOTE: We can assume slot != NULL here because xcalloc never
14271 htab_delete (htab
);
14277 htab_delete (htab
);
14281 /* When symbols change, it probably means the sources changed as well,
14282 and it might mean the static tracepoint markers are no longer at
14283 the same address or line numbers they used to be at last we
14284 checked. Losing your static tracepoints whenever you rebuild is
14285 undesirable. This function tries to resync/rematch gdb static
14286 tracepoints with the markers on the target, for static tracepoints
14287 that have not been set by marker id. Static tracepoint that have
14288 been set by marker id are reset by marker id in breakpoint_re_set.
14291 1) For a tracepoint set at a specific address, look for a marker at
14292 the old PC. If one is found there, assume to be the same marker.
14293 If the name / string id of the marker found is different from the
14294 previous known name, assume that means the user renamed the marker
14295 in the sources, and output a warning.
14297 2) For a tracepoint set at a given line number, look for a marker
14298 at the new address of the old line number. If one is found there,
14299 assume to be the same marker. If the name / string id of the
14300 marker found is different from the previous known name, assume that
14301 means the user renamed the marker in the sources, and output a
14304 3) If a marker is no longer found at the same address or line, it
14305 may mean the marker no longer exists. But it may also just mean
14306 the code changed a bit. Maybe the user added a few lines of code
14307 that made the marker move up or down (in line number terms). Ask
14308 the target for info about the marker with the string id as we knew
14309 it. If found, update line number and address in the matching
14310 static tracepoint. This will get confused if there's more than one
14311 marker with the same ID (possible in UST, although unadvised
14312 precisely because it confuses tools). */
14314 static struct symtab_and_line
14315 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14317 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14318 struct static_tracepoint_marker marker
;
14323 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14325 if (target_static_tracepoint_marker_at (pc
, &marker
))
14327 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14328 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14330 tp
->static_trace_marker_id
, marker
.str_id
);
14332 xfree (tp
->static_trace_marker_id
);
14333 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14334 release_static_tracepoint_marker (&marker
);
14339 /* Old marker wasn't found on target at lineno. Try looking it up
14341 if (!sal
.explicit_pc
14343 && sal
.symtab
!= NULL
14344 && tp
->static_trace_marker_id
!= NULL
)
14346 VEC(static_tracepoint_marker_p
) *markers
;
14349 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14351 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14353 struct symtab_and_line sal2
;
14354 struct symbol
*sym
;
14355 struct static_tracepoint_marker
*tpmarker
;
14356 struct ui_out
*uiout
= current_uiout
;
14358 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14360 xfree (tp
->static_trace_marker_id
);
14361 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14363 warning (_("marker for static tracepoint %d (%s) not "
14364 "found at previous line number"),
14365 b
->number
, tp
->static_trace_marker_id
);
14369 sal2
.pc
= tpmarker
->address
;
14371 sal2
= find_pc_line (tpmarker
->address
, 0);
14372 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14373 ui_out_text (uiout
, "Now in ");
14376 ui_out_field_string (uiout
, "func",
14377 SYMBOL_PRINT_NAME (sym
));
14378 ui_out_text (uiout
, " at ");
14380 ui_out_field_string (uiout
, "file",
14381 symtab_to_filename_for_display (sal2
.symtab
));
14382 ui_out_text (uiout
, ":");
14384 if (ui_out_is_mi_like_p (uiout
))
14386 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14388 ui_out_field_string (uiout
, "fullname", fullname
);
14391 ui_out_field_int (uiout
, "line", sal2
.line
);
14392 ui_out_text (uiout
, "\n");
14394 b
->loc
->line_number
= sal2
.line
;
14395 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14397 xfree (b
->addr_string
);
14398 b
->addr_string
= xstrprintf ("%s:%d",
14399 symtab_to_filename_for_display (sal2
.symtab
),
14400 b
->loc
->line_number
);
14402 /* Might be nice to check if function changed, and warn if
14405 release_static_tracepoint_marker (tpmarker
);
14411 /* Returns 1 iff locations A and B are sufficiently same that
14412 we don't need to report breakpoint as changed. */
14415 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14419 if (a
->address
!= b
->address
)
14422 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14425 if (a
->enabled
!= b
->enabled
)
14432 if ((a
== NULL
) != (b
== NULL
))
14438 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14439 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14440 a ranged breakpoint. */
14443 update_breakpoint_locations (struct breakpoint
*b
,
14444 struct symtabs_and_lines sals
,
14445 struct symtabs_and_lines sals_end
)
14448 struct bp_location
*existing_locations
= b
->loc
;
14450 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14452 /* Ranged breakpoints have only one start location and one end
14454 b
->enable_state
= bp_disabled
;
14455 update_global_location_list (UGLL_MAY_INSERT
);
14456 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14457 "multiple locations found\n"),
14462 /* If there's no new locations, and all existing locations are
14463 pending, don't do anything. This optimizes the common case where
14464 all locations are in the same shared library, that was unloaded.
14465 We'd like to retain the location, so that when the library is
14466 loaded again, we don't loose the enabled/disabled status of the
14467 individual locations. */
14468 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14473 for (i
= 0; i
< sals
.nelts
; ++i
)
14475 struct bp_location
*new_loc
;
14477 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14479 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14481 /* Reparse conditions, they might contain references to the
14483 if (b
->cond_string
!= NULL
)
14487 s
= b
->cond_string
;
14490 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14491 block_for_pc (sals
.sals
[i
].pc
),
14494 CATCH (e
, RETURN_MASK_ERROR
)
14496 warning (_("failed to reevaluate condition "
14497 "for breakpoint %d: %s"),
14498 b
->number
, e
.message
);
14499 new_loc
->enabled
= 0;
14504 if (sals_end
.nelts
)
14506 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14508 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14512 /* If possible, carry over 'disable' status from existing
14515 struct bp_location
*e
= existing_locations
;
14516 /* If there are multiple breakpoints with the same function name,
14517 e.g. for inline functions, comparing function names won't work.
14518 Instead compare pc addresses; this is just a heuristic as things
14519 may have moved, but in practice it gives the correct answer
14520 often enough until a better solution is found. */
14521 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14523 for (; e
; e
= e
->next
)
14525 if (!e
->enabled
&& e
->function_name
)
14527 struct bp_location
*l
= b
->loc
;
14528 if (have_ambiguous_names
)
14530 for (; l
; l
= l
->next
)
14531 if (breakpoint_locations_match (e
, l
))
14539 for (; l
; l
= l
->next
)
14540 if (l
->function_name
14541 && strcmp (e
->function_name
, l
->function_name
) == 0)
14551 if (!locations_are_equal (existing_locations
, b
->loc
))
14552 observer_notify_breakpoint_modified (b
);
14554 update_global_location_list (UGLL_MAY_INSERT
);
14557 /* Find the SaL locations corresponding to the given ADDR_STRING.
14558 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14560 static struct symtabs_and_lines
14561 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14564 struct symtabs_and_lines sals
= {0};
14565 struct gdb_exception exception
= exception_none
;
14567 gdb_assert (b
->ops
!= NULL
);
14572 b
->ops
->decode_linespec (b
, &s
, &sals
);
14574 CATCH (e
, RETURN_MASK_ERROR
)
14576 int not_found_and_ok
= 0;
14580 /* For pending breakpoints, it's expected that parsing will
14581 fail until the right shared library is loaded. User has
14582 already told to create pending breakpoints and don't need
14583 extra messages. If breakpoint is in bp_shlib_disabled
14584 state, then user already saw the message about that
14585 breakpoint being disabled, and don't want to see more
14587 if (e
.error
== NOT_FOUND_ERROR
14588 && (b
->condition_not_parsed
14589 || (b
->loc
&& b
->loc
->shlib_disabled
)
14590 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14591 || b
->enable_state
== bp_disabled
))
14592 not_found_and_ok
= 1;
14594 if (!not_found_and_ok
)
14596 /* We surely don't want to warn about the same breakpoint
14597 10 times. One solution, implemented here, is disable
14598 the breakpoint on error. Another solution would be to
14599 have separate 'warning emitted' flag. Since this
14600 happens only when a binary has changed, I don't know
14601 which approach is better. */
14602 b
->enable_state
= bp_disabled
;
14603 throw_exception (e
);
14608 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14612 for (i
= 0; i
< sals
.nelts
; ++i
)
14613 resolve_sal_pc (&sals
.sals
[i
]);
14614 if (b
->condition_not_parsed
&& s
&& s
[0])
14616 char *cond_string
, *extra_string
;
14619 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14620 &cond_string
, &thread
, &task
,
14623 b
->cond_string
= cond_string
;
14624 b
->thread
= thread
;
14627 b
->extra_string
= extra_string
;
14628 b
->condition_not_parsed
= 0;
14631 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14632 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14642 /* The default re_set method, for typical hardware or software
14643 breakpoints. Reevaluate the breakpoint and recreate its
14647 breakpoint_re_set_default (struct breakpoint
*b
)
14650 struct symtabs_and_lines sals
, sals_end
;
14651 struct symtabs_and_lines expanded
= {0};
14652 struct symtabs_and_lines expanded_end
= {0};
14654 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14657 make_cleanup (xfree
, sals
.sals
);
14661 if (b
->addr_string_range_end
)
14663 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14666 make_cleanup (xfree
, sals_end
.sals
);
14667 expanded_end
= sals_end
;
14671 update_breakpoint_locations (b
, expanded
, expanded_end
);
14674 /* Default method for creating SALs from an address string. It basically
14675 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14678 create_sals_from_address_default (char **arg
,
14679 struct linespec_result
*canonical
,
14680 enum bptype type_wanted
,
14681 char *addr_start
, char **copy_arg
)
14683 parse_breakpoint_sals (arg
, canonical
);
14686 /* Call create_breakpoints_sal for the given arguments. This is the default
14687 function for the `create_breakpoints_sal' method of
14691 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14692 struct linespec_result
*canonical
,
14694 char *extra_string
,
14695 enum bptype type_wanted
,
14696 enum bpdisp disposition
,
14698 int task
, int ignore_count
,
14699 const struct breakpoint_ops
*ops
,
14700 int from_tty
, int enabled
,
14701 int internal
, unsigned flags
)
14703 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14705 type_wanted
, disposition
,
14706 thread
, task
, ignore_count
, ops
, from_tty
,
14707 enabled
, internal
, flags
);
14710 /* Decode the line represented by S by calling decode_line_full. This is the
14711 default function for the `decode_linespec' method of breakpoint_ops. */
14714 decode_linespec_default (struct breakpoint
*b
, char **s
,
14715 struct symtabs_and_lines
*sals
)
14717 struct linespec_result canonical
;
14719 init_linespec_result (&canonical
);
14720 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14721 (struct symtab
*) NULL
, 0,
14722 &canonical
, multiple_symbols_all
,
14725 /* We should get 0 or 1 resulting SALs. */
14726 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14728 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14730 struct linespec_sals
*lsal
;
14732 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14733 *sals
= lsal
->sals
;
14734 /* Arrange it so the destructor does not free the
14736 lsal
->sals
.sals
= NULL
;
14739 destroy_linespec_result (&canonical
);
14742 /* Prepare the global context for a re-set of breakpoint B. */
14744 static struct cleanup
*
14745 prepare_re_set_context (struct breakpoint
*b
)
14747 struct cleanup
*cleanups
;
14749 input_radix
= b
->input_radix
;
14750 cleanups
= save_current_space_and_thread ();
14751 if (b
->pspace
!= NULL
)
14752 switch_to_program_space_and_thread (b
->pspace
);
14753 set_language (b
->language
);
14758 /* Reset a breakpoint given it's struct breakpoint * BINT.
14759 The value we return ends up being the return value from catch_errors.
14760 Unused in this case. */
14763 breakpoint_re_set_one (void *bint
)
14765 /* Get past catch_errs. */
14766 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14767 struct cleanup
*cleanups
;
14769 cleanups
= prepare_re_set_context (b
);
14770 b
->ops
->re_set (b
);
14771 do_cleanups (cleanups
);
14775 /* Re-set all breakpoints after symbols have been re-loaded. */
14777 breakpoint_re_set (void)
14779 struct breakpoint
*b
, *b_tmp
;
14780 enum language save_language
;
14781 int save_input_radix
;
14782 struct cleanup
*old_chain
;
14784 save_language
= current_language
->la_language
;
14785 save_input_radix
= input_radix
;
14786 old_chain
= save_current_program_space ();
14788 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14790 /* Format possible error msg. */
14791 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14793 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14794 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14795 do_cleanups (cleanups
);
14797 set_language (save_language
);
14798 input_radix
= save_input_radix
;
14800 jit_breakpoint_re_set ();
14802 do_cleanups (old_chain
);
14804 create_overlay_event_breakpoint ();
14805 create_longjmp_master_breakpoint ();
14806 create_std_terminate_master_breakpoint ();
14807 create_exception_master_breakpoint ();
14810 /* Reset the thread number of this breakpoint:
14812 - If the breakpoint is for all threads, leave it as-is.
14813 - Else, reset it to the current thread for inferior_ptid. */
14815 breakpoint_re_set_thread (struct breakpoint
*b
)
14817 if (b
->thread
!= -1)
14819 if (in_thread_list (inferior_ptid
))
14820 b
->thread
= pid_to_thread_id (inferior_ptid
);
14822 /* We're being called after following a fork. The new fork is
14823 selected as current, and unless this was a vfork will have a
14824 different program space from the original thread. Reset that
14826 b
->loc
->pspace
= current_program_space
;
14830 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14831 If from_tty is nonzero, it prints a message to that effect,
14832 which ends with a period (no newline). */
14835 set_ignore_count (int bptnum
, int count
, int from_tty
)
14837 struct breakpoint
*b
;
14842 ALL_BREAKPOINTS (b
)
14843 if (b
->number
== bptnum
)
14845 if (is_tracepoint (b
))
14847 if (from_tty
&& count
!= 0)
14848 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14853 b
->ignore_count
= count
;
14857 printf_filtered (_("Will stop next time "
14858 "breakpoint %d is reached."),
14860 else if (count
== 1)
14861 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14864 printf_filtered (_("Will ignore next %d "
14865 "crossings of breakpoint %d."),
14868 observer_notify_breakpoint_modified (b
);
14872 error (_("No breakpoint number %d."), bptnum
);
14875 /* Command to set ignore-count of breakpoint N to COUNT. */
14878 ignore_command (char *args
, int from_tty
)
14884 error_no_arg (_("a breakpoint number"));
14886 num
= get_number (&p
);
14888 error (_("bad breakpoint number: '%s'"), args
);
14890 error (_("Second argument (specified ignore-count) is missing."));
14892 set_ignore_count (num
,
14893 longest_to_int (value_as_long (parse_and_eval (p
))),
14896 printf_filtered ("\n");
14899 /* Call FUNCTION on each of the breakpoints
14900 whose numbers are given in ARGS. */
14903 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14908 struct breakpoint
*b
, *tmp
;
14910 struct get_number_or_range_state state
;
14912 if (args
== 0 || *args
== '\0')
14913 error_no_arg (_("one or more breakpoint numbers"));
14915 init_number_or_range (&state
, args
);
14917 while (!state
.finished
)
14919 const char *p
= state
.string
;
14923 num
= get_number_or_range (&state
);
14926 warning (_("bad breakpoint number at or near '%s'"), p
);
14930 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14931 if (b
->number
== num
)
14934 function (b
, data
);
14938 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14943 static struct bp_location
*
14944 find_location_by_number (char *number
)
14946 char *dot
= strchr (number
, '.');
14950 struct breakpoint
*b
;
14951 struct bp_location
*loc
;
14956 bp_num
= get_number (&p1
);
14958 error (_("Bad breakpoint number '%s'"), number
);
14960 ALL_BREAKPOINTS (b
)
14961 if (b
->number
== bp_num
)
14966 if (!b
|| b
->number
!= bp_num
)
14967 error (_("Bad breakpoint number '%s'"), number
);
14970 loc_num
= get_number (&p1
);
14972 error (_("Bad breakpoint location number '%s'"), number
);
14976 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14979 error (_("Bad breakpoint location number '%s'"), dot
+1);
14985 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14986 If from_tty is nonzero, it prints a message to that effect,
14987 which ends with a period (no newline). */
14990 disable_breakpoint (struct breakpoint
*bpt
)
14992 /* Never disable a watchpoint scope breakpoint; we want to
14993 hit them when we leave scope so we can delete both the
14994 watchpoint and its scope breakpoint at that time. */
14995 if (bpt
->type
== bp_watchpoint_scope
)
14998 bpt
->enable_state
= bp_disabled
;
15000 /* Mark breakpoint locations modified. */
15001 mark_breakpoint_modified (bpt
);
15003 if (target_supports_enable_disable_tracepoint ()
15004 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15006 struct bp_location
*location
;
15008 for (location
= bpt
->loc
; location
; location
= location
->next
)
15009 target_disable_tracepoint (location
);
15012 update_global_location_list (UGLL_DONT_INSERT
);
15014 observer_notify_breakpoint_modified (bpt
);
15017 /* A callback for iterate_over_related_breakpoints. */
15020 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
15022 disable_breakpoint (b
);
15025 /* A callback for map_breakpoint_numbers that calls
15026 disable_breakpoint. */
15029 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
15031 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
15035 disable_command (char *args
, int from_tty
)
15039 struct breakpoint
*bpt
;
15041 ALL_BREAKPOINTS (bpt
)
15042 if (user_breakpoint_p (bpt
))
15043 disable_breakpoint (bpt
);
15047 char *num
= extract_arg (&args
);
15051 if (strchr (num
, '.'))
15053 struct bp_location
*loc
= find_location_by_number (num
);
15060 mark_breakpoint_location_modified (loc
);
15062 if (target_supports_enable_disable_tracepoint ()
15063 && current_trace_status ()->running
&& loc
->owner
15064 && is_tracepoint (loc
->owner
))
15065 target_disable_tracepoint (loc
);
15067 update_global_location_list (UGLL_DONT_INSERT
);
15070 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
15071 num
= extract_arg (&args
);
15077 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
15080 int target_resources_ok
;
15082 if (bpt
->type
== bp_hardware_breakpoint
)
15085 i
= hw_breakpoint_used_count ();
15086 target_resources_ok
=
15087 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
15089 if (target_resources_ok
== 0)
15090 error (_("No hardware breakpoint support in the target."));
15091 else if (target_resources_ok
< 0)
15092 error (_("Hardware breakpoints used exceeds limit."));
15095 if (is_watchpoint (bpt
))
15097 /* Initialize it just to avoid a GCC false warning. */
15098 enum enable_state orig_enable_state
= 0;
15102 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
15104 orig_enable_state
= bpt
->enable_state
;
15105 bpt
->enable_state
= bp_enabled
;
15106 update_watchpoint (w
, 1 /* reparse */);
15108 CATCH (e
, RETURN_MASK_ALL
)
15110 bpt
->enable_state
= orig_enable_state
;
15111 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15118 bpt
->enable_state
= bp_enabled
;
15120 /* Mark breakpoint locations modified. */
15121 mark_breakpoint_modified (bpt
);
15123 if (target_supports_enable_disable_tracepoint ()
15124 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15126 struct bp_location
*location
;
15128 for (location
= bpt
->loc
; location
; location
= location
->next
)
15129 target_enable_tracepoint (location
);
15132 bpt
->disposition
= disposition
;
15133 bpt
->enable_count
= count
;
15134 update_global_location_list (UGLL_MAY_INSERT
);
15136 observer_notify_breakpoint_modified (bpt
);
15141 enable_breakpoint (struct breakpoint
*bpt
)
15143 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15147 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15149 enable_breakpoint (bpt
);
15152 /* A callback for map_breakpoint_numbers that calls
15153 enable_breakpoint. */
15156 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15158 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15161 /* The enable command enables the specified breakpoints (or all defined
15162 breakpoints) so they once again become (or continue to be) effective
15163 in stopping the inferior. */
15166 enable_command (char *args
, int from_tty
)
15170 struct breakpoint
*bpt
;
15172 ALL_BREAKPOINTS (bpt
)
15173 if (user_breakpoint_p (bpt
))
15174 enable_breakpoint (bpt
);
15178 char *num
= extract_arg (&args
);
15182 if (strchr (num
, '.'))
15184 struct bp_location
*loc
= find_location_by_number (num
);
15191 mark_breakpoint_location_modified (loc
);
15193 if (target_supports_enable_disable_tracepoint ()
15194 && current_trace_status ()->running
&& loc
->owner
15195 && is_tracepoint (loc
->owner
))
15196 target_enable_tracepoint (loc
);
15198 update_global_location_list (UGLL_MAY_INSERT
);
15201 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15202 num
= extract_arg (&args
);
15207 /* This struct packages up disposition data for application to multiple
15217 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15219 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15221 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15225 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15227 struct disp_data disp
= { disp_disable
, 1 };
15229 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15233 enable_once_command (char *args
, int from_tty
)
15235 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15239 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15241 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15243 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15247 enable_count_command (char *args
, int from_tty
)
15252 error_no_arg (_("hit count"));
15254 count
= get_number (&args
);
15256 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15260 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15262 struct disp_data disp
= { disp_del
, 1 };
15264 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15268 enable_delete_command (char *args
, int from_tty
)
15270 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15274 set_breakpoint_cmd (char *args
, int from_tty
)
15279 show_breakpoint_cmd (char *args
, int from_tty
)
15283 /* Invalidate last known value of any hardware watchpoint if
15284 the memory which that value represents has been written to by
15288 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15289 CORE_ADDR addr
, ssize_t len
,
15290 const bfd_byte
*data
)
15292 struct breakpoint
*bp
;
15294 ALL_BREAKPOINTS (bp
)
15295 if (bp
->enable_state
== bp_enabled
15296 && bp
->type
== bp_hardware_watchpoint
)
15298 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15300 if (wp
->val_valid
&& wp
->val
)
15302 struct bp_location
*loc
;
15304 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15305 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15306 && loc
->address
+ loc
->length
> addr
15307 && addr
+ len
> loc
->address
)
15309 value_free (wp
->val
);
15317 /* Create and insert a breakpoint for software single step. */
15320 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15321 struct address_space
*aspace
,
15324 struct thread_info
*tp
= inferior_thread ();
15325 struct symtab_and_line sal
;
15326 CORE_ADDR pc
= next_pc
;
15328 if (tp
->control
.single_step_breakpoints
== NULL
)
15330 tp
->control
.single_step_breakpoints
15331 = new_single_step_breakpoint (tp
->num
, gdbarch
);
15334 sal
= find_pc_line (pc
, 0);
15336 sal
.section
= find_pc_overlay (pc
);
15337 sal
.explicit_pc
= 1;
15338 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15340 update_global_location_list (UGLL_INSERT
);
15343 /* See breakpoint.h. */
15346 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15347 struct address_space
*aspace
,
15350 struct bp_location
*loc
;
15352 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15354 && breakpoint_location_address_match (loc
, aspace
, pc
))
15360 /* Check whether a software single-step breakpoint is inserted at
15364 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15367 struct breakpoint
*bpt
;
15369 ALL_BREAKPOINTS (bpt
)
15371 if (bpt
->type
== bp_single_step
15372 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15378 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15379 non-zero otherwise. */
15381 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15383 if (syscall_catchpoint_p (bp
)
15384 && bp
->enable_state
!= bp_disabled
15385 && bp
->enable_state
!= bp_call_disabled
)
15392 catch_syscall_enabled (void)
15394 struct catch_syscall_inferior_data
*inf_data
15395 = get_catch_syscall_inferior_data (current_inferior ());
15397 return inf_data
->total_syscalls_count
!= 0;
15401 catching_syscall_number (int syscall_number
)
15403 struct breakpoint
*bp
;
15405 ALL_BREAKPOINTS (bp
)
15406 if (is_syscall_catchpoint_enabled (bp
))
15408 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15410 if (c
->syscalls_to_be_caught
)
15414 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15416 if (syscall_number
== iter
)
15426 /* Complete syscall names. Used by "catch syscall". */
15427 static VEC (char_ptr
) *
15428 catch_syscall_completer (struct cmd_list_element
*cmd
,
15429 const char *text
, const char *word
)
15431 const char **list
= get_syscall_names (get_current_arch ());
15432 VEC (char_ptr
) *retlist
15433 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15439 /* Tracepoint-specific operations. */
15441 /* Set tracepoint count to NUM. */
15443 set_tracepoint_count (int num
)
15445 tracepoint_count
= num
;
15446 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15450 trace_command (char *arg
, int from_tty
)
15452 struct breakpoint_ops
*ops
;
15453 const char *arg_cp
= arg
;
15455 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15456 ops
= &tracepoint_probe_breakpoint_ops
;
15458 ops
= &tracepoint_breakpoint_ops
;
15460 create_breakpoint (get_current_arch (),
15462 NULL
, 0, NULL
, 1 /* parse arg */,
15464 bp_tracepoint
/* type_wanted */,
15465 0 /* Ignore count */,
15466 pending_break_support
,
15470 0 /* internal */, 0);
15474 ftrace_command (char *arg
, int from_tty
)
15476 create_breakpoint (get_current_arch (),
15478 NULL
, 0, NULL
, 1 /* parse arg */,
15480 bp_fast_tracepoint
/* type_wanted */,
15481 0 /* Ignore count */,
15482 pending_break_support
,
15483 &tracepoint_breakpoint_ops
,
15486 0 /* internal */, 0);
15489 /* strace command implementation. Creates a static tracepoint. */
15492 strace_command (char *arg
, int from_tty
)
15494 struct breakpoint_ops
*ops
;
15496 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15497 or with a normal static tracepoint. */
15498 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15499 ops
= &strace_marker_breakpoint_ops
;
15501 ops
= &tracepoint_breakpoint_ops
;
15503 create_breakpoint (get_current_arch (),
15505 NULL
, 0, NULL
, 1 /* parse arg */,
15507 bp_static_tracepoint
/* type_wanted */,
15508 0 /* Ignore count */,
15509 pending_break_support
,
15513 0 /* internal */, 0);
15516 /* Set up a fake reader function that gets command lines from a linked
15517 list that was acquired during tracepoint uploading. */
15519 static struct uploaded_tp
*this_utp
;
15520 static int next_cmd
;
15523 read_uploaded_action (void)
15527 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15534 /* Given information about a tracepoint as recorded on a target (which
15535 can be either a live system or a trace file), attempt to create an
15536 equivalent GDB tracepoint. This is not a reliable process, since
15537 the target does not necessarily have all the information used when
15538 the tracepoint was originally defined. */
15540 struct tracepoint
*
15541 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15543 char *addr_str
, small_buf
[100];
15544 struct tracepoint
*tp
;
15546 if (utp
->at_string
)
15547 addr_str
= utp
->at_string
;
15550 /* In the absence of a source location, fall back to raw
15551 address. Since there is no way to confirm that the address
15552 means the same thing as when the trace was started, warn the
15554 warning (_("Uploaded tracepoint %d has no "
15555 "source location, using raw address"),
15557 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15558 addr_str
= small_buf
;
15561 /* There's not much we can do with a sequence of bytecodes. */
15562 if (utp
->cond
&& !utp
->cond_string
)
15563 warning (_("Uploaded tracepoint %d condition "
15564 "has no source form, ignoring it"),
15567 if (!create_breakpoint (get_current_arch (),
15569 utp
->cond_string
, -1, NULL
,
15570 0 /* parse cond/thread */,
15572 utp
->type
/* type_wanted */,
15573 0 /* Ignore count */,
15574 pending_break_support
,
15575 &tracepoint_breakpoint_ops
,
15577 utp
->enabled
/* enabled */,
15579 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15582 /* Get the tracepoint we just created. */
15583 tp
= get_tracepoint (tracepoint_count
);
15584 gdb_assert (tp
!= NULL
);
15588 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15591 trace_pass_command (small_buf
, 0);
15594 /* If we have uploaded versions of the original commands, set up a
15595 special-purpose "reader" function and call the usual command line
15596 reader, then pass the result to the breakpoint command-setting
15598 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15600 struct command_line
*cmd_list
;
15605 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15607 breakpoint_set_commands (&tp
->base
, cmd_list
);
15609 else if (!VEC_empty (char_ptr
, utp
->actions
)
15610 || !VEC_empty (char_ptr
, utp
->step_actions
))
15611 warning (_("Uploaded tracepoint %d actions "
15612 "have no source form, ignoring them"),
15615 /* Copy any status information that might be available. */
15616 tp
->base
.hit_count
= utp
->hit_count
;
15617 tp
->traceframe_usage
= utp
->traceframe_usage
;
15622 /* Print information on tracepoint number TPNUM_EXP, or all if
15626 tracepoints_info (char *args
, int from_tty
)
15628 struct ui_out
*uiout
= current_uiout
;
15631 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15633 if (num_printed
== 0)
15635 if (args
== NULL
|| *args
== '\0')
15636 ui_out_message (uiout
, 0, "No tracepoints.\n");
15638 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15641 default_collect_info ();
15644 /* The 'enable trace' command enables tracepoints.
15645 Not supported by all targets. */
15647 enable_trace_command (char *args
, int from_tty
)
15649 enable_command (args
, from_tty
);
15652 /* The 'disable trace' command disables tracepoints.
15653 Not supported by all targets. */
15655 disable_trace_command (char *args
, int from_tty
)
15657 disable_command (args
, from_tty
);
15660 /* Remove a tracepoint (or all if no argument). */
15662 delete_trace_command (char *arg
, int from_tty
)
15664 struct breakpoint
*b
, *b_tmp
;
15670 int breaks_to_delete
= 0;
15672 /* Delete all breakpoints if no argument.
15673 Do not delete internal or call-dummy breakpoints, these
15674 have to be deleted with an explicit breakpoint number
15676 ALL_TRACEPOINTS (b
)
15677 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15679 breaks_to_delete
= 1;
15683 /* Ask user only if there are some breakpoints to delete. */
15685 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15687 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15688 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15689 delete_breakpoint (b
);
15693 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15696 /* Helper function for trace_pass_command. */
15699 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15701 tp
->pass_count
= count
;
15702 observer_notify_breakpoint_modified (&tp
->base
);
15704 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15705 tp
->base
.number
, count
);
15708 /* Set passcount for tracepoint.
15710 First command argument is passcount, second is tracepoint number.
15711 If tracepoint number omitted, apply to most recently defined.
15712 Also accepts special argument "all". */
15715 trace_pass_command (char *args
, int from_tty
)
15717 struct tracepoint
*t1
;
15718 unsigned int count
;
15720 if (args
== 0 || *args
== 0)
15721 error (_("passcount command requires an "
15722 "argument (count + optional TP num)"));
15724 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15726 args
= skip_spaces (args
);
15727 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15729 struct breakpoint
*b
;
15731 args
+= 3; /* Skip special argument "all". */
15733 error (_("Junk at end of arguments."));
15735 ALL_TRACEPOINTS (b
)
15737 t1
= (struct tracepoint
*) b
;
15738 trace_pass_set_count (t1
, count
, from_tty
);
15741 else if (*args
== '\0')
15743 t1
= get_tracepoint_by_number (&args
, NULL
);
15745 trace_pass_set_count (t1
, count
, from_tty
);
15749 struct get_number_or_range_state state
;
15751 init_number_or_range (&state
, args
);
15752 while (!state
.finished
)
15754 t1
= get_tracepoint_by_number (&args
, &state
);
15756 trace_pass_set_count (t1
, count
, from_tty
);
15761 struct tracepoint
*
15762 get_tracepoint (int num
)
15764 struct breakpoint
*t
;
15766 ALL_TRACEPOINTS (t
)
15767 if (t
->number
== num
)
15768 return (struct tracepoint
*) t
;
15773 /* Find the tracepoint with the given target-side number (which may be
15774 different from the tracepoint number after disconnecting and
15777 struct tracepoint
*
15778 get_tracepoint_by_number_on_target (int num
)
15780 struct breakpoint
*b
;
15782 ALL_TRACEPOINTS (b
)
15784 struct tracepoint
*t
= (struct tracepoint
*) b
;
15786 if (t
->number_on_target
== num
)
15793 /* Utility: parse a tracepoint number and look it up in the list.
15794 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15795 If the argument is missing, the most recent tracepoint
15796 (tracepoint_count) is returned. */
15798 struct tracepoint
*
15799 get_tracepoint_by_number (char **arg
,
15800 struct get_number_or_range_state
*state
)
15802 struct breakpoint
*t
;
15804 char *instring
= arg
== NULL
? NULL
: *arg
;
15808 gdb_assert (!state
->finished
);
15809 tpnum
= get_number_or_range (state
);
15811 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15812 tpnum
= tracepoint_count
;
15814 tpnum
= get_number (arg
);
15818 if (instring
&& *instring
)
15819 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15822 printf_filtered (_("No previous tracepoint\n"));
15826 ALL_TRACEPOINTS (t
)
15827 if (t
->number
== tpnum
)
15829 return (struct tracepoint
*) t
;
15832 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15837 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15839 if (b
->thread
!= -1)
15840 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15843 fprintf_unfiltered (fp
, " task %d", b
->task
);
15845 fprintf_unfiltered (fp
, "\n");
15848 /* Save information on user settable breakpoints (watchpoints, etc) to
15849 a new script file named FILENAME. If FILTER is non-NULL, call it
15850 on each breakpoint and only include the ones for which it returns
15854 save_breakpoints (char *filename
, int from_tty
,
15855 int (*filter
) (const struct breakpoint
*))
15857 struct breakpoint
*tp
;
15859 struct cleanup
*cleanup
;
15860 struct ui_file
*fp
;
15861 int extra_trace_bits
= 0;
15863 if (filename
== 0 || *filename
== 0)
15864 error (_("Argument required (file name in which to save)"));
15866 /* See if we have anything to save. */
15867 ALL_BREAKPOINTS (tp
)
15869 /* Skip internal and momentary breakpoints. */
15870 if (!user_breakpoint_p (tp
))
15873 /* If we have a filter, only save the breakpoints it accepts. */
15874 if (filter
&& !filter (tp
))
15879 if (is_tracepoint (tp
))
15881 extra_trace_bits
= 1;
15883 /* We can stop searching. */
15890 warning (_("Nothing to save."));
15894 filename
= tilde_expand (filename
);
15895 cleanup
= make_cleanup (xfree
, filename
);
15896 fp
= gdb_fopen (filename
, "w");
15898 error (_("Unable to open file '%s' for saving (%s)"),
15899 filename
, safe_strerror (errno
));
15900 make_cleanup_ui_file_delete (fp
);
15902 if (extra_trace_bits
)
15903 save_trace_state_variables (fp
);
15905 ALL_BREAKPOINTS (tp
)
15907 /* Skip internal and momentary breakpoints. */
15908 if (!user_breakpoint_p (tp
))
15911 /* If we have a filter, only save the breakpoints it accepts. */
15912 if (filter
&& !filter (tp
))
15915 tp
->ops
->print_recreate (tp
, fp
);
15917 /* Note, we can't rely on tp->number for anything, as we can't
15918 assume the recreated breakpoint numbers will match. Use $bpnum
15921 if (tp
->cond_string
)
15922 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15924 if (tp
->ignore_count
)
15925 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15927 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15929 struct gdb_exception exception
;
15931 fprintf_unfiltered (fp
, " commands\n");
15933 ui_out_redirect (current_uiout
, fp
);
15936 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15938 CATCH (ex
, RETURN_MASK_ALL
)
15940 ui_out_redirect (current_uiout
, NULL
);
15941 throw_exception (ex
);
15945 ui_out_redirect (current_uiout
, NULL
);
15946 fprintf_unfiltered (fp
, " end\n");
15949 if (tp
->enable_state
== bp_disabled
)
15950 fprintf_unfiltered (fp
, "disable $bpnum\n");
15952 /* If this is a multi-location breakpoint, check if the locations
15953 should be individually disabled. Watchpoint locations are
15954 special, and not user visible. */
15955 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15957 struct bp_location
*loc
;
15960 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15962 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15966 if (extra_trace_bits
&& *default_collect
)
15967 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15970 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15971 do_cleanups (cleanup
);
15974 /* The `save breakpoints' command. */
15977 save_breakpoints_command (char *args
, int from_tty
)
15979 save_breakpoints (args
, from_tty
, NULL
);
15982 /* The `save tracepoints' command. */
15985 save_tracepoints_command (char *args
, int from_tty
)
15987 save_breakpoints (args
, from_tty
, is_tracepoint
);
15990 /* Create a vector of all tracepoints. */
15992 VEC(breakpoint_p
) *
15993 all_tracepoints (void)
15995 VEC(breakpoint_p
) *tp_vec
= 0;
15996 struct breakpoint
*tp
;
15998 ALL_TRACEPOINTS (tp
)
16000 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
16007 /* This help string is used for the break, hbreak, tbreak and thbreak
16008 commands. It is defined as a macro to prevent duplication.
16009 COMMAND should be a string constant containing the name of the
16011 #define BREAK_ARGS_HELP(command) \
16012 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16013 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16014 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16015 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
16016 `-probe-dtrace' (for a DTrace probe).\n\
16017 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16018 If a line number is specified, break at start of code for that line.\n\
16019 If a function is specified, break at start of code for that function.\n\
16020 If an address is specified, break at that exact address.\n\
16021 With no LOCATION, uses current execution address of the selected\n\
16022 stack frame. This is useful for breaking on return to a stack frame.\n\
16024 THREADNUM is the number from \"info threads\".\n\
16025 CONDITION is a boolean expression.\n\
16027 Multiple breakpoints at one place are permitted, and useful if their\n\
16028 conditions are different.\n\
16030 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16032 /* List of subcommands for "catch". */
16033 static struct cmd_list_element
*catch_cmdlist
;
16035 /* List of subcommands for "tcatch". */
16036 static struct cmd_list_element
*tcatch_cmdlist
;
16039 add_catch_command (char *name
, char *docstring
,
16040 cmd_sfunc_ftype
*sfunc
,
16041 completer_ftype
*completer
,
16042 void *user_data_catch
,
16043 void *user_data_tcatch
)
16045 struct cmd_list_element
*command
;
16047 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16049 set_cmd_sfunc (command
, sfunc
);
16050 set_cmd_context (command
, user_data_catch
);
16051 set_cmd_completer (command
, completer
);
16053 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16055 set_cmd_sfunc (command
, sfunc
);
16056 set_cmd_context (command
, user_data_tcatch
);
16057 set_cmd_completer (command
, completer
);
16061 clear_syscall_counts (struct inferior
*inf
)
16063 struct catch_syscall_inferior_data
*inf_data
16064 = get_catch_syscall_inferior_data (inf
);
16066 inf_data
->total_syscalls_count
= 0;
16067 inf_data
->any_syscall_count
= 0;
16068 VEC_free (int, inf_data
->syscalls_counts
);
16072 save_command (char *arg
, int from_tty
)
16074 printf_unfiltered (_("\"save\" must be followed by "
16075 "the name of a save subcommand.\n"));
16076 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
16079 struct breakpoint
*
16080 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
16083 struct breakpoint
*b
, *b_tmp
;
16085 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
16087 if ((*callback
) (b
, data
))
16094 /* Zero if any of the breakpoint's locations could be a location where
16095 functions have been inlined, nonzero otherwise. */
16098 is_non_inline_function (struct breakpoint
*b
)
16100 /* The shared library event breakpoint is set on the address of a
16101 non-inline function. */
16102 if (b
->type
== bp_shlib_event
)
16108 /* Nonzero if the specified PC cannot be a location where functions
16109 have been inlined. */
16112 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
16113 const struct target_waitstatus
*ws
)
16115 struct breakpoint
*b
;
16116 struct bp_location
*bl
;
16118 ALL_BREAKPOINTS (b
)
16120 if (!is_non_inline_function (b
))
16123 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16125 if (!bl
->shlib_disabled
16126 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16134 /* Remove any references to OBJFILE which is going to be freed. */
16137 breakpoint_free_objfile (struct objfile
*objfile
)
16139 struct bp_location
**locp
, *loc
;
16141 ALL_BP_LOCATIONS (loc
, locp
)
16142 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
16143 loc
->symtab
= NULL
;
16147 initialize_breakpoint_ops (void)
16149 static int initialized
= 0;
16151 struct breakpoint_ops
*ops
;
16157 /* The breakpoint_ops structure to be inherit by all kinds of
16158 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16159 internal and momentary breakpoints, etc.). */
16160 ops
= &bkpt_base_breakpoint_ops
;
16161 *ops
= base_breakpoint_ops
;
16162 ops
->re_set
= bkpt_re_set
;
16163 ops
->insert_location
= bkpt_insert_location
;
16164 ops
->remove_location
= bkpt_remove_location
;
16165 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16166 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16167 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16168 ops
->decode_linespec
= bkpt_decode_linespec
;
16170 /* The breakpoint_ops structure to be used in regular breakpoints. */
16171 ops
= &bkpt_breakpoint_ops
;
16172 *ops
= bkpt_base_breakpoint_ops
;
16173 ops
->re_set
= bkpt_re_set
;
16174 ops
->resources_needed
= bkpt_resources_needed
;
16175 ops
->print_it
= bkpt_print_it
;
16176 ops
->print_mention
= bkpt_print_mention
;
16177 ops
->print_recreate
= bkpt_print_recreate
;
16179 /* Ranged breakpoints. */
16180 ops
= &ranged_breakpoint_ops
;
16181 *ops
= bkpt_breakpoint_ops
;
16182 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16183 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16184 ops
->print_it
= print_it_ranged_breakpoint
;
16185 ops
->print_one
= print_one_ranged_breakpoint
;
16186 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16187 ops
->print_mention
= print_mention_ranged_breakpoint
;
16188 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16190 /* Internal breakpoints. */
16191 ops
= &internal_breakpoint_ops
;
16192 *ops
= bkpt_base_breakpoint_ops
;
16193 ops
->re_set
= internal_bkpt_re_set
;
16194 ops
->check_status
= internal_bkpt_check_status
;
16195 ops
->print_it
= internal_bkpt_print_it
;
16196 ops
->print_mention
= internal_bkpt_print_mention
;
16198 /* Momentary breakpoints. */
16199 ops
= &momentary_breakpoint_ops
;
16200 *ops
= bkpt_base_breakpoint_ops
;
16201 ops
->re_set
= momentary_bkpt_re_set
;
16202 ops
->check_status
= momentary_bkpt_check_status
;
16203 ops
->print_it
= momentary_bkpt_print_it
;
16204 ops
->print_mention
= momentary_bkpt_print_mention
;
16206 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16207 ops
= &longjmp_breakpoint_ops
;
16208 *ops
= momentary_breakpoint_ops
;
16209 ops
->dtor
= longjmp_bkpt_dtor
;
16211 /* Probe breakpoints. */
16212 ops
= &bkpt_probe_breakpoint_ops
;
16213 *ops
= bkpt_breakpoint_ops
;
16214 ops
->insert_location
= bkpt_probe_insert_location
;
16215 ops
->remove_location
= bkpt_probe_remove_location
;
16216 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16217 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16220 ops
= &watchpoint_breakpoint_ops
;
16221 *ops
= base_breakpoint_ops
;
16222 ops
->dtor
= dtor_watchpoint
;
16223 ops
->re_set
= re_set_watchpoint
;
16224 ops
->insert_location
= insert_watchpoint
;
16225 ops
->remove_location
= remove_watchpoint
;
16226 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16227 ops
->check_status
= check_status_watchpoint
;
16228 ops
->resources_needed
= resources_needed_watchpoint
;
16229 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16230 ops
->print_it
= print_it_watchpoint
;
16231 ops
->print_mention
= print_mention_watchpoint
;
16232 ops
->print_recreate
= print_recreate_watchpoint
;
16233 ops
->explains_signal
= explains_signal_watchpoint
;
16235 /* Masked watchpoints. */
16236 ops
= &masked_watchpoint_breakpoint_ops
;
16237 *ops
= watchpoint_breakpoint_ops
;
16238 ops
->insert_location
= insert_masked_watchpoint
;
16239 ops
->remove_location
= remove_masked_watchpoint
;
16240 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16241 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16242 ops
->print_it
= print_it_masked_watchpoint
;
16243 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16244 ops
->print_mention
= print_mention_masked_watchpoint
;
16245 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16248 ops
= &tracepoint_breakpoint_ops
;
16249 *ops
= base_breakpoint_ops
;
16250 ops
->re_set
= tracepoint_re_set
;
16251 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16252 ops
->print_one_detail
= tracepoint_print_one_detail
;
16253 ops
->print_mention
= tracepoint_print_mention
;
16254 ops
->print_recreate
= tracepoint_print_recreate
;
16255 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16256 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16257 ops
->decode_linespec
= tracepoint_decode_linespec
;
16259 /* Probe tracepoints. */
16260 ops
= &tracepoint_probe_breakpoint_ops
;
16261 *ops
= tracepoint_breakpoint_ops
;
16262 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16263 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16265 /* Static tracepoints with marker (`-m'). */
16266 ops
= &strace_marker_breakpoint_ops
;
16267 *ops
= tracepoint_breakpoint_ops
;
16268 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16269 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16270 ops
->decode_linespec
= strace_marker_decode_linespec
;
16272 /* Fork catchpoints. */
16273 ops
= &catch_fork_breakpoint_ops
;
16274 *ops
= base_breakpoint_ops
;
16275 ops
->insert_location
= insert_catch_fork
;
16276 ops
->remove_location
= remove_catch_fork
;
16277 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16278 ops
->print_it
= print_it_catch_fork
;
16279 ops
->print_one
= print_one_catch_fork
;
16280 ops
->print_mention
= print_mention_catch_fork
;
16281 ops
->print_recreate
= print_recreate_catch_fork
;
16283 /* Vfork catchpoints. */
16284 ops
= &catch_vfork_breakpoint_ops
;
16285 *ops
= base_breakpoint_ops
;
16286 ops
->insert_location
= insert_catch_vfork
;
16287 ops
->remove_location
= remove_catch_vfork
;
16288 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16289 ops
->print_it
= print_it_catch_vfork
;
16290 ops
->print_one
= print_one_catch_vfork
;
16291 ops
->print_mention
= print_mention_catch_vfork
;
16292 ops
->print_recreate
= print_recreate_catch_vfork
;
16294 /* Exec catchpoints. */
16295 ops
= &catch_exec_breakpoint_ops
;
16296 *ops
= base_breakpoint_ops
;
16297 ops
->dtor
= dtor_catch_exec
;
16298 ops
->insert_location
= insert_catch_exec
;
16299 ops
->remove_location
= remove_catch_exec
;
16300 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16301 ops
->print_it
= print_it_catch_exec
;
16302 ops
->print_one
= print_one_catch_exec
;
16303 ops
->print_mention
= print_mention_catch_exec
;
16304 ops
->print_recreate
= print_recreate_catch_exec
;
16306 /* Syscall catchpoints. */
16307 ops
= &catch_syscall_breakpoint_ops
;
16308 *ops
= base_breakpoint_ops
;
16309 ops
->dtor
= dtor_catch_syscall
;
16310 ops
->insert_location
= insert_catch_syscall
;
16311 ops
->remove_location
= remove_catch_syscall
;
16312 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16313 ops
->print_it
= print_it_catch_syscall
;
16314 ops
->print_one
= print_one_catch_syscall
;
16315 ops
->print_mention
= print_mention_catch_syscall
;
16316 ops
->print_recreate
= print_recreate_catch_syscall
;
16318 /* Solib-related catchpoints. */
16319 ops
= &catch_solib_breakpoint_ops
;
16320 *ops
= base_breakpoint_ops
;
16321 ops
->dtor
= dtor_catch_solib
;
16322 ops
->insert_location
= insert_catch_solib
;
16323 ops
->remove_location
= remove_catch_solib
;
16324 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16325 ops
->check_status
= check_status_catch_solib
;
16326 ops
->print_it
= print_it_catch_solib
;
16327 ops
->print_one
= print_one_catch_solib
;
16328 ops
->print_mention
= print_mention_catch_solib
;
16329 ops
->print_recreate
= print_recreate_catch_solib
;
16331 ops
= &dprintf_breakpoint_ops
;
16332 *ops
= bkpt_base_breakpoint_ops
;
16333 ops
->re_set
= dprintf_re_set
;
16334 ops
->resources_needed
= bkpt_resources_needed
;
16335 ops
->print_it
= bkpt_print_it
;
16336 ops
->print_mention
= bkpt_print_mention
;
16337 ops
->print_recreate
= dprintf_print_recreate
;
16338 ops
->after_condition_true
= dprintf_after_condition_true
;
16339 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16342 /* Chain containing all defined "enable breakpoint" subcommands. */
16344 static struct cmd_list_element
*enablebreaklist
= NULL
;
16347 _initialize_breakpoint (void)
16349 struct cmd_list_element
*c
;
16351 initialize_breakpoint_ops ();
16353 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16354 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16355 observer_attach_inferior_exit (clear_syscall_counts
);
16356 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16358 breakpoint_objfile_key
16359 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16361 catch_syscall_inferior_data
16362 = register_inferior_data_with_cleanup (NULL
,
16363 catch_syscall_inferior_data_cleanup
);
16365 breakpoint_chain
= 0;
16366 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16367 before a breakpoint is set. */
16368 breakpoint_count
= 0;
16370 tracepoint_count
= 0;
16372 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16373 Set ignore-count of breakpoint number N to COUNT.\n\
16374 Usage is `ignore N COUNT'."));
16376 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16378 add_com ("commands", class_breakpoint
, commands_command
, _("\
16379 Set commands to be executed when a breakpoint is hit.\n\
16380 Give breakpoint number as argument after \"commands\".\n\
16381 With no argument, the targeted breakpoint is the last one set.\n\
16382 The commands themselves follow starting on the next line.\n\
16383 Type a line containing \"end\" to indicate the end of them.\n\
16384 Give \"silent\" as the first line to make the breakpoint silent;\n\
16385 then no output is printed when it is hit, except what the commands print."));
16387 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16388 Specify breakpoint number N to break only if COND is true.\n\
16389 Usage is `condition N COND', where N is an integer and COND is an\n\
16390 expression to be evaluated whenever breakpoint N is reached."));
16391 set_cmd_completer (c
, condition_completer
);
16393 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16394 Set a temporary breakpoint.\n\
16395 Like \"break\" except the breakpoint is only temporary,\n\
16396 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16397 by using \"enable delete\" on the breakpoint number.\n\
16399 BREAK_ARGS_HELP ("tbreak")));
16400 set_cmd_completer (c
, location_completer
);
16402 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16403 Set a hardware assisted breakpoint.\n\
16404 Like \"break\" except the breakpoint requires hardware support,\n\
16405 some target hardware may not have this support.\n\
16407 BREAK_ARGS_HELP ("hbreak")));
16408 set_cmd_completer (c
, location_completer
);
16410 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16411 Set a temporary hardware assisted breakpoint.\n\
16412 Like \"hbreak\" except the breakpoint is only temporary,\n\
16413 so it will be deleted when hit.\n\
16415 BREAK_ARGS_HELP ("thbreak")));
16416 set_cmd_completer (c
, location_completer
);
16418 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16419 Enable some breakpoints.\n\
16420 Give breakpoint numbers (separated by spaces) as arguments.\n\
16421 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16422 This is used to cancel the effect of the \"disable\" command.\n\
16423 With a subcommand you can enable temporarily."),
16424 &enablelist
, "enable ", 1, &cmdlist
);
16426 add_com ("ab", class_breakpoint
, enable_command
, _("\
16427 Enable some breakpoints.\n\
16428 Give breakpoint numbers (separated by spaces) as arguments.\n\
16429 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16430 This is used to cancel the effect of the \"disable\" command.\n\
16431 With a subcommand you can enable temporarily."));
16433 add_com_alias ("en", "enable", class_breakpoint
, 1);
16435 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16436 Enable some breakpoints.\n\
16437 Give breakpoint numbers (separated by spaces) as arguments.\n\
16438 This is used to cancel the effect of the \"disable\" command.\n\
16439 May be abbreviated to simply \"enable\".\n"),
16440 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16442 add_cmd ("once", no_class
, enable_once_command
, _("\
16443 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16444 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16447 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16448 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16449 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16452 add_cmd ("count", no_class
, enable_count_command
, _("\
16453 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16454 If a breakpoint is hit while enabled in this fashion,\n\
16455 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16458 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16459 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16460 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16463 add_cmd ("once", no_class
, enable_once_command
, _("\
16464 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16465 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16468 add_cmd ("count", no_class
, enable_count_command
, _("\
16469 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16470 If a breakpoint is hit while enabled in this fashion,\n\
16471 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16474 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16475 Disable some breakpoints.\n\
16476 Arguments are breakpoint numbers with spaces in between.\n\
16477 To disable all breakpoints, give no argument.\n\
16478 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16479 &disablelist
, "disable ", 1, &cmdlist
);
16480 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16481 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16483 add_com ("sb", class_breakpoint
, disable_command
, _("\
16484 Disable some breakpoints.\n\
16485 Arguments are breakpoint numbers with spaces in between.\n\
16486 To disable all breakpoints, give no argument.\n\
16487 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16489 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16490 Disable some breakpoints.\n\
16491 Arguments are breakpoint numbers with spaces in between.\n\
16492 To disable all breakpoints, give no argument.\n\
16493 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16494 This command may be abbreviated \"disable\"."),
16497 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16498 Delete some breakpoints or auto-display expressions.\n\
16499 Arguments are breakpoint numbers with spaces in between.\n\
16500 To delete all breakpoints, give no argument.\n\
16502 Also a prefix command for deletion of other GDB objects.\n\
16503 The \"unset\" command is also an alias for \"delete\"."),
16504 &deletelist
, "delete ", 1, &cmdlist
);
16505 add_com_alias ("d", "delete", class_breakpoint
, 1);
16506 add_com_alias ("del", "delete", class_breakpoint
, 1);
16508 add_com ("db", class_breakpoint
, delete_command
, _("\
16509 Delete some breakpoints.\n\
16510 Arguments are breakpoint numbers with spaces in between.\n\
16511 To delete all breakpoints, give no argument.\n"));
16513 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16514 Delete some breakpoints or auto-display expressions.\n\
16515 Arguments are breakpoint numbers with spaces in between.\n\
16516 To delete all breakpoints, give no argument.\n\
16517 This command may be abbreviated \"delete\"."),
16520 add_com ("clear", class_breakpoint
, clear_command
, _("\
16521 Clear breakpoint at specified line or function.\n\
16522 Argument may be line number, function name, or \"*\" and an address.\n\
16523 If line number is specified, all breakpoints in that line are cleared.\n\
16524 If function is specified, breakpoints at beginning of function are cleared.\n\
16525 If an address is specified, breakpoints at that address are cleared.\n\
16527 With no argument, clears all breakpoints in the line that the selected frame\n\
16528 is executing in.\n\
16530 See also the \"delete\" command which clears breakpoints by number."));
16531 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16533 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16534 Set breakpoint at specified line or function.\n"
16535 BREAK_ARGS_HELP ("break")));
16536 set_cmd_completer (c
, location_completer
);
16538 add_com_alias ("b", "break", class_run
, 1);
16539 add_com_alias ("br", "break", class_run
, 1);
16540 add_com_alias ("bre", "break", class_run
, 1);
16541 add_com_alias ("brea", "break", class_run
, 1);
16544 add_com_alias ("ba", "break", class_breakpoint
, 1);
16548 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16549 Break in function/address or break at a line in the current file."),
16550 &stoplist
, "stop ", 1, &cmdlist
);
16551 add_cmd ("in", class_breakpoint
, stopin_command
,
16552 _("Break in function or address."), &stoplist
);
16553 add_cmd ("at", class_breakpoint
, stopat_command
,
16554 _("Break at a line in the current file."), &stoplist
);
16555 add_com ("status", class_info
, 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."));
16572 add_info ("breakpoints", breakpoints_info
, _("\
16573 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16574 The \"Type\" column indicates one of:\n\
16575 \tbreakpoint - normal breakpoint\n\
16576 \twatchpoint - watchpoint\n\
16577 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16578 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16579 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16580 address and file/line number respectively.\n\
16582 Convenience variable \"$_\" and default examine address for \"x\"\n\
16583 are set to the address of the last breakpoint listed unless the command\n\
16584 is prefixed with \"server \".\n\n\
16585 Convenience variable \"$bpnum\" contains the number of the last\n\
16586 breakpoint set."));
16588 add_info_alias ("b", "breakpoints", 1);
16591 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16592 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16593 The \"Type\" column indicates one of:\n\
16594 \tbreakpoint - normal breakpoint\n\
16595 \twatchpoint - watchpoint\n\
16596 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16597 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16598 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16599 address and file/line number respectively.\n\
16601 Convenience variable \"$_\" and default examine address for \"x\"\n\
16602 are set to the address of the last breakpoint listed unless the command\n\
16603 is prefixed with \"server \".\n\n\
16604 Convenience variable \"$bpnum\" contains the number of the last\n\
16605 breakpoint set."));
16607 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16608 Status of all breakpoints, or breakpoint number NUMBER.\n\
16609 The \"Type\" column indicates one of:\n\
16610 \tbreakpoint - normal breakpoint\n\
16611 \twatchpoint - watchpoint\n\
16612 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16613 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16614 \tuntil - internal breakpoint used by the \"until\" command\n\
16615 \tfinish - internal breakpoint used by the \"finish\" command\n\
16616 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16617 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16618 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16619 address and file/line number respectively.\n\
16621 Convenience variable \"$_\" and default examine address for \"x\"\n\
16622 are set to the address of the last breakpoint listed unless the command\n\
16623 is prefixed with \"server \".\n\n\
16624 Convenience variable \"$bpnum\" contains the number of the last\n\
16626 &maintenanceinfolist
);
16628 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16629 Set catchpoints to catch events."),
16630 &catch_cmdlist
, "catch ",
16631 0/*allow-unknown*/, &cmdlist
);
16633 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16634 Set temporary catchpoints to catch events."),
16635 &tcatch_cmdlist
, "tcatch ",
16636 0/*allow-unknown*/, &cmdlist
);
16638 add_catch_command ("fork", _("Catch calls to fork."),
16639 catch_fork_command_1
,
16641 (void *) (uintptr_t) catch_fork_permanent
,
16642 (void *) (uintptr_t) catch_fork_temporary
);
16643 add_catch_command ("vfork", _("Catch calls to vfork."),
16644 catch_fork_command_1
,
16646 (void *) (uintptr_t) catch_vfork_permanent
,
16647 (void *) (uintptr_t) catch_vfork_temporary
);
16648 add_catch_command ("exec", _("Catch calls to exec."),
16649 catch_exec_command_1
,
16653 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16654 Usage: catch load [REGEX]\n\
16655 If REGEX is given, only stop for libraries matching the regular expression."),
16656 catch_load_command_1
,
16660 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16661 Usage: catch unload [REGEX]\n\
16662 If REGEX is given, only stop for libraries matching the regular expression."),
16663 catch_unload_command_1
,
16667 add_catch_command ("syscall", _("\
16668 Catch system calls by their names and/or numbers.\n\
16669 Arguments say which system calls to catch. If no arguments\n\
16670 are given, every system call will be caught.\n\
16671 Arguments, if given, should be one or more system call names\n\
16672 (if your system supports that), or system call numbers."),
16673 catch_syscall_command_1
,
16674 catch_syscall_completer
,
16678 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16679 Set a watchpoint for an expression.\n\
16680 Usage: watch [-l|-location] EXPRESSION\n\
16681 A watchpoint stops execution of your program whenever the value of\n\
16682 an expression changes.\n\
16683 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16684 the memory to which it refers."));
16685 set_cmd_completer (c
, expression_completer
);
16687 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16688 Set a read watchpoint for an expression.\n\
16689 Usage: rwatch [-l|-location] EXPRESSION\n\
16690 A watchpoint stops execution of your program whenever the value of\n\
16691 an expression is read.\n\
16692 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16693 the memory to which it refers."));
16694 set_cmd_completer (c
, expression_completer
);
16696 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16697 Set a watchpoint for an expression.\n\
16698 Usage: awatch [-l|-location] EXPRESSION\n\
16699 A watchpoint stops execution of your program whenever the value of\n\
16700 an expression is either read or written.\n\
16701 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16702 the memory to which it refers."));
16703 set_cmd_completer (c
, expression_completer
);
16705 add_info ("watchpoints", watchpoints_info
, _("\
16706 Status of specified watchpoints (all watchpoints if no argument)."));
16708 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16709 respond to changes - contrary to the description. */
16710 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16711 &can_use_hw_watchpoints
, _("\
16712 Set debugger's willingness to use watchpoint hardware."), _("\
16713 Show debugger's willingness to use watchpoint hardware."), _("\
16714 If zero, gdb will not use hardware for new watchpoints, even if\n\
16715 such is available. (However, any hardware watchpoints that were\n\
16716 created before setting this to nonzero, will continue to use watchpoint\n\
16719 show_can_use_hw_watchpoints
,
16720 &setlist
, &showlist
);
16722 can_use_hw_watchpoints
= 1;
16724 /* Tracepoint manipulation commands. */
16726 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16727 Set a tracepoint at specified line or function.\n\
16729 BREAK_ARGS_HELP ("trace") "\n\
16730 Do \"help tracepoints\" for info on other tracepoint commands."));
16731 set_cmd_completer (c
, location_completer
);
16733 add_com_alias ("tp", "trace", class_alias
, 0);
16734 add_com_alias ("tr", "trace", class_alias
, 1);
16735 add_com_alias ("tra", "trace", class_alias
, 1);
16736 add_com_alias ("trac", "trace", class_alias
, 1);
16738 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16739 Set a fast tracepoint at specified line or function.\n\
16741 BREAK_ARGS_HELP ("ftrace") "\n\
16742 Do \"help tracepoints\" for info on other tracepoint commands."));
16743 set_cmd_completer (c
, location_completer
);
16745 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16746 Set a static tracepoint at specified line, function or marker.\n\
16748 strace [LOCATION] [if CONDITION]\n\
16749 LOCATION may be a line number, function name, \"*\" and an address,\n\
16750 or -m MARKER_ID.\n\
16751 If a line number is specified, probe the marker at start of code\n\
16752 for that line. If a function is specified, probe the marker at start\n\
16753 of code for that function. If an address is specified, probe the marker\n\
16754 at that exact address. If a marker id is specified, probe the marker\n\
16755 with that name. With no LOCATION, uses current execution address of\n\
16756 the selected stack frame.\n\
16757 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16758 This collects arbitrary user data passed in the probe point call to the\n\
16759 tracing library. You can inspect it when analyzing the trace buffer,\n\
16760 by printing the $_sdata variable like any other convenience variable.\n\
16762 CONDITION is a boolean expression.\n\
16764 Multiple tracepoints at one place are permitted, and useful if their\n\
16765 conditions are different.\n\
16767 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16768 Do \"help tracepoints\" for info on other tracepoint commands."));
16769 set_cmd_completer (c
, location_completer
);
16771 add_info ("tracepoints", tracepoints_info
, _("\
16772 Status of specified tracepoints (all tracepoints if no argument).\n\
16773 Convenience variable \"$tpnum\" contains the number of the\n\
16774 last tracepoint set."));
16776 add_info_alias ("tp", "tracepoints", 1);
16778 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16779 Delete specified tracepoints.\n\
16780 Arguments are tracepoint numbers, separated by spaces.\n\
16781 No argument means delete all tracepoints."),
16783 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16785 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16786 Disable specified tracepoints.\n\
16787 Arguments are tracepoint numbers, separated by spaces.\n\
16788 No argument means disable all tracepoints."),
16790 deprecate_cmd (c
, "disable");
16792 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16793 Enable specified tracepoints.\n\
16794 Arguments are tracepoint numbers, separated by spaces.\n\
16795 No argument means enable all tracepoints."),
16797 deprecate_cmd (c
, "enable");
16799 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16800 Set the passcount for a tracepoint.\n\
16801 The trace will end when the tracepoint has been passed 'count' times.\n\
16802 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16803 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16805 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16806 _("Save breakpoint definitions as a script."),
16807 &save_cmdlist
, "save ",
16808 0/*allow-unknown*/, &cmdlist
);
16810 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16811 Save current breakpoint definitions as a script.\n\
16812 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16813 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16814 session to restore them."),
16816 set_cmd_completer (c
, filename_completer
);
16818 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16819 Save current tracepoint definitions as a script.\n\
16820 Use the 'source' command in another debug session to restore them."),
16822 set_cmd_completer (c
, filename_completer
);
16824 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16825 deprecate_cmd (c
, "save tracepoints");
16827 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16828 Breakpoint specific settings\n\
16829 Configure various breakpoint-specific variables such as\n\
16830 pending breakpoint behavior"),
16831 &breakpoint_set_cmdlist
, "set breakpoint ",
16832 0/*allow-unknown*/, &setlist
);
16833 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16834 Breakpoint specific settings\n\
16835 Configure various breakpoint-specific variables such as\n\
16836 pending breakpoint behavior"),
16837 &breakpoint_show_cmdlist
, "show breakpoint ",
16838 0/*allow-unknown*/, &showlist
);
16840 add_setshow_auto_boolean_cmd ("pending", no_class
,
16841 &pending_break_support
, _("\
16842 Set debugger's behavior regarding pending breakpoints."), _("\
16843 Show debugger's behavior regarding pending breakpoints."), _("\
16844 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16845 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16846 an error. If auto, an unrecognized breakpoint location results in a\n\
16847 user-query to see if a pending breakpoint should be created."),
16849 show_pending_break_support
,
16850 &breakpoint_set_cmdlist
,
16851 &breakpoint_show_cmdlist
);
16853 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16855 add_setshow_boolean_cmd ("auto-hw", no_class
,
16856 &automatic_hardware_breakpoints
, _("\
16857 Set automatic usage of hardware breakpoints."), _("\
16858 Show automatic usage of hardware breakpoints."), _("\
16859 If set, the debugger will automatically use hardware breakpoints for\n\
16860 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16861 a warning will be emitted for such breakpoints."),
16863 show_automatic_hardware_breakpoints
,
16864 &breakpoint_set_cmdlist
,
16865 &breakpoint_show_cmdlist
);
16867 add_setshow_boolean_cmd ("always-inserted", class_support
,
16868 &always_inserted_mode
, _("\
16869 Set mode for inserting breakpoints."), _("\
16870 Show mode for inserting breakpoints."), _("\
16871 When this mode is on, breakpoints are inserted immediately as soon as\n\
16872 they're created, kept inserted even when execution stops, and removed\n\
16873 only when the user deletes them. When this mode is off (the default),\n\
16874 breakpoints are inserted only when execution continues, and removed\n\
16875 when execution stops."),
16877 &show_always_inserted_mode
,
16878 &breakpoint_set_cmdlist
,
16879 &breakpoint_show_cmdlist
);
16881 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16882 condition_evaluation_enums
,
16883 &condition_evaluation_mode_1
, _("\
16884 Set mode of breakpoint condition evaluation."), _("\
16885 Show mode of breakpoint condition evaluation."), _("\
16886 When this is set to \"host\", breakpoint conditions will be\n\
16887 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16888 breakpoint conditions will be downloaded to the target (if the target\n\
16889 supports such feature) and conditions will be evaluated on the target's side.\n\
16890 If this is set to \"auto\" (default), this will be automatically set to\n\
16891 \"target\" if it supports condition evaluation, otherwise it will\n\
16892 be set to \"gdb\""),
16893 &set_condition_evaluation_mode
,
16894 &show_condition_evaluation_mode
,
16895 &breakpoint_set_cmdlist
,
16896 &breakpoint_show_cmdlist
);
16898 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16899 Set a breakpoint for an address range.\n\
16900 break-range START-LOCATION, END-LOCATION\n\
16901 where START-LOCATION and END-LOCATION can be one of the following:\n\
16902 LINENUM, for that line in the current file,\n\
16903 FILE:LINENUM, for that line in that file,\n\
16904 +OFFSET, for that number of lines after the current line\n\
16905 or the start of the range\n\
16906 FUNCTION, for the first line in that function,\n\
16907 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16908 *ADDRESS, for the instruction at that address.\n\
16910 The breakpoint will stop execution of the inferior whenever it executes\n\
16911 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16912 range (including START-LOCATION and END-LOCATION)."));
16914 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16915 Set a dynamic printf at specified line or function.\n\
16916 dprintf location,format string,arg1,arg2,...\n\
16917 location may be a line number, function name, or \"*\" and an address.\n\
16918 If a line number is specified, break at start of code for that line.\n\
16919 If a function is specified, break at start of code for that function."));
16920 set_cmd_completer (c
, location_completer
);
16922 add_setshow_enum_cmd ("dprintf-style", class_support
,
16923 dprintf_style_enums
, &dprintf_style
, _("\
16924 Set the style of usage for dynamic printf."), _("\
16925 Show the style of usage for dynamic printf."), _("\
16926 This setting chooses how GDB will do a dynamic printf.\n\
16927 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16928 console, as with the \"printf\" command.\n\
16929 If the value is \"call\", the print is done by calling a function in your\n\
16930 program; by default printf(), but you can choose a different function or\n\
16931 output stream by setting dprintf-function and dprintf-channel."),
16932 update_dprintf_commands
, NULL
,
16933 &setlist
, &showlist
);
16935 dprintf_function
= xstrdup ("printf");
16936 add_setshow_string_cmd ("dprintf-function", class_support
,
16937 &dprintf_function
, _("\
16938 Set the function to use for dynamic printf"), _("\
16939 Show the function to use for dynamic printf"), NULL
,
16940 update_dprintf_commands
, NULL
,
16941 &setlist
, &showlist
);
16943 dprintf_channel
= xstrdup ("");
16944 add_setshow_string_cmd ("dprintf-channel", class_support
,
16945 &dprintf_channel
, _("\
16946 Set the channel to use for dynamic printf"), _("\
16947 Show the channel to use for dynamic printf"), NULL
,
16948 update_dprintf_commands
, NULL
,
16949 &setlist
, &showlist
);
16951 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16952 &disconnected_dprintf
, _("\
16953 Set whether dprintf continues after GDB disconnects."), _("\
16954 Show whether dprintf continues after GDB disconnects."), _("\
16955 Use this to let dprintf commands continue to hit and produce output\n\
16956 even if GDB disconnects or detaches from the target."),
16959 &setlist
, &showlist
);
16961 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16962 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16963 (target agent only) This is useful for formatted output in user-defined commands."));
16965 automatic_hardware_breakpoints
= 1;
16967 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16968 observer_attach_thread_exit (remove_threaded_breakpoints
);