1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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 abstract base class all breakpoint_ops structures inherit
302 struct breakpoint_ops base_breakpoint_ops
;
304 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
305 that are implemented on top of software or hardware breakpoints
306 (user breakpoints, internal and momentary breakpoints, etc.). */
307 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
309 /* Internal breakpoints class type. */
310 static struct breakpoint_ops internal_breakpoint_ops
;
312 /* Momentary breakpoints class type. */
313 static struct breakpoint_ops momentary_breakpoint_ops
;
315 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
316 static struct breakpoint_ops longjmp_breakpoint_ops
;
318 /* The breakpoint_ops structure to be used in regular user created
320 struct breakpoint_ops bkpt_breakpoint_ops
;
322 /* Breakpoints set on probes. */
323 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
325 /* Dynamic printf class type. */
326 struct breakpoint_ops dprintf_breakpoint_ops
;
328 /* The style in which to perform a dynamic printf. This is a user
329 option because different output options have different tradeoffs;
330 if GDB does the printing, there is better error handling if there
331 is a problem with any of the arguments, but using an inferior
332 function lets you have special-purpose printers and sending of
333 output to the same place as compiled-in print functions. */
335 static const char dprintf_style_gdb
[] = "gdb";
336 static const char dprintf_style_call
[] = "call";
337 static const char dprintf_style_agent
[] = "agent";
338 static const char *const dprintf_style_enums
[] = {
344 static const char *dprintf_style
= dprintf_style_gdb
;
346 /* The function to use for dynamic printf if the preferred style is to
347 call into the inferior. The value is simply a string that is
348 copied into the command, so it can be anything that GDB can
349 evaluate to a callable address, not necessarily a function name. */
351 static char *dprintf_function
= "";
353 /* The channel to use for dynamic printf if the preferred style is to
354 call into the inferior; if a nonempty string, it will be passed to
355 the call as the first argument, with the format string as the
356 second. As with the dprintf function, this can be anything that
357 GDB knows how to evaluate, so in addition to common choices like
358 "stderr", this could be an app-specific expression like
359 "mystreams[curlogger]". */
361 static char *dprintf_channel
= "";
363 /* True if dprintf commands should continue to operate even if GDB
365 static int disconnected_dprintf
= 1;
367 /* A reference-counted struct command_line. This lets multiple
368 breakpoints share a single command list. */
369 struct counted_command_line
371 /* The reference count. */
374 /* The command list. */
375 struct command_line
*commands
;
378 struct command_line
*
379 breakpoint_commands (struct breakpoint
*b
)
381 return b
->commands
? b
->commands
->commands
: NULL
;
384 /* Flag indicating that a command has proceeded the inferior past the
385 current breakpoint. */
387 static int breakpoint_proceeded
;
390 bpdisp_text (enum bpdisp disp
)
392 /* NOTE: the following values are a part of MI protocol and
393 represent values of 'disp' field returned when inferior stops at
395 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
397 return bpdisps
[(int) disp
];
400 /* Prototypes for exported functions. */
401 /* If FALSE, gdb will not use hardware support for watchpoints, even
402 if such is available. */
403 static int can_use_hw_watchpoints
;
406 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
407 struct cmd_list_element
*c
,
410 fprintf_filtered (file
,
411 _("Debugger's willingness to use "
412 "watchpoint hardware is %s.\n"),
416 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
417 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
418 for unrecognized breakpoint locations.
419 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
420 static enum auto_boolean pending_break_support
;
422 show_pending_break_support (struct ui_file
*file
, int from_tty
,
423 struct cmd_list_element
*c
,
426 fprintf_filtered (file
,
427 _("Debugger's behavior regarding "
428 "pending breakpoints is %s.\n"),
432 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
433 set with "break" but falling in read-only memory.
434 If 0, gdb will warn about such breakpoints, but won't automatically
435 use hardware breakpoints. */
436 static int automatic_hardware_breakpoints
;
438 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
439 struct cmd_list_element
*c
,
442 fprintf_filtered (file
,
443 _("Automatic usage of hardware breakpoints is %s.\n"),
447 /* If on, GDB keeps breakpoints inserted even if the inferior is
448 stopped, and immediately inserts any new breakpoints as soon as
449 they're created. If off (default), GDB keeps breakpoints off of
450 the target as long as possible. That is, it delays inserting
451 breakpoints until the next resume, and removes them again when the
452 target fully stops. This is a bit safer in case GDB crashes while
453 processing user input. */
454 static int always_inserted_mode
= 0;
457 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
458 struct cmd_list_element
*c
, const char *value
)
460 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
464 /* See breakpoint.h. */
467 breakpoints_should_be_inserted_now (void)
469 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
471 /* If breakpoints are global, they should be inserted even if no
472 thread under gdb's control is running, or even if there are
473 no threads under GDB's control yet. */
476 else if (target_has_execution
)
478 if (always_inserted_mode
)
480 /* The user wants breakpoints inserted even if all threads
485 if (threads_are_executing ())
491 static const char condition_evaluation_both
[] = "host or target";
493 /* Modes for breakpoint condition evaluation. */
494 static const char condition_evaluation_auto
[] = "auto";
495 static const char condition_evaluation_host
[] = "host";
496 static const char condition_evaluation_target
[] = "target";
497 static const char *const condition_evaluation_enums
[] = {
498 condition_evaluation_auto
,
499 condition_evaluation_host
,
500 condition_evaluation_target
,
504 /* Global that holds the current mode for breakpoint condition evaluation. */
505 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
507 /* Global that we use to display information to the user (gets its value from
508 condition_evaluation_mode_1. */
509 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
511 /* Translate a condition evaluation mode MODE into either "host"
512 or "target". This is used mostly to translate from "auto" to the
513 real setting that is being used. It returns the translated
517 translate_condition_evaluation_mode (const char *mode
)
519 if (mode
== condition_evaluation_auto
)
521 if (target_supports_evaluation_of_breakpoint_conditions ())
522 return condition_evaluation_target
;
524 return condition_evaluation_host
;
530 /* Discovers what condition_evaluation_auto translates to. */
533 breakpoint_condition_evaluation_mode (void)
535 return translate_condition_evaluation_mode (condition_evaluation_mode
);
538 /* Return true if GDB should evaluate breakpoint conditions or false
542 gdb_evaluates_breakpoint_condition_p (void)
544 const char *mode
= breakpoint_condition_evaluation_mode ();
546 return (mode
== condition_evaluation_host
);
549 void _initialize_breakpoint (void);
551 /* Are we executing breakpoint commands? */
552 static int executing_breakpoint_commands
;
554 /* Are overlay event breakpoints enabled? */
555 static int overlay_events_enabled
;
557 /* See description in breakpoint.h. */
558 int target_exact_watchpoints
= 0;
560 /* Walk the following statement or block through all breakpoints.
561 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
562 current breakpoint. */
564 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
566 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
567 for (B = breakpoint_chain; \
568 B ? (TMP=B->next, 1): 0; \
571 /* Similar iterator for the low-level breakpoints. SAFE variant is
572 not provided so update_global_location_list must not be called
573 while executing the block of ALL_BP_LOCATIONS. */
575 #define ALL_BP_LOCATIONS(B,BP_TMP) \
576 for (BP_TMP = bp_location; \
577 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
580 /* Iterates through locations with address ADDRESS for the currently selected
581 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
582 to where the loop should start from.
583 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
584 appropriate location to start with. */
586 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
587 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
588 BP_LOCP_TMP = BP_LOCP_START; \
590 && (BP_LOCP_TMP < bp_location + bp_location_count \
591 && (*BP_LOCP_TMP)->address == ADDRESS); \
594 /* Iterator for tracepoints only. */
596 #define ALL_TRACEPOINTS(B) \
597 for (B = breakpoint_chain; B; B = B->next) \
598 if (is_tracepoint (B))
600 /* Chains of all breakpoints defined. */
602 struct breakpoint
*breakpoint_chain
;
604 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
606 static struct bp_location
**bp_location
;
608 /* Number of elements of BP_LOCATION. */
610 static unsigned bp_location_count
;
612 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
613 ADDRESS for the current elements of BP_LOCATION which get a valid
614 result from bp_location_has_shadow. You can use it for roughly
615 limiting the subrange of BP_LOCATION to scan for shadow bytes for
616 an address you need to read. */
618 static CORE_ADDR bp_location_placed_address_before_address_max
;
620 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
621 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
622 BP_LOCATION which get a valid result from bp_location_has_shadow.
623 You can use it for roughly limiting the subrange of BP_LOCATION to
624 scan for shadow bytes for an address you need to read. */
626 static CORE_ADDR bp_location_shadow_len_after_address_max
;
628 /* The locations that no longer correspond to any breakpoint, unlinked
629 from bp_location array, but for which a hit may still be reported
631 VEC(bp_location_p
) *moribund_locations
= NULL
;
633 /* Number of last breakpoint made. */
635 static int breakpoint_count
;
637 /* The value of `breakpoint_count' before the last command that
638 created breakpoints. If the last (break-like) command created more
639 than one breakpoint, then the difference between BREAKPOINT_COUNT
640 and PREV_BREAKPOINT_COUNT is more than one. */
641 static int prev_breakpoint_count
;
643 /* Number of last tracepoint made. */
645 static int tracepoint_count
;
647 static struct cmd_list_element
*breakpoint_set_cmdlist
;
648 static struct cmd_list_element
*breakpoint_show_cmdlist
;
649 struct cmd_list_element
*save_cmdlist
;
651 /* Return whether a breakpoint is an active enabled breakpoint. */
653 breakpoint_enabled (struct breakpoint
*b
)
655 return (b
->enable_state
== bp_enabled
);
658 /* Set breakpoint count to NUM. */
661 set_breakpoint_count (int num
)
663 prev_breakpoint_count
= breakpoint_count
;
664 breakpoint_count
= num
;
665 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
668 /* Used by `start_rbreak_breakpoints' below, to record the current
669 breakpoint count before "rbreak" creates any breakpoint. */
670 static int rbreak_start_breakpoint_count
;
672 /* Called at the start an "rbreak" command to record the first
676 start_rbreak_breakpoints (void)
678 rbreak_start_breakpoint_count
= breakpoint_count
;
681 /* Called at the end of an "rbreak" command to record the last
685 end_rbreak_breakpoints (void)
687 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
690 /* Used in run_command to zero the hit count when a new run starts. */
693 clear_breakpoint_hit_counts (void)
695 struct breakpoint
*b
;
701 /* Allocate a new counted_command_line with reference count of 1.
702 The new structure owns COMMANDS. */
704 static struct counted_command_line
*
705 alloc_counted_command_line (struct command_line
*commands
)
707 struct counted_command_line
*result
708 = xmalloc (sizeof (struct counted_command_line
));
711 result
->commands
= commands
;
715 /* Increment reference count. This does nothing if CMD is NULL. */
718 incref_counted_command_line (struct counted_command_line
*cmd
)
724 /* Decrement reference count. If the reference count reaches 0,
725 destroy the counted_command_line. Sets *CMDP to NULL. This does
726 nothing if *CMDP is NULL. */
729 decref_counted_command_line (struct counted_command_line
**cmdp
)
733 if (--(*cmdp
)->refc
== 0)
735 free_command_lines (&(*cmdp
)->commands
);
742 /* A cleanup function that calls decref_counted_command_line. */
745 do_cleanup_counted_command_line (void *arg
)
747 decref_counted_command_line (arg
);
750 /* Create a cleanup that calls decref_counted_command_line on the
753 static struct cleanup
*
754 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
756 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
760 /* Return the breakpoint with the specified number, or NULL
761 if the number does not refer to an existing breakpoint. */
764 get_breakpoint (int num
)
766 struct breakpoint
*b
;
769 if (b
->number
== num
)
777 /* Mark locations as "conditions have changed" in case the target supports
778 evaluating conditions on its side. */
781 mark_breakpoint_modified (struct breakpoint
*b
)
783 struct bp_location
*loc
;
785 /* This is only meaningful if the target is
786 evaluating conditions and if the user has
787 opted for condition evaluation on the target's
789 if (gdb_evaluates_breakpoint_condition_p ()
790 || !target_supports_evaluation_of_breakpoint_conditions ())
793 if (!is_breakpoint (b
))
796 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
797 loc
->condition_changed
= condition_modified
;
800 /* Mark location as "conditions have changed" in case the target supports
801 evaluating conditions on its side. */
804 mark_breakpoint_location_modified (struct bp_location
*loc
)
806 /* This is only meaningful if the target is
807 evaluating conditions and if the user has
808 opted for condition evaluation on the target's
810 if (gdb_evaluates_breakpoint_condition_p ()
811 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (loc
->owner
))
818 loc
->condition_changed
= condition_modified
;
821 /* Sets the condition-evaluation mode using the static global
822 condition_evaluation_mode. */
825 set_condition_evaluation_mode (char *args
, int from_tty
,
826 struct cmd_list_element
*c
)
828 const char *old_mode
, *new_mode
;
830 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
831 && !target_supports_evaluation_of_breakpoint_conditions ())
833 condition_evaluation_mode_1
= condition_evaluation_mode
;
834 warning (_("Target does not support breakpoint condition evaluation.\n"
835 "Using host evaluation mode instead."));
839 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
840 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
842 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
843 settings was "auto". */
844 condition_evaluation_mode
= condition_evaluation_mode_1
;
846 /* Only update the mode if the user picked a different one. */
847 if (new_mode
!= old_mode
)
849 struct bp_location
*loc
, **loc_tmp
;
850 /* If the user switched to a different evaluation mode, we
851 need to synch the changes with the target as follows:
853 "host" -> "target": Send all (valid) conditions to the target.
854 "target" -> "host": Remove all the conditions from the target.
857 if (new_mode
== condition_evaluation_target
)
859 /* Mark everything modified and synch conditions with the
861 ALL_BP_LOCATIONS (loc
, loc_tmp
)
862 mark_breakpoint_location_modified (loc
);
866 /* Manually mark non-duplicate locations to synch conditions
867 with the target. We do this to remove all the conditions the
868 target knows about. */
869 ALL_BP_LOCATIONS (loc
, loc_tmp
)
870 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
871 loc
->needs_update
= 1;
875 update_global_location_list (UGLL_MAY_INSERT
);
881 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
882 what "auto" is translating to. */
885 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
886 struct cmd_list_element
*c
, const char *value
)
888 if (condition_evaluation_mode
== condition_evaluation_auto
)
889 fprintf_filtered (file
,
890 _("Breakpoint condition evaluation "
891 "mode is %s (currently %s).\n"),
893 breakpoint_condition_evaluation_mode ());
895 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
899 /* A comparison function for bp_location AP and BP that is used by
900 bsearch. This comparison function only cares about addresses, unlike
901 the more general bp_location_compare function. */
904 bp_location_compare_addrs (const void *ap
, const void *bp
)
906 struct bp_location
*a
= *(void **) ap
;
907 struct bp_location
*b
= *(void **) bp
;
909 if (a
->address
== b
->address
)
912 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
915 /* Helper function to skip all bp_locations with addresses
916 less than ADDRESS. It returns the first bp_location that
917 is greater than or equal to ADDRESS. If none is found, just
920 static struct bp_location
**
921 get_first_locp_gte_addr (CORE_ADDR address
)
923 struct bp_location dummy_loc
;
924 struct bp_location
*dummy_locp
= &dummy_loc
;
925 struct bp_location
**locp_found
= NULL
;
927 /* Initialize the dummy location's address field. */
928 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
929 dummy_loc
.address
= address
;
931 /* Find a close match to the first location at ADDRESS. */
932 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
933 sizeof (struct bp_location
**),
934 bp_location_compare_addrs
);
936 /* Nothing was found, nothing left to do. */
937 if (locp_found
== NULL
)
940 /* We may have found a location that is at ADDRESS but is not the first in the
941 location's list. Go backwards (if possible) and locate the first one. */
942 while ((locp_found
- 1) >= bp_location
943 && (*(locp_found
- 1))->address
== address
)
950 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
953 xfree (b
->cond_string
);
954 b
->cond_string
= NULL
;
956 if (is_watchpoint (b
))
958 struct watchpoint
*w
= (struct watchpoint
*) b
;
965 struct bp_location
*loc
;
967 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
972 /* No need to free the condition agent expression
973 bytecode (if we have one). We will handle this
974 when we go through update_global_location_list. */
981 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
985 const char *arg
= exp
;
987 /* I don't know if it matters whether this is the string the user
988 typed in or the decompiled expression. */
989 b
->cond_string
= xstrdup (arg
);
990 b
->condition_not_parsed
= 0;
992 if (is_watchpoint (b
))
994 struct watchpoint
*w
= (struct watchpoint
*) b
;
996 innermost_block
= NULL
;
998 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1000 error (_("Junk at end of expression"));
1001 w
->cond_exp_valid_block
= innermost_block
;
1005 struct bp_location
*loc
;
1007 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1011 parse_exp_1 (&arg
, loc
->address
,
1012 block_for_pc (loc
->address
), 0);
1014 error (_("Junk at end of expression"));
1018 mark_breakpoint_modified (b
);
1020 observer_notify_breakpoint_modified (b
);
1023 /* Completion for the "condition" command. */
1025 static VEC (char_ptr
) *
1026 condition_completer (struct cmd_list_element
*cmd
,
1027 const char *text
, const char *word
)
1031 text
= skip_spaces_const (text
);
1032 space
= skip_to_space_const (text
);
1036 struct breakpoint
*b
;
1037 VEC (char_ptr
) *result
= NULL
;
1041 /* We don't support completion of history indices. */
1042 if (isdigit (text
[1]))
1044 return complete_internalvar (&text
[1]);
1047 /* We're completing the breakpoint number. */
1048 len
= strlen (text
);
1054 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1056 if (strncmp (number
, text
, len
) == 0)
1057 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1063 /* We're completing the expression part. */
1064 text
= skip_spaces_const (space
);
1065 return expression_completer (cmd
, text
, word
);
1068 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1071 condition_command (char *arg
, int from_tty
)
1073 struct breakpoint
*b
;
1078 error_no_arg (_("breakpoint number"));
1081 bnum
= get_number (&p
);
1083 error (_("Bad breakpoint argument: '%s'"), arg
);
1086 if (b
->number
== bnum
)
1088 /* Check if this breakpoint has a "stop" method implemented in an
1089 extension language. This method and conditions entered into GDB
1090 from the CLI are mutually exclusive. */
1091 const struct extension_language_defn
*extlang
1092 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1094 if (extlang
!= NULL
)
1096 error (_("Only one stop condition allowed. There is currently"
1097 " a %s stop condition defined for this breakpoint."),
1098 ext_lang_capitalized_name (extlang
));
1100 set_breakpoint_condition (b
, p
, from_tty
);
1102 if (is_breakpoint (b
))
1103 update_global_location_list (UGLL_MAY_INSERT
);
1108 error (_("No breakpoint number %d."), bnum
);
1111 /* Check that COMMAND do not contain commands that are suitable
1112 only for tracepoints and not suitable for ordinary breakpoints.
1113 Throw if any such commands is found. */
1116 check_no_tracepoint_commands (struct command_line
*commands
)
1118 struct command_line
*c
;
1120 for (c
= commands
; c
; c
= c
->next
)
1124 if (c
->control_type
== while_stepping_control
)
1125 error (_("The 'while-stepping' command can "
1126 "only be used for tracepoints"));
1128 for (i
= 0; i
< c
->body_count
; ++i
)
1129 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1131 /* Not that command parsing removes leading whitespace and comment
1132 lines and also empty lines. So, we only need to check for
1133 command directly. */
1134 if (strstr (c
->line
, "collect ") == c
->line
)
1135 error (_("The 'collect' command can only be used for tracepoints"));
1137 if (strstr (c
->line
, "teval ") == c
->line
)
1138 error (_("The 'teval' command can only be used for tracepoints"));
1142 /* Encapsulate tests for different types of tracepoints. */
1145 is_tracepoint_type (enum bptype type
)
1147 return (type
== bp_tracepoint
1148 || type
== bp_fast_tracepoint
1149 || type
== bp_static_tracepoint
);
1153 is_tracepoint (const struct breakpoint
*b
)
1155 return is_tracepoint_type (b
->type
);
1158 /* A helper function that validates that COMMANDS are valid for a
1159 breakpoint. This function will throw an exception if a problem is
1163 validate_commands_for_breakpoint (struct breakpoint
*b
,
1164 struct command_line
*commands
)
1166 if (is_tracepoint (b
))
1168 struct tracepoint
*t
= (struct tracepoint
*) b
;
1169 struct command_line
*c
;
1170 struct command_line
*while_stepping
= 0;
1172 /* Reset the while-stepping step count. The previous commands
1173 might have included a while-stepping action, while the new
1177 /* We need to verify that each top-level element of commands is
1178 valid for tracepoints, that there's at most one
1179 while-stepping element, and that the while-stepping's body
1180 has valid tracing commands excluding nested while-stepping.
1181 We also need to validate the tracepoint action line in the
1182 context of the tracepoint --- validate_actionline actually
1183 has side effects, like setting the tracepoint's
1184 while-stepping STEP_COUNT, in addition to checking if the
1185 collect/teval actions parse and make sense in the
1186 tracepoint's context. */
1187 for (c
= commands
; c
; c
= c
->next
)
1189 if (c
->control_type
== while_stepping_control
)
1191 if (b
->type
== bp_fast_tracepoint
)
1192 error (_("The 'while-stepping' command "
1193 "cannot be used for fast tracepoint"));
1194 else if (b
->type
== bp_static_tracepoint
)
1195 error (_("The 'while-stepping' command "
1196 "cannot be used for static tracepoint"));
1199 error (_("The 'while-stepping' command "
1200 "can be used only once"));
1205 validate_actionline (c
->line
, b
);
1209 struct command_line
*c2
;
1211 gdb_assert (while_stepping
->body_count
== 1);
1212 c2
= while_stepping
->body_list
[0];
1213 for (; c2
; c2
= c2
->next
)
1215 if (c2
->control_type
== while_stepping_control
)
1216 error (_("The 'while-stepping' command cannot be nested"));
1222 check_no_tracepoint_commands (commands
);
1226 /* Return a vector of all the static tracepoints set at ADDR. The
1227 caller is responsible for releasing the vector. */
1230 static_tracepoints_here (CORE_ADDR addr
)
1232 struct breakpoint
*b
;
1233 VEC(breakpoint_p
) *found
= 0;
1234 struct bp_location
*loc
;
1237 if (b
->type
== bp_static_tracepoint
)
1239 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1240 if (loc
->address
== addr
)
1241 VEC_safe_push(breakpoint_p
, found
, b
);
1247 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1248 validate that only allowed commands are included. */
1251 breakpoint_set_commands (struct breakpoint
*b
,
1252 struct command_line
*commands
)
1254 validate_commands_for_breakpoint (b
, commands
);
1256 decref_counted_command_line (&b
->commands
);
1257 b
->commands
= alloc_counted_command_line (commands
);
1258 observer_notify_breakpoint_modified (b
);
1261 /* Set the internal `silent' flag on the breakpoint. Note that this
1262 is not the same as the "silent" that may appear in the breakpoint's
1266 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1268 int old_silent
= b
->silent
;
1271 if (old_silent
!= silent
)
1272 observer_notify_breakpoint_modified (b
);
1275 /* Set the thread for this breakpoint. If THREAD is -1, make the
1276 breakpoint work for any thread. */
1279 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1281 int old_thread
= b
->thread
;
1284 if (old_thread
!= thread
)
1285 observer_notify_breakpoint_modified (b
);
1288 /* Set the task for this breakpoint. If TASK is 0, make the
1289 breakpoint work for any task. */
1292 breakpoint_set_task (struct breakpoint
*b
, int task
)
1294 int old_task
= b
->task
;
1297 if (old_task
!= task
)
1298 observer_notify_breakpoint_modified (b
);
1302 check_tracepoint_command (char *line
, void *closure
)
1304 struct breakpoint
*b
= closure
;
1306 validate_actionline (line
, b
);
1309 /* A structure used to pass information through
1310 map_breakpoint_numbers. */
1312 struct commands_info
1314 /* True if the command was typed at a tty. */
1317 /* The breakpoint range spec. */
1320 /* Non-NULL if the body of the commands are being read from this
1321 already-parsed command. */
1322 struct command_line
*control
;
1324 /* The command lines read from the user, or NULL if they have not
1326 struct counted_command_line
*cmd
;
1329 /* A callback for map_breakpoint_numbers that sets the commands for
1330 commands_command. */
1333 do_map_commands_command (struct breakpoint
*b
, void *data
)
1335 struct commands_info
*info
= data
;
1337 if (info
->cmd
== NULL
)
1339 struct command_line
*l
;
1341 if (info
->control
!= NULL
)
1342 l
= copy_command_lines (info
->control
->body_list
[0]);
1345 struct cleanup
*old_chain
;
1348 str
= xstrprintf (_("Type commands for breakpoint(s) "
1349 "%s, one per line."),
1352 old_chain
= make_cleanup (xfree
, str
);
1354 l
= read_command_lines (str
,
1357 ? check_tracepoint_command
: 0),
1360 do_cleanups (old_chain
);
1363 info
->cmd
= alloc_counted_command_line (l
);
1366 /* If a breakpoint was on the list more than once, we don't need to
1368 if (b
->commands
!= info
->cmd
)
1370 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1371 incref_counted_command_line (info
->cmd
);
1372 decref_counted_command_line (&b
->commands
);
1373 b
->commands
= info
->cmd
;
1374 observer_notify_breakpoint_modified (b
);
1379 commands_command_1 (char *arg
, int from_tty
,
1380 struct command_line
*control
)
1382 struct cleanup
*cleanups
;
1383 struct commands_info info
;
1385 info
.from_tty
= from_tty
;
1386 info
.control
= control
;
1388 /* If we read command lines from the user, then `info' will hold an
1389 extra reference to the commands that we must clean up. */
1390 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1392 if (arg
== NULL
|| !*arg
)
1394 if (breakpoint_count
- prev_breakpoint_count
> 1)
1395 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1397 else if (breakpoint_count
> 0)
1398 arg
= xstrprintf ("%d", breakpoint_count
);
1401 /* So that we don't try to free the incoming non-NULL
1402 argument in the cleanup below. Mapping breakpoint
1403 numbers will fail in this case. */
1408 /* The command loop has some static state, so we need to preserve
1410 arg
= xstrdup (arg
);
1413 make_cleanup (xfree
, arg
);
1417 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1419 if (info
.cmd
== NULL
)
1420 error (_("No breakpoints specified."));
1422 do_cleanups (cleanups
);
1426 commands_command (char *arg
, int from_tty
)
1428 commands_command_1 (arg
, from_tty
, NULL
);
1431 /* Like commands_command, but instead of reading the commands from
1432 input stream, takes them from an already parsed command structure.
1434 This is used by cli-script.c to DTRT with breakpoint commands
1435 that are part of if and while bodies. */
1436 enum command_control_type
1437 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1439 commands_command_1 (arg
, 0, cmd
);
1440 return simple_control
;
1443 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1446 bp_location_has_shadow (struct bp_location
*bl
)
1448 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1452 if (bl
->target_info
.shadow_len
== 0)
1453 /* BL isn't valid, or doesn't shadow memory. */
1458 /* Update BUF, which is LEN bytes read from the target address
1459 MEMADDR, by replacing a memory breakpoint with its shadowed
1462 If READBUF is not NULL, this buffer must not overlap with the of
1463 the breakpoint location's shadow_contents buffer. Otherwise, a
1464 failed assertion internal error will be raised. */
1467 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1468 const gdb_byte
*writebuf_org
,
1469 ULONGEST memaddr
, LONGEST len
,
1470 struct bp_target_info
*target_info
,
1471 struct gdbarch
*gdbarch
)
1473 /* Now do full processing of the found relevant range of elements. */
1474 CORE_ADDR bp_addr
= 0;
1478 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1479 current_program_space
->aspace
, 0))
1481 /* The breakpoint is inserted in a different address space. */
1485 /* Addresses and length of the part of the breakpoint that
1487 bp_addr
= target_info
->placed_address
;
1488 bp_size
= target_info
->shadow_len
;
1490 if (bp_addr
+ bp_size
<= memaddr
)
1492 /* The breakpoint is entirely before the chunk of memory we are
1497 if (bp_addr
>= memaddr
+ len
)
1499 /* The breakpoint is entirely after the chunk of memory we are
1504 /* Offset within shadow_contents. */
1505 if (bp_addr
< memaddr
)
1507 /* Only copy the second part of the breakpoint. */
1508 bp_size
-= memaddr
- bp_addr
;
1509 bptoffset
= memaddr
- bp_addr
;
1513 if (bp_addr
+ bp_size
> memaddr
+ len
)
1515 /* Only copy the first part of the breakpoint. */
1516 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1519 if (readbuf
!= NULL
)
1521 /* Verify that the readbuf buffer does not overlap with the
1522 shadow_contents buffer. */
1523 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1524 || readbuf
>= (target_info
->shadow_contents
1525 + target_info
->shadow_len
));
1527 /* Update the read buffer with this inserted breakpoint's
1529 memcpy (readbuf
+ bp_addr
- memaddr
,
1530 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1534 const unsigned char *bp
;
1535 CORE_ADDR addr
= target_info
->reqstd_address
;
1538 /* Update the shadow with what we want to write to memory. */
1539 memcpy (target_info
->shadow_contents
+ bptoffset
,
1540 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1542 /* Determine appropriate breakpoint contents and size for this
1544 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1546 /* Update the final write buffer with this inserted
1547 breakpoint's INSN. */
1548 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1552 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1553 by replacing any memory breakpoints with their shadowed contents.
1555 If READBUF is not NULL, this buffer must not overlap with any of
1556 the breakpoint location's shadow_contents buffers. Otherwise,
1557 a failed assertion internal error will be raised.
1559 The range of shadowed area by each bp_location is:
1560 bl->address - bp_location_placed_address_before_address_max
1561 up to bl->address + bp_location_shadow_len_after_address_max
1562 The range we were requested to resolve shadows for is:
1563 memaddr ... memaddr + len
1564 Thus the safe cutoff boundaries for performance optimization are
1565 memaddr + len <= (bl->address
1566 - bp_location_placed_address_before_address_max)
1568 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1571 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1572 const gdb_byte
*writebuf_org
,
1573 ULONGEST memaddr
, LONGEST len
)
1575 /* Left boundary, right boundary and median element of our binary
1577 unsigned bc_l
, bc_r
, bc
;
1580 /* Find BC_L which is a leftmost element which may affect BUF
1581 content. It is safe to report lower value but a failure to
1582 report higher one. */
1585 bc_r
= bp_location_count
;
1586 while (bc_l
+ 1 < bc_r
)
1588 struct bp_location
*bl
;
1590 bc
= (bc_l
+ bc_r
) / 2;
1591 bl
= bp_location
[bc
];
1593 /* Check first BL->ADDRESS will not overflow due to the added
1594 constant. Then advance the left boundary only if we are sure
1595 the BC element can in no way affect the BUF content (MEMADDR
1596 to MEMADDR + LEN range).
1598 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1599 offset so that we cannot miss a breakpoint with its shadow
1600 range tail still reaching MEMADDR. */
1602 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1604 && (bl
->address
+ bp_location_shadow_len_after_address_max
1611 /* Due to the binary search above, we need to make sure we pick the
1612 first location that's at BC_L's address. E.g., if there are
1613 multiple locations at the same address, BC_L may end up pointing
1614 at a duplicate location, and miss the "master"/"inserted"
1615 location. Say, given locations L1, L2 and L3 at addresses A and
1618 L1@A, L2@A, L3@B, ...
1620 BC_L could end up pointing at location L2, while the "master"
1621 location could be L1. Since the `loc->inserted' flag is only set
1622 on "master" locations, we'd forget to restore the shadow of L1
1625 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1628 /* Now do full processing of the found relevant range of elements. */
1630 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1632 struct bp_location
*bl
= bp_location
[bc
];
1633 CORE_ADDR bp_addr
= 0;
1637 /* bp_location array has BL->OWNER always non-NULL. */
1638 if (bl
->owner
->type
== bp_none
)
1639 warning (_("reading through apparently deleted breakpoint #%d?"),
1642 /* Performance optimization: any further element can no longer affect BUF
1645 if (bl
->address
>= bp_location_placed_address_before_address_max
1646 && memaddr
+ len
<= (bl
->address
1647 - bp_location_placed_address_before_address_max
))
1650 if (!bp_location_has_shadow (bl
))
1653 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1654 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1660 /* Return true if BPT is either a software breakpoint or a hardware
1664 is_breakpoint (const struct breakpoint
*bpt
)
1666 return (bpt
->type
== bp_breakpoint
1667 || bpt
->type
== bp_hardware_breakpoint
1668 || bpt
->type
== bp_dprintf
);
1671 /* Return true if BPT is of any hardware watchpoint kind. */
1674 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1676 return (bpt
->type
== bp_hardware_watchpoint
1677 || bpt
->type
== bp_read_watchpoint
1678 || bpt
->type
== bp_access_watchpoint
);
1681 /* Return true if BPT is of any watchpoint kind, hardware or
1685 is_watchpoint (const struct breakpoint
*bpt
)
1687 return (is_hardware_watchpoint (bpt
)
1688 || bpt
->type
== bp_watchpoint
);
1691 /* Returns true if the current thread and its running state are safe
1692 to evaluate or update watchpoint B. Watchpoints on local
1693 expressions need to be evaluated in the context of the thread that
1694 was current when the watchpoint was created, and, that thread needs
1695 to be stopped to be able to select the correct frame context.
1696 Watchpoints on global expressions can be evaluated on any thread,
1697 and in any state. It is presently left to the target allowing
1698 memory accesses when threads are running. */
1701 watchpoint_in_thread_scope (struct watchpoint
*b
)
1703 return (b
->base
.pspace
== current_program_space
1704 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1705 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1706 && !is_executing (inferior_ptid
))));
1709 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1710 associated bp_watchpoint_scope breakpoint. */
1713 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1715 struct breakpoint
*b
= &w
->base
;
1717 if (b
->related_breakpoint
!= b
)
1719 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1720 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1721 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1722 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1723 b
->related_breakpoint
= b
;
1725 b
->disposition
= disp_del_at_next_stop
;
1728 /* Extract a bitfield value from value VAL using the bit parameters contained in
1731 static struct value
*
1732 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1734 struct value
*bit_val
;
1739 bit_val
= allocate_value (value_type (val
));
1741 unpack_value_bitfield (bit_val
,
1744 value_contents_for_printing (val
),
1751 /* Assuming that B is a watchpoint:
1752 - Reparse watchpoint expression, if REPARSE is non-zero
1753 - Evaluate expression and store the result in B->val
1754 - Evaluate the condition if there is one, and store the result
1756 - Update the list of values that must be watched in B->loc.
1758 If the watchpoint disposition is disp_del_at_next_stop, then do
1759 nothing. If this is local watchpoint that is out of scope, delete
1762 Even with `set breakpoint always-inserted on' the watchpoints are
1763 removed + inserted on each stop here. Normal breakpoints must
1764 never be removed because they might be missed by a running thread
1765 when debugging in non-stop mode. On the other hand, hardware
1766 watchpoints (is_hardware_watchpoint; processed here) are specific
1767 to each LWP since they are stored in each LWP's hardware debug
1768 registers. Therefore, such LWP must be stopped first in order to
1769 be able to modify its hardware watchpoints.
1771 Hardware watchpoints must be reset exactly once after being
1772 presented to the user. It cannot be done sooner, because it would
1773 reset the data used to present the watchpoint hit to the user. And
1774 it must not be done later because it could display the same single
1775 watchpoint hit during multiple GDB stops. Note that the latter is
1776 relevant only to the hardware watchpoint types bp_read_watchpoint
1777 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1778 not user-visible - its hit is suppressed if the memory content has
1781 The following constraints influence the location where we can reset
1782 hardware watchpoints:
1784 * target_stopped_by_watchpoint and target_stopped_data_address are
1785 called several times when GDB stops.
1788 * Multiple hardware watchpoints can be hit at the same time,
1789 causing GDB to stop. GDB only presents one hardware watchpoint
1790 hit at a time as the reason for stopping, and all the other hits
1791 are presented later, one after the other, each time the user
1792 requests the execution to be resumed. Execution is not resumed
1793 for the threads still having pending hit event stored in
1794 LWP_INFO->STATUS. While the watchpoint is already removed from
1795 the inferior on the first stop the thread hit event is kept being
1796 reported from its cached value by linux_nat_stopped_data_address
1797 until the real thread resume happens after the watchpoint gets
1798 presented and thus its LWP_INFO->STATUS gets reset.
1800 Therefore the hardware watchpoint hit can get safely reset on the
1801 watchpoint removal from inferior. */
1804 update_watchpoint (struct watchpoint
*b
, int reparse
)
1806 int within_current_scope
;
1807 struct frame_id saved_frame_id
;
1810 /* If this is a local watchpoint, we only want to check if the
1811 watchpoint frame is in scope if the current thread is the thread
1812 that was used to create the watchpoint. */
1813 if (!watchpoint_in_thread_scope (b
))
1816 if (b
->base
.disposition
== disp_del_at_next_stop
)
1821 /* Determine if the watchpoint is within scope. */
1822 if (b
->exp_valid_block
== NULL
)
1823 within_current_scope
= 1;
1826 struct frame_info
*fi
= get_current_frame ();
1827 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1828 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1830 /* If we're in a function epilogue, unwinding may not work
1831 properly, so do not attempt to recreate locations at this
1832 point. See similar comments in watchpoint_check. */
1833 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1836 /* Save the current frame's ID so we can restore it after
1837 evaluating the watchpoint expression on its own frame. */
1838 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1839 took a frame parameter, so that we didn't have to change the
1842 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1844 fi
= frame_find_by_id (b
->watchpoint_frame
);
1845 within_current_scope
= (fi
!= NULL
);
1846 if (within_current_scope
)
1850 /* We don't free locations. They are stored in the bp_location array
1851 and update_global_location_list will eventually delete them and
1852 remove breakpoints if needed. */
1855 if (within_current_scope
&& reparse
)
1864 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1865 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1866 /* If the meaning of expression itself changed, the old value is
1867 no longer relevant. We don't want to report a watchpoint hit
1868 to the user when the old value and the new value may actually
1869 be completely different objects. */
1870 value_free (b
->val
);
1874 /* Note that unlike with breakpoints, the watchpoint's condition
1875 expression is stored in the breakpoint object, not in the
1876 locations (re)created below. */
1877 if (b
->base
.cond_string
!= NULL
)
1879 if (b
->cond_exp
!= NULL
)
1881 xfree (b
->cond_exp
);
1885 s
= b
->base
.cond_string
;
1886 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1890 /* If we failed to parse the expression, for example because
1891 it refers to a global variable in a not-yet-loaded shared library,
1892 don't try to insert watchpoint. We don't automatically delete
1893 such watchpoint, though, since failure to parse expression
1894 is different from out-of-scope watchpoint. */
1895 if (!target_has_execution
)
1897 /* Without execution, memory can't change. No use to try and
1898 set watchpoint locations. The watchpoint will be reset when
1899 the target gains execution, through breakpoint_re_set. */
1900 if (!can_use_hw_watchpoints
)
1902 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1903 b
->base
.type
= bp_watchpoint
;
1905 error (_("Can't set read/access watchpoint when "
1906 "hardware watchpoints are disabled."));
1909 else if (within_current_scope
&& b
->exp
)
1912 struct value
*val_chain
, *v
, *result
, *next
;
1913 struct program_space
*frame_pspace
;
1915 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1917 /* Avoid setting b->val if it's already set. The meaning of
1918 b->val is 'the last value' user saw, and we should update
1919 it only if we reported that last value to user. As it
1920 happens, the code that reports it updates b->val directly.
1921 We don't keep track of the memory value for masked
1923 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1925 if (b
->val_bitsize
!= 0)
1927 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1935 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1937 /* Look at each value on the value chain. */
1938 for (v
= val_chain
; v
; v
= value_next (v
))
1940 /* If it's a memory location, and GDB actually needed
1941 its contents to evaluate the expression, then we
1942 must watch it. If the first value returned is
1943 still lazy, that means an error occurred reading it;
1944 watch it anyway in case it becomes readable. */
1945 if (VALUE_LVAL (v
) == lval_memory
1946 && (v
== val_chain
|| ! value_lazy (v
)))
1948 struct type
*vtype
= check_typedef (value_type (v
));
1950 /* We only watch structs and arrays if user asked
1951 for it explicitly, never if they just happen to
1952 appear in the middle of some value chain. */
1954 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1955 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1959 struct bp_location
*loc
, **tmp
;
1960 int bitpos
= 0, bitsize
= 0;
1962 if (value_bitsize (v
) != 0)
1964 /* Extract the bit parameters out from the bitfield
1966 bitpos
= value_bitpos (v
);
1967 bitsize
= value_bitsize (v
);
1969 else if (v
== result
&& b
->val_bitsize
!= 0)
1971 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1972 lvalue whose bit parameters are saved in the fields
1973 VAL_BITPOS and VAL_BITSIZE. */
1974 bitpos
= b
->val_bitpos
;
1975 bitsize
= b
->val_bitsize
;
1978 addr
= value_address (v
);
1981 /* Skip the bytes that don't contain the bitfield. */
1986 if (b
->base
.type
== bp_read_watchpoint
)
1988 else if (b
->base
.type
== bp_access_watchpoint
)
1991 loc
= allocate_bp_location (&b
->base
);
1992 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1995 loc
->gdbarch
= get_type_arch (value_type (v
));
1997 loc
->pspace
= frame_pspace
;
1998 loc
->address
= addr
;
2002 /* Just cover the bytes that make up the bitfield. */
2003 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2006 loc
->length
= TYPE_LENGTH (value_type (v
));
2008 loc
->watchpoint_type
= type
;
2013 /* Change the type of breakpoint between hardware assisted or
2014 an ordinary watchpoint depending on the hardware support
2015 and free hardware slots. REPARSE is set when the inferior
2020 enum bp_loc_type loc_type
;
2021 struct bp_location
*bl
;
2023 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2027 int i
, target_resources_ok
, other_type_used
;
2030 /* Use an exact watchpoint when there's only one memory region to be
2031 watched, and only one debug register is needed to watch it. */
2032 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2034 /* We need to determine how many resources are already
2035 used for all other hardware watchpoints plus this one
2036 to see if we still have enough resources to also fit
2037 this watchpoint in as well. */
2039 /* If this is a software watchpoint, we try to turn it
2040 to a hardware one -- count resources as if B was of
2041 hardware watchpoint type. */
2042 type
= b
->base
.type
;
2043 if (type
== bp_watchpoint
)
2044 type
= bp_hardware_watchpoint
;
2046 /* This watchpoint may or may not have been placed on
2047 the list yet at this point (it won't be in the list
2048 if we're trying to create it for the first time,
2049 through watch_command), so always account for it
2052 /* Count resources used by all watchpoints except B. */
2053 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2055 /* Add in the resources needed for B. */
2056 i
+= hw_watchpoint_use_count (&b
->base
);
2059 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2060 if (target_resources_ok
<= 0)
2062 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2064 if (target_resources_ok
== 0 && !sw_mode
)
2065 error (_("Target does not support this type of "
2066 "hardware watchpoint."));
2067 else if (target_resources_ok
< 0 && !sw_mode
)
2068 error (_("There are not enough available hardware "
2069 "resources for this watchpoint."));
2071 /* Downgrade to software watchpoint. */
2072 b
->base
.type
= bp_watchpoint
;
2076 /* If this was a software watchpoint, we've just
2077 found we have enough resources to turn it to a
2078 hardware watchpoint. Otherwise, this is a
2080 b
->base
.type
= type
;
2083 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2085 if (!can_use_hw_watchpoints
)
2086 error (_("Can't set read/access watchpoint when "
2087 "hardware watchpoints are disabled."));
2089 error (_("Expression cannot be implemented with "
2090 "read/access watchpoint."));
2093 b
->base
.type
= bp_watchpoint
;
2095 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2096 : bp_loc_hardware_watchpoint
);
2097 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2098 bl
->loc_type
= loc_type
;
2101 for (v
= val_chain
; v
; v
= next
)
2103 next
= value_next (v
);
2108 /* If a software watchpoint is not watching any memory, then the
2109 above left it without any location set up. But,
2110 bpstat_stop_status requires a location to be able to report
2111 stops, so make sure there's at least a dummy one. */
2112 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2114 struct breakpoint
*base
= &b
->base
;
2115 base
->loc
= allocate_bp_location (base
);
2116 base
->loc
->pspace
= frame_pspace
;
2117 base
->loc
->address
= -1;
2118 base
->loc
->length
= -1;
2119 base
->loc
->watchpoint_type
= -1;
2122 else if (!within_current_scope
)
2124 printf_filtered (_("\
2125 Watchpoint %d deleted because the program has left the block\n\
2126 in which its expression is valid.\n"),
2128 watchpoint_del_at_next_stop (b
);
2131 /* Restore the selected frame. */
2133 select_frame (frame_find_by_id (saved_frame_id
));
2137 /* Returns 1 iff breakpoint location should be
2138 inserted in the inferior. We don't differentiate the type of BL's owner
2139 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2140 breakpoint_ops is not defined, because in insert_bp_location,
2141 tracepoint's insert_location will not be called. */
2143 should_be_inserted (struct bp_location
*bl
)
2145 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2148 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2151 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2154 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2157 /* This is set for example, when we're attached to the parent of a
2158 vfork, and have detached from the child. The child is running
2159 free, and we expect it to do an exec or exit, at which point the
2160 OS makes the parent schedulable again (and the target reports
2161 that the vfork is done). Until the child is done with the shared
2162 memory region, do not insert breakpoints in the parent, otherwise
2163 the child could still trip on the parent's breakpoints. Since
2164 the parent is blocked anyway, it won't miss any breakpoint. */
2165 if (bl
->pspace
->breakpoints_not_allowed
)
2168 /* Don't insert a breakpoint if we're trying to step past its
2170 if ((bl
->loc_type
== bp_loc_software_breakpoint
2171 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2172 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2177 fprintf_unfiltered (gdb_stdlog
,
2178 "infrun: skipping breakpoint: "
2179 "stepping past insn at: %s\n",
2180 paddress (bl
->gdbarch
, bl
->address
));
2185 /* Don't insert watchpoints if we're trying to step past the
2186 instruction that triggered one. */
2187 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2188 && stepping_past_nonsteppable_watchpoint ())
2192 fprintf_unfiltered (gdb_stdlog
,
2193 "infrun: stepping past non-steppable watchpoint. "
2194 "skipping watchpoint at %s:%d\n",
2195 paddress (bl
->gdbarch
, bl
->address
),
2204 /* Same as should_be_inserted but does the check assuming
2205 that the location is not duplicated. */
2208 unduplicated_should_be_inserted (struct bp_location
*bl
)
2211 const int save_duplicate
= bl
->duplicate
;
2214 result
= should_be_inserted (bl
);
2215 bl
->duplicate
= save_duplicate
;
2219 /* Parses a conditional described by an expression COND into an
2220 agent expression bytecode suitable for evaluation
2221 by the bytecode interpreter. Return NULL if there was
2222 any error during parsing. */
2224 static struct agent_expr
*
2225 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2227 struct agent_expr
*aexpr
= NULL
;
2228 volatile struct gdb_exception ex
;
2233 /* We don't want to stop processing, so catch any errors
2234 that may show up. */
2235 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2237 aexpr
= gen_eval_for_expr (scope
, cond
);
2242 /* If we got here, it means the condition could not be parsed to a valid
2243 bytecode expression and thus can't be evaluated on the target's side.
2244 It's no use iterating through the conditions. */
2248 /* We have a valid agent expression. */
2252 /* Based on location BL, create a list of breakpoint conditions to be
2253 passed on to the target. If we have duplicated locations with different
2254 conditions, we will add such conditions to the list. The idea is that the
2255 target will evaluate the list of conditions and will only notify GDB when
2256 one of them is true. */
2259 build_target_condition_list (struct bp_location
*bl
)
2261 struct bp_location
**locp
= NULL
, **loc2p
;
2262 int null_condition_or_parse_error
= 0;
2263 int modified
= bl
->needs_update
;
2264 struct bp_location
*loc
;
2266 /* Release conditions left over from a previous insert. */
2267 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2269 /* This is only meaningful if the target is
2270 evaluating conditions and if the user has
2271 opted for condition evaluation on the target's
2273 if (gdb_evaluates_breakpoint_condition_p ()
2274 || !target_supports_evaluation_of_breakpoint_conditions ())
2277 /* Do a first pass to check for locations with no assigned
2278 conditions or conditions that fail to parse to a valid agent expression
2279 bytecode. If any of these happen, then it's no use to send conditions
2280 to the target since this location will always trigger and generate a
2281 response back to GDB. */
2282 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2285 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2289 struct agent_expr
*aexpr
;
2291 /* Re-parse the conditions since something changed. In that
2292 case we already freed the condition bytecodes (see
2293 force_breakpoint_reinsertion). We just
2294 need to parse the condition to bytecodes again. */
2295 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2296 loc
->cond_bytecode
= aexpr
;
2298 /* Check if we managed to parse the conditional expression
2299 correctly. If not, we will not send this condition
2305 /* If we have a NULL bytecode expression, it means something
2306 went wrong or we have a null condition expression. */
2307 if (!loc
->cond_bytecode
)
2309 null_condition_or_parse_error
= 1;
2315 /* If any of these happened, it means we will have to evaluate the conditions
2316 for the location's address on gdb's side. It is no use keeping bytecodes
2317 for all the other duplicate locations, thus we free all of them here.
2319 This is so we have a finer control over which locations' conditions are
2320 being evaluated by GDB or the remote stub. */
2321 if (null_condition_or_parse_error
)
2323 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2326 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2328 /* Only go as far as the first NULL bytecode is
2330 if (!loc
->cond_bytecode
)
2333 free_agent_expr (loc
->cond_bytecode
);
2334 loc
->cond_bytecode
= NULL
;
2339 /* No NULL conditions or failed bytecode generation. Build a condition list
2340 for this location's address. */
2341 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2345 && is_breakpoint (loc
->owner
)
2346 && loc
->pspace
->num
== bl
->pspace
->num
2347 && loc
->owner
->enable_state
== bp_enabled
2349 /* Add the condition to the vector. This will be used later to send the
2350 conditions to the target. */
2351 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2352 loc
->cond_bytecode
);
2358 /* Parses a command described by string CMD into an agent expression
2359 bytecode suitable for evaluation by the bytecode interpreter.
2360 Return NULL if there was any error during parsing. */
2362 static struct agent_expr
*
2363 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2365 struct cleanup
*old_cleanups
= 0;
2366 struct expression
*expr
, **argvec
;
2367 struct agent_expr
*aexpr
= NULL
;
2368 volatile struct gdb_exception ex
;
2369 const char *cmdrest
;
2370 const char *format_start
, *format_end
;
2371 struct format_piece
*fpieces
;
2373 struct gdbarch
*gdbarch
= get_current_arch ();
2380 if (*cmdrest
== ',')
2382 cmdrest
= skip_spaces_const (cmdrest
);
2384 if (*cmdrest
++ != '"')
2385 error (_("No format string following the location"));
2387 format_start
= cmdrest
;
2389 fpieces
= parse_format_string (&cmdrest
);
2391 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2393 format_end
= cmdrest
;
2395 if (*cmdrest
++ != '"')
2396 error (_("Bad format string, non-terminated '\"'."));
2398 cmdrest
= skip_spaces_const (cmdrest
);
2400 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2401 error (_("Invalid argument syntax"));
2403 if (*cmdrest
== ',')
2405 cmdrest
= skip_spaces_const (cmdrest
);
2407 /* For each argument, make an expression. */
2409 argvec
= (struct expression
**) alloca (strlen (cmd
)
2410 * sizeof (struct expression
*));
2413 while (*cmdrest
!= '\0')
2418 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2419 argvec
[nargs
++] = expr
;
2421 if (*cmdrest
== ',')
2425 /* We don't want to stop processing, so catch any errors
2426 that may show up. */
2427 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2429 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2430 format_start
, format_end
- format_start
,
2431 fpieces
, nargs
, argvec
);
2434 do_cleanups (old_cleanups
);
2438 /* If we got here, it means the command could not be parsed to a valid
2439 bytecode expression and thus can't be evaluated on the target's side.
2440 It's no use iterating through the other commands. */
2444 /* We have a valid agent expression, return it. */
2448 /* Based on location BL, create a list of breakpoint commands to be
2449 passed on to the target. If we have duplicated locations with
2450 different commands, we will add any such to the list. */
2453 build_target_command_list (struct bp_location
*bl
)
2455 struct bp_location
**locp
= NULL
, **loc2p
;
2456 int null_command_or_parse_error
= 0;
2457 int modified
= bl
->needs_update
;
2458 struct bp_location
*loc
;
2460 /* Release commands left over from a previous insert. */
2461 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2463 if (!target_can_run_breakpoint_commands ())
2466 /* For now, limit to agent-style dprintf breakpoints. */
2467 if (dprintf_style
!= dprintf_style_agent
)
2470 /* For now, if we have any duplicate location that isn't a dprintf,
2471 don't install the target-side commands, as that would make the
2472 breakpoint not be reported to the core, and we'd lose
2474 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2477 if (is_breakpoint (loc
->owner
)
2478 && loc
->pspace
->num
== bl
->pspace
->num
2479 && loc
->owner
->type
!= bp_dprintf
)
2483 /* Do a first pass to check for locations with no assigned
2484 conditions or conditions that fail to parse to a valid agent expression
2485 bytecode. If any of these happen, then it's no use to send conditions
2486 to the target since this location will always trigger and generate a
2487 response back to GDB. */
2488 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2491 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2495 struct agent_expr
*aexpr
;
2497 /* Re-parse the commands since something changed. In that
2498 case we already freed the command bytecodes (see
2499 force_breakpoint_reinsertion). We just
2500 need to parse the command to bytecodes again. */
2501 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2502 loc
->owner
->extra_string
);
2503 loc
->cmd_bytecode
= aexpr
;
2509 /* If we have a NULL bytecode expression, it means something
2510 went wrong or we have a null command expression. */
2511 if (!loc
->cmd_bytecode
)
2513 null_command_or_parse_error
= 1;
2519 /* If anything failed, then we're not doing target-side commands,
2521 if (null_command_or_parse_error
)
2523 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2526 if (is_breakpoint (loc
->owner
)
2527 && loc
->pspace
->num
== bl
->pspace
->num
)
2529 /* Only go as far as the first NULL bytecode is
2531 if (loc
->cmd_bytecode
== NULL
)
2534 free_agent_expr (loc
->cmd_bytecode
);
2535 loc
->cmd_bytecode
= NULL
;
2540 /* No NULL commands or failed bytecode generation. Build a command list
2541 for this location's address. */
2542 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2545 if (loc
->owner
->extra_string
2546 && is_breakpoint (loc
->owner
)
2547 && loc
->pspace
->num
== bl
->pspace
->num
2548 && loc
->owner
->enable_state
== bp_enabled
2550 /* Add the command to the vector. This will be used later
2551 to send the commands to the target. */
2552 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2556 bl
->target_info
.persist
= 0;
2557 /* Maybe flag this location as persistent. */
2558 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2559 bl
->target_info
.persist
= 1;
2562 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2563 location. Any error messages are printed to TMP_ERROR_STREAM; and
2564 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2565 Returns 0 for success, 1 if the bp_location type is not supported or
2568 NOTE drow/2003-09-09: This routine could be broken down to an
2569 object-style method for each breakpoint or catchpoint type. */
2571 insert_bp_location (struct bp_location
*bl
,
2572 struct ui_file
*tmp_error_stream
,
2573 int *disabled_breaks
,
2574 int *hw_breakpoint_error
,
2575 int *hw_bp_error_explained_already
)
2577 enum errors bp_err
= GDB_NO_ERROR
;
2578 const char *bp_err_message
= NULL
;
2579 volatile struct gdb_exception e
;
2581 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2584 /* Note we don't initialize bl->target_info, as that wipes out
2585 the breakpoint location's shadow_contents if the breakpoint
2586 is still inserted at that location. This in turn breaks
2587 target_read_memory which depends on these buffers when
2588 a memory read is requested at the breakpoint location:
2589 Once the target_info has been wiped, we fail to see that
2590 we have a breakpoint inserted at that address and thus
2591 read the breakpoint instead of returning the data saved in
2592 the breakpoint location's shadow contents. */
2593 bl
->target_info
.reqstd_address
= bl
->address
;
2594 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2595 bl
->target_info
.length
= bl
->length
;
2597 /* When working with target-side conditions, we must pass all the conditions
2598 for the same breakpoint address down to the target since GDB will not
2599 insert those locations. With a list of breakpoint conditions, the target
2600 can decide when to stop and notify GDB. */
2602 if (is_breakpoint (bl
->owner
))
2604 build_target_condition_list (bl
);
2605 build_target_command_list (bl
);
2606 /* Reset the modification marker. */
2607 bl
->needs_update
= 0;
2610 if (bl
->loc_type
== bp_loc_software_breakpoint
2611 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2613 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2615 /* If the explicitly specified breakpoint type
2616 is not hardware breakpoint, check the memory map to see
2617 if the breakpoint address is in read only memory or not.
2619 Two important cases are:
2620 - location type is not hardware breakpoint, memory
2621 is readonly. We change the type of the location to
2622 hardware breakpoint.
2623 - location type is hardware breakpoint, memory is
2624 read-write. This means we've previously made the
2625 location hardware one, but then the memory map changed,
2628 When breakpoints are removed, remove_breakpoints will use
2629 location types we've just set here, the only possible
2630 problem is that memory map has changed during running
2631 program, but it's not going to work anyway with current
2633 struct mem_region
*mr
2634 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2638 if (automatic_hardware_breakpoints
)
2640 enum bp_loc_type new_type
;
2642 if (mr
->attrib
.mode
!= MEM_RW
)
2643 new_type
= bp_loc_hardware_breakpoint
;
2645 new_type
= bp_loc_software_breakpoint
;
2647 if (new_type
!= bl
->loc_type
)
2649 static int said
= 0;
2651 bl
->loc_type
= new_type
;
2654 fprintf_filtered (gdb_stdout
,
2655 _("Note: automatically using "
2656 "hardware breakpoints for "
2657 "read-only addresses.\n"));
2662 else if (bl
->loc_type
== bp_loc_software_breakpoint
2663 && mr
->attrib
.mode
!= MEM_RW
)
2665 fprintf_unfiltered (tmp_error_stream
,
2666 _("Cannot insert breakpoint %d.\n"
2667 "Cannot set software breakpoint "
2668 "at read-only address %s\n"),
2670 paddress (bl
->gdbarch
, bl
->address
));
2676 /* First check to see if we have to handle an overlay. */
2677 if (overlay_debugging
== ovly_off
2678 || bl
->section
== NULL
2679 || !(section_is_overlay (bl
->section
)))
2681 /* No overlay handling: just set the breakpoint. */
2682 TRY_CATCH (e
, RETURN_MASK_ALL
)
2686 val
= bl
->owner
->ops
->insert_location (bl
);
2688 bp_err
= GENERIC_ERROR
;
2693 bp_err_message
= e
.message
;
2698 /* This breakpoint is in an overlay section.
2699 Shall we set a breakpoint at the LMA? */
2700 if (!overlay_events_enabled
)
2702 /* Yes -- overlay event support is not active,
2703 so we must try to set a breakpoint at the LMA.
2704 This will not work for a hardware breakpoint. */
2705 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2706 warning (_("hardware breakpoint %d not supported in overlay!"),
2710 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2712 /* Set a software (trap) breakpoint at the LMA. */
2713 bl
->overlay_target_info
= bl
->target_info
;
2714 bl
->overlay_target_info
.reqstd_address
= addr
;
2716 /* No overlay handling: just set the breakpoint. */
2717 TRY_CATCH (e
, RETURN_MASK_ALL
)
2721 val
= target_insert_breakpoint (bl
->gdbarch
,
2722 &bl
->overlay_target_info
);
2724 bp_err
= GENERIC_ERROR
;
2729 bp_err_message
= e
.message
;
2732 if (bp_err
!= GDB_NO_ERROR
)
2733 fprintf_unfiltered (tmp_error_stream
,
2734 "Overlay breakpoint %d "
2735 "failed: in ROM?\n",
2739 /* Shall we set a breakpoint at the VMA? */
2740 if (section_is_mapped (bl
->section
))
2742 /* Yes. This overlay section is mapped into memory. */
2743 TRY_CATCH (e
, RETURN_MASK_ALL
)
2747 val
= bl
->owner
->ops
->insert_location (bl
);
2749 bp_err
= GENERIC_ERROR
;
2754 bp_err_message
= e
.message
;
2759 /* No. This breakpoint will not be inserted.
2760 No error, but do not mark the bp as 'inserted'. */
2765 if (bp_err
!= GDB_NO_ERROR
)
2767 /* Can't set the breakpoint. */
2769 /* In some cases, we might not be able to insert a
2770 breakpoint in a shared library that has already been
2771 removed, but we have not yet processed the shlib unload
2772 event. Unfortunately, some targets that implement
2773 breakpoint insertion themselves can't tell why the
2774 breakpoint insertion failed (e.g., the remote target
2775 doesn't define error codes), so we must treat generic
2776 errors as memory errors. */
2777 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2778 && bl
->loc_type
== bp_loc_software_breakpoint
2779 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2780 || shared_objfile_contains_address_p (bl
->pspace
,
2783 /* See also: disable_breakpoints_in_shlibs. */
2784 bl
->shlib_disabled
= 1;
2785 observer_notify_breakpoint_modified (bl
->owner
);
2786 if (!*disabled_breaks
)
2788 fprintf_unfiltered (tmp_error_stream
,
2789 "Cannot insert breakpoint %d.\n",
2791 fprintf_unfiltered (tmp_error_stream
,
2792 "Temporarily disabling shared "
2793 "library breakpoints:\n");
2795 *disabled_breaks
= 1;
2796 fprintf_unfiltered (tmp_error_stream
,
2797 "breakpoint #%d\n", bl
->owner
->number
);
2802 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2804 *hw_breakpoint_error
= 1;
2805 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2806 fprintf_unfiltered (tmp_error_stream
,
2807 "Cannot insert hardware breakpoint %d%s",
2808 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2809 if (bp_err_message
!= NULL
)
2810 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2814 if (bp_err_message
== NULL
)
2817 = memory_error_message (TARGET_XFER_E_IO
,
2818 bl
->gdbarch
, bl
->address
);
2819 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2821 fprintf_unfiltered (tmp_error_stream
,
2822 "Cannot insert breakpoint %d.\n"
2824 bl
->owner
->number
, message
);
2825 do_cleanups (old_chain
);
2829 fprintf_unfiltered (tmp_error_stream
,
2830 "Cannot insert breakpoint %d: %s\n",
2845 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2846 /* NOTE drow/2003-09-08: This state only exists for removing
2847 watchpoints. It's not clear that it's necessary... */
2848 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2852 gdb_assert (bl
->owner
->ops
!= NULL
2853 && bl
->owner
->ops
->insert_location
!= NULL
);
2855 val
= bl
->owner
->ops
->insert_location (bl
);
2857 /* If trying to set a read-watchpoint, and it turns out it's not
2858 supported, try emulating one with an access watchpoint. */
2859 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2861 struct bp_location
*loc
, **loc_temp
;
2863 /* But don't try to insert it, if there's already another
2864 hw_access location that would be considered a duplicate
2866 ALL_BP_LOCATIONS (loc
, loc_temp
)
2868 && loc
->watchpoint_type
== hw_access
2869 && watchpoint_locations_match (bl
, loc
))
2873 bl
->target_info
= loc
->target_info
;
2874 bl
->watchpoint_type
= hw_access
;
2881 bl
->watchpoint_type
= hw_access
;
2882 val
= bl
->owner
->ops
->insert_location (bl
);
2885 /* Back to the original value. */
2886 bl
->watchpoint_type
= hw_read
;
2890 bl
->inserted
= (val
== 0);
2893 else if (bl
->owner
->type
== bp_catchpoint
)
2897 gdb_assert (bl
->owner
->ops
!= NULL
2898 && bl
->owner
->ops
->insert_location
!= NULL
);
2900 val
= bl
->owner
->ops
->insert_location (bl
);
2903 bl
->owner
->enable_state
= bp_disabled
;
2907 Error inserting catchpoint %d: Your system does not support this type\n\
2908 of catchpoint."), bl
->owner
->number
);
2910 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2913 bl
->inserted
= (val
== 0);
2915 /* We've already printed an error message if there was a problem
2916 inserting this catchpoint, and we've disabled the catchpoint,
2917 so just return success. */
2924 /* This function is called when program space PSPACE is about to be
2925 deleted. It takes care of updating breakpoints to not reference
2929 breakpoint_program_space_exit (struct program_space
*pspace
)
2931 struct breakpoint
*b
, *b_temp
;
2932 struct bp_location
*loc
, **loc_temp
;
2934 /* Remove any breakpoint that was set through this program space. */
2935 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2937 if (b
->pspace
== pspace
)
2938 delete_breakpoint (b
);
2941 /* Breakpoints set through other program spaces could have locations
2942 bound to PSPACE as well. Remove those. */
2943 ALL_BP_LOCATIONS (loc
, loc_temp
)
2945 struct bp_location
*tmp
;
2947 if (loc
->pspace
== pspace
)
2949 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2950 if (loc
->owner
->loc
== loc
)
2951 loc
->owner
->loc
= loc
->next
;
2953 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2954 if (tmp
->next
== loc
)
2956 tmp
->next
= loc
->next
;
2962 /* Now update the global location list to permanently delete the
2963 removed locations above. */
2964 update_global_location_list (UGLL_DONT_INSERT
);
2967 /* Make sure all breakpoints are inserted in inferior.
2968 Throws exception on any error.
2969 A breakpoint that is already inserted won't be inserted
2970 again, so calling this function twice is safe. */
2972 insert_breakpoints (void)
2974 struct breakpoint
*bpt
;
2976 ALL_BREAKPOINTS (bpt
)
2977 if (is_hardware_watchpoint (bpt
))
2979 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2981 update_watchpoint (w
, 0 /* don't reparse. */);
2984 /* Updating watchpoints creates new locations, so update the global
2985 location list. Explicitly tell ugll to insert locations and
2986 ignore breakpoints_always_inserted_mode. */
2987 update_global_location_list (UGLL_INSERT
);
2990 /* Invoke CALLBACK for each of bp_location. */
2993 iterate_over_bp_locations (walk_bp_location_callback callback
)
2995 struct bp_location
*loc
, **loc_tmp
;
2997 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2999 callback (loc
, NULL
);
3003 /* This is used when we need to synch breakpoint conditions between GDB and the
3004 target. It is the case with deleting and disabling of breakpoints when using
3005 always-inserted mode. */
3008 update_inserted_breakpoint_locations (void)
3010 struct bp_location
*bl
, **blp_tmp
;
3013 int disabled_breaks
= 0;
3014 int hw_breakpoint_error
= 0;
3015 int hw_bp_details_reported
= 0;
3017 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3018 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3020 /* Explicitly mark the warning -- this will only be printed if
3021 there was an error. */
3022 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3024 save_current_space_and_thread ();
3026 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3028 /* We only want to update software breakpoints and hardware
3030 if (!is_breakpoint (bl
->owner
))
3033 /* We only want to update locations that are already inserted
3034 and need updating. This is to avoid unwanted insertion during
3035 deletion of breakpoints. */
3036 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3039 switch_to_program_space_and_thread (bl
->pspace
);
3041 /* For targets that support global breakpoints, there's no need
3042 to select an inferior to insert breakpoint to. In fact, even
3043 if we aren't attached to any process yet, we should still
3044 insert breakpoints. */
3045 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3046 && ptid_equal (inferior_ptid
, null_ptid
))
3049 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3050 &hw_breakpoint_error
, &hw_bp_details_reported
);
3057 target_terminal_ours_for_output ();
3058 error_stream (tmp_error_stream
);
3061 do_cleanups (cleanups
);
3064 /* Used when starting or continuing the program. */
3067 insert_breakpoint_locations (void)
3069 struct breakpoint
*bpt
;
3070 struct bp_location
*bl
, **blp_tmp
;
3073 int disabled_breaks
= 0;
3074 int hw_breakpoint_error
= 0;
3075 int hw_bp_error_explained_already
= 0;
3077 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3078 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3080 /* Explicitly mark the warning -- this will only be printed if
3081 there was an error. */
3082 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3084 save_current_space_and_thread ();
3086 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3088 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3091 /* There is no point inserting thread-specific breakpoints if
3092 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3093 has BL->OWNER always non-NULL. */
3094 if (bl
->owner
->thread
!= -1
3095 && !valid_thread_id (bl
->owner
->thread
))
3098 switch_to_program_space_and_thread (bl
->pspace
);
3100 /* For targets that support global breakpoints, there's no need
3101 to select an inferior to insert breakpoint to. In fact, even
3102 if we aren't attached to any process yet, we should still
3103 insert breakpoints. */
3104 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3105 && ptid_equal (inferior_ptid
, null_ptid
))
3108 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3109 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3114 /* If we failed to insert all locations of a watchpoint, remove
3115 them, as half-inserted watchpoint is of limited use. */
3116 ALL_BREAKPOINTS (bpt
)
3118 int some_failed
= 0;
3119 struct bp_location
*loc
;
3121 if (!is_hardware_watchpoint (bpt
))
3124 if (!breakpoint_enabled (bpt
))
3127 if (bpt
->disposition
== disp_del_at_next_stop
)
3130 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3131 if (!loc
->inserted
&& should_be_inserted (loc
))
3138 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3140 remove_breakpoint (loc
, mark_uninserted
);
3142 hw_breakpoint_error
= 1;
3143 fprintf_unfiltered (tmp_error_stream
,
3144 "Could not insert hardware watchpoint %d.\n",
3152 /* If a hardware breakpoint or watchpoint was inserted, add a
3153 message about possibly exhausted resources. */
3154 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3156 fprintf_unfiltered (tmp_error_stream
,
3157 "Could not insert hardware breakpoints:\n\
3158 You may have requested too many hardware breakpoints/watchpoints.\n");
3160 target_terminal_ours_for_output ();
3161 error_stream (tmp_error_stream
);
3164 do_cleanups (cleanups
);
3167 /* Used when the program stops.
3168 Returns zero if successful, or non-zero if there was a problem
3169 removing a breakpoint location. */
3172 remove_breakpoints (void)
3174 struct bp_location
*bl
, **blp_tmp
;
3177 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3179 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3180 val
|= remove_breakpoint (bl
, mark_uninserted
);
3185 /* When a thread exits, remove breakpoints that are related to
3189 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3191 struct breakpoint
*b
, *b_tmp
;
3193 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3195 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3197 b
->disposition
= disp_del_at_next_stop
;
3199 printf_filtered (_("\
3200 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3201 b
->number
, tp
->num
);
3203 /* Hide it from the user. */
3209 /* Remove breakpoints of process PID. */
3212 remove_breakpoints_pid (int pid
)
3214 struct bp_location
*bl
, **blp_tmp
;
3216 struct inferior
*inf
= find_inferior_pid (pid
);
3218 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3220 if (bl
->pspace
!= inf
->pspace
)
3223 if (bl
->owner
->type
== bp_dprintf
)
3228 val
= remove_breakpoint (bl
, mark_uninserted
);
3237 reattach_breakpoints (int pid
)
3239 struct cleanup
*old_chain
;
3240 struct bp_location
*bl
, **blp_tmp
;
3242 struct ui_file
*tmp_error_stream
;
3243 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3244 struct inferior
*inf
;
3245 struct thread_info
*tp
;
3247 tp
= any_live_thread_of_process (pid
);
3251 inf
= find_inferior_pid (pid
);
3252 old_chain
= save_inferior_ptid ();
3254 inferior_ptid
= tp
->ptid
;
3256 tmp_error_stream
= mem_fileopen ();
3257 make_cleanup_ui_file_delete (tmp_error_stream
);
3259 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3261 if (bl
->pspace
!= inf
->pspace
)
3267 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3270 do_cleanups (old_chain
);
3275 do_cleanups (old_chain
);
3279 static int internal_breakpoint_number
= -1;
3281 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3282 If INTERNAL is non-zero, the breakpoint number will be populated
3283 from internal_breakpoint_number and that variable decremented.
3284 Otherwise the breakpoint number will be populated from
3285 breakpoint_count and that value incremented. Internal breakpoints
3286 do not set the internal var bpnum. */
3288 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3291 b
->number
= internal_breakpoint_number
--;
3294 set_breakpoint_count (breakpoint_count
+ 1);
3295 b
->number
= breakpoint_count
;
3299 static struct breakpoint
*
3300 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3301 CORE_ADDR address
, enum bptype type
,
3302 const struct breakpoint_ops
*ops
)
3304 struct symtab_and_line sal
;
3305 struct breakpoint
*b
;
3307 init_sal (&sal
); /* Initialize to zeroes. */
3310 sal
.section
= find_pc_overlay (sal
.pc
);
3311 sal
.pspace
= current_program_space
;
3313 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3314 b
->number
= internal_breakpoint_number
--;
3315 b
->disposition
= disp_donttouch
;
3320 static const char *const longjmp_names
[] =
3322 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3324 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3326 /* Per-objfile data private to breakpoint.c. */
3327 struct breakpoint_objfile_data
3329 /* Minimal symbol for "_ovly_debug_event" (if any). */
3330 struct bound_minimal_symbol overlay_msym
;
3332 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3333 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3335 /* True if we have looked for longjmp probes. */
3336 int longjmp_searched
;
3338 /* SystemTap probe points for longjmp (if any). */
3339 VEC (probe_p
) *longjmp_probes
;
3341 /* Minimal symbol for "std::terminate()" (if any). */
3342 struct bound_minimal_symbol terminate_msym
;
3344 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3345 struct bound_minimal_symbol exception_msym
;
3347 /* True if we have looked for exception probes. */
3348 int exception_searched
;
3350 /* SystemTap probe points for unwinding (if any). */
3351 VEC (probe_p
) *exception_probes
;
3354 static const struct objfile_data
*breakpoint_objfile_key
;
3356 /* Minimal symbol not found sentinel. */
3357 static struct minimal_symbol msym_not_found
;
3359 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3362 msym_not_found_p (const struct minimal_symbol
*msym
)
3364 return msym
== &msym_not_found
;
3367 /* Return per-objfile data needed by breakpoint.c.
3368 Allocate the data if necessary. */
3370 static struct breakpoint_objfile_data
*
3371 get_breakpoint_objfile_data (struct objfile
*objfile
)
3373 struct breakpoint_objfile_data
*bp_objfile_data
;
3375 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3376 if (bp_objfile_data
== NULL
)
3378 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3379 sizeof (*bp_objfile_data
));
3381 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3382 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3384 return bp_objfile_data
;
3388 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3390 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3392 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3393 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3397 create_overlay_event_breakpoint (void)
3399 struct objfile
*objfile
;
3400 const char *const func_name
= "_ovly_debug_event";
3402 ALL_OBJFILES (objfile
)
3404 struct breakpoint
*b
;
3405 struct breakpoint_objfile_data
*bp_objfile_data
;
3408 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3410 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3413 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3415 struct bound_minimal_symbol m
;
3417 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3418 if (m
.minsym
== NULL
)
3420 /* Avoid future lookups in this objfile. */
3421 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3424 bp_objfile_data
->overlay_msym
= m
;
3427 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3428 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3430 &internal_breakpoint_ops
);
3431 b
->addr_string
= xstrdup (func_name
);
3433 if (overlay_debugging
== ovly_auto
)
3435 b
->enable_state
= bp_enabled
;
3436 overlay_events_enabled
= 1;
3440 b
->enable_state
= bp_disabled
;
3441 overlay_events_enabled
= 0;
3444 update_global_location_list (UGLL_MAY_INSERT
);
3448 create_longjmp_master_breakpoint (void)
3450 struct program_space
*pspace
;
3451 struct cleanup
*old_chain
;
3453 old_chain
= save_current_program_space ();
3455 ALL_PSPACES (pspace
)
3457 struct objfile
*objfile
;
3459 set_current_program_space (pspace
);
3461 ALL_OBJFILES (objfile
)
3464 struct gdbarch
*gdbarch
;
3465 struct breakpoint_objfile_data
*bp_objfile_data
;
3467 gdbarch
= get_objfile_arch (objfile
);
3469 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3471 if (!bp_objfile_data
->longjmp_searched
)
3475 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3478 /* We are only interested in checking one element. */
3479 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3481 if (!can_evaluate_probe_arguments (p
))
3483 /* We cannot use the probe interface here, because it does
3484 not know how to evaluate arguments. */
3485 VEC_free (probe_p
, ret
);
3489 bp_objfile_data
->longjmp_probes
= ret
;
3490 bp_objfile_data
->longjmp_searched
= 1;
3493 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3496 struct probe
*probe
;
3497 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3500 VEC_iterate (probe_p
,
3501 bp_objfile_data
->longjmp_probes
,
3505 struct breakpoint
*b
;
3507 b
= create_internal_breakpoint (gdbarch
,
3508 get_probe_address (probe
,
3511 &internal_breakpoint_ops
);
3512 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3513 b
->enable_state
= bp_disabled
;
3519 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3522 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3524 struct breakpoint
*b
;
3525 const char *func_name
;
3528 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3531 func_name
= longjmp_names
[i
];
3532 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3534 struct bound_minimal_symbol m
;
3536 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3537 if (m
.minsym
== NULL
)
3539 /* Prevent future lookups in this objfile. */
3540 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3543 bp_objfile_data
->longjmp_msym
[i
] = m
;
3546 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3547 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3548 &internal_breakpoint_ops
);
3549 b
->addr_string
= xstrdup (func_name
);
3550 b
->enable_state
= bp_disabled
;
3554 update_global_location_list (UGLL_MAY_INSERT
);
3556 do_cleanups (old_chain
);
3559 /* Create a master std::terminate breakpoint. */
3561 create_std_terminate_master_breakpoint (void)
3563 struct program_space
*pspace
;
3564 struct cleanup
*old_chain
;
3565 const char *const func_name
= "std::terminate()";
3567 old_chain
= save_current_program_space ();
3569 ALL_PSPACES (pspace
)
3571 struct objfile
*objfile
;
3574 set_current_program_space (pspace
);
3576 ALL_OBJFILES (objfile
)
3578 struct breakpoint
*b
;
3579 struct breakpoint_objfile_data
*bp_objfile_data
;
3581 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3583 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3586 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3588 struct bound_minimal_symbol m
;
3590 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3591 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3592 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3594 /* Prevent future lookups in this objfile. */
3595 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3598 bp_objfile_data
->terminate_msym
= m
;
3601 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3602 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3603 bp_std_terminate_master
,
3604 &internal_breakpoint_ops
);
3605 b
->addr_string
= xstrdup (func_name
);
3606 b
->enable_state
= bp_disabled
;
3610 update_global_location_list (UGLL_MAY_INSERT
);
3612 do_cleanups (old_chain
);
3615 /* Install a master breakpoint on the unwinder's debug hook. */
3618 create_exception_master_breakpoint (void)
3620 struct objfile
*objfile
;
3621 const char *const func_name
= "_Unwind_DebugHook";
3623 ALL_OBJFILES (objfile
)
3625 struct breakpoint
*b
;
3626 struct gdbarch
*gdbarch
;
3627 struct breakpoint_objfile_data
*bp_objfile_data
;
3630 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3632 /* We prefer the SystemTap probe point if it exists. */
3633 if (!bp_objfile_data
->exception_searched
)
3637 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3641 /* We are only interested in checking one element. */
3642 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3644 if (!can_evaluate_probe_arguments (p
))
3646 /* We cannot use the probe interface here, because it does
3647 not know how to evaluate arguments. */
3648 VEC_free (probe_p
, ret
);
3652 bp_objfile_data
->exception_probes
= ret
;
3653 bp_objfile_data
->exception_searched
= 1;
3656 if (bp_objfile_data
->exception_probes
!= NULL
)
3658 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3660 struct probe
*probe
;
3663 VEC_iterate (probe_p
,
3664 bp_objfile_data
->exception_probes
,
3668 struct breakpoint
*b
;
3670 b
= create_internal_breakpoint (gdbarch
,
3671 get_probe_address (probe
,
3673 bp_exception_master
,
3674 &internal_breakpoint_ops
);
3675 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3676 b
->enable_state
= bp_disabled
;
3682 /* Otherwise, try the hook function. */
3684 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3687 gdbarch
= get_objfile_arch (objfile
);
3689 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3691 struct bound_minimal_symbol debug_hook
;
3693 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3694 if (debug_hook
.minsym
== NULL
)
3696 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3700 bp_objfile_data
->exception_msym
= debug_hook
;
3703 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3704 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3706 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3707 &internal_breakpoint_ops
);
3708 b
->addr_string
= xstrdup (func_name
);
3709 b
->enable_state
= bp_disabled
;
3712 update_global_location_list (UGLL_MAY_INSERT
);
3716 update_breakpoints_after_exec (void)
3718 struct breakpoint
*b
, *b_tmp
;
3719 struct bp_location
*bploc
, **bplocp_tmp
;
3721 /* We're about to delete breakpoints from GDB's lists. If the
3722 INSERTED flag is true, GDB will try to lift the breakpoints by
3723 writing the breakpoints' "shadow contents" back into memory. The
3724 "shadow contents" are NOT valid after an exec, so GDB should not
3725 do that. Instead, the target is responsible from marking
3726 breakpoints out as soon as it detects an exec. We don't do that
3727 here instead, because there may be other attempts to delete
3728 breakpoints after detecting an exec and before reaching here. */
3729 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3730 if (bploc
->pspace
== current_program_space
)
3731 gdb_assert (!bploc
->inserted
);
3733 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3735 if (b
->pspace
!= current_program_space
)
3738 /* Solib breakpoints must be explicitly reset after an exec(). */
3739 if (b
->type
== bp_shlib_event
)
3741 delete_breakpoint (b
);
3745 /* JIT breakpoints must be explicitly reset after an exec(). */
3746 if (b
->type
== bp_jit_event
)
3748 delete_breakpoint (b
);
3752 /* Thread event breakpoints must be set anew after an exec(),
3753 as must overlay event and longjmp master breakpoints. */
3754 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3755 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3756 || b
->type
== bp_exception_master
)
3758 delete_breakpoint (b
);
3762 /* Step-resume breakpoints are meaningless after an exec(). */
3763 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3765 delete_breakpoint (b
);
3769 /* Just like single-step breakpoints. */
3770 if (b
->type
== bp_single_step
)
3772 delete_breakpoint (b
);
3776 /* Longjmp and longjmp-resume breakpoints are also meaningless
3778 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3779 || b
->type
== bp_longjmp_call_dummy
3780 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3782 delete_breakpoint (b
);
3786 if (b
->type
== bp_catchpoint
)
3788 /* For now, none of the bp_catchpoint breakpoints need to
3789 do anything at this point. In the future, if some of
3790 the catchpoints need to something, we will need to add
3791 a new method, and call this method from here. */
3795 /* bp_finish is a special case. The only way we ought to be able
3796 to see one of these when an exec() has happened, is if the user
3797 caught a vfork, and then said "finish". Ordinarily a finish just
3798 carries them to the call-site of the current callee, by setting
3799 a temporary bp there and resuming. But in this case, the finish
3800 will carry them entirely through the vfork & exec.
3802 We don't want to allow a bp_finish to remain inserted now. But
3803 we can't safely delete it, 'cause finish_command has a handle to
3804 the bp on a bpstat, and will later want to delete it. There's a
3805 chance (and I've seen it happen) that if we delete the bp_finish
3806 here, that its storage will get reused by the time finish_command
3807 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3808 We really must allow finish_command to delete a bp_finish.
3810 In the absence of a general solution for the "how do we know
3811 it's safe to delete something others may have handles to?"
3812 problem, what we'll do here is just uninsert the bp_finish, and
3813 let finish_command delete it.
3815 (We know the bp_finish is "doomed" in the sense that it's
3816 momentary, and will be deleted as soon as finish_command sees
3817 the inferior stopped. So it doesn't matter that the bp's
3818 address is probably bogus in the new a.out, unlike e.g., the
3819 solib breakpoints.) */
3821 if (b
->type
== bp_finish
)
3826 /* Without a symbolic address, we have little hope of the
3827 pre-exec() address meaning the same thing in the post-exec()
3829 if (b
->addr_string
== NULL
)
3831 delete_breakpoint (b
);
3838 detach_breakpoints (ptid_t ptid
)
3840 struct bp_location
*bl
, **blp_tmp
;
3842 struct cleanup
*old_chain
= save_inferior_ptid ();
3843 struct inferior
*inf
= current_inferior ();
3845 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3846 error (_("Cannot detach breakpoints of inferior_ptid"));
3848 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3849 inferior_ptid
= ptid
;
3850 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3852 if (bl
->pspace
!= inf
->pspace
)
3855 /* This function must physically remove breakpoints locations
3856 from the specified ptid, without modifying the breakpoint
3857 package's state. Locations of type bp_loc_other are only
3858 maintained at GDB side. So, there is no need to remove
3859 these bp_loc_other locations. Moreover, removing these
3860 would modify the breakpoint package's state. */
3861 if (bl
->loc_type
== bp_loc_other
)
3865 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3868 do_cleanups (old_chain
);
3872 /* Remove the breakpoint location BL from the current address space.
3873 Note that this is used to detach breakpoints from a child fork.
3874 When we get here, the child isn't in the inferior list, and neither
3875 do we have objects to represent its address space --- we should
3876 *not* look at bl->pspace->aspace here. */
3879 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3883 /* BL is never in moribund_locations by our callers. */
3884 gdb_assert (bl
->owner
!= NULL
);
3887 /* Permanent breakpoints cannot be inserted or removed. */
3890 /* The type of none suggests that owner is actually deleted.
3891 This should not ever happen. */
3892 gdb_assert (bl
->owner
->type
!= bp_none
);
3894 if (bl
->loc_type
== bp_loc_software_breakpoint
3895 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3897 /* "Normal" instruction breakpoint: either the standard
3898 trap-instruction bp (bp_breakpoint), or a
3899 bp_hardware_breakpoint. */
3901 /* First check to see if we have to handle an overlay. */
3902 if (overlay_debugging
== ovly_off
3903 || bl
->section
== NULL
3904 || !(section_is_overlay (bl
->section
)))
3906 /* No overlay handling: just remove the breakpoint. */
3908 /* If we're trying to uninsert a memory breakpoint that we
3909 know is set in a dynamic object that is marked
3910 shlib_disabled, then either the dynamic object was
3911 removed with "remove-symbol-file" or with
3912 "nosharedlibrary". In the former case, we don't know
3913 whether another dynamic object might have loaded over the
3914 breakpoint's address -- the user might well let us know
3915 about it next with add-symbol-file (the whole point of
3916 add-symbol-file is letting the user manually maintain a
3917 list of dynamically loaded objects). If we have the
3918 breakpoint's shadow memory, that is, this is a software
3919 breakpoint managed by GDB, check whether the breakpoint
3920 is still inserted in memory, to avoid overwriting wrong
3921 code with stale saved shadow contents. Note that HW
3922 breakpoints don't have shadow memory, as they're
3923 implemented using a mechanism that is not dependent on
3924 being able to modify the target's memory, and as such
3925 they should always be removed. */
3926 if (bl
->shlib_disabled
3927 && bl
->target_info
.shadow_len
!= 0
3928 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3931 val
= bl
->owner
->ops
->remove_location (bl
);
3935 /* This breakpoint is in an overlay section.
3936 Did we set a breakpoint at the LMA? */
3937 if (!overlay_events_enabled
)
3939 /* Yes -- overlay event support is not active, so we
3940 should have set a breakpoint at the LMA. Remove it.
3942 /* Ignore any failures: if the LMA is in ROM, we will
3943 have already warned when we failed to insert it. */
3944 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3945 target_remove_hw_breakpoint (bl
->gdbarch
,
3946 &bl
->overlay_target_info
);
3948 target_remove_breakpoint (bl
->gdbarch
,
3949 &bl
->overlay_target_info
);
3951 /* Did we set a breakpoint at the VMA?
3952 If so, we will have marked the breakpoint 'inserted'. */
3955 /* Yes -- remove it. Previously we did not bother to
3956 remove the breakpoint if the section had been
3957 unmapped, but let's not rely on that being safe. We
3958 don't know what the overlay manager might do. */
3960 /* However, we should remove *software* breakpoints only
3961 if the section is still mapped, or else we overwrite
3962 wrong code with the saved shadow contents. */
3963 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3964 || section_is_mapped (bl
->section
))
3965 val
= bl
->owner
->ops
->remove_location (bl
);
3971 /* No -- not inserted, so no need to remove. No error. */
3976 /* In some cases, we might not be able to remove a breakpoint in
3977 a shared library that has already been removed, but we have
3978 not yet processed the shlib unload event. Similarly for an
3979 unloaded add-symbol-file object - the user might not yet have
3980 had the chance to remove-symbol-file it. shlib_disabled will
3981 be set if the library/object has already been removed, but
3982 the breakpoint hasn't been uninserted yet, e.g., after
3983 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3984 always-inserted mode. */
3986 && (bl
->loc_type
== bp_loc_software_breakpoint
3987 && (bl
->shlib_disabled
3988 || solib_name_from_address (bl
->pspace
, bl
->address
)
3989 || shared_objfile_contains_address_p (bl
->pspace
,
3995 bl
->inserted
= (is
== mark_inserted
);
3997 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3999 gdb_assert (bl
->owner
->ops
!= NULL
4000 && bl
->owner
->ops
->remove_location
!= NULL
);
4002 bl
->inserted
= (is
== mark_inserted
);
4003 bl
->owner
->ops
->remove_location (bl
);
4005 /* Failure to remove any of the hardware watchpoints comes here. */
4006 if ((is
== mark_uninserted
) && (bl
->inserted
))
4007 warning (_("Could not remove hardware watchpoint %d."),
4010 else if (bl
->owner
->type
== bp_catchpoint
4011 && breakpoint_enabled (bl
->owner
)
4014 gdb_assert (bl
->owner
->ops
!= NULL
4015 && bl
->owner
->ops
->remove_location
!= NULL
);
4017 val
= bl
->owner
->ops
->remove_location (bl
);
4021 bl
->inserted
= (is
== mark_inserted
);
4028 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4031 struct cleanup
*old_chain
;
4033 /* BL is never in moribund_locations by our callers. */
4034 gdb_assert (bl
->owner
!= NULL
);
4037 /* Permanent breakpoints cannot be inserted or removed. */
4040 /* The type of none suggests that owner is actually deleted.
4041 This should not ever happen. */
4042 gdb_assert (bl
->owner
->type
!= bp_none
);
4044 old_chain
= save_current_space_and_thread ();
4046 switch_to_program_space_and_thread (bl
->pspace
);
4048 ret
= remove_breakpoint_1 (bl
, is
);
4050 do_cleanups (old_chain
);
4054 /* Clear the "inserted" flag in all breakpoints. */
4057 mark_breakpoints_out (void)
4059 struct bp_location
*bl
, **blp_tmp
;
4061 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4062 if (bl
->pspace
== current_program_space
4067 /* Clear the "inserted" flag in all breakpoints and delete any
4068 breakpoints which should go away between runs of the program.
4070 Plus other such housekeeping that has to be done for breakpoints
4073 Note: this function gets called at the end of a run (by
4074 generic_mourn_inferior) and when a run begins (by
4075 init_wait_for_inferior). */
4080 breakpoint_init_inferior (enum inf_context context
)
4082 struct breakpoint
*b
, *b_tmp
;
4083 struct bp_location
*bl
, **blp_tmp
;
4085 struct program_space
*pspace
= current_program_space
;
4087 /* If breakpoint locations are shared across processes, then there's
4089 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4092 mark_breakpoints_out ();
4094 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4096 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4102 case bp_longjmp_call_dummy
:
4104 /* If the call dummy breakpoint is at the entry point it will
4105 cause problems when the inferior is rerun, so we better get
4108 case bp_watchpoint_scope
:
4110 /* Also get rid of scope breakpoints. */
4112 case bp_shlib_event
:
4114 /* Also remove solib event breakpoints. Their addresses may
4115 have changed since the last time we ran the program.
4116 Actually we may now be debugging against different target;
4117 and so the solib backend that installed this breakpoint may
4118 not be used in by the target. E.g.,
4120 (gdb) file prog-linux
4121 (gdb) run # native linux target
4124 (gdb) file prog-win.exe
4125 (gdb) tar rem :9999 # remote Windows gdbserver.
4128 case bp_step_resume
:
4130 /* Also remove step-resume breakpoints. */
4132 case bp_single_step
:
4134 /* Also remove single-step breakpoints. */
4136 delete_breakpoint (b
);
4140 case bp_hardware_watchpoint
:
4141 case bp_read_watchpoint
:
4142 case bp_access_watchpoint
:
4144 struct watchpoint
*w
= (struct watchpoint
*) b
;
4146 /* Likewise for watchpoints on local expressions. */
4147 if (w
->exp_valid_block
!= NULL
)
4148 delete_breakpoint (b
);
4149 else if (context
== inf_starting
)
4151 /* Reset val field to force reread of starting value in
4152 insert_breakpoints. */
4154 value_free (w
->val
);
4165 /* Get rid of the moribund locations. */
4166 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4167 decref_bp_location (&bl
);
4168 VEC_free (bp_location_p
, moribund_locations
);
4171 /* These functions concern about actual breakpoints inserted in the
4172 target --- to e.g. check if we need to do decr_pc adjustment or if
4173 we need to hop over the bkpt --- so we check for address space
4174 match, not program space. */
4176 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4177 exists at PC. It returns ordinary_breakpoint_here if it's an
4178 ordinary breakpoint, or permanent_breakpoint_here if it's a
4179 permanent breakpoint.
4180 - When continuing from a location with an ordinary breakpoint, we
4181 actually single step once before calling insert_breakpoints.
4182 - When continuing from a location with a permanent breakpoint, we
4183 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4184 the target, to advance the PC past the breakpoint. */
4186 enum breakpoint_here
4187 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4189 struct bp_location
*bl
, **blp_tmp
;
4190 int any_breakpoint_here
= 0;
4192 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4194 if (bl
->loc_type
!= bp_loc_software_breakpoint
4195 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4198 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4199 if ((breakpoint_enabled (bl
->owner
)
4201 && breakpoint_location_address_match (bl
, aspace
, pc
))
4203 if (overlay_debugging
4204 && section_is_overlay (bl
->section
)
4205 && !section_is_mapped (bl
->section
))
4206 continue; /* unmapped overlay -- can't be a match */
4207 else if (bl
->permanent
)
4208 return permanent_breakpoint_here
;
4210 any_breakpoint_here
= 1;
4214 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4217 /* Return true if there's a moribund breakpoint at PC. */
4220 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4222 struct bp_location
*loc
;
4225 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4226 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4232 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4235 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4237 struct bp_location
*bl
, **blp_tmp
;
4239 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4241 if (bl
->loc_type
!= bp_loc_software_breakpoint
4242 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4246 && breakpoint_location_address_match (bl
, aspace
, pc
))
4248 if (overlay_debugging
4249 && section_is_overlay (bl
->section
)
4250 && !section_is_mapped (bl
->section
))
4251 continue; /* unmapped overlay -- can't be a match */
4259 /* This function returns non-zero iff there is a software breakpoint
4263 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4266 struct bp_location
*bl
, **blp_tmp
;
4268 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4270 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4274 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4277 if (overlay_debugging
4278 && section_is_overlay (bl
->section
)
4279 && !section_is_mapped (bl
->section
))
4280 continue; /* unmapped overlay -- can't be a match */
4290 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4291 CORE_ADDR addr
, ULONGEST len
)
4293 struct breakpoint
*bpt
;
4295 ALL_BREAKPOINTS (bpt
)
4297 struct bp_location
*loc
;
4299 if (bpt
->type
!= bp_hardware_watchpoint
4300 && bpt
->type
!= bp_access_watchpoint
)
4303 if (!breakpoint_enabled (bpt
))
4306 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4307 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4311 /* Check for intersection. */
4312 l
= max (loc
->address
, addr
);
4313 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4322 /* bpstat stuff. External routines' interfaces are documented
4326 is_catchpoint (struct breakpoint
*ep
)
4328 return (ep
->type
== bp_catchpoint
);
4331 /* Frees any storage that is part of a bpstat. Does not walk the
4335 bpstat_free (bpstat bs
)
4337 if (bs
->old_val
!= NULL
)
4338 value_free (bs
->old_val
);
4339 decref_counted_command_line (&bs
->commands
);
4340 decref_bp_location (&bs
->bp_location_at
);
4344 /* Clear a bpstat so that it says we are not at any breakpoint.
4345 Also free any storage that is part of a bpstat. */
4348 bpstat_clear (bpstat
*bsp
)
4365 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4366 is part of the bpstat is copied as well. */
4369 bpstat_copy (bpstat bs
)
4373 bpstat retval
= NULL
;
4378 for (; bs
!= NULL
; bs
= bs
->next
)
4380 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4381 memcpy (tmp
, bs
, sizeof (*tmp
));
4382 incref_counted_command_line (tmp
->commands
);
4383 incref_bp_location (tmp
->bp_location_at
);
4384 if (bs
->old_val
!= NULL
)
4386 tmp
->old_val
= value_copy (bs
->old_val
);
4387 release_value (tmp
->old_val
);
4391 /* This is the first thing in the chain. */
4401 /* Find the bpstat associated with this breakpoint. */
4404 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4409 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4411 if (bsp
->breakpoint_at
== breakpoint
)
4417 /* See breakpoint.h. */
4420 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4422 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4424 if (bsp
->breakpoint_at
== NULL
)
4426 /* A moribund location can never explain a signal other than
4428 if (sig
== GDB_SIGNAL_TRAP
)
4433 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4442 /* Put in *NUM the breakpoint number of the first breakpoint we are
4443 stopped at. *BSP upon return is a bpstat which points to the
4444 remaining breakpoints stopped at (but which is not guaranteed to be
4445 good for anything but further calls to bpstat_num).
4447 Return 0 if passed a bpstat which does not indicate any breakpoints.
4448 Return -1 if stopped at a breakpoint that has been deleted since
4450 Return 1 otherwise. */
4453 bpstat_num (bpstat
*bsp
, int *num
)
4455 struct breakpoint
*b
;
4458 return 0; /* No more breakpoint values */
4460 /* We assume we'll never have several bpstats that correspond to a
4461 single breakpoint -- otherwise, this function might return the
4462 same number more than once and this will look ugly. */
4463 b
= (*bsp
)->breakpoint_at
;
4464 *bsp
= (*bsp
)->next
;
4466 return -1; /* breakpoint that's been deleted since */
4468 *num
= b
->number
; /* We have its number */
4472 /* See breakpoint.h. */
4475 bpstat_clear_actions (void)
4477 struct thread_info
*tp
;
4480 if (ptid_equal (inferior_ptid
, null_ptid
))
4483 tp
= find_thread_ptid (inferior_ptid
);
4487 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4489 decref_counted_command_line (&bs
->commands
);
4491 if (bs
->old_val
!= NULL
)
4493 value_free (bs
->old_val
);
4499 /* Called when a command is about to proceed the inferior. */
4502 breakpoint_about_to_proceed (void)
4504 if (!ptid_equal (inferior_ptid
, null_ptid
))
4506 struct thread_info
*tp
= inferior_thread ();
4508 /* Allow inferior function calls in breakpoint commands to not
4509 interrupt the command list. When the call finishes
4510 successfully, the inferior will be standing at the same
4511 breakpoint as if nothing happened. */
4512 if (tp
->control
.in_infcall
)
4516 breakpoint_proceeded
= 1;
4519 /* Stub for cleaning up our state if we error-out of a breakpoint
4522 cleanup_executing_breakpoints (void *ignore
)
4524 executing_breakpoint_commands
= 0;
4527 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4528 or its equivalent. */
4531 command_line_is_silent (struct command_line
*cmd
)
4533 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4534 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4537 /* Execute all the commands associated with all the breakpoints at
4538 this location. Any of these commands could cause the process to
4539 proceed beyond this point, etc. We look out for such changes by
4540 checking the global "breakpoint_proceeded" after each command.
4542 Returns true if a breakpoint command resumed the inferior. In that
4543 case, it is the caller's responsibility to recall it again with the
4544 bpstat of the current thread. */
4547 bpstat_do_actions_1 (bpstat
*bsp
)
4550 struct cleanup
*old_chain
;
4553 /* Avoid endless recursion if a `source' command is contained
4555 if (executing_breakpoint_commands
)
4558 executing_breakpoint_commands
= 1;
4559 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4561 prevent_dont_repeat ();
4563 /* This pointer will iterate over the list of bpstat's. */
4566 breakpoint_proceeded
= 0;
4567 for (; bs
!= NULL
; bs
= bs
->next
)
4569 struct counted_command_line
*ccmd
;
4570 struct command_line
*cmd
;
4571 struct cleanup
*this_cmd_tree_chain
;
4573 /* Take ownership of the BSP's command tree, if it has one.
4575 The command tree could legitimately contain commands like
4576 'step' and 'next', which call clear_proceed_status, which
4577 frees stop_bpstat's command tree. To make sure this doesn't
4578 free the tree we're executing out from under us, we need to
4579 take ownership of the tree ourselves. Since a given bpstat's
4580 commands are only executed once, we don't need to copy it; we
4581 can clear the pointer in the bpstat, and make sure we free
4582 the tree when we're done. */
4583 ccmd
= bs
->commands
;
4584 bs
->commands
= NULL
;
4585 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4586 cmd
= ccmd
? ccmd
->commands
: NULL
;
4587 if (command_line_is_silent (cmd
))
4589 /* The action has been already done by bpstat_stop_status. */
4595 execute_control_command (cmd
);
4597 if (breakpoint_proceeded
)
4603 /* We can free this command tree now. */
4604 do_cleanups (this_cmd_tree_chain
);
4606 if (breakpoint_proceeded
)
4608 if (target_can_async_p ())
4609 /* If we are in async mode, then the target might be still
4610 running, not stopped at any breakpoint, so nothing for
4611 us to do here -- just return to the event loop. */
4614 /* In sync mode, when execute_control_command returns
4615 we're already standing on the next breakpoint.
4616 Breakpoint commands for that stop were not run, since
4617 execute_command does not run breakpoint commands --
4618 only command_line_handler does, but that one is not
4619 involved in execution of breakpoint commands. So, we
4620 can now execute breakpoint commands. It should be
4621 noted that making execute_command do bpstat actions is
4622 not an option -- in this case we'll have recursive
4623 invocation of bpstat for each breakpoint with a
4624 command, and can easily blow up GDB stack. Instead, we
4625 return true, which will trigger the caller to recall us
4626 with the new stop_bpstat. */
4631 do_cleanups (old_chain
);
4636 bpstat_do_actions (void)
4638 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4640 /* Do any commands attached to breakpoint we are stopped at. */
4641 while (!ptid_equal (inferior_ptid
, null_ptid
)
4642 && target_has_execution
4643 && !is_exited (inferior_ptid
)
4644 && !is_executing (inferior_ptid
))
4645 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4646 and only return when it is stopped at the next breakpoint, we
4647 keep doing breakpoint actions until it returns false to
4648 indicate the inferior was not resumed. */
4649 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4652 discard_cleanups (cleanup_if_error
);
4655 /* Print out the (old or new) value associated with a watchpoint. */
4658 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4661 fprintf_unfiltered (stream
, _("<unreadable>"));
4664 struct value_print_options opts
;
4665 get_user_print_options (&opts
);
4666 value_print (val
, stream
, &opts
);
4670 /* Generic routine for printing messages indicating why we
4671 stopped. The behavior of this function depends on the value
4672 'print_it' in the bpstat structure. Under some circumstances we
4673 may decide not to print anything here and delegate the task to
4676 static enum print_stop_action
4677 print_bp_stop_message (bpstat bs
)
4679 switch (bs
->print_it
)
4682 /* Nothing should be printed for this bpstat entry. */
4683 return PRINT_UNKNOWN
;
4687 /* We still want to print the frame, but we already printed the
4688 relevant messages. */
4689 return PRINT_SRC_AND_LOC
;
4692 case print_it_normal
:
4694 struct breakpoint
*b
= bs
->breakpoint_at
;
4696 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4697 which has since been deleted. */
4699 return PRINT_UNKNOWN
;
4701 /* Normal case. Call the breakpoint's print_it method. */
4702 return b
->ops
->print_it (bs
);
4707 internal_error (__FILE__
, __LINE__
,
4708 _("print_bp_stop_message: unrecognized enum value"));
4713 /* A helper function that prints a shared library stopped event. */
4716 print_solib_event (int is_catchpoint
)
4719 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4721 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4725 if (any_added
|| any_deleted
)
4726 ui_out_text (current_uiout
,
4727 _("Stopped due to shared library event:\n"));
4729 ui_out_text (current_uiout
,
4730 _("Stopped due to shared library event (no "
4731 "libraries added or removed)\n"));
4734 if (ui_out_is_mi_like_p (current_uiout
))
4735 ui_out_field_string (current_uiout
, "reason",
4736 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4740 struct cleanup
*cleanup
;
4744 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4745 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4748 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4753 ui_out_text (current_uiout
, " ");
4754 ui_out_field_string (current_uiout
, "library", name
);
4755 ui_out_text (current_uiout
, "\n");
4758 do_cleanups (cleanup
);
4763 struct so_list
*iter
;
4765 struct cleanup
*cleanup
;
4767 ui_out_text (current_uiout
, _(" Inferior loaded "));
4768 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4771 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4776 ui_out_text (current_uiout
, " ");
4777 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4778 ui_out_text (current_uiout
, "\n");
4781 do_cleanups (cleanup
);
4785 /* Print a message indicating what happened. This is called from
4786 normal_stop(). The input to this routine is the head of the bpstat
4787 list - a list of the eventpoints that caused this stop. KIND is
4788 the target_waitkind for the stopping event. This
4789 routine calls the generic print routine for printing a message
4790 about reasons for stopping. This will print (for example) the
4791 "Breakpoint n," part of the output. The return value of this
4794 PRINT_UNKNOWN: Means we printed nothing.
4795 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4796 code to print the location. An example is
4797 "Breakpoint 1, " which should be followed by
4799 PRINT_SRC_ONLY: Means we printed something, but there is no need
4800 to also print the location part of the message.
4801 An example is the catch/throw messages, which
4802 don't require a location appended to the end.
4803 PRINT_NOTHING: We have done some printing and we don't need any
4804 further info to be printed. */
4806 enum print_stop_action
4807 bpstat_print (bpstat bs
, int kind
)
4811 /* Maybe another breakpoint in the chain caused us to stop.
4812 (Currently all watchpoints go on the bpstat whether hit or not.
4813 That probably could (should) be changed, provided care is taken
4814 with respect to bpstat_explains_signal). */
4815 for (; bs
; bs
= bs
->next
)
4817 val
= print_bp_stop_message (bs
);
4818 if (val
== PRINT_SRC_ONLY
4819 || val
== PRINT_SRC_AND_LOC
4820 || val
== PRINT_NOTHING
)
4824 /* If we had hit a shared library event breakpoint,
4825 print_bp_stop_message would print out this message. If we hit an
4826 OS-level shared library event, do the same thing. */
4827 if (kind
== TARGET_WAITKIND_LOADED
)
4829 print_solib_event (0);
4830 return PRINT_NOTHING
;
4833 /* We reached the end of the chain, or we got a null BS to start
4834 with and nothing was printed. */
4835 return PRINT_UNKNOWN
;
4838 /* Evaluate the expression EXP and return 1 if value is zero.
4839 This returns the inverse of the condition because it is called
4840 from catch_errors which returns 0 if an exception happened, and if an
4841 exception happens we want execution to stop.
4842 The argument is a "struct expression *" that has been cast to a
4843 "void *" to make it pass through catch_errors. */
4846 breakpoint_cond_eval (void *exp
)
4848 struct value
*mark
= value_mark ();
4849 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4851 value_free_to_mark (mark
);
4855 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4858 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4862 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4864 **bs_link_pointer
= bs
;
4865 *bs_link_pointer
= &bs
->next
;
4866 bs
->breakpoint_at
= bl
->owner
;
4867 bs
->bp_location_at
= bl
;
4868 incref_bp_location (bl
);
4869 /* If the condition is false, etc., don't do the commands. */
4870 bs
->commands
= NULL
;
4872 bs
->print_it
= print_it_normal
;
4876 /* The target has stopped with waitstatus WS. Check if any hardware
4877 watchpoints have triggered, according to the target. */
4880 watchpoints_triggered (struct target_waitstatus
*ws
)
4882 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4884 struct breakpoint
*b
;
4886 if (!stopped_by_watchpoint
)
4888 /* We were not stopped by a watchpoint. Mark all watchpoints
4889 as not triggered. */
4891 if (is_hardware_watchpoint (b
))
4893 struct watchpoint
*w
= (struct watchpoint
*) b
;
4895 w
->watchpoint_triggered
= watch_triggered_no
;
4901 if (!target_stopped_data_address (¤t_target
, &addr
))
4903 /* We were stopped by a watchpoint, but we don't know where.
4904 Mark all watchpoints as unknown. */
4906 if (is_hardware_watchpoint (b
))
4908 struct watchpoint
*w
= (struct watchpoint
*) b
;
4910 w
->watchpoint_triggered
= watch_triggered_unknown
;
4916 /* The target could report the data address. Mark watchpoints
4917 affected by this data address as triggered, and all others as not
4921 if (is_hardware_watchpoint (b
))
4923 struct watchpoint
*w
= (struct watchpoint
*) b
;
4924 struct bp_location
*loc
;
4926 w
->watchpoint_triggered
= watch_triggered_no
;
4927 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4929 if (is_masked_watchpoint (b
))
4931 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4932 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4934 if (newaddr
== start
)
4936 w
->watchpoint_triggered
= watch_triggered_yes
;
4940 /* Exact match not required. Within range is sufficient. */
4941 else if (target_watchpoint_addr_within_range (¤t_target
,
4945 w
->watchpoint_triggered
= watch_triggered_yes
;
4954 /* Possible return values for watchpoint_check (this can't be an enum
4955 because of check_errors). */
4956 /* The watchpoint has been deleted. */
4957 #define WP_DELETED 1
4958 /* The value has changed. */
4959 #define WP_VALUE_CHANGED 2
4960 /* The value has not changed. */
4961 #define WP_VALUE_NOT_CHANGED 3
4962 /* Ignore this watchpoint, no matter if the value changed or not. */
4965 #define BP_TEMPFLAG 1
4966 #define BP_HARDWAREFLAG 2
4968 /* Evaluate watchpoint condition expression and check if its value
4971 P should be a pointer to struct bpstat, but is defined as a void *
4972 in order for this function to be usable with catch_errors. */
4975 watchpoint_check (void *p
)
4977 bpstat bs
= (bpstat
) p
;
4978 struct watchpoint
*b
;
4979 struct frame_info
*fr
;
4980 int within_current_scope
;
4982 /* BS is built from an existing struct breakpoint. */
4983 gdb_assert (bs
->breakpoint_at
!= NULL
);
4984 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4986 /* If this is a local watchpoint, we only want to check if the
4987 watchpoint frame is in scope if the current thread is the thread
4988 that was used to create the watchpoint. */
4989 if (!watchpoint_in_thread_scope (b
))
4992 if (b
->exp_valid_block
== NULL
)
4993 within_current_scope
= 1;
4996 struct frame_info
*frame
= get_current_frame ();
4997 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4998 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5000 /* in_function_epilogue_p() returns a non-zero value if we're
5001 still in the function but the stack frame has already been
5002 invalidated. Since we can't rely on the values of local
5003 variables after the stack has been destroyed, we are treating
5004 the watchpoint in that state as `not changed' without further
5005 checking. Don't mark watchpoints as changed if the current
5006 frame is in an epilogue - even if they are in some other
5007 frame, our view of the stack is likely to be wrong and
5008 frame_find_by_id could error out. */
5009 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
5012 fr
= frame_find_by_id (b
->watchpoint_frame
);
5013 within_current_scope
= (fr
!= NULL
);
5015 /* If we've gotten confused in the unwinder, we might have
5016 returned a frame that can't describe this variable. */
5017 if (within_current_scope
)
5019 struct symbol
*function
;
5021 function
= get_frame_function (fr
);
5022 if (function
== NULL
5023 || !contained_in (b
->exp_valid_block
,
5024 SYMBOL_BLOCK_VALUE (function
)))
5025 within_current_scope
= 0;
5028 if (within_current_scope
)
5029 /* If we end up stopping, the current frame will get selected
5030 in normal_stop. So this call to select_frame won't affect
5035 if (within_current_scope
)
5037 /* We use value_{,free_to_}mark because it could be a *long*
5038 time before we return to the command level and call
5039 free_all_values. We can't call free_all_values because we
5040 might be in the middle of evaluating a function call. */
5044 struct value
*new_val
;
5046 if (is_masked_watchpoint (&b
->base
))
5047 /* Since we don't know the exact trigger address (from
5048 stopped_data_address), just tell the user we've triggered
5049 a mask watchpoint. */
5050 return WP_VALUE_CHANGED
;
5052 mark
= value_mark ();
5053 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5055 if (b
->val_bitsize
!= 0)
5056 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5058 /* We use value_equal_contents instead of value_equal because
5059 the latter coerces an array to a pointer, thus comparing just
5060 the address of the array instead of its contents. This is
5061 not what we want. */
5062 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5063 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5065 if (new_val
!= NULL
)
5067 release_value (new_val
);
5068 value_free_to_mark (mark
);
5070 bs
->old_val
= b
->val
;
5073 return WP_VALUE_CHANGED
;
5077 /* Nothing changed. */
5078 value_free_to_mark (mark
);
5079 return WP_VALUE_NOT_CHANGED
;
5084 struct ui_out
*uiout
= current_uiout
;
5086 /* This seems like the only logical thing to do because
5087 if we temporarily ignored the watchpoint, then when
5088 we reenter the block in which it is valid it contains
5089 garbage (in the case of a function, it may have two
5090 garbage values, one before and one after the prologue).
5091 So we can't even detect the first assignment to it and
5092 watch after that (since the garbage may or may not equal
5093 the first value assigned). */
5094 /* We print all the stop information in
5095 breakpoint_ops->print_it, but in this case, by the time we
5096 call breakpoint_ops->print_it this bp will be deleted
5097 already. So we have no choice but print the information
5099 if (ui_out_is_mi_like_p (uiout
))
5101 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5102 ui_out_text (uiout
, "\nWatchpoint ");
5103 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5105 " deleted because the program has left the block in\n\
5106 which its expression is valid.\n");
5108 /* Make sure the watchpoint's commands aren't executed. */
5109 decref_counted_command_line (&b
->base
.commands
);
5110 watchpoint_del_at_next_stop (b
);
5116 /* Return true if it looks like target has stopped due to hitting
5117 breakpoint location BL. This function does not check if we should
5118 stop, only if BL explains the stop. */
5121 bpstat_check_location (const struct bp_location
*bl
,
5122 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5123 const struct target_waitstatus
*ws
)
5125 struct breakpoint
*b
= bl
->owner
;
5127 /* BL is from an existing breakpoint. */
5128 gdb_assert (b
!= NULL
);
5130 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5133 /* Determine if the watched values have actually changed, and we
5134 should stop. If not, set BS->stop to 0. */
5137 bpstat_check_watchpoint (bpstat bs
)
5139 const struct bp_location
*bl
;
5140 struct watchpoint
*b
;
5142 /* BS is built for existing struct breakpoint. */
5143 bl
= bs
->bp_location_at
;
5144 gdb_assert (bl
!= NULL
);
5145 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5146 gdb_assert (b
!= NULL
);
5149 int must_check_value
= 0;
5151 if (b
->base
.type
== bp_watchpoint
)
5152 /* For a software watchpoint, we must always check the
5154 must_check_value
= 1;
5155 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5156 /* We have a hardware watchpoint (read, write, or access)
5157 and the target earlier reported an address watched by
5159 must_check_value
= 1;
5160 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5161 && b
->base
.type
== bp_hardware_watchpoint
)
5162 /* We were stopped by a hardware watchpoint, but the target could
5163 not report the data address. We must check the watchpoint's
5164 value. Access and read watchpoints are out of luck; without
5165 a data address, we can't figure it out. */
5166 must_check_value
= 1;
5168 if (must_check_value
)
5171 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5173 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5174 int e
= catch_errors (watchpoint_check
, bs
, message
,
5176 do_cleanups (cleanups
);
5180 /* We've already printed what needs to be printed. */
5181 bs
->print_it
= print_it_done
;
5185 bs
->print_it
= print_it_noop
;
5188 case WP_VALUE_CHANGED
:
5189 if (b
->base
.type
== bp_read_watchpoint
)
5191 /* There are two cases to consider here:
5193 1. We're watching the triggered memory for reads.
5194 In that case, trust the target, and always report
5195 the watchpoint hit to the user. Even though
5196 reads don't cause value changes, the value may
5197 have changed since the last time it was read, and
5198 since we're not trapping writes, we will not see
5199 those, and as such we should ignore our notion of
5202 2. We're watching the triggered memory for both
5203 reads and writes. There are two ways this may
5206 2.1. This is a target that can't break on data
5207 reads only, but can break on accesses (reads or
5208 writes), such as e.g., x86. We detect this case
5209 at the time we try to insert read watchpoints.
5211 2.2. Otherwise, the target supports read
5212 watchpoints, but, the user set an access or write
5213 watchpoint watching the same memory as this read
5216 If we're watching memory writes as well as reads,
5217 ignore watchpoint hits when we find that the
5218 value hasn't changed, as reads don't cause
5219 changes. This still gives false positives when
5220 the program writes the same value to memory as
5221 what there was already in memory (we will confuse
5222 it for a read), but it's much better than
5225 int other_write_watchpoint
= 0;
5227 if (bl
->watchpoint_type
== hw_read
)
5229 struct breakpoint
*other_b
;
5231 ALL_BREAKPOINTS (other_b
)
5232 if (other_b
->type
== bp_hardware_watchpoint
5233 || other_b
->type
== bp_access_watchpoint
)
5235 struct watchpoint
*other_w
=
5236 (struct watchpoint
*) other_b
;
5238 if (other_w
->watchpoint_triggered
5239 == watch_triggered_yes
)
5241 other_write_watchpoint
= 1;
5247 if (other_write_watchpoint
5248 || bl
->watchpoint_type
== hw_access
)
5250 /* We're watching the same memory for writes,
5251 and the value changed since the last time we
5252 updated it, so this trap must be for a write.
5254 bs
->print_it
= print_it_noop
;
5259 case WP_VALUE_NOT_CHANGED
:
5260 if (b
->base
.type
== bp_hardware_watchpoint
5261 || b
->base
.type
== bp_watchpoint
)
5263 /* Don't stop: write watchpoints shouldn't fire if
5264 the value hasn't changed. */
5265 bs
->print_it
= print_it_noop
;
5273 /* Error from catch_errors. */
5274 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5275 watchpoint_del_at_next_stop (b
);
5276 /* We've already printed what needs to be printed. */
5277 bs
->print_it
= print_it_done
;
5281 else /* must_check_value == 0 */
5283 /* This is a case where some watchpoint(s) triggered, but
5284 not at the address of this watchpoint, or else no
5285 watchpoint triggered after all. So don't print
5286 anything for this watchpoint. */
5287 bs
->print_it
= print_it_noop
;
5293 /* For breakpoints that are currently marked as telling gdb to stop,
5294 check conditions (condition proper, frame, thread and ignore count)
5295 of breakpoint referred to by BS. If we should not stop for this
5296 breakpoint, set BS->stop to 0. */
5299 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5301 const struct bp_location
*bl
;
5302 struct breakpoint
*b
;
5303 int value_is_zero
= 0;
5304 struct expression
*cond
;
5306 gdb_assert (bs
->stop
);
5308 /* BS is built for existing struct breakpoint. */
5309 bl
= bs
->bp_location_at
;
5310 gdb_assert (bl
!= NULL
);
5311 b
= bs
->breakpoint_at
;
5312 gdb_assert (b
!= NULL
);
5314 /* Even if the target evaluated the condition on its end and notified GDB, we
5315 need to do so again since GDB does not know if we stopped due to a
5316 breakpoint or a single step breakpoint. */
5318 if (frame_id_p (b
->frame_id
)
5319 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5325 /* If this is a thread/task-specific breakpoint, don't waste cpu
5326 evaluating the condition if this isn't the specified
5328 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5329 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5336 /* Evaluate extension language breakpoints that have a "stop" method
5338 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5340 if (is_watchpoint (b
))
5342 struct watchpoint
*w
= (struct watchpoint
*) b
;
5349 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5351 int within_current_scope
= 1;
5352 struct watchpoint
* w
;
5354 /* We use value_mark and value_free_to_mark because it could
5355 be a long time before we return to the command level and
5356 call free_all_values. We can't call free_all_values
5357 because we might be in the middle of evaluating a
5359 struct value
*mark
= value_mark ();
5361 if (is_watchpoint (b
))
5362 w
= (struct watchpoint
*) b
;
5366 /* Need to select the frame, with all that implies so that
5367 the conditions will have the right context. Because we
5368 use the frame, we will not see an inlined function's
5369 variables when we arrive at a breakpoint at the start
5370 of the inlined function; the current frame will be the
5372 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5373 select_frame (get_current_frame ());
5376 struct frame_info
*frame
;
5378 /* For local watchpoint expressions, which particular
5379 instance of a local is being watched matters, so we
5380 keep track of the frame to evaluate the expression
5381 in. To evaluate the condition however, it doesn't
5382 really matter which instantiation of the function
5383 where the condition makes sense triggers the
5384 watchpoint. This allows an expression like "watch
5385 global if q > 10" set in `func', catch writes to
5386 global on all threads that call `func', or catch
5387 writes on all recursive calls of `func' by a single
5388 thread. We simply always evaluate the condition in
5389 the innermost frame that's executing where it makes
5390 sense to evaluate the condition. It seems
5392 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5394 select_frame (frame
);
5396 within_current_scope
= 0;
5398 if (within_current_scope
)
5400 = catch_errors (breakpoint_cond_eval
, cond
,
5401 "Error in testing breakpoint condition:\n",
5405 warning (_("Watchpoint condition cannot be tested "
5406 "in the current scope"));
5407 /* If we failed to set the right context for this
5408 watchpoint, unconditionally report it. */
5411 /* FIXME-someday, should give breakpoint #. */
5412 value_free_to_mark (mark
);
5415 if (cond
&& value_is_zero
)
5419 else if (b
->ignore_count
> 0)
5423 /* Increase the hit count even though we don't stop. */
5425 observer_notify_breakpoint_modified (b
);
5430 /* Get a bpstat associated with having just stopped at address
5431 BP_ADDR in thread PTID.
5433 Determine whether we stopped at a breakpoint, etc, or whether we
5434 don't understand this stop. Result is a chain of bpstat's such
5437 if we don't understand the stop, the result is a null pointer.
5439 if we understand why we stopped, the result is not null.
5441 Each element of the chain refers to a particular breakpoint or
5442 watchpoint at which we have stopped. (We may have stopped for
5443 several reasons concurrently.)
5445 Each element of the chain has valid next, breakpoint_at,
5446 commands, FIXME??? fields. */
5449 bpstat_stop_status (struct address_space
*aspace
,
5450 CORE_ADDR bp_addr
, ptid_t ptid
,
5451 const struct target_waitstatus
*ws
)
5453 struct breakpoint
*b
= NULL
;
5454 struct bp_location
*bl
;
5455 struct bp_location
*loc
;
5456 /* First item of allocated bpstat's. */
5457 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5458 /* Pointer to the last thing in the chain currently. */
5461 int need_remove_insert
;
5464 /* First, build the bpstat chain with locations that explain a
5465 target stop, while being careful to not set the target running,
5466 as that may invalidate locations (in particular watchpoint
5467 locations are recreated). Resuming will happen here with
5468 breakpoint conditions or watchpoint expressions that include
5469 inferior function calls. */
5473 if (!breakpoint_enabled (b
))
5476 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5478 /* For hardware watchpoints, we look only at the first
5479 location. The watchpoint_check function will work on the
5480 entire expression, not the individual locations. For
5481 read watchpoints, the watchpoints_triggered function has
5482 checked all locations already. */
5483 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5486 if (!bl
->enabled
|| bl
->shlib_disabled
)
5489 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5492 /* Come here if it's a watchpoint, or if the break address
5495 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5498 /* Assume we stop. Should we find a watchpoint that is not
5499 actually triggered, or if the condition of the breakpoint
5500 evaluates as false, we'll reset 'stop' to 0. */
5504 /* If this is a scope breakpoint, mark the associated
5505 watchpoint as triggered so that we will handle the
5506 out-of-scope event. We'll get to the watchpoint next
5508 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5510 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5512 w
->watchpoint_triggered
= watch_triggered_yes
;
5517 /* Check if a moribund breakpoint explains the stop. */
5518 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5520 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5522 bs
= bpstat_alloc (loc
, &bs_link
);
5523 /* For hits of moribund locations, we should just proceed. */
5526 bs
->print_it
= print_it_noop
;
5530 /* A bit of special processing for shlib breakpoints. We need to
5531 process solib loading here, so that the lists of loaded and
5532 unloaded libraries are correct before we handle "catch load" and
5534 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5536 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5538 handle_solib_event ();
5543 /* Now go through the locations that caused the target to stop, and
5544 check whether we're interested in reporting this stop to higher
5545 layers, or whether we should resume the target transparently. */
5549 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5554 b
= bs
->breakpoint_at
;
5555 b
->ops
->check_status (bs
);
5558 bpstat_check_breakpoint_conditions (bs
, ptid
);
5563 observer_notify_breakpoint_modified (b
);
5565 /* We will stop here. */
5566 if (b
->disposition
== disp_disable
)
5568 --(b
->enable_count
);
5569 if (b
->enable_count
<= 0)
5570 b
->enable_state
= bp_disabled
;
5575 bs
->commands
= b
->commands
;
5576 incref_counted_command_line (bs
->commands
);
5577 if (command_line_is_silent (bs
->commands
5578 ? bs
->commands
->commands
: NULL
))
5581 b
->ops
->after_condition_true (bs
);
5586 /* Print nothing for this entry if we don't stop or don't
5588 if (!bs
->stop
|| !bs
->print
)
5589 bs
->print_it
= print_it_noop
;
5592 /* If we aren't stopping, the value of some hardware watchpoint may
5593 not have changed, but the intermediate memory locations we are
5594 watching may have. Don't bother if we're stopping; this will get
5596 need_remove_insert
= 0;
5597 if (! bpstat_causes_stop (bs_head
))
5598 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5600 && bs
->breakpoint_at
5601 && is_hardware_watchpoint (bs
->breakpoint_at
))
5603 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5605 update_watchpoint (w
, 0 /* don't reparse. */);
5606 need_remove_insert
= 1;
5609 if (need_remove_insert
)
5610 update_global_location_list (UGLL_MAY_INSERT
);
5611 else if (removed_any
)
5612 update_global_location_list (UGLL_DONT_INSERT
);
5618 handle_jit_event (void)
5620 struct frame_info
*frame
;
5621 struct gdbarch
*gdbarch
;
5623 /* Switch terminal for any messages produced by
5624 breakpoint_re_set. */
5625 target_terminal_ours_for_output ();
5627 frame
= get_current_frame ();
5628 gdbarch
= get_frame_arch (frame
);
5630 jit_event_handler (gdbarch
);
5632 target_terminal_inferior ();
5635 /* Prepare WHAT final decision for infrun. */
5637 /* Decide what infrun needs to do with this bpstat. */
5640 bpstat_what (bpstat bs_head
)
5642 struct bpstat_what retval
;
5646 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5647 retval
.call_dummy
= STOP_NONE
;
5648 retval
.is_longjmp
= 0;
5650 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5652 /* Extract this BS's action. After processing each BS, we check
5653 if its action overrides all we've seem so far. */
5654 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5657 if (bs
->breakpoint_at
== NULL
)
5659 /* I suspect this can happen if it was a momentary
5660 breakpoint which has since been deleted. */
5664 bptype
= bs
->breakpoint_at
->type
;
5671 case bp_hardware_breakpoint
:
5672 case bp_single_step
:
5675 case bp_shlib_event
:
5679 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5681 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5684 this_action
= BPSTAT_WHAT_SINGLE
;
5687 case bp_hardware_watchpoint
:
5688 case bp_read_watchpoint
:
5689 case bp_access_watchpoint
:
5693 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5695 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5699 /* There was a watchpoint, but we're not stopping.
5700 This requires no further action. */
5704 case bp_longjmp_call_dummy
:
5706 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5707 retval
.is_longjmp
= bptype
!= bp_exception
;
5709 case bp_longjmp_resume
:
5710 case bp_exception_resume
:
5711 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5712 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5714 case bp_step_resume
:
5716 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5719 /* It is for the wrong frame. */
5720 this_action
= BPSTAT_WHAT_SINGLE
;
5723 case bp_hp_step_resume
:
5725 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5728 /* It is for the wrong frame. */
5729 this_action
= BPSTAT_WHAT_SINGLE
;
5732 case bp_watchpoint_scope
:
5733 case bp_thread_event
:
5734 case bp_overlay_event
:
5735 case bp_longjmp_master
:
5736 case bp_std_terminate_master
:
5737 case bp_exception_master
:
5738 this_action
= BPSTAT_WHAT_SINGLE
;
5744 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5746 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5750 /* There was a catchpoint, but we're not stopping.
5751 This requires no further action. */
5756 this_action
= BPSTAT_WHAT_SINGLE
;
5759 /* Make sure the action is stop (silent or noisy),
5760 so infrun.c pops the dummy frame. */
5761 retval
.call_dummy
= STOP_STACK_DUMMY
;
5762 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5764 case bp_std_terminate
:
5765 /* Make sure the action is stop (silent or noisy),
5766 so infrun.c pops the dummy frame. */
5767 retval
.call_dummy
= STOP_STD_TERMINATE
;
5768 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5771 case bp_fast_tracepoint
:
5772 case bp_static_tracepoint
:
5773 /* Tracepoint hits should not be reported back to GDB, and
5774 if one got through somehow, it should have been filtered
5776 internal_error (__FILE__
, __LINE__
,
5777 _("bpstat_what: tracepoint encountered"));
5779 case bp_gnu_ifunc_resolver
:
5780 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5781 this_action
= BPSTAT_WHAT_SINGLE
;
5783 case bp_gnu_ifunc_resolver_return
:
5784 /* The breakpoint will be removed, execution will restart from the
5785 PC of the former breakpoint. */
5786 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5791 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5793 this_action
= BPSTAT_WHAT_SINGLE
;
5797 internal_error (__FILE__
, __LINE__
,
5798 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5801 retval
.main_action
= max (retval
.main_action
, this_action
);
5804 /* These operations may affect the bs->breakpoint_at state so they are
5805 delayed after MAIN_ACTION is decided above. */
5810 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5812 handle_jit_event ();
5815 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5817 struct breakpoint
*b
= bs
->breakpoint_at
;
5823 case bp_gnu_ifunc_resolver
:
5824 gnu_ifunc_resolver_stop (b
);
5826 case bp_gnu_ifunc_resolver_return
:
5827 gnu_ifunc_resolver_return_stop (b
);
5835 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5836 without hardware support). This isn't related to a specific bpstat,
5837 just to things like whether watchpoints are set. */
5840 bpstat_should_step (void)
5842 struct breakpoint
*b
;
5845 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5851 bpstat_causes_stop (bpstat bs
)
5853 for (; bs
!= NULL
; bs
= bs
->next
)
5862 /* Compute a string of spaces suitable to indent the next line
5863 so it starts at the position corresponding to the table column
5864 named COL_NAME in the currently active table of UIOUT. */
5867 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5869 static char wrap_indent
[80];
5870 int i
, total_width
, width
, align
;
5874 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5876 if (strcmp (text
, col_name
) == 0)
5878 gdb_assert (total_width
< sizeof wrap_indent
);
5879 memset (wrap_indent
, ' ', total_width
);
5880 wrap_indent
[total_width
] = 0;
5885 total_width
+= width
+ 1;
5891 /* Determine if the locations of this breakpoint will have their conditions
5892 evaluated by the target, host or a mix of both. Returns the following:
5894 "host": Host evals condition.
5895 "host or target": Host or Target evals condition.
5896 "target": Target evals condition.
5900 bp_condition_evaluator (struct breakpoint
*b
)
5902 struct bp_location
*bl
;
5903 char host_evals
= 0;
5904 char target_evals
= 0;
5909 if (!is_breakpoint (b
))
5912 if (gdb_evaluates_breakpoint_condition_p ()
5913 || !target_supports_evaluation_of_breakpoint_conditions ())
5914 return condition_evaluation_host
;
5916 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5918 if (bl
->cond_bytecode
)
5924 if (host_evals
&& target_evals
)
5925 return condition_evaluation_both
;
5926 else if (target_evals
)
5927 return condition_evaluation_target
;
5929 return condition_evaluation_host
;
5932 /* Determine the breakpoint location's condition evaluator. This is
5933 similar to bp_condition_evaluator, but for locations. */
5936 bp_location_condition_evaluator (struct bp_location
*bl
)
5938 if (bl
&& !is_breakpoint (bl
->owner
))
5941 if (gdb_evaluates_breakpoint_condition_p ()
5942 || !target_supports_evaluation_of_breakpoint_conditions ())
5943 return condition_evaluation_host
;
5945 if (bl
&& bl
->cond_bytecode
)
5946 return condition_evaluation_target
;
5948 return condition_evaluation_host
;
5951 /* Print the LOC location out of the list of B->LOC locations. */
5954 print_breakpoint_location (struct breakpoint
*b
,
5955 struct bp_location
*loc
)
5957 struct ui_out
*uiout
= current_uiout
;
5958 struct cleanup
*old_chain
= save_current_program_space ();
5960 if (loc
!= NULL
&& loc
->shlib_disabled
)
5964 set_current_program_space (loc
->pspace
);
5966 if (b
->display_canonical
)
5967 ui_out_field_string (uiout
, "what", b
->addr_string
);
5968 else if (loc
&& loc
->symtab
)
5971 = find_pc_sect_function (loc
->address
, loc
->section
);
5974 ui_out_text (uiout
, "in ");
5975 ui_out_field_string (uiout
, "func",
5976 SYMBOL_PRINT_NAME (sym
));
5977 ui_out_text (uiout
, " ");
5978 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5979 ui_out_text (uiout
, "at ");
5981 ui_out_field_string (uiout
, "file",
5982 symtab_to_filename_for_display (loc
->symtab
));
5983 ui_out_text (uiout
, ":");
5985 if (ui_out_is_mi_like_p (uiout
))
5986 ui_out_field_string (uiout
, "fullname",
5987 symtab_to_fullname (loc
->symtab
));
5989 ui_out_field_int (uiout
, "line", loc
->line_number
);
5993 struct ui_file
*stb
= mem_fileopen ();
5994 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5996 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5998 ui_out_field_stream (uiout
, "at", stb
);
6000 do_cleanups (stb_chain
);
6003 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6005 if (loc
&& is_breakpoint (b
)
6006 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6007 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6009 ui_out_text (uiout
, " (");
6010 ui_out_field_string (uiout
, "evaluated-by",
6011 bp_location_condition_evaluator (loc
));
6012 ui_out_text (uiout
, ")");
6015 do_cleanups (old_chain
);
6019 bptype_string (enum bptype type
)
6021 struct ep_type_description
6026 static struct ep_type_description bptypes
[] =
6028 {bp_none
, "?deleted?"},
6029 {bp_breakpoint
, "breakpoint"},
6030 {bp_hardware_breakpoint
, "hw breakpoint"},
6031 {bp_single_step
, "sw single-step"},
6032 {bp_until
, "until"},
6033 {bp_finish
, "finish"},
6034 {bp_watchpoint
, "watchpoint"},
6035 {bp_hardware_watchpoint
, "hw watchpoint"},
6036 {bp_read_watchpoint
, "read watchpoint"},
6037 {bp_access_watchpoint
, "acc watchpoint"},
6038 {bp_longjmp
, "longjmp"},
6039 {bp_longjmp_resume
, "longjmp resume"},
6040 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6041 {bp_exception
, "exception"},
6042 {bp_exception_resume
, "exception resume"},
6043 {bp_step_resume
, "step resume"},
6044 {bp_hp_step_resume
, "high-priority step resume"},
6045 {bp_watchpoint_scope
, "watchpoint scope"},
6046 {bp_call_dummy
, "call dummy"},
6047 {bp_std_terminate
, "std::terminate"},
6048 {bp_shlib_event
, "shlib events"},
6049 {bp_thread_event
, "thread events"},
6050 {bp_overlay_event
, "overlay events"},
6051 {bp_longjmp_master
, "longjmp master"},
6052 {bp_std_terminate_master
, "std::terminate master"},
6053 {bp_exception_master
, "exception master"},
6054 {bp_catchpoint
, "catchpoint"},
6055 {bp_tracepoint
, "tracepoint"},
6056 {bp_fast_tracepoint
, "fast tracepoint"},
6057 {bp_static_tracepoint
, "static tracepoint"},
6058 {bp_dprintf
, "dprintf"},
6059 {bp_jit_event
, "jit events"},
6060 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6061 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6064 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6065 || ((int) type
!= bptypes
[(int) type
].type
))
6066 internal_error (__FILE__
, __LINE__
,
6067 _("bptypes table does not describe type #%d."),
6070 return bptypes
[(int) type
].description
;
6073 /* For MI, output a field named 'thread-groups' with a list as the value.
6074 For CLI, prefix the list with the string 'inf'. */
6077 output_thread_groups (struct ui_out
*uiout
,
6078 const char *field_name
,
6082 struct cleanup
*back_to
;
6083 int is_mi
= ui_out_is_mi_like_p (uiout
);
6087 /* For backward compatibility, don't display inferiors in CLI unless
6088 there are several. Always display them for MI. */
6089 if (!is_mi
&& mi_only
)
6092 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6094 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6100 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6101 ui_out_field_string (uiout
, NULL
, mi_group
);
6106 ui_out_text (uiout
, " inf ");
6108 ui_out_text (uiout
, ", ");
6110 ui_out_text (uiout
, plongest (inf
));
6114 do_cleanups (back_to
);
6117 /* Print B to gdb_stdout. */
6120 print_one_breakpoint_location (struct breakpoint
*b
,
6121 struct bp_location
*loc
,
6123 struct bp_location
**last_loc
,
6126 struct command_line
*l
;
6127 static char bpenables
[] = "nynny";
6129 struct ui_out
*uiout
= current_uiout
;
6130 int header_of_multiple
= 0;
6131 int part_of_multiple
= (loc
!= NULL
);
6132 struct value_print_options opts
;
6134 get_user_print_options (&opts
);
6136 gdb_assert (!loc
|| loc_number
!= 0);
6137 /* See comment in print_one_breakpoint concerning treatment of
6138 breakpoints with single disabled location. */
6141 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6142 header_of_multiple
= 1;
6150 if (part_of_multiple
)
6153 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6154 ui_out_field_string (uiout
, "number", formatted
);
6159 ui_out_field_int (uiout
, "number", b
->number
);
6164 if (part_of_multiple
)
6165 ui_out_field_skip (uiout
, "type");
6167 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6171 if (part_of_multiple
)
6172 ui_out_field_skip (uiout
, "disp");
6174 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6179 if (part_of_multiple
)
6180 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6182 ui_out_field_fmt (uiout
, "enabled", "%c",
6183 bpenables
[(int) b
->enable_state
]);
6184 ui_out_spaces (uiout
, 2);
6188 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6190 /* Although the print_one can possibly print all locations,
6191 calling it here is not likely to get any nice result. So,
6192 make sure there's just one location. */
6193 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6194 b
->ops
->print_one (b
, last_loc
);
6200 internal_error (__FILE__
, __LINE__
,
6201 _("print_one_breakpoint: bp_none encountered\n"));
6205 case bp_hardware_watchpoint
:
6206 case bp_read_watchpoint
:
6207 case bp_access_watchpoint
:
6209 struct watchpoint
*w
= (struct watchpoint
*) b
;
6211 /* Field 4, the address, is omitted (which makes the columns
6212 not line up too nicely with the headers, but the effect
6213 is relatively readable). */
6214 if (opts
.addressprint
)
6215 ui_out_field_skip (uiout
, "addr");
6217 ui_out_field_string (uiout
, "what", w
->exp_string
);
6222 case bp_hardware_breakpoint
:
6223 case bp_single_step
:
6227 case bp_longjmp_resume
:
6228 case bp_longjmp_call_dummy
:
6230 case bp_exception_resume
:
6231 case bp_step_resume
:
6232 case bp_hp_step_resume
:
6233 case bp_watchpoint_scope
:
6235 case bp_std_terminate
:
6236 case bp_shlib_event
:
6237 case bp_thread_event
:
6238 case bp_overlay_event
:
6239 case bp_longjmp_master
:
6240 case bp_std_terminate_master
:
6241 case bp_exception_master
:
6243 case bp_fast_tracepoint
:
6244 case bp_static_tracepoint
:
6247 case bp_gnu_ifunc_resolver
:
6248 case bp_gnu_ifunc_resolver_return
:
6249 if (opts
.addressprint
)
6252 if (header_of_multiple
)
6253 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6254 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6255 ui_out_field_string (uiout
, "addr", "<PENDING>");
6257 ui_out_field_core_addr (uiout
, "addr",
6258 loc
->gdbarch
, loc
->address
);
6261 if (!header_of_multiple
)
6262 print_breakpoint_location (b
, loc
);
6269 if (loc
!= NULL
&& !header_of_multiple
)
6271 struct inferior
*inf
;
6272 VEC(int) *inf_num
= NULL
;
6277 if (inf
->pspace
== loc
->pspace
)
6278 VEC_safe_push (int, inf_num
, inf
->num
);
6281 /* For backward compatibility, don't display inferiors in CLI unless
6282 there are several. Always display for MI. */
6284 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6285 && (number_of_program_spaces () > 1
6286 || number_of_inferiors () > 1)
6287 /* LOC is for existing B, it cannot be in
6288 moribund_locations and thus having NULL OWNER. */
6289 && loc
->owner
->type
!= bp_catchpoint
))
6291 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6292 VEC_free (int, inf_num
);
6295 if (!part_of_multiple
)
6297 if (b
->thread
!= -1)
6299 /* FIXME: This seems to be redundant and lost here; see the
6300 "stop only in" line a little further down. */
6301 ui_out_text (uiout
, " thread ");
6302 ui_out_field_int (uiout
, "thread", b
->thread
);
6304 else if (b
->task
!= 0)
6306 ui_out_text (uiout
, " task ");
6307 ui_out_field_int (uiout
, "task", b
->task
);
6311 ui_out_text (uiout
, "\n");
6313 if (!part_of_multiple
)
6314 b
->ops
->print_one_detail (b
, uiout
);
6316 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6319 ui_out_text (uiout
, "\tstop only in stack frame at ");
6320 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6322 ui_out_field_core_addr (uiout
, "frame",
6323 b
->gdbarch
, b
->frame_id
.stack_addr
);
6324 ui_out_text (uiout
, "\n");
6327 if (!part_of_multiple
&& b
->cond_string
)
6330 if (is_tracepoint (b
))
6331 ui_out_text (uiout
, "\ttrace only if ");
6333 ui_out_text (uiout
, "\tstop only if ");
6334 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6336 /* Print whether the target is doing the breakpoint's condition
6337 evaluation. If GDB is doing the evaluation, don't print anything. */
6338 if (is_breakpoint (b
)
6339 && breakpoint_condition_evaluation_mode ()
6340 == condition_evaluation_target
)
6342 ui_out_text (uiout
, " (");
6343 ui_out_field_string (uiout
, "evaluated-by",
6344 bp_condition_evaluator (b
));
6345 ui_out_text (uiout
, " evals)");
6347 ui_out_text (uiout
, "\n");
6350 if (!part_of_multiple
&& b
->thread
!= -1)
6352 /* FIXME should make an annotation for this. */
6353 ui_out_text (uiout
, "\tstop only in thread ");
6354 ui_out_field_int (uiout
, "thread", b
->thread
);
6355 ui_out_text (uiout
, "\n");
6358 if (!part_of_multiple
)
6362 /* FIXME should make an annotation for this. */
6363 if (is_catchpoint (b
))
6364 ui_out_text (uiout
, "\tcatchpoint");
6365 else if (is_tracepoint (b
))
6366 ui_out_text (uiout
, "\ttracepoint");
6368 ui_out_text (uiout
, "\tbreakpoint");
6369 ui_out_text (uiout
, " already hit ");
6370 ui_out_field_int (uiout
, "times", b
->hit_count
);
6371 if (b
->hit_count
== 1)
6372 ui_out_text (uiout
, " time\n");
6374 ui_out_text (uiout
, " times\n");
6378 /* Output the count also if it is zero, but only if this is mi. */
6379 if (ui_out_is_mi_like_p (uiout
))
6380 ui_out_field_int (uiout
, "times", b
->hit_count
);
6384 if (!part_of_multiple
&& b
->ignore_count
)
6387 ui_out_text (uiout
, "\tignore next ");
6388 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6389 ui_out_text (uiout
, " hits\n");
6392 /* Note that an enable count of 1 corresponds to "enable once"
6393 behavior, which is reported by the combination of enablement and
6394 disposition, so we don't need to mention it here. */
6395 if (!part_of_multiple
&& b
->enable_count
> 1)
6398 ui_out_text (uiout
, "\tdisable after ");
6399 /* Tweak the wording to clarify that ignore and enable counts
6400 are distinct, and have additive effect. */
6401 if (b
->ignore_count
)
6402 ui_out_text (uiout
, "additional ");
6404 ui_out_text (uiout
, "next ");
6405 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6406 ui_out_text (uiout
, " hits\n");
6409 if (!part_of_multiple
&& is_tracepoint (b
))
6411 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6413 if (tp
->traceframe_usage
)
6415 ui_out_text (uiout
, "\ttrace buffer usage ");
6416 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6417 ui_out_text (uiout
, " bytes\n");
6421 l
= b
->commands
? b
->commands
->commands
: NULL
;
6422 if (!part_of_multiple
&& l
)
6424 struct cleanup
*script_chain
;
6427 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6428 print_command_lines (uiout
, l
, 4);
6429 do_cleanups (script_chain
);
6432 if (is_tracepoint (b
))
6434 struct tracepoint
*t
= (struct tracepoint
*) b
;
6436 if (!part_of_multiple
&& t
->pass_count
)
6438 annotate_field (10);
6439 ui_out_text (uiout
, "\tpass count ");
6440 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6441 ui_out_text (uiout
, " \n");
6444 /* Don't display it when tracepoint or tracepoint location is
6446 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6448 annotate_field (11);
6450 if (ui_out_is_mi_like_p (uiout
))
6451 ui_out_field_string (uiout
, "installed",
6452 loc
->inserted
? "y" : "n");
6456 ui_out_text (uiout
, "\t");
6458 ui_out_text (uiout
, "\tnot ");
6459 ui_out_text (uiout
, "installed on target\n");
6464 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6466 if (is_watchpoint (b
))
6468 struct watchpoint
*w
= (struct watchpoint
*) b
;
6470 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6472 else if (b
->addr_string
)
6473 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6478 print_one_breakpoint (struct breakpoint
*b
,
6479 struct bp_location
**last_loc
,
6482 struct cleanup
*bkpt_chain
;
6483 struct ui_out
*uiout
= current_uiout
;
6485 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6487 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6488 do_cleanups (bkpt_chain
);
6490 /* If this breakpoint has custom print function,
6491 it's already printed. Otherwise, print individual
6492 locations, if any. */
6493 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6495 /* If breakpoint has a single location that is disabled, we
6496 print it as if it had several locations, since otherwise it's
6497 hard to represent "breakpoint enabled, location disabled"
6500 Note that while hardware watchpoints have several locations
6501 internally, that's not a property exposed to user. */
6503 && !is_hardware_watchpoint (b
)
6504 && (b
->loc
->next
|| !b
->loc
->enabled
))
6506 struct bp_location
*loc
;
6509 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6511 struct cleanup
*inner2
=
6512 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6513 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6514 do_cleanups (inner2
);
6521 breakpoint_address_bits (struct breakpoint
*b
)
6523 int print_address_bits
= 0;
6524 struct bp_location
*loc
;
6526 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6530 /* Software watchpoints that aren't watching memory don't have
6531 an address to print. */
6532 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6535 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6536 if (addr_bit
> print_address_bits
)
6537 print_address_bits
= addr_bit
;
6540 return print_address_bits
;
6543 struct captured_breakpoint_query_args
6549 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6551 struct captured_breakpoint_query_args
*args
= data
;
6552 struct breakpoint
*b
;
6553 struct bp_location
*dummy_loc
= NULL
;
6557 if (args
->bnum
== b
->number
)
6559 print_one_breakpoint (b
, &dummy_loc
, 0);
6567 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6568 char **error_message
)
6570 struct captured_breakpoint_query_args args
;
6573 /* For the moment we don't trust print_one_breakpoint() to not throw
6575 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6576 error_message
, RETURN_MASK_ALL
) < 0)
6582 /* Return true if this breakpoint was set by the user, false if it is
6583 internal or momentary. */
6586 user_breakpoint_p (struct breakpoint
*b
)
6588 return b
->number
> 0;
6591 /* Print information on user settable breakpoint (watchpoint, etc)
6592 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6593 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6594 FILTER is non-NULL, call it on each breakpoint and only include the
6595 ones for which it returns non-zero. Return the total number of
6596 breakpoints listed. */
6599 breakpoint_1 (char *args
, int allflag
,
6600 int (*filter
) (const struct breakpoint
*))
6602 struct breakpoint
*b
;
6603 struct bp_location
*last_loc
= NULL
;
6604 int nr_printable_breakpoints
;
6605 struct cleanup
*bkpttbl_chain
;
6606 struct value_print_options opts
;
6607 int print_address_bits
= 0;
6608 int print_type_col_width
= 14;
6609 struct ui_out
*uiout
= current_uiout
;
6611 get_user_print_options (&opts
);
6613 /* Compute the number of rows in the table, as well as the size
6614 required for address fields. */
6615 nr_printable_breakpoints
= 0;
6618 /* If we have a filter, only list the breakpoints it accepts. */
6619 if (filter
&& !filter (b
))
6622 /* If we have an "args" string, it is a list of breakpoints to
6623 accept. Skip the others. */
6624 if (args
!= NULL
&& *args
!= '\0')
6626 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6628 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6632 if (allflag
|| user_breakpoint_p (b
))
6634 int addr_bit
, type_len
;
6636 addr_bit
= breakpoint_address_bits (b
);
6637 if (addr_bit
> print_address_bits
)
6638 print_address_bits
= addr_bit
;
6640 type_len
= strlen (bptype_string (b
->type
));
6641 if (type_len
> print_type_col_width
)
6642 print_type_col_width
= type_len
;
6644 nr_printable_breakpoints
++;
6648 if (opts
.addressprint
)
6650 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6651 nr_printable_breakpoints
,
6655 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6656 nr_printable_breakpoints
,
6659 if (nr_printable_breakpoints
> 0)
6660 annotate_breakpoints_headers ();
6661 if (nr_printable_breakpoints
> 0)
6663 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6664 if (nr_printable_breakpoints
> 0)
6666 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6667 "type", "Type"); /* 2 */
6668 if (nr_printable_breakpoints
> 0)
6670 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6671 if (nr_printable_breakpoints
> 0)
6673 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6674 if (opts
.addressprint
)
6676 if (nr_printable_breakpoints
> 0)
6678 if (print_address_bits
<= 32)
6679 ui_out_table_header (uiout
, 10, ui_left
,
6680 "addr", "Address"); /* 5 */
6682 ui_out_table_header (uiout
, 18, ui_left
,
6683 "addr", "Address"); /* 5 */
6685 if (nr_printable_breakpoints
> 0)
6687 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6688 ui_out_table_body (uiout
);
6689 if (nr_printable_breakpoints
> 0)
6690 annotate_breakpoints_table ();
6695 /* If we have a filter, only list the breakpoints it accepts. */
6696 if (filter
&& !filter (b
))
6699 /* If we have an "args" string, it is a list of breakpoints to
6700 accept. Skip the others. */
6702 if (args
!= NULL
&& *args
!= '\0')
6704 if (allflag
) /* maintenance info breakpoint */
6706 if (parse_and_eval_long (args
) != b
->number
)
6709 else /* all others */
6711 if (!number_is_in_list (args
, b
->number
))
6715 /* We only print out user settable breakpoints unless the
6717 if (allflag
|| user_breakpoint_p (b
))
6718 print_one_breakpoint (b
, &last_loc
, allflag
);
6721 do_cleanups (bkpttbl_chain
);
6723 if (nr_printable_breakpoints
== 0)
6725 /* If there's a filter, let the caller decide how to report
6729 if (args
== NULL
|| *args
== '\0')
6730 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6732 ui_out_message (uiout
, 0,
6733 "No breakpoint or watchpoint matching '%s'.\n",
6739 if (last_loc
&& !server_command
)
6740 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6743 /* FIXME? Should this be moved up so that it is only called when
6744 there have been breakpoints? */
6745 annotate_breakpoints_table_end ();
6747 return nr_printable_breakpoints
;
6750 /* Display the value of default-collect in a way that is generally
6751 compatible with the breakpoint list. */
6754 default_collect_info (void)
6756 struct ui_out
*uiout
= current_uiout
;
6758 /* If it has no value (which is frequently the case), say nothing; a
6759 message like "No default-collect." gets in user's face when it's
6761 if (!*default_collect
)
6764 /* The following phrase lines up nicely with per-tracepoint collect
6766 ui_out_text (uiout
, "default collect ");
6767 ui_out_field_string (uiout
, "default-collect", default_collect
);
6768 ui_out_text (uiout
, " \n");
6772 breakpoints_info (char *args
, int from_tty
)
6774 breakpoint_1 (args
, 0, NULL
);
6776 default_collect_info ();
6780 watchpoints_info (char *args
, int from_tty
)
6782 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6783 struct ui_out
*uiout
= current_uiout
;
6785 if (num_printed
== 0)
6787 if (args
== NULL
|| *args
== '\0')
6788 ui_out_message (uiout
, 0, "No watchpoints.\n");
6790 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6795 maintenance_info_breakpoints (char *args
, int from_tty
)
6797 breakpoint_1 (args
, 1, NULL
);
6799 default_collect_info ();
6803 breakpoint_has_pc (struct breakpoint
*b
,
6804 struct program_space
*pspace
,
6805 CORE_ADDR pc
, struct obj_section
*section
)
6807 struct bp_location
*bl
= b
->loc
;
6809 for (; bl
; bl
= bl
->next
)
6811 if (bl
->pspace
== pspace
6812 && bl
->address
== pc
6813 && (!overlay_debugging
|| bl
->section
== section
))
6819 /* Print a message describing any user-breakpoints set at PC. This
6820 concerns with logical breakpoints, so we match program spaces, not
6824 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6825 struct program_space
*pspace
, CORE_ADDR pc
,
6826 struct obj_section
*section
, int thread
)
6829 struct breakpoint
*b
;
6832 others
+= (user_breakpoint_p (b
)
6833 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6837 printf_filtered (_("Note: breakpoint "));
6838 else /* if (others == ???) */
6839 printf_filtered (_("Note: breakpoints "));
6841 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6844 printf_filtered ("%d", b
->number
);
6845 if (b
->thread
== -1 && thread
!= -1)
6846 printf_filtered (" (all threads)");
6847 else if (b
->thread
!= -1)
6848 printf_filtered (" (thread %d)", b
->thread
);
6849 printf_filtered ("%s%s ",
6850 ((b
->enable_state
== bp_disabled
6851 || b
->enable_state
== bp_call_disabled
)
6855 : ((others
== 1) ? " and" : ""));
6857 printf_filtered (_("also set at pc "));
6858 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6859 printf_filtered (".\n");
6864 /* Return true iff it is meaningful to use the address member of
6865 BPT. For some breakpoint types, the address member is irrelevant
6866 and it makes no sense to attempt to compare it to other addresses
6867 (or use it for any other purpose either).
6869 More specifically, each of the following breakpoint types will
6870 always have a zero valued address and we don't want to mark
6871 breakpoints of any of these types to be a duplicate of an actual
6872 breakpoint at address zero:
6880 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6882 enum bptype type
= bpt
->type
;
6884 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6887 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6888 true if LOC1 and LOC2 represent the same watchpoint location. */
6891 watchpoint_locations_match (struct bp_location
*loc1
,
6892 struct bp_location
*loc2
)
6894 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6895 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6897 /* Both of them must exist. */
6898 gdb_assert (w1
!= NULL
);
6899 gdb_assert (w2
!= NULL
);
6901 /* If the target can evaluate the condition expression in hardware,
6902 then we we need to insert both watchpoints even if they are at
6903 the same place. Otherwise the watchpoint will only trigger when
6904 the condition of whichever watchpoint was inserted evaluates to
6905 true, not giving a chance for GDB to check the condition of the
6906 other watchpoint. */
6908 && target_can_accel_watchpoint_condition (loc1
->address
,
6910 loc1
->watchpoint_type
,
6913 && target_can_accel_watchpoint_condition (loc2
->address
,
6915 loc2
->watchpoint_type
,
6919 /* Note that this checks the owner's type, not the location's. In
6920 case the target does not support read watchpoints, but does
6921 support access watchpoints, we'll have bp_read_watchpoint
6922 watchpoints with hw_access locations. Those should be considered
6923 duplicates of hw_read locations. The hw_read locations will
6924 become hw_access locations later. */
6925 return (loc1
->owner
->type
== loc2
->owner
->type
6926 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6927 && loc1
->address
== loc2
->address
6928 && loc1
->length
== loc2
->length
);
6931 /* See breakpoint.h. */
6934 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6935 struct address_space
*aspace2
, CORE_ADDR addr2
)
6937 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6938 || aspace1
== aspace2
)
6942 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6943 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6944 matches ASPACE2. On targets that have global breakpoints, the address
6945 space doesn't really matter. */
6948 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6949 int len1
, struct address_space
*aspace2
,
6952 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6953 || aspace1
== aspace2
)
6954 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6957 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6958 a ranged breakpoint. In most targets, a match happens only if ASPACE
6959 matches the breakpoint's address space. On targets that have global
6960 breakpoints, the address space doesn't really matter. */
6963 breakpoint_location_address_match (struct bp_location
*bl
,
6964 struct address_space
*aspace
,
6967 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6970 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6971 bl
->address
, bl
->length
,
6975 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6976 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6977 true, otherwise returns false. */
6980 tracepoint_locations_match (struct bp_location
*loc1
,
6981 struct bp_location
*loc2
)
6983 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6984 /* Since tracepoint locations are never duplicated with others', tracepoint
6985 locations at the same address of different tracepoints are regarded as
6986 different locations. */
6987 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6992 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6993 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6994 represent the same location. */
6997 breakpoint_locations_match (struct bp_location
*loc1
,
6998 struct bp_location
*loc2
)
7000 int hw_point1
, hw_point2
;
7002 /* Both of them must not be in moribund_locations. */
7003 gdb_assert (loc1
->owner
!= NULL
);
7004 gdb_assert (loc2
->owner
!= NULL
);
7006 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7007 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7009 if (hw_point1
!= hw_point2
)
7012 return watchpoint_locations_match (loc1
, loc2
);
7013 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7014 return tracepoint_locations_match (loc1
, loc2
);
7016 /* We compare bp_location.length in order to cover ranged breakpoints. */
7017 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7018 loc2
->pspace
->aspace
, loc2
->address
)
7019 && loc1
->length
== loc2
->length
);
7023 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7024 int bnum
, int have_bnum
)
7026 /* The longest string possibly returned by hex_string_custom
7027 is 50 chars. These must be at least that big for safety. */
7031 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7032 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7034 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7035 bnum
, astr1
, astr2
);
7037 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7040 /* Adjust a breakpoint's address to account for architectural
7041 constraints on breakpoint placement. Return the adjusted address.
7042 Note: Very few targets require this kind of adjustment. For most
7043 targets, this function is simply the identity function. */
7046 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7047 CORE_ADDR bpaddr
, enum bptype bptype
)
7049 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7051 /* Very few targets need any kind of breakpoint adjustment. */
7054 else if (bptype
== bp_watchpoint
7055 || bptype
== bp_hardware_watchpoint
7056 || bptype
== bp_read_watchpoint
7057 || bptype
== bp_access_watchpoint
7058 || bptype
== bp_catchpoint
)
7060 /* Watchpoints and the various bp_catch_* eventpoints should not
7061 have their addresses modified. */
7064 else if (bptype
== bp_single_step
)
7066 /* Single-step breakpoints should not have their addresses
7067 modified. If there's any architectural constrain that
7068 applies to this address, then it should have already been
7069 taken into account when the breakpoint was created in the
7070 first place. If we didn't do this, stepping through e.g.,
7071 Thumb-2 IT blocks would break. */
7076 CORE_ADDR adjusted_bpaddr
;
7078 /* Some targets have architectural constraints on the placement
7079 of breakpoint instructions. Obtain the adjusted address. */
7080 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7082 /* An adjusted breakpoint address can significantly alter
7083 a user's expectations. Print a warning if an adjustment
7085 if (adjusted_bpaddr
!= bpaddr
)
7086 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7088 return adjusted_bpaddr
;
7093 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7094 struct breakpoint
*owner
)
7096 memset (loc
, 0, sizeof (*loc
));
7098 gdb_assert (ops
!= NULL
);
7103 loc
->cond_bytecode
= NULL
;
7104 loc
->shlib_disabled
= 0;
7107 switch (owner
->type
)
7110 case bp_single_step
:
7114 case bp_longjmp_resume
:
7115 case bp_longjmp_call_dummy
:
7117 case bp_exception_resume
:
7118 case bp_step_resume
:
7119 case bp_hp_step_resume
:
7120 case bp_watchpoint_scope
:
7122 case bp_std_terminate
:
7123 case bp_shlib_event
:
7124 case bp_thread_event
:
7125 case bp_overlay_event
:
7127 case bp_longjmp_master
:
7128 case bp_std_terminate_master
:
7129 case bp_exception_master
:
7130 case bp_gnu_ifunc_resolver
:
7131 case bp_gnu_ifunc_resolver_return
:
7133 loc
->loc_type
= bp_loc_software_breakpoint
;
7134 mark_breakpoint_location_modified (loc
);
7136 case bp_hardware_breakpoint
:
7137 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7138 mark_breakpoint_location_modified (loc
);
7140 case bp_hardware_watchpoint
:
7141 case bp_read_watchpoint
:
7142 case bp_access_watchpoint
:
7143 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7148 case bp_fast_tracepoint
:
7149 case bp_static_tracepoint
:
7150 loc
->loc_type
= bp_loc_other
;
7153 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7159 /* Allocate a struct bp_location. */
7161 static struct bp_location
*
7162 allocate_bp_location (struct breakpoint
*bpt
)
7164 return bpt
->ops
->allocate_location (bpt
);
7168 free_bp_location (struct bp_location
*loc
)
7170 loc
->ops
->dtor (loc
);
7174 /* Increment reference count. */
7177 incref_bp_location (struct bp_location
*bl
)
7182 /* Decrement reference count. If the reference count reaches 0,
7183 destroy the bp_location. Sets *BLP to NULL. */
7186 decref_bp_location (struct bp_location
**blp
)
7188 gdb_assert ((*blp
)->refc
> 0);
7190 if (--(*blp
)->refc
== 0)
7191 free_bp_location (*blp
);
7195 /* Add breakpoint B at the end of the global breakpoint chain. */
7198 add_to_breakpoint_chain (struct breakpoint
*b
)
7200 struct breakpoint
*b1
;
7202 /* Add this breakpoint to the end of the chain so that a list of
7203 breakpoints will come out in order of increasing numbers. */
7205 b1
= breakpoint_chain
;
7207 breakpoint_chain
= b
;
7216 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7219 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7220 struct gdbarch
*gdbarch
,
7222 const struct breakpoint_ops
*ops
)
7224 memset (b
, 0, sizeof (*b
));
7226 gdb_assert (ops
!= NULL
);
7230 b
->gdbarch
= gdbarch
;
7231 b
->language
= current_language
->la_language
;
7232 b
->input_radix
= input_radix
;
7234 b
->enable_state
= bp_enabled
;
7237 b
->ignore_count
= 0;
7239 b
->frame_id
= null_frame_id
;
7240 b
->condition_not_parsed
= 0;
7241 b
->py_bp_object
= NULL
;
7242 b
->related_breakpoint
= b
;
7245 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7246 that has type BPTYPE and has no locations as yet. */
7248 static struct breakpoint
*
7249 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7251 const struct breakpoint_ops
*ops
)
7253 struct breakpoint
*b
= XNEW (struct breakpoint
);
7255 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7256 add_to_breakpoint_chain (b
);
7260 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7261 resolutions should be made as the user specified the location explicitly
7265 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7267 gdb_assert (loc
->owner
!= NULL
);
7269 if (loc
->owner
->type
== bp_breakpoint
7270 || loc
->owner
->type
== bp_hardware_breakpoint
7271 || is_tracepoint (loc
->owner
))
7274 const char *function_name
;
7275 CORE_ADDR func_addr
;
7277 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7278 &func_addr
, NULL
, &is_gnu_ifunc
);
7280 if (is_gnu_ifunc
&& !explicit_loc
)
7282 struct breakpoint
*b
= loc
->owner
;
7284 gdb_assert (loc
->pspace
== current_program_space
);
7285 if (gnu_ifunc_resolve_name (function_name
,
7286 &loc
->requested_address
))
7288 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7289 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7290 loc
->requested_address
,
7293 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7294 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7296 /* Create only the whole new breakpoint of this type but do not
7297 mess more complicated breakpoints with multiple locations. */
7298 b
->type
= bp_gnu_ifunc_resolver
;
7299 /* Remember the resolver's address for use by the return
7301 loc
->related_address
= func_addr
;
7306 loc
->function_name
= xstrdup (function_name
);
7310 /* Attempt to determine architecture of location identified by SAL. */
7312 get_sal_arch (struct symtab_and_line sal
)
7315 return get_objfile_arch (sal
.section
->objfile
);
7317 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7322 /* Low level routine for partially initializing a breakpoint of type
7323 BPTYPE. The newly created breakpoint's address, section, source
7324 file name, and line number are provided by SAL.
7326 It is expected that the caller will complete the initialization of
7327 the newly created breakpoint struct as well as output any status
7328 information regarding the creation of a new breakpoint. */
7331 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7332 struct symtab_and_line sal
, enum bptype bptype
,
7333 const struct breakpoint_ops
*ops
)
7335 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7337 add_location_to_breakpoint (b
, &sal
);
7339 if (bptype
!= bp_catchpoint
)
7340 gdb_assert (sal
.pspace
!= NULL
);
7342 /* Store the program space that was used to set the breakpoint,
7343 except for ordinary breakpoints, which are independent of the
7345 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7346 b
->pspace
= sal
.pspace
;
7349 /* set_raw_breakpoint is a low level routine for allocating and
7350 partially initializing a breakpoint of type BPTYPE. The newly
7351 created breakpoint's address, section, source file name, and line
7352 number are provided by SAL. The newly created and partially
7353 initialized breakpoint is added to the breakpoint chain and
7354 is also returned as the value of this function.
7356 It is expected that the caller will complete the initialization of
7357 the newly created breakpoint struct as well as output any status
7358 information regarding the creation of a new breakpoint. In
7359 particular, set_raw_breakpoint does NOT set the breakpoint
7360 number! Care should be taken to not allow an error to occur
7361 prior to completing the initialization of the breakpoint. If this
7362 should happen, a bogus breakpoint will be left on the chain. */
7365 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7366 struct symtab_and_line sal
, enum bptype bptype
,
7367 const struct breakpoint_ops
*ops
)
7369 struct breakpoint
*b
= XNEW (struct breakpoint
);
7371 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7372 add_to_breakpoint_chain (b
);
7377 /* Note that the breakpoint object B describes a permanent breakpoint
7378 instruction, hard-wired into the inferior's code. */
7380 make_breakpoint_permanent (struct breakpoint
*b
)
7382 struct bp_location
*bl
;
7384 /* By definition, permanent breakpoints are already present in the
7385 code. Mark all locations as inserted. For now,
7386 make_breakpoint_permanent is called in just one place, so it's
7387 hard to say if it's reasonable to have permanent breakpoint with
7388 multiple locations or not, but it's easy to implement. */
7389 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7396 /* Call this routine when stepping and nexting to enable a breakpoint
7397 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7398 initiated the operation. */
7401 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7403 struct breakpoint
*b
, *b_tmp
;
7404 int thread
= tp
->num
;
7406 /* To avoid having to rescan all objfile symbols at every step,
7407 we maintain a list of continually-inserted but always disabled
7408 longjmp "master" breakpoints. Here, we simply create momentary
7409 clones of those and enable them for the requested thread. */
7410 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7411 if (b
->pspace
== current_program_space
7412 && (b
->type
== bp_longjmp_master
7413 || b
->type
== bp_exception_master
))
7415 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7416 struct breakpoint
*clone
;
7418 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7419 after their removal. */
7420 clone
= momentary_breakpoint_from_master (b
, type
,
7421 &longjmp_breakpoint_ops
, 1);
7422 clone
->thread
= thread
;
7425 tp
->initiating_frame
= frame
;
7428 /* Delete all longjmp breakpoints from THREAD. */
7430 delete_longjmp_breakpoint (int thread
)
7432 struct breakpoint
*b
, *b_tmp
;
7434 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7435 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7437 if (b
->thread
== thread
)
7438 delete_breakpoint (b
);
7443 delete_longjmp_breakpoint_at_next_stop (int thread
)
7445 struct breakpoint
*b
, *b_tmp
;
7447 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7448 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7450 if (b
->thread
== thread
)
7451 b
->disposition
= disp_del_at_next_stop
;
7455 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7456 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7457 pointer to any of them. Return NULL if this system cannot place longjmp
7461 set_longjmp_breakpoint_for_call_dummy (void)
7463 struct breakpoint
*b
, *retval
= NULL
;
7466 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7468 struct breakpoint
*new_b
;
7470 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7471 &momentary_breakpoint_ops
,
7473 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7475 /* Link NEW_B into the chain of RETVAL breakpoints. */
7477 gdb_assert (new_b
->related_breakpoint
== new_b
);
7480 new_b
->related_breakpoint
= retval
;
7481 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7482 retval
= retval
->related_breakpoint
;
7483 retval
->related_breakpoint
= new_b
;
7489 /* Verify all existing dummy frames and their associated breakpoints for
7490 TP. Remove those which can no longer be found in the current frame
7493 You should call this function only at places where it is safe to currently
7494 unwind the whole stack. Failed stack unwind would discard live dummy
7498 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7500 struct breakpoint
*b
, *b_tmp
;
7502 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7503 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7505 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7507 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7508 dummy_b
= dummy_b
->related_breakpoint
;
7509 if (dummy_b
->type
!= bp_call_dummy
7510 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7513 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7515 while (b
->related_breakpoint
!= b
)
7517 if (b_tmp
== b
->related_breakpoint
)
7518 b_tmp
= b
->related_breakpoint
->next
;
7519 delete_breakpoint (b
->related_breakpoint
);
7521 delete_breakpoint (b
);
7526 enable_overlay_breakpoints (void)
7528 struct breakpoint
*b
;
7531 if (b
->type
== bp_overlay_event
)
7533 b
->enable_state
= bp_enabled
;
7534 update_global_location_list (UGLL_MAY_INSERT
);
7535 overlay_events_enabled
= 1;
7540 disable_overlay_breakpoints (void)
7542 struct breakpoint
*b
;
7545 if (b
->type
== bp_overlay_event
)
7547 b
->enable_state
= bp_disabled
;
7548 update_global_location_list (UGLL_DONT_INSERT
);
7549 overlay_events_enabled
= 0;
7553 /* Set an active std::terminate breakpoint for each std::terminate
7554 master breakpoint. */
7556 set_std_terminate_breakpoint (void)
7558 struct breakpoint
*b
, *b_tmp
;
7560 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7561 if (b
->pspace
== current_program_space
7562 && b
->type
== bp_std_terminate_master
)
7564 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7565 &momentary_breakpoint_ops
, 1);
7569 /* Delete all the std::terminate breakpoints. */
7571 delete_std_terminate_breakpoint (void)
7573 struct breakpoint
*b
, *b_tmp
;
7575 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7576 if (b
->type
== bp_std_terminate
)
7577 delete_breakpoint (b
);
7581 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7583 struct breakpoint
*b
;
7585 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7586 &internal_breakpoint_ops
);
7588 b
->enable_state
= bp_enabled
;
7589 /* addr_string has to be used or breakpoint_re_set will delete me. */
7591 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7593 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7599 remove_thread_event_breakpoints (void)
7601 struct breakpoint
*b
, *b_tmp
;
7603 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7604 if (b
->type
== bp_thread_event
7605 && b
->loc
->pspace
== current_program_space
)
7606 delete_breakpoint (b
);
7609 struct lang_and_radix
7615 /* Create a breakpoint for JIT code registration and unregistration. */
7618 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7620 struct breakpoint
*b
;
7622 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7623 &internal_breakpoint_ops
);
7624 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7628 /* Remove JIT code registration and unregistration breakpoint(s). */
7631 remove_jit_event_breakpoints (void)
7633 struct breakpoint
*b
, *b_tmp
;
7635 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7636 if (b
->type
== bp_jit_event
7637 && b
->loc
->pspace
== current_program_space
)
7638 delete_breakpoint (b
);
7642 remove_solib_event_breakpoints (void)
7644 struct breakpoint
*b
, *b_tmp
;
7646 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7647 if (b
->type
== bp_shlib_event
7648 && b
->loc
->pspace
== current_program_space
)
7649 delete_breakpoint (b
);
7652 /* See breakpoint.h. */
7655 remove_solib_event_breakpoints_at_next_stop (void)
7657 struct breakpoint
*b
, *b_tmp
;
7659 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7660 if (b
->type
== bp_shlib_event
7661 && b
->loc
->pspace
== current_program_space
)
7662 b
->disposition
= disp_del_at_next_stop
;
7665 /* Helper for create_solib_event_breakpoint /
7666 create_and_insert_solib_event_breakpoint. Allows specifying which
7667 INSERT_MODE to pass through to update_global_location_list. */
7669 static struct breakpoint
*
7670 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7671 enum ugll_insert_mode insert_mode
)
7673 struct breakpoint
*b
;
7675 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7676 &internal_breakpoint_ops
);
7677 update_global_location_list_nothrow (insert_mode
);
7682 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7684 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7687 /* See breakpoint.h. */
7690 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7692 struct breakpoint
*b
;
7694 /* Explicitly tell update_global_location_list to insert
7696 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7697 if (!b
->loc
->inserted
)
7699 delete_breakpoint (b
);
7705 /* Disable any breakpoints that are on code in shared libraries. Only
7706 apply to enabled breakpoints, disabled ones can just stay disabled. */
7709 disable_breakpoints_in_shlibs (void)
7711 struct bp_location
*loc
, **locp_tmp
;
7713 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7715 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7716 struct breakpoint
*b
= loc
->owner
;
7718 /* We apply the check to all breakpoints, including disabled for
7719 those with loc->duplicate set. This is so that when breakpoint
7720 becomes enabled, or the duplicate is removed, gdb will try to
7721 insert all breakpoints. If we don't set shlib_disabled here,
7722 we'll try to insert those breakpoints and fail. */
7723 if (((b
->type
== bp_breakpoint
)
7724 || (b
->type
== bp_jit_event
)
7725 || (b
->type
== bp_hardware_breakpoint
)
7726 || (is_tracepoint (b
)))
7727 && loc
->pspace
== current_program_space
7728 && !loc
->shlib_disabled
7729 && solib_name_from_address (loc
->pspace
, loc
->address
)
7732 loc
->shlib_disabled
= 1;
7737 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7738 notification of unloaded_shlib. Only apply to enabled breakpoints,
7739 disabled ones can just stay disabled. */
7742 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7744 struct bp_location
*loc
, **locp_tmp
;
7745 int disabled_shlib_breaks
= 0;
7747 /* SunOS a.out shared libraries are always mapped, so do not
7748 disable breakpoints; they will only be reported as unloaded
7749 through clear_solib when GDB discards its shared library
7750 list. See clear_solib for more information. */
7751 if (exec_bfd
!= NULL
7752 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7755 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7757 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7758 struct breakpoint
*b
= loc
->owner
;
7760 if (solib
->pspace
== loc
->pspace
7761 && !loc
->shlib_disabled
7762 && (((b
->type
== bp_breakpoint
7763 || b
->type
== bp_jit_event
7764 || b
->type
== bp_hardware_breakpoint
)
7765 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7766 || loc
->loc_type
== bp_loc_software_breakpoint
))
7767 || is_tracepoint (b
))
7768 && solib_contains_address_p (solib
, loc
->address
))
7770 loc
->shlib_disabled
= 1;
7771 /* At this point, we cannot rely on remove_breakpoint
7772 succeeding so we must mark the breakpoint as not inserted
7773 to prevent future errors occurring in remove_breakpoints. */
7776 /* This may cause duplicate notifications for the same breakpoint. */
7777 observer_notify_breakpoint_modified (b
);
7779 if (!disabled_shlib_breaks
)
7781 target_terminal_ours_for_output ();
7782 warning (_("Temporarily disabling breakpoints "
7783 "for unloaded shared library \"%s\""),
7786 disabled_shlib_breaks
= 1;
7791 /* Disable any breakpoints and tracepoints in OBJFILE upon
7792 notification of free_objfile. Only apply to enabled breakpoints,
7793 disabled ones can just stay disabled. */
7796 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7798 struct breakpoint
*b
;
7800 if (objfile
== NULL
)
7803 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7804 managed by the user with add-symbol-file/remove-symbol-file.
7805 Similarly to how breakpoints in shared libraries are handled in
7806 response to "nosharedlibrary", mark breakpoints in such modules
7807 shlib_disabled so they end up uninserted on the next global
7808 location list update. Shared libraries not loaded by the user
7809 aren't handled here -- they're already handled in
7810 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7811 solib_unloaded observer. We skip objfiles that are not
7812 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7814 if ((objfile
->flags
& OBJF_SHARED
) == 0
7815 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7820 struct bp_location
*loc
;
7821 int bp_modified
= 0;
7823 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7826 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7828 CORE_ADDR loc_addr
= loc
->address
;
7830 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7831 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7834 if (loc
->shlib_disabled
!= 0)
7837 if (objfile
->pspace
!= loc
->pspace
)
7840 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7841 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7844 if (is_addr_in_objfile (loc_addr
, objfile
))
7846 loc
->shlib_disabled
= 1;
7847 /* At this point, we don't know whether the object was
7848 unmapped from the inferior or not, so leave the
7849 inserted flag alone. We'll handle failure to
7850 uninsert quietly, in case the object was indeed
7853 mark_breakpoint_location_modified (loc
);
7860 observer_notify_breakpoint_modified (b
);
7864 /* FORK & VFORK catchpoints. */
7866 /* An instance of this type is used to represent a fork or vfork
7867 catchpoint. It includes a "struct breakpoint" as a kind of base
7868 class; users downcast to "struct breakpoint *" when needed. A
7869 breakpoint is really of this type iff its ops pointer points to
7870 CATCH_FORK_BREAKPOINT_OPS. */
7872 struct fork_catchpoint
7874 /* The base class. */
7875 struct breakpoint base
;
7877 /* Process id of a child process whose forking triggered this
7878 catchpoint. This field is only valid immediately after this
7879 catchpoint has triggered. */
7880 ptid_t forked_inferior_pid
;
7883 /* Implement the "insert" breakpoint_ops method for fork
7887 insert_catch_fork (struct bp_location
*bl
)
7889 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7892 /* Implement the "remove" breakpoint_ops method for fork
7896 remove_catch_fork (struct bp_location
*bl
)
7898 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7901 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7905 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7906 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7907 const struct target_waitstatus
*ws
)
7909 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7911 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7914 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7918 /* Implement the "print_it" breakpoint_ops method for fork
7921 static enum print_stop_action
7922 print_it_catch_fork (bpstat bs
)
7924 struct ui_out
*uiout
= current_uiout
;
7925 struct breakpoint
*b
= bs
->breakpoint_at
;
7926 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7928 annotate_catchpoint (b
->number
);
7929 if (b
->disposition
== disp_del
)
7930 ui_out_text (uiout
, "\nTemporary catchpoint ");
7932 ui_out_text (uiout
, "\nCatchpoint ");
7933 if (ui_out_is_mi_like_p (uiout
))
7935 ui_out_field_string (uiout
, "reason",
7936 async_reason_lookup (EXEC_ASYNC_FORK
));
7937 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7939 ui_out_field_int (uiout
, "bkptno", b
->number
);
7940 ui_out_text (uiout
, " (forked process ");
7941 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7942 ui_out_text (uiout
, "), ");
7943 return PRINT_SRC_AND_LOC
;
7946 /* Implement the "print_one" breakpoint_ops method for fork
7950 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7952 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7953 struct value_print_options opts
;
7954 struct ui_out
*uiout
= current_uiout
;
7956 get_user_print_options (&opts
);
7958 /* Field 4, the address, is omitted (which makes the columns not
7959 line up too nicely with the headers, but the effect is relatively
7961 if (opts
.addressprint
)
7962 ui_out_field_skip (uiout
, "addr");
7964 ui_out_text (uiout
, "fork");
7965 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7967 ui_out_text (uiout
, ", process ");
7968 ui_out_field_int (uiout
, "what",
7969 ptid_get_pid (c
->forked_inferior_pid
));
7970 ui_out_spaces (uiout
, 1);
7973 if (ui_out_is_mi_like_p (uiout
))
7974 ui_out_field_string (uiout
, "catch-type", "fork");
7977 /* Implement the "print_mention" breakpoint_ops method for fork
7981 print_mention_catch_fork (struct breakpoint
*b
)
7983 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7986 /* Implement the "print_recreate" breakpoint_ops method for fork
7990 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7992 fprintf_unfiltered (fp
, "catch fork");
7993 print_recreate_thread (b
, fp
);
7996 /* The breakpoint_ops structure to be used in fork catchpoints. */
7998 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8000 /* Implement the "insert" breakpoint_ops method for vfork
8004 insert_catch_vfork (struct bp_location
*bl
)
8006 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8009 /* Implement the "remove" breakpoint_ops method for vfork
8013 remove_catch_vfork (struct bp_location
*bl
)
8015 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8018 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8022 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8023 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8024 const struct target_waitstatus
*ws
)
8026 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8028 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8031 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8035 /* Implement the "print_it" breakpoint_ops method for vfork
8038 static enum print_stop_action
8039 print_it_catch_vfork (bpstat bs
)
8041 struct ui_out
*uiout
= current_uiout
;
8042 struct breakpoint
*b
= bs
->breakpoint_at
;
8043 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8045 annotate_catchpoint (b
->number
);
8046 if (b
->disposition
== disp_del
)
8047 ui_out_text (uiout
, "\nTemporary catchpoint ");
8049 ui_out_text (uiout
, "\nCatchpoint ");
8050 if (ui_out_is_mi_like_p (uiout
))
8052 ui_out_field_string (uiout
, "reason",
8053 async_reason_lookup (EXEC_ASYNC_VFORK
));
8054 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8056 ui_out_field_int (uiout
, "bkptno", b
->number
);
8057 ui_out_text (uiout
, " (vforked process ");
8058 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8059 ui_out_text (uiout
, "), ");
8060 return PRINT_SRC_AND_LOC
;
8063 /* Implement the "print_one" breakpoint_ops method for vfork
8067 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8069 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8070 struct value_print_options opts
;
8071 struct ui_out
*uiout
= current_uiout
;
8073 get_user_print_options (&opts
);
8074 /* Field 4, the address, is omitted (which makes the columns not
8075 line up too nicely with the headers, but the effect is relatively
8077 if (opts
.addressprint
)
8078 ui_out_field_skip (uiout
, "addr");
8080 ui_out_text (uiout
, "vfork");
8081 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8083 ui_out_text (uiout
, ", process ");
8084 ui_out_field_int (uiout
, "what",
8085 ptid_get_pid (c
->forked_inferior_pid
));
8086 ui_out_spaces (uiout
, 1);
8089 if (ui_out_is_mi_like_p (uiout
))
8090 ui_out_field_string (uiout
, "catch-type", "vfork");
8093 /* Implement the "print_mention" breakpoint_ops method for vfork
8097 print_mention_catch_vfork (struct breakpoint
*b
)
8099 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8102 /* Implement the "print_recreate" breakpoint_ops method for vfork
8106 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8108 fprintf_unfiltered (fp
, "catch vfork");
8109 print_recreate_thread (b
, fp
);
8112 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8114 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8116 /* An instance of this type is used to represent an solib catchpoint.
8117 It includes a "struct breakpoint" as a kind of base class; users
8118 downcast to "struct breakpoint *" when needed. A breakpoint is
8119 really of this type iff its ops pointer points to
8120 CATCH_SOLIB_BREAKPOINT_OPS. */
8122 struct solib_catchpoint
8124 /* The base class. */
8125 struct breakpoint base
;
8127 /* True for "catch load", false for "catch unload". */
8128 unsigned char is_load
;
8130 /* Regular expression to match, if any. COMPILED is only valid when
8131 REGEX is non-NULL. */
8137 dtor_catch_solib (struct breakpoint
*b
)
8139 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8142 regfree (&self
->compiled
);
8143 xfree (self
->regex
);
8145 base_breakpoint_ops
.dtor (b
);
8149 insert_catch_solib (struct bp_location
*ignore
)
8155 remove_catch_solib (struct bp_location
*ignore
)
8161 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8162 struct address_space
*aspace
,
8164 const struct target_waitstatus
*ws
)
8166 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8167 struct breakpoint
*other
;
8169 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8172 ALL_BREAKPOINTS (other
)
8174 struct bp_location
*other_bl
;
8176 if (other
== bl
->owner
)
8179 if (other
->type
!= bp_shlib_event
)
8182 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8185 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8187 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8196 check_status_catch_solib (struct bpstats
*bs
)
8198 struct solib_catchpoint
*self
8199 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8204 struct so_list
*iter
;
8207 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8212 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8221 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8226 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8232 bs
->print_it
= print_it_noop
;
8235 static enum print_stop_action
8236 print_it_catch_solib (bpstat bs
)
8238 struct breakpoint
*b
= bs
->breakpoint_at
;
8239 struct ui_out
*uiout
= current_uiout
;
8241 annotate_catchpoint (b
->number
);
8242 if (b
->disposition
== disp_del
)
8243 ui_out_text (uiout
, "\nTemporary catchpoint ");
8245 ui_out_text (uiout
, "\nCatchpoint ");
8246 ui_out_field_int (uiout
, "bkptno", b
->number
);
8247 ui_out_text (uiout
, "\n");
8248 if (ui_out_is_mi_like_p (uiout
))
8249 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8250 print_solib_event (1);
8251 return PRINT_SRC_AND_LOC
;
8255 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8257 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8258 struct value_print_options opts
;
8259 struct ui_out
*uiout
= current_uiout
;
8262 get_user_print_options (&opts
);
8263 /* Field 4, the address, is omitted (which makes the columns not
8264 line up too nicely with the headers, but the effect is relatively
8266 if (opts
.addressprint
)
8269 ui_out_field_skip (uiout
, "addr");
8276 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8278 msg
= xstrdup (_("load of library"));
8283 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8285 msg
= xstrdup (_("unload of library"));
8287 ui_out_field_string (uiout
, "what", msg
);
8290 if (ui_out_is_mi_like_p (uiout
))
8291 ui_out_field_string (uiout
, "catch-type",
8292 self
->is_load
? "load" : "unload");
8296 print_mention_catch_solib (struct breakpoint
*b
)
8298 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8300 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8301 self
->is_load
? "load" : "unload");
8305 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8307 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8309 fprintf_unfiltered (fp
, "%s %s",
8310 b
->disposition
== disp_del
? "tcatch" : "catch",
8311 self
->is_load
? "load" : "unload");
8313 fprintf_unfiltered (fp
, " %s", self
->regex
);
8314 fprintf_unfiltered (fp
, "\n");
8317 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8319 /* Shared helper function (MI and CLI) for creating and installing
8320 a shared object event catchpoint. If IS_LOAD is non-zero then
8321 the events to be caught are load events, otherwise they are
8322 unload events. If IS_TEMP is non-zero the catchpoint is a
8323 temporary one. If ENABLED is non-zero the catchpoint is
8324 created in an enabled state. */
8327 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8329 struct solib_catchpoint
*c
;
8330 struct gdbarch
*gdbarch
= get_current_arch ();
8331 struct cleanup
*cleanup
;
8335 arg
= skip_spaces (arg
);
8337 c
= XCNEW (struct solib_catchpoint
);
8338 cleanup
= make_cleanup (xfree
, c
);
8344 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8347 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8349 make_cleanup (xfree
, err
);
8350 error (_("Invalid regexp (%s): %s"), err
, arg
);
8352 c
->regex
= xstrdup (arg
);
8355 c
->is_load
= is_load
;
8356 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8357 &catch_solib_breakpoint_ops
);
8359 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8361 discard_cleanups (cleanup
);
8362 install_breakpoint (0, &c
->base
, 1);
8365 /* A helper function that does all the work for "catch load" and
8369 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8370 struct cmd_list_element
*command
)
8373 const int enabled
= 1;
8375 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8377 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8381 catch_load_command_1 (char *arg
, int from_tty
,
8382 struct cmd_list_element
*command
)
8384 catch_load_or_unload (arg
, from_tty
, 1, command
);
8388 catch_unload_command_1 (char *arg
, int from_tty
,
8389 struct cmd_list_element
*command
)
8391 catch_load_or_unload (arg
, from_tty
, 0, command
);
8394 /* An instance of this type is used to represent a syscall catchpoint.
8395 It includes a "struct breakpoint" as a kind of base class; users
8396 downcast to "struct breakpoint *" when needed. A breakpoint is
8397 really of this type iff its ops pointer points to
8398 CATCH_SYSCALL_BREAKPOINT_OPS. */
8400 struct syscall_catchpoint
8402 /* The base class. */
8403 struct breakpoint base
;
8405 /* Syscall numbers used for the 'catch syscall' feature. If no
8406 syscall has been specified for filtering, its value is NULL.
8407 Otherwise, it holds a list of all syscalls to be caught. The
8408 list elements are allocated with xmalloc. */
8409 VEC(int) *syscalls_to_be_caught
;
8412 /* Implement the "dtor" breakpoint_ops method for syscall
8416 dtor_catch_syscall (struct breakpoint
*b
)
8418 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8420 VEC_free (int, c
->syscalls_to_be_caught
);
8422 base_breakpoint_ops
.dtor (b
);
8425 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8427 struct catch_syscall_inferior_data
8429 /* We keep a count of the number of times the user has requested a
8430 particular syscall to be tracked, and pass this information to the
8431 target. This lets capable targets implement filtering directly. */
8433 /* Number of times that "any" syscall is requested. */
8434 int any_syscall_count
;
8436 /* Count of each system call. */
8437 VEC(int) *syscalls_counts
;
8439 /* This counts all syscall catch requests, so we can readily determine
8440 if any catching is necessary. */
8441 int total_syscalls_count
;
8444 static struct catch_syscall_inferior_data
*
8445 get_catch_syscall_inferior_data (struct inferior
*inf
)
8447 struct catch_syscall_inferior_data
*inf_data
;
8449 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8450 if (inf_data
== NULL
)
8452 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8453 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8460 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8466 /* Implement the "insert" breakpoint_ops method for syscall
8470 insert_catch_syscall (struct bp_location
*bl
)
8472 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8473 struct inferior
*inf
= current_inferior ();
8474 struct catch_syscall_inferior_data
*inf_data
8475 = get_catch_syscall_inferior_data (inf
);
8477 ++inf_data
->total_syscalls_count
;
8478 if (!c
->syscalls_to_be_caught
)
8479 ++inf_data
->any_syscall_count
;
8485 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8490 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8492 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8493 uintptr_t vec_addr_offset
8494 = old_size
* ((uintptr_t) sizeof (int));
8496 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8497 vec_addr
= ((uintptr_t) VEC_address (int,
8498 inf_data
->syscalls_counts
)
8500 memset ((void *) vec_addr
, 0,
8501 (iter
+ 1 - old_size
) * sizeof (int));
8503 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8504 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8508 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8509 inf_data
->total_syscalls_count
!= 0,
8510 inf_data
->any_syscall_count
,
8512 inf_data
->syscalls_counts
),
8514 inf_data
->syscalls_counts
));
8517 /* Implement the "remove" breakpoint_ops method for syscall
8521 remove_catch_syscall (struct bp_location
*bl
)
8523 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8524 struct inferior
*inf
= current_inferior ();
8525 struct catch_syscall_inferior_data
*inf_data
8526 = get_catch_syscall_inferior_data (inf
);
8528 --inf_data
->total_syscalls_count
;
8529 if (!c
->syscalls_to_be_caught
)
8530 --inf_data
->any_syscall_count
;
8536 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8540 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8541 /* Shouldn't happen. */
8543 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8544 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8548 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8549 inf_data
->total_syscalls_count
!= 0,
8550 inf_data
->any_syscall_count
,
8552 inf_data
->syscalls_counts
),
8554 inf_data
->syscalls_counts
));
8557 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8561 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8562 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8563 const struct target_waitstatus
*ws
)
8565 /* We must check if we are catching specific syscalls in this
8566 breakpoint. If we are, then we must guarantee that the called
8567 syscall is the same syscall we are catching. */
8568 int syscall_number
= 0;
8569 const struct syscall_catchpoint
*c
8570 = (const struct syscall_catchpoint
*) bl
->owner
;
8572 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8573 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8576 syscall_number
= ws
->value
.syscall_number
;
8578 /* Now, checking if the syscall is the same. */
8579 if (c
->syscalls_to_be_caught
)
8584 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8586 if (syscall_number
== iter
)
8595 /* Implement the "print_it" breakpoint_ops method for syscall
8598 static enum print_stop_action
8599 print_it_catch_syscall (bpstat bs
)
8601 struct ui_out
*uiout
= current_uiout
;
8602 struct breakpoint
*b
= bs
->breakpoint_at
;
8603 /* These are needed because we want to know in which state a
8604 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8605 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8606 must print "called syscall" or "returned from syscall". */
8608 struct target_waitstatus last
;
8611 get_last_target_status (&ptid
, &last
);
8613 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8615 annotate_catchpoint (b
->number
);
8617 if (b
->disposition
== disp_del
)
8618 ui_out_text (uiout
, "\nTemporary catchpoint ");
8620 ui_out_text (uiout
, "\nCatchpoint ");
8621 if (ui_out_is_mi_like_p (uiout
))
8623 ui_out_field_string (uiout
, "reason",
8624 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8625 ? EXEC_ASYNC_SYSCALL_ENTRY
8626 : EXEC_ASYNC_SYSCALL_RETURN
));
8627 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8629 ui_out_field_int (uiout
, "bkptno", b
->number
);
8631 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8632 ui_out_text (uiout
, " (call to syscall ");
8634 ui_out_text (uiout
, " (returned from syscall ");
8636 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8637 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8639 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8641 ui_out_text (uiout
, "), ");
8643 return PRINT_SRC_AND_LOC
;
8646 /* Implement the "print_one" breakpoint_ops method for syscall
8650 print_one_catch_syscall (struct breakpoint
*b
,
8651 struct bp_location
**last_loc
)
8653 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8654 struct value_print_options opts
;
8655 struct ui_out
*uiout
= current_uiout
;
8657 get_user_print_options (&opts
);
8658 /* Field 4, the address, is omitted (which makes the columns not
8659 line up too nicely with the headers, but the effect is relatively
8661 if (opts
.addressprint
)
8662 ui_out_field_skip (uiout
, "addr");
8665 if (c
->syscalls_to_be_caught
8666 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8667 ui_out_text (uiout
, "syscalls \"");
8669 ui_out_text (uiout
, "syscall \"");
8671 if (c
->syscalls_to_be_caught
)
8674 char *text
= xstrprintf ("%s", "");
8677 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8682 get_syscall_by_number (iter
, &s
);
8685 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8687 text
= xstrprintf ("%s%d, ", text
, iter
);
8689 /* We have to xfree the last 'text' (now stored at 'x')
8690 because xstrprintf dynamically allocates new space for it
8694 /* Remove the last comma. */
8695 text
[strlen (text
) - 2] = '\0';
8696 ui_out_field_string (uiout
, "what", text
);
8699 ui_out_field_string (uiout
, "what", "<any syscall>");
8700 ui_out_text (uiout
, "\" ");
8702 if (ui_out_is_mi_like_p (uiout
))
8703 ui_out_field_string (uiout
, "catch-type", "syscall");
8706 /* Implement the "print_mention" breakpoint_ops method for syscall
8710 print_mention_catch_syscall (struct breakpoint
*b
)
8712 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8714 if (c
->syscalls_to_be_caught
)
8718 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8719 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8721 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8724 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8728 get_syscall_by_number (iter
, &s
);
8731 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8733 printf_filtered (" %d", s
.number
);
8735 printf_filtered (")");
8738 printf_filtered (_("Catchpoint %d (any syscall)"),
8742 /* Implement the "print_recreate" breakpoint_ops method for syscall
8746 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8748 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8750 fprintf_unfiltered (fp
, "catch syscall");
8752 if (c
->syscalls_to_be_caught
)
8757 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8762 get_syscall_by_number (iter
, &s
);
8764 fprintf_unfiltered (fp
, " %s", s
.name
);
8766 fprintf_unfiltered (fp
, " %d", s
.number
);
8769 print_recreate_thread (b
, fp
);
8772 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8774 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8776 /* Returns non-zero if 'b' is a syscall catchpoint. */
8779 syscall_catchpoint_p (struct breakpoint
*b
)
8781 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8784 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8785 is non-zero, then make the breakpoint temporary. If COND_STRING is
8786 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8787 the breakpoint_ops structure associated to the catchpoint. */
8790 init_catchpoint (struct breakpoint
*b
,
8791 struct gdbarch
*gdbarch
, int tempflag
,
8793 const struct breakpoint_ops
*ops
)
8795 struct symtab_and_line sal
;
8798 sal
.pspace
= current_program_space
;
8800 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8802 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8803 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8807 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8809 add_to_breakpoint_chain (b
);
8810 set_breakpoint_number (internal
, b
);
8811 if (is_tracepoint (b
))
8812 set_tracepoint_count (breakpoint_count
);
8815 observer_notify_breakpoint_created (b
);
8818 update_global_location_list (UGLL_MAY_INSERT
);
8822 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8823 int tempflag
, char *cond_string
,
8824 const struct breakpoint_ops
*ops
)
8826 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8828 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8830 c
->forked_inferior_pid
= null_ptid
;
8832 install_breakpoint (0, &c
->base
, 1);
8835 /* Exec catchpoints. */
8837 /* An instance of this type is used to represent an exec catchpoint.
8838 It includes a "struct breakpoint" as a kind of base class; users
8839 downcast to "struct breakpoint *" when needed. A breakpoint is
8840 really of this type iff its ops pointer points to
8841 CATCH_EXEC_BREAKPOINT_OPS. */
8843 struct exec_catchpoint
8845 /* The base class. */
8846 struct breakpoint base
;
8848 /* Filename of a program whose exec triggered this catchpoint.
8849 This field is only valid immediately after this catchpoint has
8851 char *exec_pathname
;
8854 /* Implement the "dtor" breakpoint_ops method for exec
8858 dtor_catch_exec (struct breakpoint
*b
)
8860 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8862 xfree (c
->exec_pathname
);
8864 base_breakpoint_ops
.dtor (b
);
8868 insert_catch_exec (struct bp_location
*bl
)
8870 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8874 remove_catch_exec (struct bp_location
*bl
)
8876 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8880 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8881 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8882 const struct target_waitstatus
*ws
)
8884 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8886 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8889 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8893 static enum print_stop_action
8894 print_it_catch_exec (bpstat bs
)
8896 struct ui_out
*uiout
= current_uiout
;
8897 struct breakpoint
*b
= bs
->breakpoint_at
;
8898 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8900 annotate_catchpoint (b
->number
);
8901 if (b
->disposition
== disp_del
)
8902 ui_out_text (uiout
, "\nTemporary catchpoint ");
8904 ui_out_text (uiout
, "\nCatchpoint ");
8905 if (ui_out_is_mi_like_p (uiout
))
8907 ui_out_field_string (uiout
, "reason",
8908 async_reason_lookup (EXEC_ASYNC_EXEC
));
8909 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8911 ui_out_field_int (uiout
, "bkptno", b
->number
);
8912 ui_out_text (uiout
, " (exec'd ");
8913 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8914 ui_out_text (uiout
, "), ");
8916 return PRINT_SRC_AND_LOC
;
8920 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8922 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8923 struct value_print_options opts
;
8924 struct ui_out
*uiout
= current_uiout
;
8926 get_user_print_options (&opts
);
8928 /* Field 4, the address, is omitted (which makes the columns
8929 not line up too nicely with the headers, but the effect
8930 is relatively readable). */
8931 if (opts
.addressprint
)
8932 ui_out_field_skip (uiout
, "addr");
8934 ui_out_text (uiout
, "exec");
8935 if (c
->exec_pathname
!= NULL
)
8937 ui_out_text (uiout
, ", program \"");
8938 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8939 ui_out_text (uiout
, "\" ");
8942 if (ui_out_is_mi_like_p (uiout
))
8943 ui_out_field_string (uiout
, "catch-type", "exec");
8947 print_mention_catch_exec (struct breakpoint
*b
)
8949 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8952 /* Implement the "print_recreate" breakpoint_ops method for exec
8956 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8958 fprintf_unfiltered (fp
, "catch exec");
8959 print_recreate_thread (b
, fp
);
8962 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8965 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8966 const struct breakpoint_ops
*ops
)
8968 struct syscall_catchpoint
*c
;
8969 struct gdbarch
*gdbarch
= get_current_arch ();
8971 c
= XNEW (struct syscall_catchpoint
);
8972 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8973 c
->syscalls_to_be_caught
= filter
;
8975 install_breakpoint (0, &c
->base
, 1);
8979 hw_breakpoint_used_count (void)
8982 struct breakpoint
*b
;
8983 struct bp_location
*bl
;
8987 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8988 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8990 /* Special types of hardware breakpoints may use more than
8992 i
+= b
->ops
->resources_needed (bl
);
8999 /* Returns the resources B would use if it were a hardware
9003 hw_watchpoint_use_count (struct breakpoint
*b
)
9006 struct bp_location
*bl
;
9008 if (!breakpoint_enabled (b
))
9011 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9013 /* Special types of hardware watchpoints may use more than
9015 i
+= b
->ops
->resources_needed (bl
);
9021 /* Returns the sum the used resources of all hardware watchpoints of
9022 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9023 the sum of the used resources of all hardware watchpoints of other
9024 types _not_ TYPE. */
9027 hw_watchpoint_used_count_others (struct breakpoint
*except
,
9028 enum bptype type
, int *other_type_used
)
9031 struct breakpoint
*b
;
9033 *other_type_used
= 0;
9038 if (!breakpoint_enabled (b
))
9041 if (b
->type
== type
)
9042 i
+= hw_watchpoint_use_count (b
);
9043 else if (is_hardware_watchpoint (b
))
9044 *other_type_used
= 1;
9051 disable_watchpoints_before_interactive_call_start (void)
9053 struct breakpoint
*b
;
9057 if (is_watchpoint (b
) && breakpoint_enabled (b
))
9059 b
->enable_state
= bp_call_disabled
;
9060 update_global_location_list (UGLL_DONT_INSERT
);
9066 enable_watchpoints_after_interactive_call_stop (void)
9068 struct breakpoint
*b
;
9072 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
9074 b
->enable_state
= bp_enabled
;
9075 update_global_location_list (UGLL_MAY_INSERT
);
9081 disable_breakpoints_before_startup (void)
9083 current_program_space
->executing_startup
= 1;
9084 update_global_location_list (UGLL_DONT_INSERT
);
9088 enable_breakpoints_after_startup (void)
9090 current_program_space
->executing_startup
= 0;
9091 breakpoint_re_set ();
9094 /* Create a new single-step breakpoint for thread THREAD, with no
9097 static struct breakpoint
*
9098 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
9100 struct breakpoint
*b
= XNEW (struct breakpoint
);
9102 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
9103 &momentary_breakpoint_ops
);
9105 b
->disposition
= disp_donttouch
;
9106 b
->frame_id
= null_frame_id
;
9109 gdb_assert (b
->thread
!= 0);
9111 add_to_breakpoint_chain (b
);
9116 /* Set a momentary breakpoint of type TYPE at address specified by
9117 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
9121 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9122 struct frame_id frame_id
, enum bptype type
)
9124 struct breakpoint
*b
;
9126 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9128 gdb_assert (!frame_id_artificial_p (frame_id
));
9130 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9131 b
->enable_state
= bp_enabled
;
9132 b
->disposition
= disp_donttouch
;
9133 b
->frame_id
= frame_id
;
9135 /* If we're debugging a multi-threaded program, then we want
9136 momentary breakpoints to be active in only a single thread of
9138 if (in_thread_list (inferior_ptid
))
9139 b
->thread
= pid_to_thread_id (inferior_ptid
);
9141 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
9146 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9147 The new breakpoint will have type TYPE, use OPS as its
9148 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9150 static struct breakpoint
*
9151 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9153 const struct breakpoint_ops
*ops
,
9156 struct breakpoint
*copy
;
9158 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9159 copy
->loc
= allocate_bp_location (copy
);
9160 set_breakpoint_location_function (copy
->loc
, 1);
9162 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9163 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9164 copy
->loc
->address
= orig
->loc
->address
;
9165 copy
->loc
->section
= orig
->loc
->section
;
9166 copy
->loc
->pspace
= orig
->loc
->pspace
;
9167 copy
->loc
->probe
= orig
->loc
->probe
;
9168 copy
->loc
->line_number
= orig
->loc
->line_number
;
9169 copy
->loc
->symtab
= orig
->loc
->symtab
;
9170 copy
->loc
->enabled
= loc_enabled
;
9171 copy
->frame_id
= orig
->frame_id
;
9172 copy
->thread
= orig
->thread
;
9173 copy
->pspace
= orig
->pspace
;
9175 copy
->enable_state
= bp_enabled
;
9176 copy
->disposition
= disp_donttouch
;
9177 copy
->number
= internal_breakpoint_number
--;
9179 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9183 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9187 clone_momentary_breakpoint (struct breakpoint
*orig
)
9189 /* If there's nothing to clone, then return nothing. */
9193 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9197 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9200 struct symtab_and_line sal
;
9202 sal
= find_pc_line (pc
, 0);
9204 sal
.section
= find_pc_overlay (pc
);
9205 sal
.explicit_pc
= 1;
9207 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9211 /* Tell the user we have just set a breakpoint B. */
9214 mention (struct breakpoint
*b
)
9216 b
->ops
->print_mention (b
);
9217 if (ui_out_is_mi_like_p (current_uiout
))
9219 printf_filtered ("\n");
9223 static int bp_loc_is_permanent (struct bp_location
*loc
);
9225 static struct bp_location
*
9226 add_location_to_breakpoint (struct breakpoint
*b
,
9227 const struct symtab_and_line
*sal
)
9229 struct bp_location
*loc
, **tmp
;
9230 CORE_ADDR adjusted_address
;
9231 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9233 if (loc_gdbarch
== NULL
)
9234 loc_gdbarch
= b
->gdbarch
;
9236 /* Adjust the breakpoint's address prior to allocating a location.
9237 Once we call allocate_bp_location(), that mostly uninitialized
9238 location will be placed on the location chain. Adjustment of the
9239 breakpoint may cause target_read_memory() to be called and we do
9240 not want its scan of the location chain to find a breakpoint and
9241 location that's only been partially initialized. */
9242 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9245 /* Sort the locations by their ADDRESS. */
9246 loc
= allocate_bp_location (b
);
9247 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9248 tmp
= &((*tmp
)->next
))
9253 loc
->requested_address
= sal
->pc
;
9254 loc
->address
= adjusted_address
;
9255 loc
->pspace
= sal
->pspace
;
9256 loc
->probe
.probe
= sal
->probe
;
9257 loc
->probe
.objfile
= sal
->objfile
;
9258 gdb_assert (loc
->pspace
!= NULL
);
9259 loc
->section
= sal
->section
;
9260 loc
->gdbarch
= loc_gdbarch
;
9261 loc
->line_number
= sal
->line
;
9262 loc
->symtab
= sal
->symtab
;
9264 set_breakpoint_location_function (loc
,
9265 sal
->explicit_pc
|| sal
->explicit_line
);
9267 if (bp_loc_is_permanent (loc
))
9277 /* Return 1 if LOC is pointing to a permanent breakpoint,
9278 return 0 otherwise. */
9281 bp_loc_is_permanent (struct bp_location
*loc
)
9285 const gdb_byte
*bpoint
;
9286 gdb_byte
*target_mem
;
9287 struct cleanup
*cleanup
;
9290 gdb_assert (loc
!= NULL
);
9292 addr
= loc
->address
;
9293 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9295 /* Software breakpoints unsupported? */
9299 target_mem
= alloca (len
);
9301 /* Enable the automatic memory restoration from breakpoints while
9302 we read the memory. Otherwise we could say about our temporary
9303 breakpoints they are permanent. */
9304 cleanup
= save_current_space_and_thread ();
9306 switch_to_program_space_and_thread (loc
->pspace
);
9307 make_show_memory_breakpoints_cleanup (0);
9309 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9310 && memcmp (target_mem
, bpoint
, len
) == 0)
9313 do_cleanups (cleanup
);
9318 /* Build a command list for the dprintf corresponding to the current
9319 settings of the dprintf style options. */
9322 update_dprintf_command_list (struct breakpoint
*b
)
9324 char *dprintf_args
= b
->extra_string
;
9325 char *printf_line
= NULL
;
9330 dprintf_args
= skip_spaces (dprintf_args
);
9332 /* Allow a comma, as it may have terminated a location, but don't
9334 if (*dprintf_args
== ',')
9336 dprintf_args
= skip_spaces (dprintf_args
);
9338 if (*dprintf_args
!= '"')
9339 error (_("Bad format string, missing '\"'."));
9341 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9342 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9343 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9345 if (!dprintf_function
)
9346 error (_("No function supplied for dprintf call"));
9348 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9349 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9354 printf_line
= xstrprintf ("call (void) %s (%s)",
9358 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9360 if (target_can_run_breakpoint_commands ())
9361 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9364 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9365 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9369 internal_error (__FILE__
, __LINE__
,
9370 _("Invalid dprintf style."));
9372 gdb_assert (printf_line
!= NULL
);
9373 /* Manufacture a printf sequence. */
9375 struct command_line
*printf_cmd_line
9376 = xmalloc (sizeof (struct command_line
));
9378 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9379 printf_cmd_line
->control_type
= simple_control
;
9380 printf_cmd_line
->body_count
= 0;
9381 printf_cmd_line
->body_list
= NULL
;
9382 printf_cmd_line
->next
= NULL
;
9383 printf_cmd_line
->line
= printf_line
;
9385 breakpoint_set_commands (b
, printf_cmd_line
);
9389 /* Update all dprintf commands, making their command lists reflect
9390 current style settings. */
9393 update_dprintf_commands (char *args
, int from_tty
,
9394 struct cmd_list_element
*c
)
9396 struct breakpoint
*b
;
9400 if (b
->type
== bp_dprintf
)
9401 update_dprintf_command_list (b
);
9405 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9406 as textual description of the location, and COND_STRING
9407 as condition expression. */
9410 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9411 struct symtabs_and_lines sals
, char *addr_string
,
9412 char *filter
, char *cond_string
,
9414 enum bptype type
, enum bpdisp disposition
,
9415 int thread
, int task
, int ignore_count
,
9416 const struct breakpoint_ops
*ops
, int from_tty
,
9417 int enabled
, int internal
, unsigned flags
,
9418 int display_canonical
)
9422 if (type
== bp_hardware_breakpoint
)
9424 int target_resources_ok
;
9426 i
= hw_breakpoint_used_count ();
9427 target_resources_ok
=
9428 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9430 if (target_resources_ok
== 0)
9431 error (_("No hardware breakpoint support in the target."));
9432 else if (target_resources_ok
< 0)
9433 error (_("Hardware breakpoints used exceeds limit."));
9436 gdb_assert (sals
.nelts
> 0);
9438 for (i
= 0; i
< sals
.nelts
; ++i
)
9440 struct symtab_and_line sal
= sals
.sals
[i
];
9441 struct bp_location
*loc
;
9445 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9447 loc_gdbarch
= gdbarch
;
9449 describe_other_breakpoints (loc_gdbarch
,
9450 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9455 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9459 b
->cond_string
= cond_string
;
9460 b
->extra_string
= extra_string
;
9461 b
->ignore_count
= ignore_count
;
9462 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9463 b
->disposition
= disposition
;
9465 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9466 b
->loc
->inserted
= 1;
9468 if (type
== bp_static_tracepoint
)
9470 struct tracepoint
*t
= (struct tracepoint
*) b
;
9471 struct static_tracepoint_marker marker
;
9473 if (strace_marker_p (b
))
9475 /* We already know the marker exists, otherwise, we
9476 wouldn't see a sal for it. */
9477 char *p
= &addr_string
[3];
9481 p
= skip_spaces (p
);
9483 endp
= skip_to_space (p
);
9485 marker_str
= savestring (p
, endp
- p
);
9486 t
->static_trace_marker_id
= marker_str
;
9488 printf_filtered (_("Probed static tracepoint "
9490 t
->static_trace_marker_id
);
9492 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9494 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9495 release_static_tracepoint_marker (&marker
);
9497 printf_filtered (_("Probed static tracepoint "
9499 t
->static_trace_marker_id
);
9502 warning (_("Couldn't determine the static "
9503 "tracepoint marker to probe"));
9510 loc
= add_location_to_breakpoint (b
, &sal
);
9511 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9517 const char *arg
= b
->cond_string
;
9519 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9520 block_for_pc (loc
->address
), 0);
9522 error (_("Garbage '%s' follows condition"), arg
);
9525 /* Dynamic printf requires and uses additional arguments on the
9526 command line, otherwise it's an error. */
9527 if (type
== bp_dprintf
)
9529 if (b
->extra_string
)
9530 update_dprintf_command_list (b
);
9532 error (_("Format string required"));
9534 else if (b
->extra_string
)
9535 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9538 b
->display_canonical
= display_canonical
;
9540 b
->addr_string
= addr_string
;
9542 /* addr_string has to be used or breakpoint_re_set will delete
9545 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9550 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9551 struct symtabs_and_lines sals
, char *addr_string
,
9552 char *filter
, char *cond_string
,
9554 enum bptype type
, enum bpdisp disposition
,
9555 int thread
, int task
, int ignore_count
,
9556 const struct breakpoint_ops
*ops
, int from_tty
,
9557 int enabled
, int internal
, unsigned flags
,
9558 int display_canonical
)
9560 struct breakpoint
*b
;
9561 struct cleanup
*old_chain
;
9563 if (is_tracepoint_type (type
))
9565 struct tracepoint
*t
;
9567 t
= XCNEW (struct tracepoint
);
9571 b
= XNEW (struct breakpoint
);
9573 old_chain
= make_cleanup (xfree
, b
);
9575 init_breakpoint_sal (b
, gdbarch
,
9577 filter
, cond_string
, extra_string
,
9579 thread
, task
, ignore_count
,
9581 enabled
, internal
, flags
,
9583 discard_cleanups (old_chain
);
9585 install_breakpoint (internal
, b
, 0);
9588 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9589 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9590 value. COND_STRING, if not NULL, specified the condition to be
9591 used for all breakpoints. Essentially the only case where
9592 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9593 function. In that case, it's still not possible to specify
9594 separate conditions for different overloaded functions, so
9595 we take just a single condition string.
9597 NOTE: If the function succeeds, the caller is expected to cleanup
9598 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9599 array contents). If the function fails (error() is called), the
9600 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9601 COND and SALS arrays and each of those arrays contents. */
9604 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9605 struct linespec_result
*canonical
,
9606 char *cond_string
, char *extra_string
,
9607 enum bptype type
, enum bpdisp disposition
,
9608 int thread
, int task
, int ignore_count
,
9609 const struct breakpoint_ops
*ops
, int from_tty
,
9610 int enabled
, int internal
, unsigned flags
)
9613 struct linespec_sals
*lsal
;
9615 if (canonical
->pre_expanded
)
9616 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9618 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9620 /* Note that 'addr_string' can be NULL in the case of a plain
9621 'break', without arguments. */
9622 char *addr_string
= (canonical
->addr_string
9623 ? xstrdup (canonical
->addr_string
)
9625 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9626 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9628 make_cleanup (xfree
, filter_string
);
9629 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9632 cond_string
, extra_string
,
9634 thread
, task
, ignore_count
, ops
,
9635 from_tty
, enabled
, internal
, flags
,
9636 canonical
->special_display
);
9637 discard_cleanups (inner
);
9641 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9642 followed by conditionals. On return, SALS contains an array of SAL
9643 addresses found. ADDR_STRING contains a vector of (canonical)
9644 address strings. ADDRESS points to the end of the SAL.
9646 The array and the line spec strings are allocated on the heap, it is
9647 the caller's responsibility to free them. */
9650 parse_breakpoint_sals (char **address
,
9651 struct linespec_result
*canonical
)
9653 /* If no arg given, or if first arg is 'if ', use the default
9655 if ((*address
) == NULL
9656 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9658 /* The last displayed codepoint, if it's valid, is our default breakpoint
9660 if (last_displayed_sal_is_valid ())
9662 struct linespec_sals lsal
;
9663 struct symtab_and_line sal
;
9666 init_sal (&sal
); /* Initialize to zeroes. */
9667 lsal
.sals
.sals
= (struct symtab_and_line
*)
9668 xmalloc (sizeof (struct symtab_and_line
));
9670 /* Set sal's pspace, pc, symtab, and line to the values
9671 corresponding to the last call to print_frame_info.
9672 Be sure to reinitialize LINE with NOTCURRENT == 0
9673 as the breakpoint line number is inappropriate otherwise.
9674 find_pc_line would adjust PC, re-set it back. */
9675 get_last_displayed_sal (&sal
);
9677 sal
= find_pc_line (pc
, 0);
9679 /* "break" without arguments is equivalent to "break *PC"
9680 where PC is the last displayed codepoint's address. So
9681 make sure to set sal.explicit_pc to prevent GDB from
9682 trying to expand the list of sals to include all other
9683 instances with the same symtab and line. */
9685 sal
.explicit_pc
= 1;
9687 lsal
.sals
.sals
[0] = sal
;
9688 lsal
.sals
.nelts
= 1;
9689 lsal
.canonical
= NULL
;
9691 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9694 error (_("No default breakpoint address now."));
9698 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9700 /* Force almost all breakpoints to be in terms of the
9701 current_source_symtab (which is decode_line_1's default).
9702 This should produce the results we want almost all of the
9703 time while leaving default_breakpoint_* alone.
9705 ObjC: However, don't match an Objective-C method name which
9706 may have a '+' or '-' succeeded by a '['. */
9707 if (last_displayed_sal_is_valid ()
9709 || ((strchr ("+-", (*address
)[0]) != NULL
)
9710 && ((*address
)[1] != '['))))
9711 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9712 get_last_displayed_symtab (),
9713 get_last_displayed_line (),
9714 canonical
, NULL
, NULL
);
9716 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9717 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9722 /* Convert each SAL into a real PC. Verify that the PC can be
9723 inserted as a breakpoint. If it can't throw an error. */
9726 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9730 for (i
= 0; i
< sals
->nelts
; i
++)
9731 resolve_sal_pc (&sals
->sals
[i
]);
9734 /* Fast tracepoints may have restrictions on valid locations. For
9735 instance, a fast tracepoint using a jump instead of a trap will
9736 likely have to overwrite more bytes than a trap would, and so can
9737 only be placed where the instruction is longer than the jump, or a
9738 multi-instruction sequence does not have a jump into the middle of
9742 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9743 struct symtabs_and_lines
*sals
)
9746 struct symtab_and_line
*sal
;
9748 struct cleanup
*old_chain
;
9750 for (i
= 0; i
< sals
->nelts
; i
++)
9752 struct gdbarch
*sarch
;
9754 sal
= &sals
->sals
[i
];
9756 sarch
= get_sal_arch (*sal
);
9757 /* We fall back to GDBARCH if there is no architecture
9758 associated with SAL. */
9761 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9763 old_chain
= make_cleanup (xfree
, msg
);
9766 error (_("May not have a fast tracepoint at 0x%s%s"),
9767 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9769 do_cleanups (old_chain
);
9773 /* Issue an invalid thread ID error. */
9775 static void ATTRIBUTE_NORETURN
9776 invalid_thread_id_error (int id
)
9778 error (_("Unknown thread %d."), id
);
9781 /* Given TOK, a string specification of condition and thread, as
9782 accepted by the 'break' command, extract the condition
9783 string and thread number and set *COND_STRING and *THREAD.
9784 PC identifies the context at which the condition should be parsed.
9785 If no condition is found, *COND_STRING is set to NULL.
9786 If no thread is found, *THREAD is set to -1. */
9789 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9790 char **cond_string
, int *thread
, int *task
,
9793 *cond_string
= NULL
;
9800 const char *end_tok
;
9802 const char *cond_start
= NULL
;
9803 const char *cond_end
= NULL
;
9805 tok
= skip_spaces_const (tok
);
9807 if ((*tok
== '"' || *tok
== ',') && rest
)
9809 *rest
= savestring (tok
, strlen (tok
));
9813 end_tok
= skip_to_space_const (tok
);
9815 toklen
= end_tok
- tok
;
9817 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9819 struct expression
*expr
;
9821 tok
= cond_start
= end_tok
+ 1;
9822 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9825 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9827 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9832 *thread
= strtol (tok
, &tmptok
, 0);
9834 error (_("Junk after thread keyword."));
9835 if (!valid_thread_id (*thread
))
9836 invalid_thread_id_error (*thread
);
9839 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9844 *task
= strtol (tok
, &tmptok
, 0);
9846 error (_("Junk after task keyword."));
9847 if (!valid_task_id (*task
))
9848 error (_("Unknown task %d."), *task
);
9853 *rest
= savestring (tok
, strlen (tok
));
9857 error (_("Junk at end of arguments."));
9861 /* Decode a static tracepoint marker spec. */
9863 static struct symtabs_and_lines
9864 decode_static_tracepoint_spec (char **arg_p
)
9866 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9867 struct symtabs_and_lines sals
;
9868 struct cleanup
*old_chain
;
9869 char *p
= &(*arg_p
)[3];
9874 p
= skip_spaces (p
);
9876 endp
= skip_to_space (p
);
9878 marker_str
= savestring (p
, endp
- p
);
9879 old_chain
= make_cleanup (xfree
, marker_str
);
9881 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9882 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9883 error (_("No known static tracepoint marker named %s"), marker_str
);
9885 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9886 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9888 for (i
= 0; i
< sals
.nelts
; i
++)
9890 struct static_tracepoint_marker
*marker
;
9892 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9894 init_sal (&sals
.sals
[i
]);
9896 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9897 sals
.sals
[i
].pc
= marker
->address
;
9899 release_static_tracepoint_marker (marker
);
9902 do_cleanups (old_chain
);
9908 /* Set a breakpoint. This function is shared between CLI and MI
9909 functions for setting a breakpoint. This function has two major
9910 modes of operations, selected by the PARSE_ARG parameter. If
9911 non-zero, the function will parse ARG, extracting location,
9912 condition, thread and extra string. Otherwise, ARG is just the
9913 breakpoint's location, with condition, thread, and extra string
9914 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9915 If INTERNAL is non-zero, the breakpoint number will be allocated
9916 from the internal breakpoint count. Returns true if any breakpoint
9917 was created; false otherwise. */
9920 create_breakpoint (struct gdbarch
*gdbarch
,
9921 char *arg
, char *cond_string
,
9922 int thread
, char *extra_string
,
9924 int tempflag
, enum bptype type_wanted
,
9926 enum auto_boolean pending_break_support
,
9927 const struct breakpoint_ops
*ops
,
9928 int from_tty
, int enabled
, int internal
,
9931 volatile struct gdb_exception e
;
9932 char *copy_arg
= NULL
;
9933 char *addr_start
= arg
;
9934 struct linespec_result canonical
;
9935 struct cleanup
*old_chain
;
9936 struct cleanup
*bkpt_chain
= NULL
;
9939 int prev_bkpt_count
= breakpoint_count
;
9941 gdb_assert (ops
!= NULL
);
9943 init_linespec_result (&canonical
);
9945 TRY_CATCH (e
, RETURN_MASK_ALL
)
9947 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9948 addr_start
, ©_arg
);
9951 /* If caller is interested in rc value from parse, set value. */
9955 if (VEC_empty (linespec_sals
, canonical
.sals
))
9961 case NOT_FOUND_ERROR
:
9963 /* If pending breakpoint support is turned off, throw
9966 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9967 throw_exception (e
);
9969 exception_print (gdb_stderr
, e
);
9971 /* If pending breakpoint support is auto query and the user
9972 selects no, then simply return the error code. */
9973 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9974 && !nquery (_("Make %s pending on future shared library load? "),
9975 bptype_string (type_wanted
)))
9978 /* At this point, either the user was queried about setting
9979 a pending breakpoint and selected yes, or pending
9980 breakpoint behavior is on and thus a pending breakpoint
9981 is defaulted on behalf of the user. */
9983 struct linespec_sals lsal
;
9985 copy_arg
= xstrdup (addr_start
);
9986 lsal
.canonical
= xstrdup (copy_arg
);
9987 lsal
.sals
.nelts
= 1;
9988 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9989 init_sal (&lsal
.sals
.sals
[0]);
9991 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9995 throw_exception (e
);
9999 throw_exception (e
);
10002 /* Create a chain of things that always need to be cleaned up. */
10003 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
10005 /* ----------------------------- SNIP -----------------------------
10006 Anything added to the cleanup chain beyond this point is assumed
10007 to be part of a breakpoint. If the breakpoint create succeeds
10008 then the memory is not reclaimed. */
10009 bkpt_chain
= make_cleanup (null_cleanup
, 0);
10011 /* Resolve all line numbers to PC's and verify that the addresses
10012 are ok for the target. */
10016 struct linespec_sals
*iter
;
10018 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10019 breakpoint_sals_to_pc (&iter
->sals
);
10022 /* Fast tracepoints may have additional restrictions on location. */
10023 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
10026 struct linespec_sals
*iter
;
10028 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10029 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
10032 /* Verify that condition can be parsed, before setting any
10033 breakpoints. Allocate a separate condition expression for each
10040 struct linespec_sals
*lsal
;
10042 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
10044 /* Here we only parse 'arg' to separate condition
10045 from thread number, so parsing in context of first
10046 sal is OK. When setting the breakpoint we'll
10047 re-parse it in context of each sal. */
10049 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
10050 &thread
, &task
, &rest
);
10052 make_cleanup (xfree
, cond_string
);
10054 make_cleanup (xfree
, rest
);
10056 extra_string
= rest
;
10061 error (_("Garbage '%s' at end of location"), arg
);
10063 /* Create a private copy of condition string. */
10066 cond_string
= xstrdup (cond_string
);
10067 make_cleanup (xfree
, cond_string
);
10069 /* Create a private copy of any extra string. */
10072 extra_string
= xstrdup (extra_string
);
10073 make_cleanup (xfree
, extra_string
);
10077 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
10078 cond_string
, extra_string
, type_wanted
,
10079 tempflag
? disp_del
: disp_donttouch
,
10080 thread
, task
, ignore_count
, ops
,
10081 from_tty
, enabled
, internal
, flags
);
10085 struct breakpoint
*b
;
10087 make_cleanup (xfree
, copy_arg
);
10089 if (is_tracepoint_type (type_wanted
))
10091 struct tracepoint
*t
;
10093 t
= XCNEW (struct tracepoint
);
10097 b
= XNEW (struct breakpoint
);
10099 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
10101 b
->addr_string
= copy_arg
;
10103 b
->cond_string
= NULL
;
10106 /* Create a private copy of condition string. */
10109 cond_string
= xstrdup (cond_string
);
10110 make_cleanup (xfree
, cond_string
);
10112 b
->cond_string
= cond_string
;
10114 b
->extra_string
= NULL
;
10115 b
->ignore_count
= ignore_count
;
10116 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10117 b
->condition_not_parsed
= 1;
10118 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10119 if ((type_wanted
!= bp_breakpoint
10120 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
10121 b
->pspace
= current_program_space
;
10123 install_breakpoint (internal
, b
, 0);
10126 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
10128 warning (_("Multiple breakpoints were set.\nUse the "
10129 "\"delete\" command to delete unwanted breakpoints."));
10130 prev_breakpoint_count
= prev_bkpt_count
;
10133 /* That's it. Discard the cleanups for data inserted into the
10135 discard_cleanups (bkpt_chain
);
10136 /* But cleanup everything else. */
10137 do_cleanups (old_chain
);
10139 /* error call may happen here - have BKPT_CHAIN already discarded. */
10140 update_global_location_list (UGLL_MAY_INSERT
);
10145 /* Set a breakpoint.
10146 ARG is a string describing breakpoint address,
10147 condition, and thread.
10148 FLAG specifies if a breakpoint is hardware on,
10149 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10150 and BP_TEMPFLAG. */
10153 break_command_1 (char *arg
, int flag
, int from_tty
)
10155 int tempflag
= flag
& BP_TEMPFLAG
;
10156 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10157 ? bp_hardware_breakpoint
10159 struct breakpoint_ops
*ops
;
10160 const char *arg_cp
= arg
;
10162 /* Matching breakpoints on probes. */
10163 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10164 ops
= &bkpt_probe_breakpoint_ops
;
10166 ops
= &bkpt_breakpoint_ops
;
10168 create_breakpoint (get_current_arch (),
10170 NULL
, 0, NULL
, 1 /* parse arg */,
10171 tempflag
, type_wanted
,
10172 0 /* Ignore count */,
10173 pending_break_support
,
10181 /* Helper function for break_command_1 and disassemble_command. */
10184 resolve_sal_pc (struct symtab_and_line
*sal
)
10188 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10190 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10191 error (_("No line %d in file \"%s\"."),
10192 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10195 /* If this SAL corresponds to a breakpoint inserted using a line
10196 number, then skip the function prologue if necessary. */
10197 if (sal
->explicit_line
)
10198 skip_prologue_sal (sal
);
10201 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10203 const struct blockvector
*bv
;
10204 const struct block
*b
;
10205 struct symbol
*sym
;
10207 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10208 SYMTAB_COMPUNIT (sal
->symtab
));
10211 sym
= block_linkage_function (b
);
10214 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10215 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10220 /* It really is worthwhile to have the section, so we'll
10221 just have to look harder. This case can be executed
10222 if we have line numbers but no functions (as can
10223 happen in assembly source). */
10225 struct bound_minimal_symbol msym
;
10226 struct cleanup
*old_chain
= save_current_space_and_thread ();
10228 switch_to_program_space_and_thread (sal
->pspace
);
10230 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10232 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10234 do_cleanups (old_chain
);
10241 break_command (char *arg
, int from_tty
)
10243 break_command_1 (arg
, 0, from_tty
);
10247 tbreak_command (char *arg
, int from_tty
)
10249 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10253 hbreak_command (char *arg
, int from_tty
)
10255 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10259 thbreak_command (char *arg
, int from_tty
)
10261 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10265 stop_command (char *arg
, int from_tty
)
10267 printf_filtered (_("Specify the type of breakpoint to set.\n\
10268 Usage: stop in <function | address>\n\
10269 stop at <line>\n"));
10273 stopin_command (char *arg
, int from_tty
)
10277 if (arg
== (char *) NULL
)
10279 else if (*arg
!= '*')
10281 char *argptr
= arg
;
10284 /* Look for a ':'. If this is a line number specification, then
10285 say it is bad, otherwise, it should be an address or
10286 function/method name. */
10287 while (*argptr
&& !hasColon
)
10289 hasColon
= (*argptr
== ':');
10294 badInput
= (*argptr
!= ':'); /* Not a class::method */
10296 badInput
= isdigit (*arg
); /* a simple line number */
10300 printf_filtered (_("Usage: stop in <function | address>\n"));
10302 break_command_1 (arg
, 0, from_tty
);
10306 stopat_command (char *arg
, int from_tty
)
10310 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10314 char *argptr
= arg
;
10317 /* Look for a ':'. If there is a '::' then get out, otherwise
10318 it is probably a line number. */
10319 while (*argptr
&& !hasColon
)
10321 hasColon
= (*argptr
== ':');
10326 badInput
= (*argptr
== ':'); /* we have class::method */
10328 badInput
= !isdigit (*arg
); /* not a line number */
10332 printf_filtered (_("Usage: stop at <line>\n"));
10334 break_command_1 (arg
, 0, from_tty
);
10337 /* The dynamic printf command is mostly like a regular breakpoint, but
10338 with a prewired command list consisting of a single output command,
10339 built from extra arguments supplied on the dprintf command
10343 dprintf_command (char *arg
, int from_tty
)
10345 create_breakpoint (get_current_arch (),
10347 NULL
, 0, NULL
, 1 /* parse arg */,
10349 0 /* Ignore count */,
10350 pending_break_support
,
10351 &dprintf_breakpoint_ops
,
10359 agent_printf_command (char *arg
, int from_tty
)
10361 error (_("May only run agent-printf on the target"));
10364 /* Implement the "breakpoint_hit" breakpoint_ops method for
10365 ranged breakpoints. */
10368 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10369 struct address_space
*aspace
,
10371 const struct target_waitstatus
*ws
)
10373 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10374 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10377 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10378 bl
->length
, aspace
, bp_addr
);
10381 /* Implement the "resources_needed" breakpoint_ops method for
10382 ranged breakpoints. */
10385 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10387 return target_ranged_break_num_registers ();
10390 /* Implement the "print_it" breakpoint_ops method for
10391 ranged breakpoints. */
10393 static enum print_stop_action
10394 print_it_ranged_breakpoint (bpstat bs
)
10396 struct breakpoint
*b
= bs
->breakpoint_at
;
10397 struct bp_location
*bl
= b
->loc
;
10398 struct ui_out
*uiout
= current_uiout
;
10400 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10402 /* Ranged breakpoints have only one location. */
10403 gdb_assert (bl
&& bl
->next
== NULL
);
10405 annotate_breakpoint (b
->number
);
10406 if (b
->disposition
== disp_del
)
10407 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10409 ui_out_text (uiout
, "\nRanged breakpoint ");
10410 if (ui_out_is_mi_like_p (uiout
))
10412 ui_out_field_string (uiout
, "reason",
10413 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10414 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10416 ui_out_field_int (uiout
, "bkptno", b
->number
);
10417 ui_out_text (uiout
, ", ");
10419 return PRINT_SRC_AND_LOC
;
10422 /* Implement the "print_one" breakpoint_ops method for
10423 ranged breakpoints. */
10426 print_one_ranged_breakpoint (struct breakpoint
*b
,
10427 struct bp_location
**last_loc
)
10429 struct bp_location
*bl
= b
->loc
;
10430 struct value_print_options opts
;
10431 struct ui_out
*uiout
= current_uiout
;
10433 /* Ranged breakpoints have only one location. */
10434 gdb_assert (bl
&& bl
->next
== NULL
);
10436 get_user_print_options (&opts
);
10438 if (opts
.addressprint
)
10439 /* We don't print the address range here, it will be printed later
10440 by print_one_detail_ranged_breakpoint. */
10441 ui_out_field_skip (uiout
, "addr");
10442 annotate_field (5);
10443 print_breakpoint_location (b
, bl
);
10447 /* Implement the "print_one_detail" breakpoint_ops method for
10448 ranged breakpoints. */
10451 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10452 struct ui_out
*uiout
)
10454 CORE_ADDR address_start
, address_end
;
10455 struct bp_location
*bl
= b
->loc
;
10456 struct ui_file
*stb
= mem_fileopen ();
10457 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10461 address_start
= bl
->address
;
10462 address_end
= address_start
+ bl
->length
- 1;
10464 ui_out_text (uiout
, "\taddress range: ");
10465 fprintf_unfiltered (stb
, "[%s, %s]",
10466 print_core_address (bl
->gdbarch
, address_start
),
10467 print_core_address (bl
->gdbarch
, address_end
));
10468 ui_out_field_stream (uiout
, "addr", stb
);
10469 ui_out_text (uiout
, "\n");
10471 do_cleanups (cleanup
);
10474 /* Implement the "print_mention" breakpoint_ops method for
10475 ranged breakpoints. */
10478 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10480 struct bp_location
*bl
= b
->loc
;
10481 struct ui_out
*uiout
= current_uiout
;
10484 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10486 if (ui_out_is_mi_like_p (uiout
))
10489 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10490 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10491 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10494 /* Implement the "print_recreate" breakpoint_ops method for
10495 ranged breakpoints. */
10498 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10500 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10501 b
->addr_string_range_end
);
10502 print_recreate_thread (b
, fp
);
10505 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10507 static struct breakpoint_ops ranged_breakpoint_ops
;
10509 /* Find the address where the end of the breakpoint range should be
10510 placed, given the SAL of the end of the range. This is so that if
10511 the user provides a line number, the end of the range is set to the
10512 last instruction of the given line. */
10515 find_breakpoint_range_end (struct symtab_and_line sal
)
10519 /* If the user provided a PC value, use it. Otherwise,
10520 find the address of the end of the given location. */
10521 if (sal
.explicit_pc
)
10528 ret
= find_line_pc_range (sal
, &start
, &end
);
10530 error (_("Could not find location of the end of the range."));
10532 /* find_line_pc_range returns the start of the next line. */
10539 /* Implement the "break-range" CLI command. */
10542 break_range_command (char *arg
, int from_tty
)
10544 char *arg_start
, *addr_string_start
, *addr_string_end
;
10545 struct linespec_result canonical_start
, canonical_end
;
10546 int bp_count
, can_use_bp
, length
;
10548 struct breakpoint
*b
;
10549 struct symtab_and_line sal_start
, sal_end
;
10550 struct cleanup
*cleanup_bkpt
;
10551 struct linespec_sals
*lsal_start
, *lsal_end
;
10553 /* We don't support software ranged breakpoints. */
10554 if (target_ranged_break_num_registers () < 0)
10555 error (_("This target does not support hardware ranged breakpoints."));
10557 bp_count
= hw_breakpoint_used_count ();
10558 bp_count
+= target_ranged_break_num_registers ();
10559 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10561 if (can_use_bp
< 0)
10562 error (_("Hardware breakpoints used exceeds limit."));
10564 arg
= skip_spaces (arg
);
10565 if (arg
== NULL
|| arg
[0] == '\0')
10566 error(_("No address range specified."));
10568 init_linespec_result (&canonical_start
);
10571 parse_breakpoint_sals (&arg
, &canonical_start
);
10573 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10576 error (_("Too few arguments."));
10577 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10578 error (_("Could not find location of the beginning of the range."));
10580 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10582 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10583 || lsal_start
->sals
.nelts
!= 1)
10584 error (_("Cannot create a ranged breakpoint with multiple locations."));
10586 sal_start
= lsal_start
->sals
.sals
[0];
10587 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10588 make_cleanup (xfree
, addr_string_start
);
10590 arg
++; /* Skip the comma. */
10591 arg
= skip_spaces (arg
);
10593 /* Parse the end location. */
10595 init_linespec_result (&canonical_end
);
10598 /* We call decode_line_full directly here instead of using
10599 parse_breakpoint_sals because we need to specify the start location's
10600 symtab and line as the default symtab and line for the end of the
10601 range. This makes it possible to have ranges like "foo.c:27, +14",
10602 where +14 means 14 lines from the start location. */
10603 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10604 sal_start
.symtab
, sal_start
.line
,
10605 &canonical_end
, NULL
, NULL
);
10607 make_cleanup_destroy_linespec_result (&canonical_end
);
10609 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10610 error (_("Could not find location of the end of the range."));
10612 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10613 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10614 || lsal_end
->sals
.nelts
!= 1)
10615 error (_("Cannot create a ranged breakpoint with multiple locations."));
10617 sal_end
= lsal_end
->sals
.sals
[0];
10618 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10619 make_cleanup (xfree
, addr_string_end
);
10621 end
= find_breakpoint_range_end (sal_end
);
10622 if (sal_start
.pc
> end
)
10623 error (_("Invalid address range, end precedes start."));
10625 length
= end
- sal_start
.pc
+ 1;
10627 /* Length overflowed. */
10628 error (_("Address range too large."));
10629 else if (length
== 1)
10631 /* This range is simple enough to be handled by
10632 the `hbreak' command. */
10633 hbreak_command (addr_string_start
, 1);
10635 do_cleanups (cleanup_bkpt
);
10640 /* Now set up the breakpoint. */
10641 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10642 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10643 set_breakpoint_count (breakpoint_count
+ 1);
10644 b
->number
= breakpoint_count
;
10645 b
->disposition
= disp_donttouch
;
10646 b
->addr_string
= xstrdup (addr_string_start
);
10647 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10648 b
->loc
->length
= length
;
10650 do_cleanups (cleanup_bkpt
);
10653 observer_notify_breakpoint_created (b
);
10654 update_global_location_list (UGLL_MAY_INSERT
);
10657 /* Return non-zero if EXP is verified as constant. Returned zero
10658 means EXP is variable. Also the constant detection may fail for
10659 some constant expressions and in such case still falsely return
10663 watchpoint_exp_is_const (const struct expression
*exp
)
10665 int i
= exp
->nelts
;
10671 /* We are only interested in the descriptor of each element. */
10672 operator_length (exp
, i
, &oplenp
, &argsp
);
10675 switch (exp
->elts
[i
].opcode
)
10685 case BINOP_LOGICAL_AND
:
10686 case BINOP_LOGICAL_OR
:
10687 case BINOP_BITWISE_AND
:
10688 case BINOP_BITWISE_IOR
:
10689 case BINOP_BITWISE_XOR
:
10691 case BINOP_NOTEQUAL
:
10718 case OP_OBJC_NSSTRING
:
10721 case UNOP_LOGICAL_NOT
:
10722 case UNOP_COMPLEMENT
:
10727 case UNOP_CAST_TYPE
:
10728 case UNOP_REINTERPRET_CAST
:
10729 case UNOP_DYNAMIC_CAST
:
10730 /* Unary, binary and ternary operators: We have to check
10731 their operands. If they are constant, then so is the
10732 result of that operation. For instance, if A and B are
10733 determined to be constants, then so is "A + B".
10735 UNOP_IND is one exception to the rule above, because the
10736 value of *ADDR is not necessarily a constant, even when
10741 /* Check whether the associated symbol is a constant.
10743 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10744 possible that a buggy compiler could mark a variable as
10745 constant even when it is not, and TYPE_CONST would return
10746 true in this case, while SYMBOL_CLASS wouldn't.
10748 We also have to check for function symbols because they
10749 are always constant. */
10751 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10753 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10754 && SYMBOL_CLASS (s
) != LOC_CONST
10755 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10760 /* The default action is to return 0 because we are using
10761 the optimistic approach here: If we don't know something,
10762 then it is not a constant. */
10771 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10774 dtor_watchpoint (struct breakpoint
*self
)
10776 struct watchpoint
*w
= (struct watchpoint
*) self
;
10778 xfree (w
->cond_exp
);
10780 xfree (w
->exp_string
);
10781 xfree (w
->exp_string_reparse
);
10782 value_free (w
->val
);
10784 base_breakpoint_ops
.dtor (self
);
10787 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10790 re_set_watchpoint (struct breakpoint
*b
)
10792 struct watchpoint
*w
= (struct watchpoint
*) b
;
10794 /* Watchpoint can be either on expression using entirely global
10795 variables, or it can be on local variables.
10797 Watchpoints of the first kind are never auto-deleted, and even
10798 persist across program restarts. Since they can use variables
10799 from shared libraries, we need to reparse expression as libraries
10800 are loaded and unloaded.
10802 Watchpoints on local variables can also change meaning as result
10803 of solib event. For example, if a watchpoint uses both a local
10804 and a global variables in expression, it's a local watchpoint,
10805 but unloading of a shared library will make the expression
10806 invalid. This is not a very common use case, but we still
10807 re-evaluate expression, to avoid surprises to the user.
10809 Note that for local watchpoints, we re-evaluate it only if
10810 watchpoints frame id is still valid. If it's not, it means the
10811 watchpoint is out of scope and will be deleted soon. In fact,
10812 I'm not sure we'll ever be called in this case.
10814 If a local watchpoint's frame id is still valid, then
10815 w->exp_valid_block is likewise valid, and we can safely use it.
10817 Don't do anything about disabled watchpoints, since they will be
10818 reevaluated again when enabled. */
10819 update_watchpoint (w
, 1 /* reparse */);
10822 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10825 insert_watchpoint (struct bp_location
*bl
)
10827 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10828 int length
= w
->exact
? 1 : bl
->length
;
10830 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10834 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10837 remove_watchpoint (struct bp_location
*bl
)
10839 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10840 int length
= w
->exact
? 1 : bl
->length
;
10842 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10847 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10848 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10849 const struct target_waitstatus
*ws
)
10851 struct breakpoint
*b
= bl
->owner
;
10852 struct watchpoint
*w
= (struct watchpoint
*) b
;
10854 /* Continuable hardware watchpoints are treated as non-existent if the
10855 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10856 some data address). Otherwise gdb won't stop on a break instruction
10857 in the code (not from a breakpoint) when a hardware watchpoint has
10858 been defined. Also skip watchpoints which we know did not trigger
10859 (did not match the data address). */
10860 if (is_hardware_watchpoint (b
)
10861 && w
->watchpoint_triggered
== watch_triggered_no
)
10868 check_status_watchpoint (bpstat bs
)
10870 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10872 bpstat_check_watchpoint (bs
);
10875 /* Implement the "resources_needed" breakpoint_ops method for
10876 hardware watchpoints. */
10879 resources_needed_watchpoint (const struct bp_location
*bl
)
10881 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10882 int length
= w
->exact
? 1 : bl
->length
;
10884 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10887 /* Implement the "works_in_software_mode" breakpoint_ops method for
10888 hardware watchpoints. */
10891 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10893 /* Read and access watchpoints only work with hardware support. */
10894 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10897 static enum print_stop_action
10898 print_it_watchpoint (bpstat bs
)
10900 struct cleanup
*old_chain
;
10901 struct breakpoint
*b
;
10902 struct ui_file
*stb
;
10903 enum print_stop_action result
;
10904 struct watchpoint
*w
;
10905 struct ui_out
*uiout
= current_uiout
;
10907 gdb_assert (bs
->bp_location_at
!= NULL
);
10909 b
= bs
->breakpoint_at
;
10910 w
= (struct watchpoint
*) b
;
10912 stb
= mem_fileopen ();
10913 old_chain
= make_cleanup_ui_file_delete (stb
);
10917 case bp_watchpoint
:
10918 case bp_hardware_watchpoint
:
10919 annotate_watchpoint (b
->number
);
10920 if (ui_out_is_mi_like_p (uiout
))
10921 ui_out_field_string
10923 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10925 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10926 ui_out_text (uiout
, "\nOld value = ");
10927 watchpoint_value_print (bs
->old_val
, stb
);
10928 ui_out_field_stream (uiout
, "old", stb
);
10929 ui_out_text (uiout
, "\nNew value = ");
10930 watchpoint_value_print (w
->val
, stb
);
10931 ui_out_field_stream (uiout
, "new", stb
);
10932 ui_out_text (uiout
, "\n");
10933 /* More than one watchpoint may have been triggered. */
10934 result
= PRINT_UNKNOWN
;
10937 case bp_read_watchpoint
:
10938 if (ui_out_is_mi_like_p (uiout
))
10939 ui_out_field_string
10941 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10943 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10944 ui_out_text (uiout
, "\nValue = ");
10945 watchpoint_value_print (w
->val
, stb
);
10946 ui_out_field_stream (uiout
, "value", stb
);
10947 ui_out_text (uiout
, "\n");
10948 result
= PRINT_UNKNOWN
;
10951 case bp_access_watchpoint
:
10952 if (bs
->old_val
!= NULL
)
10954 annotate_watchpoint (b
->number
);
10955 if (ui_out_is_mi_like_p (uiout
))
10956 ui_out_field_string
10958 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10960 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10961 ui_out_text (uiout
, "\nOld value = ");
10962 watchpoint_value_print (bs
->old_val
, stb
);
10963 ui_out_field_stream (uiout
, "old", stb
);
10964 ui_out_text (uiout
, "\nNew value = ");
10969 if (ui_out_is_mi_like_p (uiout
))
10970 ui_out_field_string
10972 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10973 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10974 ui_out_text (uiout
, "\nValue = ");
10976 watchpoint_value_print (w
->val
, stb
);
10977 ui_out_field_stream (uiout
, "new", stb
);
10978 ui_out_text (uiout
, "\n");
10979 result
= PRINT_UNKNOWN
;
10982 result
= PRINT_UNKNOWN
;
10985 do_cleanups (old_chain
);
10989 /* Implement the "print_mention" breakpoint_ops method for hardware
10993 print_mention_watchpoint (struct breakpoint
*b
)
10995 struct cleanup
*ui_out_chain
;
10996 struct watchpoint
*w
= (struct watchpoint
*) b
;
10997 struct ui_out
*uiout
= current_uiout
;
11001 case bp_watchpoint
:
11002 ui_out_text (uiout
, "Watchpoint ");
11003 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11005 case bp_hardware_watchpoint
:
11006 ui_out_text (uiout
, "Hardware watchpoint ");
11007 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11009 case bp_read_watchpoint
:
11010 ui_out_text (uiout
, "Hardware read watchpoint ");
11011 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11013 case bp_access_watchpoint
:
11014 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
11015 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11018 internal_error (__FILE__
, __LINE__
,
11019 _("Invalid hardware watchpoint type."));
11022 ui_out_field_int (uiout
, "number", b
->number
);
11023 ui_out_text (uiout
, ": ");
11024 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11025 do_cleanups (ui_out_chain
);
11028 /* Implement the "print_recreate" breakpoint_ops method for
11032 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11034 struct watchpoint
*w
= (struct watchpoint
*) b
;
11038 case bp_watchpoint
:
11039 case bp_hardware_watchpoint
:
11040 fprintf_unfiltered (fp
, "watch");
11042 case bp_read_watchpoint
:
11043 fprintf_unfiltered (fp
, "rwatch");
11045 case bp_access_watchpoint
:
11046 fprintf_unfiltered (fp
, "awatch");
11049 internal_error (__FILE__
, __LINE__
,
11050 _("Invalid watchpoint type."));
11053 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
11054 print_recreate_thread (b
, fp
);
11057 /* Implement the "explains_signal" breakpoint_ops method for
11061 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
11063 /* A software watchpoint cannot cause a signal other than
11064 GDB_SIGNAL_TRAP. */
11065 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
11071 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11073 static struct breakpoint_ops watchpoint_breakpoint_ops
;
11075 /* Implement the "insert" breakpoint_ops method for
11076 masked hardware watchpoints. */
11079 insert_masked_watchpoint (struct bp_location
*bl
)
11081 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11083 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11084 bl
->watchpoint_type
);
11087 /* Implement the "remove" breakpoint_ops method for
11088 masked hardware watchpoints. */
11091 remove_masked_watchpoint (struct bp_location
*bl
)
11093 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11095 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11096 bl
->watchpoint_type
);
11099 /* Implement the "resources_needed" breakpoint_ops method for
11100 masked hardware watchpoints. */
11103 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11105 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11107 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11110 /* Implement the "works_in_software_mode" breakpoint_ops method for
11111 masked hardware watchpoints. */
11114 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11119 /* Implement the "print_it" breakpoint_ops method for
11120 masked hardware watchpoints. */
11122 static enum print_stop_action
11123 print_it_masked_watchpoint (bpstat bs
)
11125 struct breakpoint
*b
= bs
->breakpoint_at
;
11126 struct ui_out
*uiout
= current_uiout
;
11128 /* Masked watchpoints have only one location. */
11129 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11133 case bp_hardware_watchpoint
:
11134 annotate_watchpoint (b
->number
);
11135 if (ui_out_is_mi_like_p (uiout
))
11136 ui_out_field_string
11138 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11141 case bp_read_watchpoint
:
11142 if (ui_out_is_mi_like_p (uiout
))
11143 ui_out_field_string
11145 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11148 case bp_access_watchpoint
:
11149 if (ui_out_is_mi_like_p (uiout
))
11150 ui_out_field_string
11152 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11155 internal_error (__FILE__
, __LINE__
,
11156 _("Invalid hardware watchpoint type."));
11160 ui_out_text (uiout
, _("\n\
11161 Check the underlying instruction at PC for the memory\n\
11162 address and value which triggered this watchpoint.\n"));
11163 ui_out_text (uiout
, "\n");
11165 /* More than one watchpoint may have been triggered. */
11166 return PRINT_UNKNOWN
;
11169 /* Implement the "print_one_detail" breakpoint_ops method for
11170 masked hardware watchpoints. */
11173 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11174 struct ui_out
*uiout
)
11176 struct watchpoint
*w
= (struct watchpoint
*) b
;
11178 /* Masked watchpoints have only one location. */
11179 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11181 ui_out_text (uiout
, "\tmask ");
11182 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11183 ui_out_text (uiout
, "\n");
11186 /* Implement the "print_mention" breakpoint_ops method for
11187 masked hardware watchpoints. */
11190 print_mention_masked_watchpoint (struct breakpoint
*b
)
11192 struct watchpoint
*w
= (struct watchpoint
*) b
;
11193 struct ui_out
*uiout
= current_uiout
;
11194 struct cleanup
*ui_out_chain
;
11198 case bp_hardware_watchpoint
:
11199 ui_out_text (uiout
, "Masked hardware watchpoint ");
11200 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11202 case bp_read_watchpoint
:
11203 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11204 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11206 case bp_access_watchpoint
:
11207 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11208 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11211 internal_error (__FILE__
, __LINE__
,
11212 _("Invalid hardware watchpoint type."));
11215 ui_out_field_int (uiout
, "number", b
->number
);
11216 ui_out_text (uiout
, ": ");
11217 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11218 do_cleanups (ui_out_chain
);
11221 /* Implement the "print_recreate" breakpoint_ops method for
11222 masked hardware watchpoints. */
11225 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11227 struct watchpoint
*w
= (struct watchpoint
*) b
;
11232 case bp_hardware_watchpoint
:
11233 fprintf_unfiltered (fp
, "watch");
11235 case bp_read_watchpoint
:
11236 fprintf_unfiltered (fp
, "rwatch");
11238 case bp_access_watchpoint
:
11239 fprintf_unfiltered (fp
, "awatch");
11242 internal_error (__FILE__
, __LINE__
,
11243 _("Invalid hardware watchpoint type."));
11246 sprintf_vma (tmp
, w
->hw_wp_mask
);
11247 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11248 print_recreate_thread (b
, fp
);
11251 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11253 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11255 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11258 is_masked_watchpoint (const struct breakpoint
*b
)
11260 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11263 /* accessflag: hw_write: watch write,
11264 hw_read: watch read,
11265 hw_access: watch access (read or write) */
11267 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11268 int just_location
, int internal
)
11270 volatile struct gdb_exception e
;
11271 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11272 struct expression
*exp
;
11273 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11274 struct value
*val
, *mark
, *result
;
11275 int saved_bitpos
= 0, saved_bitsize
= 0;
11276 struct frame_info
*frame
;
11277 const char *exp_start
= NULL
;
11278 const char *exp_end
= NULL
;
11279 const char *tok
, *end_tok
;
11281 const char *cond_start
= NULL
;
11282 const char *cond_end
= NULL
;
11283 enum bptype bp_type
;
11286 /* Flag to indicate whether we are going to use masks for
11287 the hardware watchpoint. */
11289 CORE_ADDR mask
= 0;
11290 struct watchpoint
*w
;
11292 struct cleanup
*back_to
;
11294 /* Make sure that we actually have parameters to parse. */
11295 if (arg
!= NULL
&& arg
[0] != '\0')
11297 const char *value_start
;
11299 exp_end
= arg
+ strlen (arg
);
11301 /* Look for "parameter value" pairs at the end
11302 of the arguments string. */
11303 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11305 /* Skip whitespace at the end of the argument list. */
11306 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11309 /* Find the beginning of the last token.
11310 This is the value of the parameter. */
11311 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11313 value_start
= tok
+ 1;
11315 /* Skip whitespace. */
11316 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11321 /* Find the beginning of the second to last token.
11322 This is the parameter itself. */
11323 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11326 toklen
= end_tok
- tok
+ 1;
11328 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11330 /* At this point we've found a "thread" token, which means
11331 the user is trying to set a watchpoint that triggers
11332 only in a specific thread. */
11336 error(_("You can specify only one thread."));
11338 /* Extract the thread ID from the next token. */
11339 thread
= strtol (value_start
, &endp
, 0);
11341 /* Check if the user provided a valid numeric value for the
11343 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11344 error (_("Invalid thread ID specification %s."), value_start
);
11346 /* Check if the thread actually exists. */
11347 if (!valid_thread_id (thread
))
11348 invalid_thread_id_error (thread
);
11350 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11352 /* We've found a "mask" token, which means the user wants to
11353 create a hardware watchpoint that is going to have the mask
11355 struct value
*mask_value
, *mark
;
11358 error(_("You can specify only one mask."));
11360 use_mask
= just_location
= 1;
11362 mark
= value_mark ();
11363 mask_value
= parse_to_comma_and_eval (&value_start
);
11364 mask
= value_as_address (mask_value
);
11365 value_free_to_mark (mark
);
11368 /* We didn't recognize what we found. We should stop here. */
11371 /* Truncate the string and get rid of the "parameter value" pair before
11372 the arguments string is parsed by the parse_exp_1 function. */
11379 /* Parse the rest of the arguments. From here on out, everything
11380 is in terms of a newly allocated string instead of the original
11382 innermost_block
= NULL
;
11383 expression
= savestring (arg
, exp_end
- arg
);
11384 back_to
= make_cleanup (xfree
, expression
);
11385 exp_start
= arg
= expression
;
11386 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11388 /* Remove trailing whitespace from the expression before saving it.
11389 This makes the eventual display of the expression string a bit
11391 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11394 /* Checking if the expression is not constant. */
11395 if (watchpoint_exp_is_const (exp
))
11399 len
= exp_end
- exp_start
;
11400 while (len
> 0 && isspace (exp_start
[len
- 1]))
11402 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11405 exp_valid_block
= innermost_block
;
11406 mark
= value_mark ();
11407 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11409 if (val
!= NULL
&& just_location
)
11411 saved_bitpos
= value_bitpos (val
);
11412 saved_bitsize
= value_bitsize (val
);
11419 exp_valid_block
= NULL
;
11420 val
= value_addr (result
);
11421 release_value (val
);
11422 value_free_to_mark (mark
);
11426 ret
= target_masked_watch_num_registers (value_as_address (val
),
11429 error (_("This target does not support masked watchpoints."));
11430 else if (ret
== -2)
11431 error (_("Invalid mask or memory region."));
11434 else if (val
!= NULL
)
11435 release_value (val
);
11437 tok
= skip_spaces_const (arg
);
11438 end_tok
= skip_to_space_const (tok
);
11440 toklen
= end_tok
- tok
;
11441 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11443 struct expression
*cond
;
11445 innermost_block
= NULL
;
11446 tok
= cond_start
= end_tok
+ 1;
11447 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11449 /* The watchpoint expression may not be local, but the condition
11450 may still be. E.g.: `watch global if local > 0'. */
11451 cond_exp_valid_block
= innermost_block
;
11457 error (_("Junk at end of command."));
11459 frame
= block_innermost_frame (exp_valid_block
);
11461 /* If the expression is "local", then set up a "watchpoint scope"
11462 breakpoint at the point where we've left the scope of the watchpoint
11463 expression. Create the scope breakpoint before the watchpoint, so
11464 that we will encounter it first in bpstat_stop_status. */
11465 if (exp_valid_block
&& frame
)
11467 if (frame_id_p (frame_unwind_caller_id (frame
)))
11470 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11471 frame_unwind_caller_pc (frame
),
11472 bp_watchpoint_scope
,
11473 &momentary_breakpoint_ops
);
11475 scope_breakpoint
->enable_state
= bp_enabled
;
11477 /* Automatically delete the breakpoint when it hits. */
11478 scope_breakpoint
->disposition
= disp_del
;
11480 /* Only break in the proper frame (help with recursion). */
11481 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11483 /* Set the address at which we will stop. */
11484 scope_breakpoint
->loc
->gdbarch
11485 = frame_unwind_caller_arch (frame
);
11486 scope_breakpoint
->loc
->requested_address
11487 = frame_unwind_caller_pc (frame
);
11488 scope_breakpoint
->loc
->address
11489 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11490 scope_breakpoint
->loc
->requested_address
,
11491 scope_breakpoint
->type
);
11495 /* Now set up the breakpoint. We create all watchpoints as hardware
11496 watchpoints here even if hardware watchpoints are turned off, a call
11497 to update_watchpoint later in this function will cause the type to
11498 drop back to bp_watchpoint (software watchpoint) if required. */
11500 if (accessflag
== hw_read
)
11501 bp_type
= bp_read_watchpoint
;
11502 else if (accessflag
== hw_access
)
11503 bp_type
= bp_access_watchpoint
;
11505 bp_type
= bp_hardware_watchpoint
;
11507 w
= XCNEW (struct watchpoint
);
11510 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11511 &masked_watchpoint_breakpoint_ops
);
11513 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11514 &watchpoint_breakpoint_ops
);
11515 b
->thread
= thread
;
11516 b
->disposition
= disp_donttouch
;
11517 b
->pspace
= current_program_space
;
11519 w
->exp_valid_block
= exp_valid_block
;
11520 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11523 struct type
*t
= value_type (val
);
11524 CORE_ADDR addr
= value_as_address (val
);
11527 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11528 name
= type_to_string (t
);
11530 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11531 core_addr_to_string (addr
));
11534 w
->exp_string
= xstrprintf ("-location %.*s",
11535 (int) (exp_end
- exp_start
), exp_start
);
11537 /* The above expression is in C. */
11538 b
->language
= language_c
;
11541 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11545 w
->hw_wp_mask
= mask
;
11550 w
->val_bitpos
= saved_bitpos
;
11551 w
->val_bitsize
= saved_bitsize
;
11556 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11558 b
->cond_string
= 0;
11562 w
->watchpoint_frame
= get_frame_id (frame
);
11563 w
->watchpoint_thread
= inferior_ptid
;
11567 w
->watchpoint_frame
= null_frame_id
;
11568 w
->watchpoint_thread
= null_ptid
;
11571 if (scope_breakpoint
!= NULL
)
11573 /* The scope breakpoint is related to the watchpoint. We will
11574 need to act on them together. */
11575 b
->related_breakpoint
= scope_breakpoint
;
11576 scope_breakpoint
->related_breakpoint
= b
;
11579 if (!just_location
)
11580 value_free_to_mark (mark
);
11582 TRY_CATCH (e
, RETURN_MASK_ALL
)
11584 /* Finally update the new watchpoint. This creates the locations
11585 that should be inserted. */
11586 update_watchpoint (w
, 1);
11590 delete_breakpoint (b
);
11591 throw_exception (e
);
11594 install_breakpoint (internal
, b
, 1);
11595 do_cleanups (back_to
);
11598 /* Return count of debug registers needed to watch the given expression.
11599 If the watchpoint cannot be handled in hardware return zero. */
11602 can_use_hardware_watchpoint (struct value
*v
)
11604 int found_memory_cnt
= 0;
11605 struct value
*head
= v
;
11607 /* Did the user specifically forbid us to use hardware watchpoints? */
11608 if (!can_use_hw_watchpoints
)
11611 /* Make sure that the value of the expression depends only upon
11612 memory contents, and values computed from them within GDB. If we
11613 find any register references or function calls, we can't use a
11614 hardware watchpoint.
11616 The idea here is that evaluating an expression generates a series
11617 of values, one holding the value of every subexpression. (The
11618 expression a*b+c has five subexpressions: a, b, a*b, c, and
11619 a*b+c.) GDB's values hold almost enough information to establish
11620 the criteria given above --- they identify memory lvalues,
11621 register lvalues, computed values, etcetera. So we can evaluate
11622 the expression, and then scan the chain of values that leaves
11623 behind to decide whether we can detect any possible change to the
11624 expression's final value using only hardware watchpoints.
11626 However, I don't think that the values returned by inferior
11627 function calls are special in any way. So this function may not
11628 notice that an expression involving an inferior function call
11629 can't be watched with hardware watchpoints. FIXME. */
11630 for (; v
; v
= value_next (v
))
11632 if (VALUE_LVAL (v
) == lval_memory
)
11634 if (v
!= head
&& value_lazy (v
))
11635 /* A lazy memory lvalue in the chain is one that GDB never
11636 needed to fetch; we either just used its address (e.g.,
11637 `a' in `a.b') or we never needed it at all (e.g., `a'
11638 in `a,b'). This doesn't apply to HEAD; if that is
11639 lazy then it was not readable, but watch it anyway. */
11643 /* Ahh, memory we actually used! Check if we can cover
11644 it with hardware watchpoints. */
11645 struct type
*vtype
= check_typedef (value_type (v
));
11647 /* We only watch structs and arrays if user asked for it
11648 explicitly, never if they just happen to appear in a
11649 middle of some value chain. */
11651 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11652 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11654 CORE_ADDR vaddr
= value_address (v
);
11658 len
= (target_exact_watchpoints
11659 && is_scalar_type_recursive (vtype
))?
11660 1 : TYPE_LENGTH (value_type (v
));
11662 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11666 found_memory_cnt
+= num_regs
;
11670 else if (VALUE_LVAL (v
) != not_lval
11671 && deprecated_value_modifiable (v
) == 0)
11672 return 0; /* These are values from the history (e.g., $1). */
11673 else if (VALUE_LVAL (v
) == lval_register
)
11674 return 0; /* Cannot watch a register with a HW watchpoint. */
11677 /* The expression itself looks suitable for using a hardware
11678 watchpoint, but give the target machine a chance to reject it. */
11679 return found_memory_cnt
;
11683 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11685 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11688 /* A helper function that looks for the "-location" argument and then
11689 calls watch_command_1. */
11692 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11694 int just_location
= 0;
11697 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11698 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11700 arg
= skip_spaces (arg
);
11704 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11708 watch_command (char *arg
, int from_tty
)
11710 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11714 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11716 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11720 rwatch_command (char *arg
, int from_tty
)
11722 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11726 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11728 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11732 awatch_command (char *arg
, int from_tty
)
11734 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11738 /* Helper routines for the until_command routine in infcmd.c. Here
11739 because it uses the mechanisms of breakpoints. */
11741 struct until_break_command_continuation_args
11743 struct breakpoint
*breakpoint
;
11744 struct breakpoint
*breakpoint2
;
11748 /* This function is called by fetch_inferior_event via the
11749 cmd_continuation pointer, to complete the until command. It takes
11750 care of cleaning up the temporary breakpoints set up by the until
11753 until_break_command_continuation (void *arg
, int err
)
11755 struct until_break_command_continuation_args
*a
= arg
;
11757 delete_breakpoint (a
->breakpoint
);
11758 if (a
->breakpoint2
)
11759 delete_breakpoint (a
->breakpoint2
);
11760 delete_longjmp_breakpoint (a
->thread_num
);
11764 until_break_command (char *arg
, int from_tty
, int anywhere
)
11766 struct symtabs_and_lines sals
;
11767 struct symtab_and_line sal
;
11768 struct frame_info
*frame
;
11769 struct gdbarch
*frame_gdbarch
;
11770 struct frame_id stack_frame_id
;
11771 struct frame_id caller_frame_id
;
11772 struct breakpoint
*breakpoint
;
11773 struct breakpoint
*breakpoint2
= NULL
;
11774 struct cleanup
*old_chain
;
11776 struct thread_info
*tp
;
11778 clear_proceed_status (0);
11780 /* Set a breakpoint where the user wants it and at return from
11783 if (last_displayed_sal_is_valid ())
11784 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11785 get_last_displayed_symtab (),
11786 get_last_displayed_line ());
11788 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11789 (struct symtab
*) NULL
, 0);
11791 if (sals
.nelts
!= 1)
11792 error (_("Couldn't get information on specified line."));
11794 sal
= sals
.sals
[0];
11795 xfree (sals
.sals
); /* malloc'd, so freed. */
11798 error (_("Junk at end of arguments."));
11800 resolve_sal_pc (&sal
);
11802 tp
= inferior_thread ();
11805 old_chain
= make_cleanup (null_cleanup
, NULL
);
11807 /* Note linespec handling above invalidates the frame chain.
11808 Installing a breakpoint also invalidates the frame chain (as it
11809 may need to switch threads), so do any frame handling before
11812 frame
= get_selected_frame (NULL
);
11813 frame_gdbarch
= get_frame_arch (frame
);
11814 stack_frame_id
= get_stack_frame_id (frame
);
11815 caller_frame_id
= frame_unwind_caller_id (frame
);
11817 /* Keep within the current frame, or in frames called by the current
11820 if (frame_id_p (caller_frame_id
))
11822 struct symtab_and_line sal2
;
11824 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11825 sal2
.pc
= frame_unwind_caller_pc (frame
);
11826 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11830 make_cleanup_delete_breakpoint (breakpoint2
);
11832 set_longjmp_breakpoint (tp
, caller_frame_id
);
11833 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11836 /* set_momentary_breakpoint could invalidate FRAME. */
11840 /* If the user told us to continue until a specified location,
11841 we don't specify a frame at which we need to stop. */
11842 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11843 null_frame_id
, bp_until
);
11845 /* Otherwise, specify the selected frame, because we want to stop
11846 only at the very same frame. */
11847 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11848 stack_frame_id
, bp_until
);
11849 make_cleanup_delete_breakpoint (breakpoint
);
11851 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11853 /* If we are running asynchronously, and proceed call above has
11854 actually managed to start the target, arrange for breakpoints to
11855 be deleted when the target stops. Otherwise, we're already
11856 stopped and delete breakpoints via cleanup chain. */
11858 if (target_can_async_p () && is_running (inferior_ptid
))
11860 struct until_break_command_continuation_args
*args
;
11861 args
= xmalloc (sizeof (*args
));
11863 args
->breakpoint
= breakpoint
;
11864 args
->breakpoint2
= breakpoint2
;
11865 args
->thread_num
= thread
;
11867 discard_cleanups (old_chain
);
11868 add_continuation (inferior_thread (),
11869 until_break_command_continuation
, args
,
11873 do_cleanups (old_chain
);
11876 /* This function attempts to parse an optional "if <cond>" clause
11877 from the arg string. If one is not found, it returns NULL.
11879 Else, it returns a pointer to the condition string. (It does not
11880 attempt to evaluate the string against a particular block.) And,
11881 it updates arg to point to the first character following the parsed
11882 if clause in the arg string. */
11885 ep_parse_optional_if_clause (char **arg
)
11889 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11892 /* Skip the "if" keyword. */
11895 /* Skip any extra leading whitespace, and record the start of the
11896 condition string. */
11897 *arg
= skip_spaces (*arg
);
11898 cond_string
= *arg
;
11900 /* Assume that the condition occupies the remainder of the arg
11902 (*arg
) += strlen (cond_string
);
11904 return cond_string
;
11907 /* Commands to deal with catching events, such as signals, exceptions,
11908 process start/exit, etc. */
11912 catch_fork_temporary
, catch_vfork_temporary
,
11913 catch_fork_permanent
, catch_vfork_permanent
11918 catch_fork_command_1 (char *arg
, int from_tty
,
11919 struct cmd_list_element
*command
)
11921 struct gdbarch
*gdbarch
= get_current_arch ();
11922 char *cond_string
= NULL
;
11923 catch_fork_kind fork_kind
;
11926 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11927 tempflag
= (fork_kind
== catch_fork_temporary
11928 || fork_kind
== catch_vfork_temporary
);
11932 arg
= skip_spaces (arg
);
11934 /* The allowed syntax is:
11936 catch [v]fork if <cond>
11938 First, check if there's an if clause. */
11939 cond_string
= ep_parse_optional_if_clause (&arg
);
11941 if ((*arg
!= '\0') && !isspace (*arg
))
11942 error (_("Junk at end of arguments."));
11944 /* If this target supports it, create a fork or vfork catchpoint
11945 and enable reporting of such events. */
11948 case catch_fork_temporary
:
11949 case catch_fork_permanent
:
11950 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11951 &catch_fork_breakpoint_ops
);
11953 case catch_vfork_temporary
:
11954 case catch_vfork_permanent
:
11955 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11956 &catch_vfork_breakpoint_ops
);
11959 error (_("unsupported or unknown fork kind; cannot catch it"));
11965 catch_exec_command_1 (char *arg
, int from_tty
,
11966 struct cmd_list_element
*command
)
11968 struct exec_catchpoint
*c
;
11969 struct gdbarch
*gdbarch
= get_current_arch ();
11971 char *cond_string
= NULL
;
11973 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11977 arg
= skip_spaces (arg
);
11979 /* The allowed syntax is:
11981 catch exec if <cond>
11983 First, check if there's an if clause. */
11984 cond_string
= ep_parse_optional_if_clause (&arg
);
11986 if ((*arg
!= '\0') && !isspace (*arg
))
11987 error (_("Junk at end of arguments."));
11989 c
= XNEW (struct exec_catchpoint
);
11990 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11991 &catch_exec_breakpoint_ops
);
11992 c
->exec_pathname
= NULL
;
11994 install_breakpoint (0, &c
->base
, 1);
11998 init_ada_exception_breakpoint (struct breakpoint
*b
,
11999 struct gdbarch
*gdbarch
,
12000 struct symtab_and_line sal
,
12002 const struct breakpoint_ops
*ops
,
12009 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
12011 loc_gdbarch
= gdbarch
;
12013 describe_other_breakpoints (loc_gdbarch
,
12014 sal
.pspace
, sal
.pc
, sal
.section
, -1);
12015 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12016 version for exception catchpoints, because two catchpoints
12017 used for different exception names will use the same address.
12018 In this case, a "breakpoint ... also set at..." warning is
12019 unproductive. Besides, the warning phrasing is also a bit
12020 inappropriate, we should use the word catchpoint, and tell
12021 the user what type of catchpoint it is. The above is good
12022 enough for now, though. */
12025 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12027 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12028 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12029 b
->addr_string
= addr_string
;
12030 b
->language
= language_ada
;
12033 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12034 filter list, or NULL if no filtering is required. */
12036 catch_syscall_split_args (char *arg
)
12038 VEC(int) *result
= NULL
;
12039 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
12041 while (*arg
!= '\0')
12043 int i
, syscall_number
;
12045 char cur_name
[128];
12048 /* Skip whitespace. */
12049 arg
= skip_spaces (arg
);
12051 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
12052 cur_name
[i
] = arg
[i
];
12053 cur_name
[i
] = '\0';
12056 /* Check if the user provided a syscall name or a number. */
12057 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
12058 if (*endptr
== '\0')
12059 get_syscall_by_number (syscall_number
, &s
);
12062 /* We have a name. Let's check if it's valid and convert it
12064 get_syscall_by_name (cur_name
, &s
);
12066 if (s
.number
== UNKNOWN_SYSCALL
)
12067 /* Here we have to issue an error instead of a warning,
12068 because GDB cannot do anything useful if there's no
12069 syscall number to be caught. */
12070 error (_("Unknown syscall name '%s'."), cur_name
);
12073 /* Ok, it's valid. */
12074 VEC_safe_push (int, result
, s
.number
);
12077 discard_cleanups (cleanup
);
12081 /* Implement the "catch syscall" command. */
12084 catch_syscall_command_1 (char *arg
, int from_tty
,
12085 struct cmd_list_element
*command
)
12090 struct gdbarch
*gdbarch
= get_current_arch ();
12092 /* Checking if the feature if supported. */
12093 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
12094 error (_("The feature 'catch syscall' is not supported on \
12095 this architecture yet."));
12097 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12099 arg
= skip_spaces (arg
);
12101 /* We need to do this first "dummy" translation in order
12102 to get the syscall XML file loaded or, most important,
12103 to display a warning to the user if there's no XML file
12104 for his/her architecture. */
12105 get_syscall_by_number (0, &s
);
12107 /* The allowed syntax is:
12109 catch syscall <name | number> [<name | number> ... <name | number>]
12111 Let's check if there's a syscall name. */
12114 filter
= catch_syscall_split_args (arg
);
12118 create_syscall_event_catchpoint (tempflag
, filter
,
12119 &catch_syscall_breakpoint_ops
);
12123 catch_command (char *arg
, int from_tty
)
12125 error (_("Catch requires an event name."));
12130 tcatch_command (char *arg
, int from_tty
)
12132 error (_("Catch requires an event name."));
12135 /* A qsort comparison function that sorts breakpoints in order. */
12138 compare_breakpoints (const void *a
, const void *b
)
12140 const breakpoint_p
*ba
= a
;
12141 uintptr_t ua
= (uintptr_t) *ba
;
12142 const breakpoint_p
*bb
= b
;
12143 uintptr_t ub
= (uintptr_t) *bb
;
12145 if ((*ba
)->number
< (*bb
)->number
)
12147 else if ((*ba
)->number
> (*bb
)->number
)
12150 /* Now sort by address, in case we see, e..g, two breakpoints with
12154 return ua
> ub
? 1 : 0;
12157 /* Delete breakpoints by address or line. */
12160 clear_command (char *arg
, int from_tty
)
12162 struct breakpoint
*b
, *prev
;
12163 VEC(breakpoint_p
) *found
= 0;
12166 struct symtabs_and_lines sals
;
12167 struct symtab_and_line sal
;
12169 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12173 sals
= decode_line_with_current_source (arg
,
12174 (DECODE_LINE_FUNFIRSTLINE
12175 | DECODE_LINE_LIST_MODE
));
12176 make_cleanup (xfree
, sals
.sals
);
12181 sals
.sals
= (struct symtab_and_line
*)
12182 xmalloc (sizeof (struct symtab_and_line
));
12183 make_cleanup (xfree
, sals
.sals
);
12184 init_sal (&sal
); /* Initialize to zeroes. */
12186 /* Set sal's line, symtab, pc, and pspace to the values
12187 corresponding to the last call to print_frame_info. If the
12188 codepoint is not valid, this will set all the fields to 0. */
12189 get_last_displayed_sal (&sal
);
12190 if (sal
.symtab
== 0)
12191 error (_("No source file specified."));
12193 sals
.sals
[0] = sal
;
12199 /* We don't call resolve_sal_pc here. That's not as bad as it
12200 seems, because all existing breakpoints typically have both
12201 file/line and pc set. So, if clear is given file/line, we can
12202 match this to existing breakpoint without obtaining pc at all.
12204 We only support clearing given the address explicitly
12205 present in breakpoint table. Say, we've set breakpoint
12206 at file:line. There were several PC values for that file:line,
12207 due to optimization, all in one block.
12209 We've picked one PC value. If "clear" is issued with another
12210 PC corresponding to the same file:line, the breakpoint won't
12211 be cleared. We probably can still clear the breakpoint, but
12212 since the other PC value is never presented to user, user
12213 can only find it by guessing, and it does not seem important
12214 to support that. */
12216 /* For each line spec given, delete bps which correspond to it. Do
12217 it in two passes, solely to preserve the current behavior that
12218 from_tty is forced true if we delete more than one
12222 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12223 for (i
= 0; i
< sals
.nelts
; i
++)
12225 const char *sal_fullname
;
12227 /* If exact pc given, clear bpts at that pc.
12228 If line given (pc == 0), clear all bpts on specified line.
12229 If defaulting, clear all bpts on default line
12232 defaulting sal.pc != 0 tests to do
12237 1 0 <can't happen> */
12239 sal
= sals
.sals
[i
];
12240 sal_fullname
= (sal
.symtab
== NULL
12241 ? NULL
: symtab_to_fullname (sal
.symtab
));
12243 /* Find all matching breakpoints and add them to 'found'. */
12244 ALL_BREAKPOINTS (b
)
12247 /* Are we going to delete b? */
12248 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12250 struct bp_location
*loc
= b
->loc
;
12251 for (; loc
; loc
= loc
->next
)
12253 /* If the user specified file:line, don't allow a PC
12254 match. This matches historical gdb behavior. */
12255 int pc_match
= (!sal
.explicit_line
12257 && (loc
->pspace
== sal
.pspace
)
12258 && (loc
->address
== sal
.pc
)
12259 && (!section_is_overlay (loc
->section
)
12260 || loc
->section
== sal
.section
));
12261 int line_match
= 0;
12263 if ((default_match
|| sal
.explicit_line
)
12264 && loc
->symtab
!= NULL
12265 && sal_fullname
!= NULL
12266 && sal
.pspace
== loc
->pspace
12267 && loc
->line_number
== sal
.line
12268 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12269 sal_fullname
) == 0)
12272 if (pc_match
|| line_match
)
12281 VEC_safe_push(breakpoint_p
, found
, b
);
12285 /* Now go thru the 'found' chain and delete them. */
12286 if (VEC_empty(breakpoint_p
, found
))
12289 error (_("No breakpoint at %s."), arg
);
12291 error (_("No breakpoint at this line."));
12294 /* Remove duplicates from the vec. */
12295 qsort (VEC_address (breakpoint_p
, found
),
12296 VEC_length (breakpoint_p
, found
),
12297 sizeof (breakpoint_p
),
12298 compare_breakpoints
);
12299 prev
= VEC_index (breakpoint_p
, found
, 0);
12300 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12304 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12309 if (VEC_length(breakpoint_p
, found
) > 1)
12310 from_tty
= 1; /* Always report if deleted more than one. */
12313 if (VEC_length(breakpoint_p
, found
) == 1)
12314 printf_unfiltered (_("Deleted breakpoint "));
12316 printf_unfiltered (_("Deleted breakpoints "));
12319 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12322 printf_unfiltered ("%d ", b
->number
);
12323 delete_breakpoint (b
);
12326 putchar_unfiltered ('\n');
12328 do_cleanups (cleanups
);
12331 /* Delete breakpoint in BS if they are `delete' breakpoints and
12332 all breakpoints that are marked for deletion, whether hit or not.
12333 This is called after any breakpoint is hit, or after errors. */
12336 breakpoint_auto_delete (bpstat bs
)
12338 struct breakpoint
*b
, *b_tmp
;
12340 for (; bs
; bs
= bs
->next
)
12341 if (bs
->breakpoint_at
12342 && bs
->breakpoint_at
->disposition
== disp_del
12344 delete_breakpoint (bs
->breakpoint_at
);
12346 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12348 if (b
->disposition
== disp_del_at_next_stop
)
12349 delete_breakpoint (b
);
12353 /* A comparison function for bp_location AP and BP being interfaced to
12354 qsort. Sort elements primarily by their ADDRESS (no matter what
12355 does breakpoint_address_is_meaningful say for its OWNER),
12356 secondarily by ordering first permanent elements and
12357 terciarily just ensuring the array is sorted stable way despite
12358 qsort being an unstable algorithm. */
12361 bp_location_compare (const void *ap
, const void *bp
)
12363 struct bp_location
*a
= *(void **) ap
;
12364 struct bp_location
*b
= *(void **) bp
;
12366 if (a
->address
!= b
->address
)
12367 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12369 /* Sort locations at the same address by their pspace number, keeping
12370 locations of the same inferior (in a multi-inferior environment)
12373 if (a
->pspace
->num
!= b
->pspace
->num
)
12374 return ((a
->pspace
->num
> b
->pspace
->num
)
12375 - (a
->pspace
->num
< b
->pspace
->num
));
12377 /* Sort permanent breakpoints first. */
12378 if (a
->permanent
!= b
->permanent
)
12379 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12381 /* Make the internal GDB representation stable across GDB runs
12382 where A and B memory inside GDB can differ. Breakpoint locations of
12383 the same type at the same address can be sorted in arbitrary order. */
12385 if (a
->owner
->number
!= b
->owner
->number
)
12386 return ((a
->owner
->number
> b
->owner
->number
)
12387 - (a
->owner
->number
< b
->owner
->number
));
12389 return (a
> b
) - (a
< b
);
12392 /* Set bp_location_placed_address_before_address_max and
12393 bp_location_shadow_len_after_address_max according to the current
12394 content of the bp_location array. */
12397 bp_location_target_extensions_update (void)
12399 struct bp_location
*bl
, **blp_tmp
;
12401 bp_location_placed_address_before_address_max
= 0;
12402 bp_location_shadow_len_after_address_max
= 0;
12404 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12406 CORE_ADDR start
, end
, addr
;
12408 if (!bp_location_has_shadow (bl
))
12411 start
= bl
->target_info
.placed_address
;
12412 end
= start
+ bl
->target_info
.shadow_len
;
12414 gdb_assert (bl
->address
>= start
);
12415 addr
= bl
->address
- start
;
12416 if (addr
> bp_location_placed_address_before_address_max
)
12417 bp_location_placed_address_before_address_max
= addr
;
12419 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12421 gdb_assert (bl
->address
< end
);
12422 addr
= end
- bl
->address
;
12423 if (addr
> bp_location_shadow_len_after_address_max
)
12424 bp_location_shadow_len_after_address_max
= addr
;
12428 /* Download tracepoint locations if they haven't been. */
12431 download_tracepoint_locations (void)
12433 struct breakpoint
*b
;
12434 struct cleanup
*old_chain
;
12436 if (!target_can_download_tracepoint ())
12439 old_chain
= save_current_space_and_thread ();
12441 ALL_TRACEPOINTS (b
)
12443 struct bp_location
*bl
;
12444 struct tracepoint
*t
;
12445 int bp_location_downloaded
= 0;
12447 if ((b
->type
== bp_fast_tracepoint
12448 ? !may_insert_fast_tracepoints
12449 : !may_insert_tracepoints
))
12452 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12454 /* In tracepoint, locations are _never_ duplicated, so
12455 should_be_inserted is equivalent to
12456 unduplicated_should_be_inserted. */
12457 if (!should_be_inserted (bl
) || bl
->inserted
)
12460 switch_to_program_space_and_thread (bl
->pspace
);
12462 target_download_tracepoint (bl
);
12465 bp_location_downloaded
= 1;
12467 t
= (struct tracepoint
*) b
;
12468 t
->number_on_target
= b
->number
;
12469 if (bp_location_downloaded
)
12470 observer_notify_breakpoint_modified (b
);
12473 do_cleanups (old_chain
);
12476 /* Swap the insertion/duplication state between two locations. */
12479 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12481 const int left_inserted
= left
->inserted
;
12482 const int left_duplicate
= left
->duplicate
;
12483 const int left_needs_update
= left
->needs_update
;
12484 const struct bp_target_info left_target_info
= left
->target_info
;
12486 /* Locations of tracepoints can never be duplicated. */
12487 if (is_tracepoint (left
->owner
))
12488 gdb_assert (!left
->duplicate
);
12489 if (is_tracepoint (right
->owner
))
12490 gdb_assert (!right
->duplicate
);
12492 left
->inserted
= right
->inserted
;
12493 left
->duplicate
= right
->duplicate
;
12494 left
->needs_update
= right
->needs_update
;
12495 left
->target_info
= right
->target_info
;
12496 right
->inserted
= left_inserted
;
12497 right
->duplicate
= left_duplicate
;
12498 right
->needs_update
= left_needs_update
;
12499 right
->target_info
= left_target_info
;
12502 /* Force the re-insertion of the locations at ADDRESS. This is called
12503 once a new/deleted/modified duplicate location is found and we are evaluating
12504 conditions on the target's side. Such conditions need to be updated on
12508 force_breakpoint_reinsertion (struct bp_location
*bl
)
12510 struct bp_location
**locp
= NULL
, **loc2p
;
12511 struct bp_location
*loc
;
12512 CORE_ADDR address
= 0;
12515 address
= bl
->address
;
12516 pspace_num
= bl
->pspace
->num
;
12518 /* This is only meaningful if the target is
12519 evaluating conditions and if the user has
12520 opted for condition evaluation on the target's
12522 if (gdb_evaluates_breakpoint_condition_p ()
12523 || !target_supports_evaluation_of_breakpoint_conditions ())
12526 /* Flag all breakpoint locations with this address and
12527 the same program space as the location
12528 as "its condition has changed". We need to
12529 update the conditions on the target's side. */
12530 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12534 if (!is_breakpoint (loc
->owner
)
12535 || pspace_num
!= loc
->pspace
->num
)
12538 /* Flag the location appropriately. We use a different state to
12539 let everyone know that we already updated the set of locations
12540 with addr bl->address and program space bl->pspace. This is so
12541 we don't have to keep calling these functions just to mark locations
12542 that have already been marked. */
12543 loc
->condition_changed
= condition_updated
;
12545 /* Free the agent expression bytecode as well. We will compute
12547 if (loc
->cond_bytecode
)
12549 free_agent_expr (loc
->cond_bytecode
);
12550 loc
->cond_bytecode
= NULL
;
12554 /* Called whether new breakpoints are created, or existing breakpoints
12555 deleted, to update the global location list and recompute which
12556 locations are duplicate of which.
12558 The INSERT_MODE flag determines whether locations may not, may, or
12559 shall be inserted now. See 'enum ugll_insert_mode' for more
12563 update_global_location_list (enum ugll_insert_mode insert_mode
)
12565 struct breakpoint
*b
;
12566 struct bp_location
**locp
, *loc
;
12567 struct cleanup
*cleanups
;
12568 /* Last breakpoint location address that was marked for update. */
12569 CORE_ADDR last_addr
= 0;
12570 /* Last breakpoint location program space that was marked for update. */
12571 int last_pspace_num
= -1;
12573 /* Used in the duplicates detection below. When iterating over all
12574 bp_locations, points to the first bp_location of a given address.
12575 Breakpoints and watchpoints of different types are never
12576 duplicates of each other. Keep one pointer for each type of
12577 breakpoint/watchpoint, so we only need to loop over all locations
12579 struct bp_location
*bp_loc_first
; /* breakpoint */
12580 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12581 struct bp_location
*awp_loc_first
; /* access watchpoint */
12582 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12584 /* Saved former bp_location array which we compare against the newly
12585 built bp_location from the current state of ALL_BREAKPOINTS. */
12586 struct bp_location
**old_location
, **old_locp
;
12587 unsigned old_location_count
;
12589 old_location
= bp_location
;
12590 old_location_count
= bp_location_count
;
12591 bp_location
= NULL
;
12592 bp_location_count
= 0;
12593 cleanups
= make_cleanup (xfree
, old_location
);
12595 ALL_BREAKPOINTS (b
)
12596 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12597 bp_location_count
++;
12599 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12600 locp
= bp_location
;
12601 ALL_BREAKPOINTS (b
)
12602 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12604 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12605 bp_location_compare
);
12607 bp_location_target_extensions_update ();
12609 /* Identify bp_location instances that are no longer present in the
12610 new list, and therefore should be freed. Note that it's not
12611 necessary that those locations should be removed from inferior --
12612 if there's another location at the same address (previously
12613 marked as duplicate), we don't need to remove/insert the
12616 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12617 and former bp_location array state respectively. */
12619 locp
= bp_location
;
12620 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12623 struct bp_location
*old_loc
= *old_locp
;
12624 struct bp_location
**loc2p
;
12626 /* Tells if 'old_loc' is found among the new locations. If
12627 not, we have to free it. */
12628 int found_object
= 0;
12629 /* Tells if the location should remain inserted in the target. */
12630 int keep_in_target
= 0;
12633 /* Skip LOCP entries which will definitely never be needed.
12634 Stop either at or being the one matching OLD_LOC. */
12635 while (locp
< bp_location
+ bp_location_count
12636 && (*locp
)->address
< old_loc
->address
)
12640 (loc2p
< bp_location
+ bp_location_count
12641 && (*loc2p
)->address
== old_loc
->address
);
12644 /* Check if this is a new/duplicated location or a duplicated
12645 location that had its condition modified. If so, we want to send
12646 its condition to the target if evaluation of conditions is taking
12648 if ((*loc2p
)->condition_changed
== condition_modified
12649 && (last_addr
!= old_loc
->address
12650 || last_pspace_num
!= old_loc
->pspace
->num
))
12652 force_breakpoint_reinsertion (*loc2p
);
12653 last_pspace_num
= old_loc
->pspace
->num
;
12656 if (*loc2p
== old_loc
)
12660 /* We have already handled this address, update it so that we don't
12661 have to go through updates again. */
12662 last_addr
= old_loc
->address
;
12664 /* Target-side condition evaluation: Handle deleted locations. */
12666 force_breakpoint_reinsertion (old_loc
);
12668 /* If this location is no longer present, and inserted, look if
12669 there's maybe a new location at the same address. If so,
12670 mark that one inserted, and don't remove this one. This is
12671 needed so that we don't have a time window where a breakpoint
12672 at certain location is not inserted. */
12674 if (old_loc
->inserted
)
12676 /* If the location is inserted now, we might have to remove
12679 if (found_object
&& should_be_inserted (old_loc
))
12681 /* The location is still present in the location list,
12682 and still should be inserted. Don't do anything. */
12683 keep_in_target
= 1;
12687 /* This location still exists, but it won't be kept in the
12688 target since it may have been disabled. We proceed to
12689 remove its target-side condition. */
12691 /* The location is either no longer present, or got
12692 disabled. See if there's another location at the
12693 same address, in which case we don't need to remove
12694 this one from the target. */
12696 /* OLD_LOC comes from existing struct breakpoint. */
12697 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12700 (loc2p
< bp_location
+ bp_location_count
12701 && (*loc2p
)->address
== old_loc
->address
);
12704 struct bp_location
*loc2
= *loc2p
;
12706 if (breakpoint_locations_match (loc2
, old_loc
))
12708 /* Read watchpoint locations are switched to
12709 access watchpoints, if the former are not
12710 supported, but the latter are. */
12711 if (is_hardware_watchpoint (old_loc
->owner
))
12713 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12714 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12717 /* loc2 is a duplicated location. We need to check
12718 if it should be inserted in case it will be
12720 if (loc2
!= old_loc
12721 && unduplicated_should_be_inserted (loc2
))
12723 swap_insertion (old_loc
, loc2
);
12724 keep_in_target
= 1;
12732 if (!keep_in_target
)
12734 if (remove_breakpoint (old_loc
, mark_uninserted
))
12736 /* This is just about all we can do. We could keep
12737 this location on the global list, and try to
12738 remove it next time, but there's no particular
12739 reason why we will succeed next time.
12741 Note that at this point, old_loc->owner is still
12742 valid, as delete_breakpoint frees the breakpoint
12743 only after calling us. */
12744 printf_filtered (_("warning: Error removing "
12745 "breakpoint %d\n"),
12746 old_loc
->owner
->number
);
12754 if (removed
&& non_stop
12755 && breakpoint_address_is_meaningful (old_loc
->owner
)
12756 && !is_hardware_watchpoint (old_loc
->owner
))
12758 /* This location was removed from the target. In
12759 non-stop mode, a race condition is possible where
12760 we've removed a breakpoint, but stop events for that
12761 breakpoint are already queued and will arrive later.
12762 We apply an heuristic to be able to distinguish such
12763 SIGTRAPs from other random SIGTRAPs: we keep this
12764 breakpoint location for a bit, and will retire it
12765 after we see some number of events. The theory here
12766 is that reporting of events should, "on the average",
12767 be fair, so after a while we'll see events from all
12768 threads that have anything of interest, and no longer
12769 need to keep this breakpoint location around. We
12770 don't hold locations forever so to reduce chances of
12771 mistaking a non-breakpoint SIGTRAP for a breakpoint
12774 The heuristic failing can be disastrous on
12775 decr_pc_after_break targets.
12777 On decr_pc_after_break targets, like e.g., x86-linux,
12778 if we fail to recognize a late breakpoint SIGTRAP,
12779 because events_till_retirement has reached 0 too
12780 soon, we'll fail to do the PC adjustment, and report
12781 a random SIGTRAP to the user. When the user resumes
12782 the inferior, it will most likely immediately crash
12783 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12784 corrupted, because of being resumed e.g., in the
12785 middle of a multi-byte instruction, or skipped a
12786 one-byte instruction. This was actually seen happen
12787 on native x86-linux, and should be less rare on
12788 targets that do not support new thread events, like
12789 remote, due to the heuristic depending on
12792 Mistaking a random SIGTRAP for a breakpoint trap
12793 causes similar symptoms (PC adjustment applied when
12794 it shouldn't), but then again, playing with SIGTRAPs
12795 behind the debugger's back is asking for trouble.
12797 Since hardware watchpoint traps are always
12798 distinguishable from other traps, so we don't need to
12799 apply keep hardware watchpoint moribund locations
12800 around. We simply always ignore hardware watchpoint
12801 traps we can no longer explain. */
12803 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12804 old_loc
->owner
= NULL
;
12806 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12810 old_loc
->owner
= NULL
;
12811 decref_bp_location (&old_loc
);
12816 /* Rescan breakpoints at the same address and section, marking the
12817 first one as "first" and any others as "duplicates". This is so
12818 that the bpt instruction is only inserted once. If we have a
12819 permanent breakpoint at the same place as BPT, make that one the
12820 official one, and the rest as duplicates. Permanent breakpoints
12821 are sorted first for the same address.
12823 Do the same for hardware watchpoints, but also considering the
12824 watchpoint's type (regular/access/read) and length. */
12826 bp_loc_first
= NULL
;
12827 wp_loc_first
= NULL
;
12828 awp_loc_first
= NULL
;
12829 rwp_loc_first
= NULL
;
12830 ALL_BP_LOCATIONS (loc
, locp
)
12832 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12834 struct bp_location
**loc_first_p
;
12837 if (!unduplicated_should_be_inserted (loc
)
12838 || !breakpoint_address_is_meaningful (b
)
12839 /* Don't detect duplicate for tracepoint locations because they are
12840 never duplicated. See the comments in field `duplicate' of
12841 `struct bp_location'. */
12842 || is_tracepoint (b
))
12844 /* Clear the condition modification flag. */
12845 loc
->condition_changed
= condition_unchanged
;
12849 /* Permanent breakpoint should always be inserted. */
12850 if (loc
->permanent
&& ! loc
->inserted
)
12851 internal_error (__FILE__
, __LINE__
,
12852 _("allegedly permanent breakpoint is not "
12853 "actually inserted"));
12855 if (b
->type
== bp_hardware_watchpoint
)
12856 loc_first_p
= &wp_loc_first
;
12857 else if (b
->type
== bp_read_watchpoint
)
12858 loc_first_p
= &rwp_loc_first
;
12859 else if (b
->type
== bp_access_watchpoint
)
12860 loc_first_p
= &awp_loc_first
;
12862 loc_first_p
= &bp_loc_first
;
12864 if (*loc_first_p
== NULL
12865 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12866 || !breakpoint_locations_match (loc
, *loc_first_p
))
12868 *loc_first_p
= loc
;
12869 loc
->duplicate
= 0;
12871 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12873 loc
->needs_update
= 1;
12874 /* Clear the condition modification flag. */
12875 loc
->condition_changed
= condition_unchanged
;
12881 /* This and the above ensure the invariant that the first location
12882 is not duplicated, and is the inserted one.
12883 All following are marked as duplicated, and are not inserted. */
12885 swap_insertion (loc
, *loc_first_p
);
12886 loc
->duplicate
= 1;
12888 /* Clear the condition modification flag. */
12889 loc
->condition_changed
= condition_unchanged
;
12891 if (loc
->inserted
&& !loc
->permanent
12892 && (*loc_first_p
)->permanent
)
12893 internal_error (__FILE__
, __LINE__
,
12894 _("another breakpoint was inserted on top of "
12895 "a permanent breakpoint"));
12898 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12900 if (insert_mode
!= UGLL_DONT_INSERT
)
12901 insert_breakpoint_locations ();
12904 /* Even though the caller told us to not insert new
12905 locations, we may still need to update conditions on the
12906 target's side of breakpoints that were already inserted
12907 if the target is evaluating breakpoint conditions. We
12908 only update conditions for locations that are marked
12910 update_inserted_breakpoint_locations ();
12914 if (insert_mode
!= UGLL_DONT_INSERT
)
12915 download_tracepoint_locations ();
12917 do_cleanups (cleanups
);
12921 breakpoint_retire_moribund (void)
12923 struct bp_location
*loc
;
12926 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12927 if (--(loc
->events_till_retirement
) == 0)
12929 decref_bp_location (&loc
);
12930 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12936 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12938 volatile struct gdb_exception e
;
12940 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12941 update_global_location_list (insert_mode
);
12944 /* Clear BKP from a BPS. */
12947 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12951 for (bs
= bps
; bs
; bs
= bs
->next
)
12952 if (bs
->breakpoint_at
== bpt
)
12954 bs
->breakpoint_at
= NULL
;
12955 bs
->old_val
= NULL
;
12956 /* bs->commands will be freed later. */
12960 /* Callback for iterate_over_threads. */
12962 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12964 struct breakpoint
*bpt
= data
;
12966 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12970 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12974 say_where (struct breakpoint
*b
)
12976 struct value_print_options opts
;
12978 get_user_print_options (&opts
);
12980 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12982 if (b
->loc
== NULL
)
12984 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12988 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12990 printf_filtered (" at ");
12991 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12994 if (b
->loc
->symtab
!= NULL
)
12996 /* If there is a single location, we can print the location
12998 if (b
->loc
->next
== NULL
)
12999 printf_filtered (": file %s, line %d.",
13000 symtab_to_filename_for_display (b
->loc
->symtab
),
13001 b
->loc
->line_number
);
13003 /* This is not ideal, but each location may have a
13004 different file name, and this at least reflects the
13005 real situation somewhat. */
13006 printf_filtered (": %s.", b
->addr_string
);
13011 struct bp_location
*loc
= b
->loc
;
13013 for (; loc
; loc
= loc
->next
)
13015 printf_filtered (" (%d locations)", n
);
13020 /* Default bp_location_ops methods. */
13023 bp_location_dtor (struct bp_location
*self
)
13025 xfree (self
->cond
);
13026 if (self
->cond_bytecode
)
13027 free_agent_expr (self
->cond_bytecode
);
13028 xfree (self
->function_name
);
13030 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
13031 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
13034 static const struct bp_location_ops bp_location_ops
=
13039 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13043 base_breakpoint_dtor (struct breakpoint
*self
)
13045 decref_counted_command_line (&self
->commands
);
13046 xfree (self
->cond_string
);
13047 xfree (self
->extra_string
);
13048 xfree (self
->addr_string
);
13049 xfree (self
->filter
);
13050 xfree (self
->addr_string_range_end
);
13053 static struct bp_location
*
13054 base_breakpoint_allocate_location (struct breakpoint
*self
)
13056 struct bp_location
*loc
;
13058 loc
= XNEW (struct bp_location
);
13059 init_bp_location (loc
, &bp_location_ops
, self
);
13064 base_breakpoint_re_set (struct breakpoint
*b
)
13066 /* Nothing to re-set. */
13069 #define internal_error_pure_virtual_called() \
13070 gdb_assert_not_reached ("pure virtual function called")
13073 base_breakpoint_insert_location (struct bp_location
*bl
)
13075 internal_error_pure_virtual_called ();
13079 base_breakpoint_remove_location (struct bp_location
*bl
)
13081 internal_error_pure_virtual_called ();
13085 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
13086 struct address_space
*aspace
,
13088 const struct target_waitstatus
*ws
)
13090 internal_error_pure_virtual_called ();
13094 base_breakpoint_check_status (bpstat bs
)
13099 /* A "works_in_software_mode" breakpoint_ops method that just internal
13103 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13105 internal_error_pure_virtual_called ();
13108 /* A "resources_needed" breakpoint_ops method that just internal
13112 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13114 internal_error_pure_virtual_called ();
13117 static enum print_stop_action
13118 base_breakpoint_print_it (bpstat bs
)
13120 internal_error_pure_virtual_called ();
13124 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13125 struct ui_out
*uiout
)
13131 base_breakpoint_print_mention (struct breakpoint
*b
)
13133 internal_error_pure_virtual_called ();
13137 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13139 internal_error_pure_virtual_called ();
13143 base_breakpoint_create_sals_from_address (char **arg
,
13144 struct linespec_result
*canonical
,
13145 enum bptype type_wanted
,
13149 internal_error_pure_virtual_called ();
13153 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13154 struct linespec_result
*c
,
13156 char *extra_string
,
13157 enum bptype type_wanted
,
13158 enum bpdisp disposition
,
13160 int task
, int ignore_count
,
13161 const struct breakpoint_ops
*o
,
13162 int from_tty
, int enabled
,
13163 int internal
, unsigned flags
)
13165 internal_error_pure_virtual_called ();
13169 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13170 struct symtabs_and_lines
*sals
)
13172 internal_error_pure_virtual_called ();
13175 /* The default 'explains_signal' method. */
13178 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13183 /* The default "after_condition_true" method. */
13186 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13188 /* Nothing to do. */
13191 struct breakpoint_ops base_breakpoint_ops
=
13193 base_breakpoint_dtor
,
13194 base_breakpoint_allocate_location
,
13195 base_breakpoint_re_set
,
13196 base_breakpoint_insert_location
,
13197 base_breakpoint_remove_location
,
13198 base_breakpoint_breakpoint_hit
,
13199 base_breakpoint_check_status
,
13200 base_breakpoint_resources_needed
,
13201 base_breakpoint_works_in_software_mode
,
13202 base_breakpoint_print_it
,
13204 base_breakpoint_print_one_detail
,
13205 base_breakpoint_print_mention
,
13206 base_breakpoint_print_recreate
,
13207 base_breakpoint_create_sals_from_address
,
13208 base_breakpoint_create_breakpoints_sal
,
13209 base_breakpoint_decode_linespec
,
13210 base_breakpoint_explains_signal
,
13211 base_breakpoint_after_condition_true
,
13214 /* Default breakpoint_ops methods. */
13217 bkpt_re_set (struct breakpoint
*b
)
13219 /* FIXME: is this still reachable? */
13220 if (b
->addr_string
== NULL
)
13222 /* Anything without a string can't be re-set. */
13223 delete_breakpoint (b
);
13227 breakpoint_re_set_default (b
);
13231 bkpt_insert_location (struct bp_location
*bl
)
13233 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13234 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13236 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13240 bkpt_remove_location (struct bp_location
*bl
)
13242 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13243 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13245 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13249 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13250 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13251 const struct target_waitstatus
*ws
)
13253 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13254 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13257 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13261 if (overlay_debugging
/* unmapped overlay section */
13262 && section_is_overlay (bl
->section
)
13263 && !section_is_mapped (bl
->section
))
13270 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13271 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13272 const struct target_waitstatus
*ws
)
13274 if (dprintf_style
== dprintf_style_agent
13275 && target_can_run_breakpoint_commands ())
13277 /* An agent-style dprintf never causes a stop. If we see a trap
13278 for this address it must be for a breakpoint that happens to
13279 be set at the same address. */
13283 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13287 bkpt_resources_needed (const struct bp_location
*bl
)
13289 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13294 static enum print_stop_action
13295 bkpt_print_it (bpstat bs
)
13297 struct breakpoint
*b
;
13298 const struct bp_location
*bl
;
13300 struct ui_out
*uiout
= current_uiout
;
13302 gdb_assert (bs
->bp_location_at
!= NULL
);
13304 bl
= bs
->bp_location_at
;
13305 b
= bs
->breakpoint_at
;
13307 bp_temp
= b
->disposition
== disp_del
;
13308 if (bl
->address
!= bl
->requested_address
)
13309 breakpoint_adjustment_warning (bl
->requested_address
,
13312 annotate_breakpoint (b
->number
);
13314 ui_out_text (uiout
, "\nTemporary breakpoint ");
13316 ui_out_text (uiout
, "\nBreakpoint ");
13317 if (ui_out_is_mi_like_p (uiout
))
13319 ui_out_field_string (uiout
, "reason",
13320 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13321 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13323 ui_out_field_int (uiout
, "bkptno", b
->number
);
13324 ui_out_text (uiout
, ", ");
13326 return PRINT_SRC_AND_LOC
;
13330 bkpt_print_mention (struct breakpoint
*b
)
13332 if (ui_out_is_mi_like_p (current_uiout
))
13337 case bp_breakpoint
:
13338 case bp_gnu_ifunc_resolver
:
13339 if (b
->disposition
== disp_del
)
13340 printf_filtered (_("Temporary breakpoint"));
13342 printf_filtered (_("Breakpoint"));
13343 printf_filtered (_(" %d"), b
->number
);
13344 if (b
->type
== bp_gnu_ifunc_resolver
)
13345 printf_filtered (_(" at gnu-indirect-function resolver"));
13347 case bp_hardware_breakpoint
:
13348 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13351 printf_filtered (_("Dprintf %d"), b
->number
);
13359 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13361 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13362 fprintf_unfiltered (fp
, "tbreak");
13363 else if (tp
->type
== bp_breakpoint
)
13364 fprintf_unfiltered (fp
, "break");
13365 else if (tp
->type
== bp_hardware_breakpoint
13366 && tp
->disposition
== disp_del
)
13367 fprintf_unfiltered (fp
, "thbreak");
13368 else if (tp
->type
== bp_hardware_breakpoint
)
13369 fprintf_unfiltered (fp
, "hbreak");
13371 internal_error (__FILE__
, __LINE__
,
13372 _("unhandled breakpoint type %d"), (int) tp
->type
);
13374 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13375 print_recreate_thread (tp
, fp
);
13379 bkpt_create_sals_from_address (char **arg
,
13380 struct linespec_result
*canonical
,
13381 enum bptype type_wanted
,
13382 char *addr_start
, char **copy_arg
)
13384 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13385 addr_start
, copy_arg
);
13389 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13390 struct linespec_result
*canonical
,
13392 char *extra_string
,
13393 enum bptype type_wanted
,
13394 enum bpdisp disposition
,
13396 int task
, int ignore_count
,
13397 const struct breakpoint_ops
*ops
,
13398 int from_tty
, int enabled
,
13399 int internal
, unsigned flags
)
13401 create_breakpoints_sal_default (gdbarch
, canonical
,
13402 cond_string
, extra_string
,
13404 disposition
, thread
, task
,
13405 ignore_count
, ops
, from_tty
,
13406 enabled
, internal
, flags
);
13410 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13411 struct symtabs_and_lines
*sals
)
13413 decode_linespec_default (b
, s
, sals
);
13416 /* Virtual table for internal breakpoints. */
13419 internal_bkpt_re_set (struct breakpoint
*b
)
13423 /* Delete overlay event and longjmp master breakpoints; they
13424 will be reset later by breakpoint_re_set. */
13425 case bp_overlay_event
:
13426 case bp_longjmp_master
:
13427 case bp_std_terminate_master
:
13428 case bp_exception_master
:
13429 delete_breakpoint (b
);
13432 /* This breakpoint is special, it's set up when the inferior
13433 starts and we really don't want to touch it. */
13434 case bp_shlib_event
:
13436 /* Like bp_shlib_event, this breakpoint type is special. Once
13437 it is set up, we do not want to touch it. */
13438 case bp_thread_event
:
13444 internal_bkpt_check_status (bpstat bs
)
13446 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13448 /* If requested, stop when the dynamic linker notifies GDB of
13449 events. This allows the user to get control and place
13450 breakpoints in initializer routines for dynamically loaded
13451 objects (among other things). */
13452 bs
->stop
= stop_on_solib_events
;
13453 bs
->print
= stop_on_solib_events
;
13459 static enum print_stop_action
13460 internal_bkpt_print_it (bpstat bs
)
13462 struct breakpoint
*b
;
13464 b
= bs
->breakpoint_at
;
13468 case bp_shlib_event
:
13469 /* Did we stop because the user set the stop_on_solib_events
13470 variable? (If so, we report this as a generic, "Stopped due
13471 to shlib event" message.) */
13472 print_solib_event (0);
13475 case bp_thread_event
:
13476 /* Not sure how we will get here.
13477 GDB should not stop for these breakpoints. */
13478 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13481 case bp_overlay_event
:
13482 /* By analogy with the thread event, GDB should not stop for these. */
13483 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13486 case bp_longjmp_master
:
13487 /* These should never be enabled. */
13488 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13491 case bp_std_terminate_master
:
13492 /* These should never be enabled. */
13493 printf_filtered (_("std::terminate Master Breakpoint: "
13494 "gdb should not stop!\n"));
13497 case bp_exception_master
:
13498 /* These should never be enabled. */
13499 printf_filtered (_("Exception Master Breakpoint: "
13500 "gdb should not stop!\n"));
13504 return PRINT_NOTHING
;
13508 internal_bkpt_print_mention (struct breakpoint
*b
)
13510 /* Nothing to mention. These breakpoints are internal. */
13513 /* Virtual table for momentary breakpoints */
13516 momentary_bkpt_re_set (struct breakpoint
*b
)
13518 /* Keep temporary breakpoints, which can be encountered when we step
13519 over a dlopen call and solib_add is resetting the breakpoints.
13520 Otherwise these should have been blown away via the cleanup chain
13521 or by breakpoint_init_inferior when we rerun the executable. */
13525 momentary_bkpt_check_status (bpstat bs
)
13527 /* Nothing. The point of these breakpoints is causing a stop. */
13530 static enum print_stop_action
13531 momentary_bkpt_print_it (bpstat bs
)
13533 struct ui_out
*uiout
= current_uiout
;
13535 if (ui_out_is_mi_like_p (uiout
))
13537 struct breakpoint
*b
= bs
->breakpoint_at
;
13542 ui_out_field_string
13544 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13548 ui_out_field_string
13550 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13555 return PRINT_UNKNOWN
;
13559 momentary_bkpt_print_mention (struct breakpoint
*b
)
13561 /* Nothing to mention. These breakpoints are internal. */
13564 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13566 It gets cleared already on the removal of the first one of such placed
13567 breakpoints. This is OK as they get all removed altogether. */
13570 longjmp_bkpt_dtor (struct breakpoint
*self
)
13572 struct thread_info
*tp
= find_thread_id (self
->thread
);
13575 tp
->initiating_frame
= null_frame_id
;
13577 momentary_breakpoint_ops
.dtor (self
);
13580 /* Specific methods for probe breakpoints. */
13583 bkpt_probe_insert_location (struct bp_location
*bl
)
13585 int v
= bkpt_insert_location (bl
);
13589 /* The insertion was successful, now let's set the probe's semaphore
13591 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13592 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13601 bkpt_probe_remove_location (struct bp_location
*bl
)
13603 /* Let's clear the semaphore before removing the location. */
13604 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13605 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13609 return bkpt_remove_location (bl
);
13613 bkpt_probe_create_sals_from_address (char **arg
,
13614 struct linespec_result
*canonical
,
13615 enum bptype type_wanted
,
13616 char *addr_start
, char **copy_arg
)
13618 struct linespec_sals lsal
;
13620 lsal
.sals
= parse_probes (arg
, canonical
);
13622 *copy_arg
= xstrdup (canonical
->addr_string
);
13623 lsal
.canonical
= xstrdup (*copy_arg
);
13625 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13629 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13630 struct symtabs_and_lines
*sals
)
13632 *sals
= parse_probes (s
, NULL
);
13634 error (_("probe not found"));
13637 /* The breakpoint_ops structure to be used in tracepoints. */
13640 tracepoint_re_set (struct breakpoint
*b
)
13642 breakpoint_re_set_default (b
);
13646 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13647 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13648 const struct target_waitstatus
*ws
)
13650 /* By definition, the inferior does not report stops at
13656 tracepoint_print_one_detail (const struct breakpoint
*self
,
13657 struct ui_out
*uiout
)
13659 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13660 if (tp
->static_trace_marker_id
)
13662 gdb_assert (self
->type
== bp_static_tracepoint
);
13664 ui_out_text (uiout
, "\tmarker id is ");
13665 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13666 tp
->static_trace_marker_id
);
13667 ui_out_text (uiout
, "\n");
13672 tracepoint_print_mention (struct breakpoint
*b
)
13674 if (ui_out_is_mi_like_p (current_uiout
))
13679 case bp_tracepoint
:
13680 printf_filtered (_("Tracepoint"));
13681 printf_filtered (_(" %d"), b
->number
);
13683 case bp_fast_tracepoint
:
13684 printf_filtered (_("Fast tracepoint"));
13685 printf_filtered (_(" %d"), b
->number
);
13687 case bp_static_tracepoint
:
13688 printf_filtered (_("Static tracepoint"));
13689 printf_filtered (_(" %d"), b
->number
);
13692 internal_error (__FILE__
, __LINE__
,
13693 _("unhandled tracepoint type %d"), (int) b
->type
);
13700 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13702 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13704 if (self
->type
== bp_fast_tracepoint
)
13705 fprintf_unfiltered (fp
, "ftrace");
13706 if (self
->type
== bp_static_tracepoint
)
13707 fprintf_unfiltered (fp
, "strace");
13708 else if (self
->type
== bp_tracepoint
)
13709 fprintf_unfiltered (fp
, "trace");
13711 internal_error (__FILE__
, __LINE__
,
13712 _("unhandled tracepoint type %d"), (int) self
->type
);
13714 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13715 print_recreate_thread (self
, fp
);
13717 if (tp
->pass_count
)
13718 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13722 tracepoint_create_sals_from_address (char **arg
,
13723 struct linespec_result
*canonical
,
13724 enum bptype type_wanted
,
13725 char *addr_start
, char **copy_arg
)
13727 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13728 addr_start
, copy_arg
);
13732 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13733 struct linespec_result
*canonical
,
13735 char *extra_string
,
13736 enum bptype type_wanted
,
13737 enum bpdisp disposition
,
13739 int task
, int ignore_count
,
13740 const struct breakpoint_ops
*ops
,
13741 int from_tty
, int enabled
,
13742 int internal
, unsigned flags
)
13744 create_breakpoints_sal_default (gdbarch
, canonical
,
13745 cond_string
, extra_string
,
13747 disposition
, thread
, task
,
13748 ignore_count
, ops
, from_tty
,
13749 enabled
, internal
, flags
);
13753 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13754 struct symtabs_and_lines
*sals
)
13756 decode_linespec_default (b
, s
, sals
);
13759 struct breakpoint_ops tracepoint_breakpoint_ops
;
13761 /* The breakpoint_ops structure to be use on tracepoints placed in a
13765 tracepoint_probe_create_sals_from_address (char **arg
,
13766 struct linespec_result
*canonical
,
13767 enum bptype type_wanted
,
13768 char *addr_start
, char **copy_arg
)
13770 /* We use the same method for breakpoint on probes. */
13771 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13772 addr_start
, copy_arg
);
13776 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13777 struct symtabs_and_lines
*sals
)
13779 /* We use the same method for breakpoint on probes. */
13780 bkpt_probe_decode_linespec (b
, s
, sals
);
13783 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13785 /* Dprintf breakpoint_ops methods. */
13788 dprintf_re_set (struct breakpoint
*b
)
13790 breakpoint_re_set_default (b
);
13792 /* This breakpoint could have been pending, and be resolved now, and
13793 if so, we should now have the extra string. If we don't, the
13794 dprintf was malformed when created, but we couldn't tell because
13795 we can't extract the extra string until the location is
13797 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13798 error (_("Format string required"));
13800 /* 1 - connect to target 1, that can run breakpoint commands.
13801 2 - create a dprintf, which resolves fine.
13802 3 - disconnect from target 1
13803 4 - connect to target 2, that can NOT run breakpoint commands.
13805 After steps #3/#4, you'll want the dprintf command list to
13806 be updated, because target 1 and 2 may well return different
13807 answers for target_can_run_breakpoint_commands().
13808 Given absence of finer grained resetting, we get to do
13809 it all the time. */
13810 if (b
->extra_string
!= NULL
)
13811 update_dprintf_command_list (b
);
13814 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13817 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13819 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13821 print_recreate_thread (tp
, fp
);
13824 /* Implement the "after_condition_true" breakpoint_ops method for
13827 dprintf's are implemented with regular commands in their command
13828 list, but we run the commands here instead of before presenting the
13829 stop to the user, as dprintf's don't actually cause a stop. This
13830 also makes it so that the commands of multiple dprintfs at the same
13831 address are all handled. */
13834 dprintf_after_condition_true (struct bpstats
*bs
)
13836 struct cleanup
*old_chain
;
13837 struct bpstats tmp_bs
= { NULL
};
13838 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13840 /* dprintf's never cause a stop. This wasn't set in the
13841 check_status hook instead because that would make the dprintf's
13842 condition not be evaluated. */
13845 /* Run the command list here. Take ownership of it instead of
13846 copying. We never want these commands to run later in
13847 bpstat_do_actions, if a breakpoint that causes a stop happens to
13848 be set at same address as this dprintf, or even if running the
13849 commands here throws. */
13850 tmp_bs
.commands
= bs
->commands
;
13851 bs
->commands
= NULL
;
13852 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13854 bpstat_do_actions_1 (&tmp_bs_p
);
13856 /* 'tmp_bs.commands' will usually be NULL by now, but
13857 bpstat_do_actions_1 may return early without processing the whole
13859 do_cleanups (old_chain
);
13862 /* The breakpoint_ops structure to be used on static tracepoints with
13866 strace_marker_create_sals_from_address (char **arg
,
13867 struct linespec_result
*canonical
,
13868 enum bptype type_wanted
,
13869 char *addr_start
, char **copy_arg
)
13871 struct linespec_sals lsal
;
13873 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13875 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13877 canonical
->addr_string
= xstrdup (*copy_arg
);
13878 lsal
.canonical
= xstrdup (*copy_arg
);
13879 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13883 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13884 struct linespec_result
*canonical
,
13886 char *extra_string
,
13887 enum bptype type_wanted
,
13888 enum bpdisp disposition
,
13890 int task
, int ignore_count
,
13891 const struct breakpoint_ops
*ops
,
13892 int from_tty
, int enabled
,
13893 int internal
, unsigned flags
)
13896 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13897 canonical
->sals
, 0);
13899 /* If the user is creating a static tracepoint by marker id
13900 (strace -m MARKER_ID), then store the sals index, so that
13901 breakpoint_re_set can try to match up which of the newly
13902 found markers corresponds to this one, and, don't try to
13903 expand multiple locations for each sal, given than SALS
13904 already should contain all sals for MARKER_ID. */
13906 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13908 struct symtabs_and_lines expanded
;
13909 struct tracepoint
*tp
;
13910 struct cleanup
*old_chain
;
13913 expanded
.nelts
= 1;
13914 expanded
.sals
= &lsal
->sals
.sals
[i
];
13916 addr_string
= xstrdup (canonical
->addr_string
);
13917 old_chain
= make_cleanup (xfree
, addr_string
);
13919 tp
= XCNEW (struct tracepoint
);
13920 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13922 cond_string
, extra_string
,
13923 type_wanted
, disposition
,
13924 thread
, task
, ignore_count
, ops
,
13925 from_tty
, enabled
, internal
, flags
,
13926 canonical
->special_display
);
13927 /* Given that its possible to have multiple markers with
13928 the same string id, if the user is creating a static
13929 tracepoint by marker id ("strace -m MARKER_ID"), then
13930 store the sals index, so that breakpoint_re_set can
13931 try to match up which of the newly found markers
13932 corresponds to this one */
13933 tp
->static_trace_marker_id_idx
= i
;
13935 install_breakpoint (internal
, &tp
->base
, 0);
13937 discard_cleanups (old_chain
);
13942 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13943 struct symtabs_and_lines
*sals
)
13945 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13947 *sals
= decode_static_tracepoint_spec (s
);
13948 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13950 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13954 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13957 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13960 strace_marker_p (struct breakpoint
*b
)
13962 return b
->ops
== &strace_marker_breakpoint_ops
;
13965 /* Delete a breakpoint and clean up all traces of it in the data
13969 delete_breakpoint (struct breakpoint
*bpt
)
13971 struct breakpoint
*b
;
13973 gdb_assert (bpt
!= NULL
);
13975 /* Has this bp already been deleted? This can happen because
13976 multiple lists can hold pointers to bp's. bpstat lists are
13979 One example of this happening is a watchpoint's scope bp. When
13980 the scope bp triggers, we notice that the watchpoint is out of
13981 scope, and delete it. We also delete its scope bp. But the
13982 scope bp is marked "auto-deleting", and is already on a bpstat.
13983 That bpstat is then checked for auto-deleting bp's, which are
13986 A real solution to this problem might involve reference counts in
13987 bp's, and/or giving them pointers back to their referencing
13988 bpstat's, and teaching delete_breakpoint to only free a bp's
13989 storage when no more references were extent. A cheaper bandaid
13991 if (bpt
->type
== bp_none
)
13994 /* At least avoid this stale reference until the reference counting
13995 of breakpoints gets resolved. */
13996 if (bpt
->related_breakpoint
!= bpt
)
13998 struct breakpoint
*related
;
13999 struct watchpoint
*w
;
14001 if (bpt
->type
== bp_watchpoint_scope
)
14002 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
14003 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
14004 w
= (struct watchpoint
*) bpt
;
14008 watchpoint_del_at_next_stop (w
);
14010 /* Unlink bpt from the bpt->related_breakpoint ring. */
14011 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
14012 related
= related
->related_breakpoint
);
14013 related
->related_breakpoint
= bpt
->related_breakpoint
;
14014 bpt
->related_breakpoint
= bpt
;
14017 /* watch_command_1 creates a watchpoint but only sets its number if
14018 update_watchpoint succeeds in creating its bp_locations. If there's
14019 a problem in that process, we'll be asked to delete the half-created
14020 watchpoint. In that case, don't announce the deletion. */
14022 observer_notify_breakpoint_deleted (bpt
);
14024 if (breakpoint_chain
== bpt
)
14025 breakpoint_chain
= bpt
->next
;
14027 ALL_BREAKPOINTS (b
)
14028 if (b
->next
== bpt
)
14030 b
->next
= bpt
->next
;
14034 /* Be sure no bpstat's are pointing at the breakpoint after it's
14036 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14037 in all threads for now. Note that we cannot just remove bpstats
14038 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14039 commands are associated with the bpstat; if we remove it here,
14040 then the later call to bpstat_do_actions (&stop_bpstat); in
14041 event-top.c won't do anything, and temporary breakpoints with
14042 commands won't work. */
14044 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
14046 /* Now that breakpoint is removed from breakpoint list, update the
14047 global location list. This will remove locations that used to
14048 belong to this breakpoint. Do this before freeing the breakpoint
14049 itself, since remove_breakpoint looks at location's owner. It
14050 might be better design to have location completely
14051 self-contained, but it's not the case now. */
14052 update_global_location_list (UGLL_DONT_INSERT
);
14054 bpt
->ops
->dtor (bpt
);
14055 /* On the chance that someone will soon try again to delete this
14056 same bp, we mark it as deleted before freeing its storage. */
14057 bpt
->type
= bp_none
;
14062 do_delete_breakpoint_cleanup (void *b
)
14064 delete_breakpoint (b
);
14068 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
14070 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
14073 /* Iterator function to call a user-provided callback function once
14074 for each of B and its related breakpoints. */
14077 iterate_over_related_breakpoints (struct breakpoint
*b
,
14078 void (*function
) (struct breakpoint
*,
14082 struct breakpoint
*related
;
14087 struct breakpoint
*next
;
14089 /* FUNCTION may delete RELATED. */
14090 next
= related
->related_breakpoint
;
14092 if (next
== related
)
14094 /* RELATED is the last ring entry. */
14095 function (related
, data
);
14097 /* FUNCTION may have deleted it, so we'd never reach back to
14098 B. There's nothing left to do anyway, so just break
14103 function (related
, data
);
14107 while (related
!= b
);
14111 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14113 delete_breakpoint (b
);
14116 /* A callback for map_breakpoint_numbers that calls
14117 delete_breakpoint. */
14120 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14122 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14126 delete_command (char *arg
, int from_tty
)
14128 struct breakpoint
*b
, *b_tmp
;
14134 int breaks_to_delete
= 0;
14136 /* Delete all breakpoints if no argument. Do not delete
14137 internal breakpoints, these have to be deleted with an
14138 explicit breakpoint number argument. */
14139 ALL_BREAKPOINTS (b
)
14140 if (user_breakpoint_p (b
))
14142 breaks_to_delete
= 1;
14146 /* Ask user only if there are some breakpoints to delete. */
14148 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14150 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14151 if (user_breakpoint_p (b
))
14152 delete_breakpoint (b
);
14156 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14160 all_locations_are_pending (struct bp_location
*loc
)
14162 for (; loc
; loc
= loc
->next
)
14163 if (!loc
->shlib_disabled
14164 && !loc
->pspace
->executing_startup
)
14169 /* Subroutine of update_breakpoint_locations to simplify it.
14170 Return non-zero if multiple fns in list LOC have the same name.
14171 Null names are ignored. */
14174 ambiguous_names_p (struct bp_location
*loc
)
14176 struct bp_location
*l
;
14177 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14178 (int (*) (const void *,
14179 const void *)) streq
,
14180 NULL
, xcalloc
, xfree
);
14182 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14185 const char *name
= l
->function_name
;
14187 /* Allow for some names to be NULL, ignore them. */
14191 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14193 /* NOTE: We can assume slot != NULL here because xcalloc never
14197 htab_delete (htab
);
14203 htab_delete (htab
);
14207 /* When symbols change, it probably means the sources changed as well,
14208 and it might mean the static tracepoint markers are no longer at
14209 the same address or line numbers they used to be at last we
14210 checked. Losing your static tracepoints whenever you rebuild is
14211 undesirable. This function tries to resync/rematch gdb static
14212 tracepoints with the markers on the target, for static tracepoints
14213 that have not been set by marker id. Static tracepoint that have
14214 been set by marker id are reset by marker id in breakpoint_re_set.
14217 1) For a tracepoint set at a specific address, look for a marker at
14218 the old PC. If one is found there, assume to be the same marker.
14219 If the name / string id of the marker found is different from the
14220 previous known name, assume that means the user renamed the marker
14221 in the sources, and output a warning.
14223 2) For a tracepoint set at a given line number, look for a marker
14224 at the new address of the old line number. If one is found there,
14225 assume to be the same marker. If the name / string id of the
14226 marker found is different from the previous known name, assume that
14227 means the user renamed the marker in the sources, and output a
14230 3) If a marker is no longer found at the same address or line, it
14231 may mean the marker no longer exists. But it may also just mean
14232 the code changed a bit. Maybe the user added a few lines of code
14233 that made the marker move up or down (in line number terms). Ask
14234 the target for info about the marker with the string id as we knew
14235 it. If found, update line number and address in the matching
14236 static tracepoint. This will get confused if there's more than one
14237 marker with the same ID (possible in UST, although unadvised
14238 precisely because it confuses tools). */
14240 static struct symtab_and_line
14241 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14243 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14244 struct static_tracepoint_marker marker
;
14249 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14251 if (target_static_tracepoint_marker_at (pc
, &marker
))
14253 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14254 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14256 tp
->static_trace_marker_id
, marker
.str_id
);
14258 xfree (tp
->static_trace_marker_id
);
14259 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14260 release_static_tracepoint_marker (&marker
);
14265 /* Old marker wasn't found on target at lineno. Try looking it up
14267 if (!sal
.explicit_pc
14269 && sal
.symtab
!= NULL
14270 && tp
->static_trace_marker_id
!= NULL
)
14272 VEC(static_tracepoint_marker_p
) *markers
;
14275 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14277 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14279 struct symtab_and_line sal2
;
14280 struct symbol
*sym
;
14281 struct static_tracepoint_marker
*tpmarker
;
14282 struct ui_out
*uiout
= current_uiout
;
14284 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14286 xfree (tp
->static_trace_marker_id
);
14287 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14289 warning (_("marker for static tracepoint %d (%s) not "
14290 "found at previous line number"),
14291 b
->number
, tp
->static_trace_marker_id
);
14295 sal2
.pc
= tpmarker
->address
;
14297 sal2
= find_pc_line (tpmarker
->address
, 0);
14298 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14299 ui_out_text (uiout
, "Now in ");
14302 ui_out_field_string (uiout
, "func",
14303 SYMBOL_PRINT_NAME (sym
));
14304 ui_out_text (uiout
, " at ");
14306 ui_out_field_string (uiout
, "file",
14307 symtab_to_filename_for_display (sal2
.symtab
));
14308 ui_out_text (uiout
, ":");
14310 if (ui_out_is_mi_like_p (uiout
))
14312 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14314 ui_out_field_string (uiout
, "fullname", fullname
);
14317 ui_out_field_int (uiout
, "line", sal2
.line
);
14318 ui_out_text (uiout
, "\n");
14320 b
->loc
->line_number
= sal2
.line
;
14321 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14323 xfree (b
->addr_string
);
14324 b
->addr_string
= xstrprintf ("%s:%d",
14325 symtab_to_filename_for_display (sal2
.symtab
),
14326 b
->loc
->line_number
);
14328 /* Might be nice to check if function changed, and warn if
14331 release_static_tracepoint_marker (tpmarker
);
14337 /* Returns 1 iff locations A and B are sufficiently same that
14338 we don't need to report breakpoint as changed. */
14341 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14345 if (a
->address
!= b
->address
)
14348 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14351 if (a
->enabled
!= b
->enabled
)
14358 if ((a
== NULL
) != (b
== NULL
))
14364 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14365 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14366 a ranged breakpoint. */
14369 update_breakpoint_locations (struct breakpoint
*b
,
14370 struct symtabs_and_lines sals
,
14371 struct symtabs_and_lines sals_end
)
14374 struct bp_location
*existing_locations
= b
->loc
;
14376 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14378 /* Ranged breakpoints have only one start location and one end
14380 b
->enable_state
= bp_disabled
;
14381 update_global_location_list (UGLL_MAY_INSERT
);
14382 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14383 "multiple locations found\n"),
14388 /* If there's no new locations, and all existing locations are
14389 pending, don't do anything. This optimizes the common case where
14390 all locations are in the same shared library, that was unloaded.
14391 We'd like to retain the location, so that when the library is
14392 loaded again, we don't loose the enabled/disabled status of the
14393 individual locations. */
14394 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14399 for (i
= 0; i
< sals
.nelts
; ++i
)
14401 struct bp_location
*new_loc
;
14403 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14405 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14407 /* Reparse conditions, they might contain references to the
14409 if (b
->cond_string
!= NULL
)
14412 volatile struct gdb_exception e
;
14414 s
= b
->cond_string
;
14415 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14417 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14418 block_for_pc (sals
.sals
[i
].pc
),
14423 warning (_("failed to reevaluate condition "
14424 "for breakpoint %d: %s"),
14425 b
->number
, e
.message
);
14426 new_loc
->enabled
= 0;
14430 if (sals_end
.nelts
)
14432 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14434 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14438 /* If possible, carry over 'disable' status from existing
14441 struct bp_location
*e
= existing_locations
;
14442 /* If there are multiple breakpoints with the same function name,
14443 e.g. for inline functions, comparing function names won't work.
14444 Instead compare pc addresses; this is just a heuristic as things
14445 may have moved, but in practice it gives the correct answer
14446 often enough until a better solution is found. */
14447 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14449 for (; e
; e
= e
->next
)
14451 if (!e
->enabled
&& e
->function_name
)
14453 struct bp_location
*l
= b
->loc
;
14454 if (have_ambiguous_names
)
14456 for (; l
; l
= l
->next
)
14457 if (breakpoint_locations_match (e
, l
))
14465 for (; l
; l
= l
->next
)
14466 if (l
->function_name
14467 && strcmp (e
->function_name
, l
->function_name
) == 0)
14477 if (!locations_are_equal (existing_locations
, b
->loc
))
14478 observer_notify_breakpoint_modified (b
);
14480 update_global_location_list (UGLL_MAY_INSERT
);
14483 /* Find the SaL locations corresponding to the given ADDR_STRING.
14484 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14486 static struct symtabs_and_lines
14487 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14490 struct symtabs_and_lines sals
= {0};
14491 volatile struct gdb_exception e
;
14493 gdb_assert (b
->ops
!= NULL
);
14496 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14498 b
->ops
->decode_linespec (b
, &s
, &sals
);
14502 int not_found_and_ok
= 0;
14503 /* For pending breakpoints, it's expected that parsing will
14504 fail until the right shared library is loaded. User has
14505 already told to create pending breakpoints and don't need
14506 extra messages. If breakpoint is in bp_shlib_disabled
14507 state, then user already saw the message about that
14508 breakpoint being disabled, and don't want to see more
14510 if (e
.error
== NOT_FOUND_ERROR
14511 && (b
->condition_not_parsed
14512 || (b
->loc
&& b
->loc
->shlib_disabled
)
14513 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14514 || b
->enable_state
== bp_disabled
))
14515 not_found_and_ok
= 1;
14517 if (!not_found_and_ok
)
14519 /* We surely don't want to warn about the same breakpoint
14520 10 times. One solution, implemented here, is disable
14521 the breakpoint on error. Another solution would be to
14522 have separate 'warning emitted' flag. Since this
14523 happens only when a binary has changed, I don't know
14524 which approach is better. */
14525 b
->enable_state
= bp_disabled
;
14526 throw_exception (e
);
14530 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14534 for (i
= 0; i
< sals
.nelts
; ++i
)
14535 resolve_sal_pc (&sals
.sals
[i
]);
14536 if (b
->condition_not_parsed
&& s
&& s
[0])
14538 char *cond_string
, *extra_string
;
14541 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14542 &cond_string
, &thread
, &task
,
14545 b
->cond_string
= cond_string
;
14546 b
->thread
= thread
;
14549 b
->extra_string
= extra_string
;
14550 b
->condition_not_parsed
= 0;
14553 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14554 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14564 /* The default re_set method, for typical hardware or software
14565 breakpoints. Reevaluate the breakpoint and recreate its
14569 breakpoint_re_set_default (struct breakpoint
*b
)
14572 struct symtabs_and_lines sals
, sals_end
;
14573 struct symtabs_and_lines expanded
= {0};
14574 struct symtabs_and_lines expanded_end
= {0};
14576 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14579 make_cleanup (xfree
, sals
.sals
);
14583 if (b
->addr_string_range_end
)
14585 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14588 make_cleanup (xfree
, sals_end
.sals
);
14589 expanded_end
= sals_end
;
14593 update_breakpoint_locations (b
, expanded
, expanded_end
);
14596 /* Default method for creating SALs from an address string. It basically
14597 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14600 create_sals_from_address_default (char **arg
,
14601 struct linespec_result
*canonical
,
14602 enum bptype type_wanted
,
14603 char *addr_start
, char **copy_arg
)
14605 parse_breakpoint_sals (arg
, canonical
);
14608 /* Call create_breakpoints_sal for the given arguments. This is the default
14609 function for the `create_breakpoints_sal' method of
14613 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14614 struct linespec_result
*canonical
,
14616 char *extra_string
,
14617 enum bptype type_wanted
,
14618 enum bpdisp disposition
,
14620 int task
, int ignore_count
,
14621 const struct breakpoint_ops
*ops
,
14622 int from_tty
, int enabled
,
14623 int internal
, unsigned flags
)
14625 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14627 type_wanted
, disposition
,
14628 thread
, task
, ignore_count
, ops
, from_tty
,
14629 enabled
, internal
, flags
);
14632 /* Decode the line represented by S by calling decode_line_full. This is the
14633 default function for the `decode_linespec' method of breakpoint_ops. */
14636 decode_linespec_default (struct breakpoint
*b
, char **s
,
14637 struct symtabs_and_lines
*sals
)
14639 struct linespec_result canonical
;
14641 init_linespec_result (&canonical
);
14642 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14643 (struct symtab
*) NULL
, 0,
14644 &canonical
, multiple_symbols_all
,
14647 /* We should get 0 or 1 resulting SALs. */
14648 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14650 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14652 struct linespec_sals
*lsal
;
14654 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14655 *sals
= lsal
->sals
;
14656 /* Arrange it so the destructor does not free the
14658 lsal
->sals
.sals
= NULL
;
14661 destroy_linespec_result (&canonical
);
14664 /* Prepare the global context for a re-set of breakpoint B. */
14666 static struct cleanup
*
14667 prepare_re_set_context (struct breakpoint
*b
)
14669 struct cleanup
*cleanups
;
14671 input_radix
= b
->input_radix
;
14672 cleanups
= save_current_space_and_thread ();
14673 if (b
->pspace
!= NULL
)
14674 switch_to_program_space_and_thread (b
->pspace
);
14675 set_language (b
->language
);
14680 /* Reset a breakpoint given it's struct breakpoint * BINT.
14681 The value we return ends up being the return value from catch_errors.
14682 Unused in this case. */
14685 breakpoint_re_set_one (void *bint
)
14687 /* Get past catch_errs. */
14688 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14689 struct cleanup
*cleanups
;
14691 cleanups
= prepare_re_set_context (b
);
14692 b
->ops
->re_set (b
);
14693 do_cleanups (cleanups
);
14697 /* Re-set all breakpoints after symbols have been re-loaded. */
14699 breakpoint_re_set (void)
14701 struct breakpoint
*b
, *b_tmp
;
14702 enum language save_language
;
14703 int save_input_radix
;
14704 struct cleanup
*old_chain
;
14706 save_language
= current_language
->la_language
;
14707 save_input_radix
= input_radix
;
14708 old_chain
= save_current_program_space ();
14710 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14712 /* Format possible error msg. */
14713 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14715 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14716 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14717 do_cleanups (cleanups
);
14719 set_language (save_language
);
14720 input_radix
= save_input_radix
;
14722 jit_breakpoint_re_set ();
14724 do_cleanups (old_chain
);
14726 create_overlay_event_breakpoint ();
14727 create_longjmp_master_breakpoint ();
14728 create_std_terminate_master_breakpoint ();
14729 create_exception_master_breakpoint ();
14732 /* Reset the thread number of this breakpoint:
14734 - If the breakpoint is for all threads, leave it as-is.
14735 - Else, reset it to the current thread for inferior_ptid. */
14737 breakpoint_re_set_thread (struct breakpoint
*b
)
14739 if (b
->thread
!= -1)
14741 if (in_thread_list (inferior_ptid
))
14742 b
->thread
= pid_to_thread_id (inferior_ptid
);
14744 /* We're being called after following a fork. The new fork is
14745 selected as current, and unless this was a vfork will have a
14746 different program space from the original thread. Reset that
14748 b
->loc
->pspace
= current_program_space
;
14752 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14753 If from_tty is nonzero, it prints a message to that effect,
14754 which ends with a period (no newline). */
14757 set_ignore_count (int bptnum
, int count
, int from_tty
)
14759 struct breakpoint
*b
;
14764 ALL_BREAKPOINTS (b
)
14765 if (b
->number
== bptnum
)
14767 if (is_tracepoint (b
))
14769 if (from_tty
&& count
!= 0)
14770 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14775 b
->ignore_count
= count
;
14779 printf_filtered (_("Will stop next time "
14780 "breakpoint %d is reached."),
14782 else if (count
== 1)
14783 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14786 printf_filtered (_("Will ignore next %d "
14787 "crossings of breakpoint %d."),
14790 observer_notify_breakpoint_modified (b
);
14794 error (_("No breakpoint number %d."), bptnum
);
14797 /* Command to set ignore-count of breakpoint N to COUNT. */
14800 ignore_command (char *args
, int from_tty
)
14806 error_no_arg (_("a breakpoint number"));
14808 num
= get_number (&p
);
14810 error (_("bad breakpoint number: '%s'"), args
);
14812 error (_("Second argument (specified ignore-count) is missing."));
14814 set_ignore_count (num
,
14815 longest_to_int (value_as_long (parse_and_eval (p
))),
14818 printf_filtered ("\n");
14821 /* Call FUNCTION on each of the breakpoints
14822 whose numbers are given in ARGS. */
14825 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14830 struct breakpoint
*b
, *tmp
;
14832 struct get_number_or_range_state state
;
14835 error_no_arg (_("one or more breakpoint numbers"));
14837 init_number_or_range (&state
, args
);
14839 while (!state
.finished
)
14841 const char *p
= state
.string
;
14845 num
= get_number_or_range (&state
);
14848 warning (_("bad breakpoint number at or near '%s'"), p
);
14852 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14853 if (b
->number
== num
)
14856 function (b
, data
);
14860 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14865 static struct bp_location
*
14866 find_location_by_number (char *number
)
14868 char *dot
= strchr (number
, '.');
14872 struct breakpoint
*b
;
14873 struct bp_location
*loc
;
14878 bp_num
= get_number (&p1
);
14880 error (_("Bad breakpoint number '%s'"), number
);
14882 ALL_BREAKPOINTS (b
)
14883 if (b
->number
== bp_num
)
14888 if (!b
|| b
->number
!= bp_num
)
14889 error (_("Bad breakpoint number '%s'"), number
);
14892 loc_num
= get_number (&p1
);
14894 error (_("Bad breakpoint location number '%s'"), number
);
14898 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14901 error (_("Bad breakpoint location number '%s'"), dot
+1);
14907 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14908 If from_tty is nonzero, it prints a message to that effect,
14909 which ends with a period (no newline). */
14912 disable_breakpoint (struct breakpoint
*bpt
)
14914 /* Never disable a watchpoint scope breakpoint; we want to
14915 hit them when we leave scope so we can delete both the
14916 watchpoint and its scope breakpoint at that time. */
14917 if (bpt
->type
== bp_watchpoint_scope
)
14920 bpt
->enable_state
= bp_disabled
;
14922 /* Mark breakpoint locations modified. */
14923 mark_breakpoint_modified (bpt
);
14925 if (target_supports_enable_disable_tracepoint ()
14926 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14928 struct bp_location
*location
;
14930 for (location
= bpt
->loc
; location
; location
= location
->next
)
14931 target_disable_tracepoint (location
);
14934 update_global_location_list (UGLL_DONT_INSERT
);
14936 observer_notify_breakpoint_modified (bpt
);
14939 /* A callback for iterate_over_related_breakpoints. */
14942 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14944 disable_breakpoint (b
);
14947 /* A callback for map_breakpoint_numbers that calls
14948 disable_breakpoint. */
14951 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14953 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14957 disable_command (char *args
, int from_tty
)
14961 struct breakpoint
*bpt
;
14963 ALL_BREAKPOINTS (bpt
)
14964 if (user_breakpoint_p (bpt
))
14965 disable_breakpoint (bpt
);
14969 char *num
= extract_arg (&args
);
14973 if (strchr (num
, '.'))
14975 struct bp_location
*loc
= find_location_by_number (num
);
14982 mark_breakpoint_location_modified (loc
);
14984 if (target_supports_enable_disable_tracepoint ()
14985 && current_trace_status ()->running
&& loc
->owner
14986 && is_tracepoint (loc
->owner
))
14987 target_disable_tracepoint (loc
);
14989 update_global_location_list (UGLL_DONT_INSERT
);
14992 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14993 num
= extract_arg (&args
);
14999 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
15002 int target_resources_ok
;
15004 if (bpt
->type
== bp_hardware_breakpoint
)
15007 i
= hw_breakpoint_used_count ();
15008 target_resources_ok
=
15009 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
15011 if (target_resources_ok
== 0)
15012 error (_("No hardware breakpoint support in the target."));
15013 else if (target_resources_ok
< 0)
15014 error (_("Hardware breakpoints used exceeds limit."));
15017 if (is_watchpoint (bpt
))
15019 /* Initialize it just to avoid a GCC false warning. */
15020 enum enable_state orig_enable_state
= 0;
15021 volatile struct gdb_exception e
;
15023 TRY_CATCH (e
, RETURN_MASK_ALL
)
15025 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
15027 orig_enable_state
= bpt
->enable_state
;
15028 bpt
->enable_state
= bp_enabled
;
15029 update_watchpoint (w
, 1 /* reparse */);
15033 bpt
->enable_state
= orig_enable_state
;
15034 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15040 bpt
->enable_state
= bp_enabled
;
15042 /* Mark breakpoint locations modified. */
15043 mark_breakpoint_modified (bpt
);
15045 if (target_supports_enable_disable_tracepoint ()
15046 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15048 struct bp_location
*location
;
15050 for (location
= bpt
->loc
; location
; location
= location
->next
)
15051 target_enable_tracepoint (location
);
15054 bpt
->disposition
= disposition
;
15055 bpt
->enable_count
= count
;
15056 update_global_location_list (UGLL_MAY_INSERT
);
15058 observer_notify_breakpoint_modified (bpt
);
15063 enable_breakpoint (struct breakpoint
*bpt
)
15065 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15069 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15071 enable_breakpoint (bpt
);
15074 /* A callback for map_breakpoint_numbers that calls
15075 enable_breakpoint. */
15078 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15080 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15083 /* The enable command enables the specified breakpoints (or all defined
15084 breakpoints) so they once again become (or continue to be) effective
15085 in stopping the inferior. */
15088 enable_command (char *args
, int from_tty
)
15092 struct breakpoint
*bpt
;
15094 ALL_BREAKPOINTS (bpt
)
15095 if (user_breakpoint_p (bpt
))
15096 enable_breakpoint (bpt
);
15100 char *num
= extract_arg (&args
);
15104 if (strchr (num
, '.'))
15106 struct bp_location
*loc
= find_location_by_number (num
);
15113 mark_breakpoint_location_modified (loc
);
15115 if (target_supports_enable_disable_tracepoint ()
15116 && current_trace_status ()->running
&& loc
->owner
15117 && is_tracepoint (loc
->owner
))
15118 target_enable_tracepoint (loc
);
15120 update_global_location_list (UGLL_MAY_INSERT
);
15123 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15124 num
= extract_arg (&args
);
15129 /* This struct packages up disposition data for application to multiple
15139 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15141 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15143 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15147 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15149 struct disp_data disp
= { disp_disable
, 1 };
15151 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15155 enable_once_command (char *args
, int from_tty
)
15157 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15161 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15163 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15165 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15169 enable_count_command (char *args
, int from_tty
)
15171 int count
= get_number (&args
);
15173 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15177 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15179 struct disp_data disp
= { disp_del
, 1 };
15181 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15185 enable_delete_command (char *args
, int from_tty
)
15187 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15191 set_breakpoint_cmd (char *args
, int from_tty
)
15196 show_breakpoint_cmd (char *args
, int from_tty
)
15200 /* Invalidate last known value of any hardware watchpoint if
15201 the memory which that value represents has been written to by
15205 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15206 CORE_ADDR addr
, ssize_t len
,
15207 const bfd_byte
*data
)
15209 struct breakpoint
*bp
;
15211 ALL_BREAKPOINTS (bp
)
15212 if (bp
->enable_state
== bp_enabled
15213 && bp
->type
== bp_hardware_watchpoint
)
15215 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15217 if (wp
->val_valid
&& wp
->val
)
15219 struct bp_location
*loc
;
15221 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15222 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15223 && loc
->address
+ loc
->length
> addr
15224 && addr
+ len
> loc
->address
)
15226 value_free (wp
->val
);
15234 /* Create and insert a breakpoint for software single step. */
15237 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15238 struct address_space
*aspace
,
15241 struct thread_info
*tp
= inferior_thread ();
15242 struct symtab_and_line sal
;
15243 CORE_ADDR pc
= next_pc
;
15245 if (tp
->control
.single_step_breakpoints
== NULL
)
15247 tp
->control
.single_step_breakpoints
15248 = new_single_step_breakpoint (tp
->num
, gdbarch
);
15251 sal
= find_pc_line (pc
, 0);
15253 sal
.section
= find_pc_overlay (pc
);
15254 sal
.explicit_pc
= 1;
15255 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15257 update_global_location_list (UGLL_INSERT
);
15260 /* See breakpoint.h. */
15263 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15264 struct address_space
*aspace
,
15267 struct bp_location
*loc
;
15269 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15271 && breakpoint_location_address_match (loc
, aspace
, pc
))
15277 /* Check whether a software single-step breakpoint is inserted at
15281 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15284 struct breakpoint
*bpt
;
15286 ALL_BREAKPOINTS (bpt
)
15288 if (bpt
->type
== bp_single_step
15289 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15295 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15296 non-zero otherwise. */
15298 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15300 if (syscall_catchpoint_p (bp
)
15301 && bp
->enable_state
!= bp_disabled
15302 && bp
->enable_state
!= bp_call_disabled
)
15309 catch_syscall_enabled (void)
15311 struct catch_syscall_inferior_data
*inf_data
15312 = get_catch_syscall_inferior_data (current_inferior ());
15314 return inf_data
->total_syscalls_count
!= 0;
15318 catching_syscall_number (int syscall_number
)
15320 struct breakpoint
*bp
;
15322 ALL_BREAKPOINTS (bp
)
15323 if (is_syscall_catchpoint_enabled (bp
))
15325 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15327 if (c
->syscalls_to_be_caught
)
15331 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15333 if (syscall_number
== iter
)
15343 /* Complete syscall names. Used by "catch syscall". */
15344 static VEC (char_ptr
) *
15345 catch_syscall_completer (struct cmd_list_element
*cmd
,
15346 const char *text
, const char *word
)
15348 const char **list
= get_syscall_names ();
15349 VEC (char_ptr
) *retlist
15350 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15356 /* Tracepoint-specific operations. */
15358 /* Set tracepoint count to NUM. */
15360 set_tracepoint_count (int num
)
15362 tracepoint_count
= num
;
15363 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15367 trace_command (char *arg
, int from_tty
)
15369 struct breakpoint_ops
*ops
;
15370 const char *arg_cp
= arg
;
15372 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15373 ops
= &tracepoint_probe_breakpoint_ops
;
15375 ops
= &tracepoint_breakpoint_ops
;
15377 create_breakpoint (get_current_arch (),
15379 NULL
, 0, NULL
, 1 /* parse arg */,
15381 bp_tracepoint
/* type_wanted */,
15382 0 /* Ignore count */,
15383 pending_break_support
,
15387 0 /* internal */, 0);
15391 ftrace_command (char *arg
, int from_tty
)
15393 create_breakpoint (get_current_arch (),
15395 NULL
, 0, NULL
, 1 /* parse arg */,
15397 bp_fast_tracepoint
/* type_wanted */,
15398 0 /* Ignore count */,
15399 pending_break_support
,
15400 &tracepoint_breakpoint_ops
,
15403 0 /* internal */, 0);
15406 /* strace command implementation. Creates a static tracepoint. */
15409 strace_command (char *arg
, int from_tty
)
15411 struct breakpoint_ops
*ops
;
15413 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15414 or with a normal static tracepoint. */
15415 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15416 ops
= &strace_marker_breakpoint_ops
;
15418 ops
= &tracepoint_breakpoint_ops
;
15420 create_breakpoint (get_current_arch (),
15422 NULL
, 0, NULL
, 1 /* parse arg */,
15424 bp_static_tracepoint
/* type_wanted */,
15425 0 /* Ignore count */,
15426 pending_break_support
,
15430 0 /* internal */, 0);
15433 /* Set up a fake reader function that gets command lines from a linked
15434 list that was acquired during tracepoint uploading. */
15436 static struct uploaded_tp
*this_utp
;
15437 static int next_cmd
;
15440 read_uploaded_action (void)
15444 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15451 /* Given information about a tracepoint as recorded on a target (which
15452 can be either a live system or a trace file), attempt to create an
15453 equivalent GDB tracepoint. This is not a reliable process, since
15454 the target does not necessarily have all the information used when
15455 the tracepoint was originally defined. */
15457 struct tracepoint
*
15458 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15460 char *addr_str
, small_buf
[100];
15461 struct tracepoint
*tp
;
15463 if (utp
->at_string
)
15464 addr_str
= utp
->at_string
;
15467 /* In the absence of a source location, fall back to raw
15468 address. Since there is no way to confirm that the address
15469 means the same thing as when the trace was started, warn the
15471 warning (_("Uploaded tracepoint %d has no "
15472 "source location, using raw address"),
15474 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15475 addr_str
= small_buf
;
15478 /* There's not much we can do with a sequence of bytecodes. */
15479 if (utp
->cond
&& !utp
->cond_string
)
15480 warning (_("Uploaded tracepoint %d condition "
15481 "has no source form, ignoring it"),
15484 if (!create_breakpoint (get_current_arch (),
15486 utp
->cond_string
, -1, NULL
,
15487 0 /* parse cond/thread */,
15489 utp
->type
/* type_wanted */,
15490 0 /* Ignore count */,
15491 pending_break_support
,
15492 &tracepoint_breakpoint_ops
,
15494 utp
->enabled
/* enabled */,
15496 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15499 /* Get the tracepoint we just created. */
15500 tp
= get_tracepoint (tracepoint_count
);
15501 gdb_assert (tp
!= NULL
);
15505 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15508 trace_pass_command (small_buf
, 0);
15511 /* If we have uploaded versions of the original commands, set up a
15512 special-purpose "reader" function and call the usual command line
15513 reader, then pass the result to the breakpoint command-setting
15515 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15517 struct command_line
*cmd_list
;
15522 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15524 breakpoint_set_commands (&tp
->base
, cmd_list
);
15526 else if (!VEC_empty (char_ptr
, utp
->actions
)
15527 || !VEC_empty (char_ptr
, utp
->step_actions
))
15528 warning (_("Uploaded tracepoint %d actions "
15529 "have no source form, ignoring them"),
15532 /* Copy any status information that might be available. */
15533 tp
->base
.hit_count
= utp
->hit_count
;
15534 tp
->traceframe_usage
= utp
->traceframe_usage
;
15539 /* Print information on tracepoint number TPNUM_EXP, or all if
15543 tracepoints_info (char *args
, int from_tty
)
15545 struct ui_out
*uiout
= current_uiout
;
15548 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15550 if (num_printed
== 0)
15552 if (args
== NULL
|| *args
== '\0')
15553 ui_out_message (uiout
, 0, "No tracepoints.\n");
15555 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15558 default_collect_info ();
15561 /* The 'enable trace' command enables tracepoints.
15562 Not supported by all targets. */
15564 enable_trace_command (char *args
, int from_tty
)
15566 enable_command (args
, from_tty
);
15569 /* The 'disable trace' command disables tracepoints.
15570 Not supported by all targets. */
15572 disable_trace_command (char *args
, int from_tty
)
15574 disable_command (args
, from_tty
);
15577 /* Remove a tracepoint (or all if no argument). */
15579 delete_trace_command (char *arg
, int from_tty
)
15581 struct breakpoint
*b
, *b_tmp
;
15587 int breaks_to_delete
= 0;
15589 /* Delete all breakpoints if no argument.
15590 Do not delete internal or call-dummy breakpoints, these
15591 have to be deleted with an explicit breakpoint number
15593 ALL_TRACEPOINTS (b
)
15594 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15596 breaks_to_delete
= 1;
15600 /* Ask user only if there are some breakpoints to delete. */
15602 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15604 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15605 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15606 delete_breakpoint (b
);
15610 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15613 /* Helper function for trace_pass_command. */
15616 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15618 tp
->pass_count
= count
;
15619 observer_notify_breakpoint_modified (&tp
->base
);
15621 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15622 tp
->base
.number
, count
);
15625 /* Set passcount for tracepoint.
15627 First command argument is passcount, second is tracepoint number.
15628 If tracepoint number omitted, apply to most recently defined.
15629 Also accepts special argument "all". */
15632 trace_pass_command (char *args
, int from_tty
)
15634 struct tracepoint
*t1
;
15635 unsigned int count
;
15637 if (args
== 0 || *args
== 0)
15638 error (_("passcount command requires an "
15639 "argument (count + optional TP num)"));
15641 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15643 args
= skip_spaces (args
);
15644 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15646 struct breakpoint
*b
;
15648 args
+= 3; /* Skip special argument "all". */
15650 error (_("Junk at end of arguments."));
15652 ALL_TRACEPOINTS (b
)
15654 t1
= (struct tracepoint
*) b
;
15655 trace_pass_set_count (t1
, count
, from_tty
);
15658 else if (*args
== '\0')
15660 t1
= get_tracepoint_by_number (&args
, NULL
);
15662 trace_pass_set_count (t1
, count
, from_tty
);
15666 struct get_number_or_range_state state
;
15668 init_number_or_range (&state
, args
);
15669 while (!state
.finished
)
15671 t1
= get_tracepoint_by_number (&args
, &state
);
15673 trace_pass_set_count (t1
, count
, from_tty
);
15678 struct tracepoint
*
15679 get_tracepoint (int num
)
15681 struct breakpoint
*t
;
15683 ALL_TRACEPOINTS (t
)
15684 if (t
->number
== num
)
15685 return (struct tracepoint
*) t
;
15690 /* Find the tracepoint with the given target-side number (which may be
15691 different from the tracepoint number after disconnecting and
15694 struct tracepoint
*
15695 get_tracepoint_by_number_on_target (int num
)
15697 struct breakpoint
*b
;
15699 ALL_TRACEPOINTS (b
)
15701 struct tracepoint
*t
= (struct tracepoint
*) b
;
15703 if (t
->number_on_target
== num
)
15710 /* Utility: parse a tracepoint number and look it up in the list.
15711 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15712 If the argument is missing, the most recent tracepoint
15713 (tracepoint_count) is returned. */
15715 struct tracepoint
*
15716 get_tracepoint_by_number (char **arg
,
15717 struct get_number_or_range_state
*state
)
15719 struct breakpoint
*t
;
15721 char *instring
= arg
== NULL
? NULL
: *arg
;
15725 gdb_assert (!state
->finished
);
15726 tpnum
= get_number_or_range (state
);
15728 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15729 tpnum
= tracepoint_count
;
15731 tpnum
= get_number (arg
);
15735 if (instring
&& *instring
)
15736 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15739 printf_filtered (_("No previous tracepoint\n"));
15743 ALL_TRACEPOINTS (t
)
15744 if (t
->number
== tpnum
)
15746 return (struct tracepoint
*) t
;
15749 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15754 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15756 if (b
->thread
!= -1)
15757 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15760 fprintf_unfiltered (fp
, " task %d", b
->task
);
15762 fprintf_unfiltered (fp
, "\n");
15765 /* Save information on user settable breakpoints (watchpoints, etc) to
15766 a new script file named FILENAME. If FILTER is non-NULL, call it
15767 on each breakpoint and only include the ones for which it returns
15771 save_breakpoints (char *filename
, int from_tty
,
15772 int (*filter
) (const struct breakpoint
*))
15774 struct breakpoint
*tp
;
15776 struct cleanup
*cleanup
;
15777 struct ui_file
*fp
;
15778 int extra_trace_bits
= 0;
15780 if (filename
== 0 || *filename
== 0)
15781 error (_("Argument required (file name in which to save)"));
15783 /* See if we have anything to save. */
15784 ALL_BREAKPOINTS (tp
)
15786 /* Skip internal and momentary breakpoints. */
15787 if (!user_breakpoint_p (tp
))
15790 /* If we have a filter, only save the breakpoints it accepts. */
15791 if (filter
&& !filter (tp
))
15796 if (is_tracepoint (tp
))
15798 extra_trace_bits
= 1;
15800 /* We can stop searching. */
15807 warning (_("Nothing to save."));
15811 filename
= tilde_expand (filename
);
15812 cleanup
= make_cleanup (xfree
, filename
);
15813 fp
= gdb_fopen (filename
, "w");
15815 error (_("Unable to open file '%s' for saving (%s)"),
15816 filename
, safe_strerror (errno
));
15817 make_cleanup_ui_file_delete (fp
);
15819 if (extra_trace_bits
)
15820 save_trace_state_variables (fp
);
15822 ALL_BREAKPOINTS (tp
)
15824 /* Skip internal and momentary breakpoints. */
15825 if (!user_breakpoint_p (tp
))
15828 /* If we have a filter, only save the breakpoints it accepts. */
15829 if (filter
&& !filter (tp
))
15832 tp
->ops
->print_recreate (tp
, fp
);
15834 /* Note, we can't rely on tp->number for anything, as we can't
15835 assume the recreated breakpoint numbers will match. Use $bpnum
15838 if (tp
->cond_string
)
15839 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15841 if (tp
->ignore_count
)
15842 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15844 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15846 volatile struct gdb_exception ex
;
15848 fprintf_unfiltered (fp
, " commands\n");
15850 ui_out_redirect (current_uiout
, fp
);
15851 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15853 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15855 ui_out_redirect (current_uiout
, NULL
);
15858 throw_exception (ex
);
15860 fprintf_unfiltered (fp
, " end\n");
15863 if (tp
->enable_state
== bp_disabled
)
15864 fprintf_unfiltered (fp
, "disable $bpnum\n");
15866 /* If this is a multi-location breakpoint, check if the locations
15867 should be individually disabled. Watchpoint locations are
15868 special, and not user visible. */
15869 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15871 struct bp_location
*loc
;
15874 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15876 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15880 if (extra_trace_bits
&& *default_collect
)
15881 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15884 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15885 do_cleanups (cleanup
);
15888 /* The `save breakpoints' command. */
15891 save_breakpoints_command (char *args
, int from_tty
)
15893 save_breakpoints (args
, from_tty
, NULL
);
15896 /* The `save tracepoints' command. */
15899 save_tracepoints_command (char *args
, int from_tty
)
15901 save_breakpoints (args
, from_tty
, is_tracepoint
);
15904 /* Create a vector of all tracepoints. */
15906 VEC(breakpoint_p
) *
15907 all_tracepoints (void)
15909 VEC(breakpoint_p
) *tp_vec
= 0;
15910 struct breakpoint
*tp
;
15912 ALL_TRACEPOINTS (tp
)
15914 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15921 /* This help string is used for the break, hbreak, tbreak and thbreak
15922 commands. It is defined as a macro to prevent duplication.
15923 COMMAND should be a string constant containing the name of the
15925 #define BREAK_ARGS_HELP(command) \
15926 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15927 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15928 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15929 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15930 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15931 If a line number is specified, break at start of code for that line.\n\
15932 If a function is specified, break at start of code for that function.\n\
15933 If an address is specified, break at that exact address.\n\
15934 With no LOCATION, uses current execution address of the selected\n\
15935 stack frame. This is useful for breaking on return to a stack frame.\n\
15937 THREADNUM is the number from \"info threads\".\n\
15938 CONDITION is a boolean expression.\n\
15940 Multiple breakpoints at one place are permitted, and useful if their\n\
15941 conditions are different.\n\
15943 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15945 /* List of subcommands for "catch". */
15946 static struct cmd_list_element
*catch_cmdlist
;
15948 /* List of subcommands for "tcatch". */
15949 static struct cmd_list_element
*tcatch_cmdlist
;
15952 add_catch_command (char *name
, char *docstring
,
15953 cmd_sfunc_ftype
*sfunc
,
15954 completer_ftype
*completer
,
15955 void *user_data_catch
,
15956 void *user_data_tcatch
)
15958 struct cmd_list_element
*command
;
15960 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15962 set_cmd_sfunc (command
, sfunc
);
15963 set_cmd_context (command
, user_data_catch
);
15964 set_cmd_completer (command
, completer
);
15966 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15968 set_cmd_sfunc (command
, sfunc
);
15969 set_cmd_context (command
, user_data_tcatch
);
15970 set_cmd_completer (command
, completer
);
15974 clear_syscall_counts (struct inferior
*inf
)
15976 struct catch_syscall_inferior_data
*inf_data
15977 = get_catch_syscall_inferior_data (inf
);
15979 inf_data
->total_syscalls_count
= 0;
15980 inf_data
->any_syscall_count
= 0;
15981 VEC_free (int, inf_data
->syscalls_counts
);
15985 save_command (char *arg
, int from_tty
)
15987 printf_unfiltered (_("\"save\" must be followed by "
15988 "the name of a save subcommand.\n"));
15989 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15992 struct breakpoint
*
15993 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15996 struct breakpoint
*b
, *b_tmp
;
15998 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
16000 if ((*callback
) (b
, data
))
16007 /* Zero if any of the breakpoint's locations could be a location where
16008 functions have been inlined, nonzero otherwise. */
16011 is_non_inline_function (struct breakpoint
*b
)
16013 /* The shared library event breakpoint is set on the address of a
16014 non-inline function. */
16015 if (b
->type
== bp_shlib_event
)
16021 /* Nonzero if the specified PC cannot be a location where functions
16022 have been inlined. */
16025 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
16026 const struct target_waitstatus
*ws
)
16028 struct breakpoint
*b
;
16029 struct bp_location
*bl
;
16031 ALL_BREAKPOINTS (b
)
16033 if (!is_non_inline_function (b
))
16036 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16038 if (!bl
->shlib_disabled
16039 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16047 /* Remove any references to OBJFILE which is going to be freed. */
16050 breakpoint_free_objfile (struct objfile
*objfile
)
16052 struct bp_location
**locp
, *loc
;
16054 ALL_BP_LOCATIONS (loc
, locp
)
16055 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
16056 loc
->symtab
= NULL
;
16060 initialize_breakpoint_ops (void)
16062 static int initialized
= 0;
16064 struct breakpoint_ops
*ops
;
16070 /* The breakpoint_ops structure to be inherit by all kinds of
16071 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16072 internal and momentary breakpoints, etc.). */
16073 ops
= &bkpt_base_breakpoint_ops
;
16074 *ops
= base_breakpoint_ops
;
16075 ops
->re_set
= bkpt_re_set
;
16076 ops
->insert_location
= bkpt_insert_location
;
16077 ops
->remove_location
= bkpt_remove_location
;
16078 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16079 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16080 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16081 ops
->decode_linespec
= bkpt_decode_linespec
;
16083 /* The breakpoint_ops structure to be used in regular breakpoints. */
16084 ops
= &bkpt_breakpoint_ops
;
16085 *ops
= bkpt_base_breakpoint_ops
;
16086 ops
->re_set
= bkpt_re_set
;
16087 ops
->resources_needed
= bkpt_resources_needed
;
16088 ops
->print_it
= bkpt_print_it
;
16089 ops
->print_mention
= bkpt_print_mention
;
16090 ops
->print_recreate
= bkpt_print_recreate
;
16092 /* Ranged breakpoints. */
16093 ops
= &ranged_breakpoint_ops
;
16094 *ops
= bkpt_breakpoint_ops
;
16095 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16096 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16097 ops
->print_it
= print_it_ranged_breakpoint
;
16098 ops
->print_one
= print_one_ranged_breakpoint
;
16099 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16100 ops
->print_mention
= print_mention_ranged_breakpoint
;
16101 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16103 /* Internal breakpoints. */
16104 ops
= &internal_breakpoint_ops
;
16105 *ops
= bkpt_base_breakpoint_ops
;
16106 ops
->re_set
= internal_bkpt_re_set
;
16107 ops
->check_status
= internal_bkpt_check_status
;
16108 ops
->print_it
= internal_bkpt_print_it
;
16109 ops
->print_mention
= internal_bkpt_print_mention
;
16111 /* Momentary breakpoints. */
16112 ops
= &momentary_breakpoint_ops
;
16113 *ops
= bkpt_base_breakpoint_ops
;
16114 ops
->re_set
= momentary_bkpt_re_set
;
16115 ops
->check_status
= momentary_bkpt_check_status
;
16116 ops
->print_it
= momentary_bkpt_print_it
;
16117 ops
->print_mention
= momentary_bkpt_print_mention
;
16119 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16120 ops
= &longjmp_breakpoint_ops
;
16121 *ops
= momentary_breakpoint_ops
;
16122 ops
->dtor
= longjmp_bkpt_dtor
;
16124 /* Probe breakpoints. */
16125 ops
= &bkpt_probe_breakpoint_ops
;
16126 *ops
= bkpt_breakpoint_ops
;
16127 ops
->insert_location
= bkpt_probe_insert_location
;
16128 ops
->remove_location
= bkpt_probe_remove_location
;
16129 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16130 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16133 ops
= &watchpoint_breakpoint_ops
;
16134 *ops
= base_breakpoint_ops
;
16135 ops
->dtor
= dtor_watchpoint
;
16136 ops
->re_set
= re_set_watchpoint
;
16137 ops
->insert_location
= insert_watchpoint
;
16138 ops
->remove_location
= remove_watchpoint
;
16139 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16140 ops
->check_status
= check_status_watchpoint
;
16141 ops
->resources_needed
= resources_needed_watchpoint
;
16142 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16143 ops
->print_it
= print_it_watchpoint
;
16144 ops
->print_mention
= print_mention_watchpoint
;
16145 ops
->print_recreate
= print_recreate_watchpoint
;
16146 ops
->explains_signal
= explains_signal_watchpoint
;
16148 /* Masked watchpoints. */
16149 ops
= &masked_watchpoint_breakpoint_ops
;
16150 *ops
= watchpoint_breakpoint_ops
;
16151 ops
->insert_location
= insert_masked_watchpoint
;
16152 ops
->remove_location
= remove_masked_watchpoint
;
16153 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16154 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16155 ops
->print_it
= print_it_masked_watchpoint
;
16156 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16157 ops
->print_mention
= print_mention_masked_watchpoint
;
16158 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16161 ops
= &tracepoint_breakpoint_ops
;
16162 *ops
= base_breakpoint_ops
;
16163 ops
->re_set
= tracepoint_re_set
;
16164 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16165 ops
->print_one_detail
= tracepoint_print_one_detail
;
16166 ops
->print_mention
= tracepoint_print_mention
;
16167 ops
->print_recreate
= tracepoint_print_recreate
;
16168 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16169 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16170 ops
->decode_linespec
= tracepoint_decode_linespec
;
16172 /* Probe tracepoints. */
16173 ops
= &tracepoint_probe_breakpoint_ops
;
16174 *ops
= tracepoint_breakpoint_ops
;
16175 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16176 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16178 /* Static tracepoints with marker (`-m'). */
16179 ops
= &strace_marker_breakpoint_ops
;
16180 *ops
= tracepoint_breakpoint_ops
;
16181 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16182 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16183 ops
->decode_linespec
= strace_marker_decode_linespec
;
16185 /* Fork catchpoints. */
16186 ops
= &catch_fork_breakpoint_ops
;
16187 *ops
= base_breakpoint_ops
;
16188 ops
->insert_location
= insert_catch_fork
;
16189 ops
->remove_location
= remove_catch_fork
;
16190 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16191 ops
->print_it
= print_it_catch_fork
;
16192 ops
->print_one
= print_one_catch_fork
;
16193 ops
->print_mention
= print_mention_catch_fork
;
16194 ops
->print_recreate
= print_recreate_catch_fork
;
16196 /* Vfork catchpoints. */
16197 ops
= &catch_vfork_breakpoint_ops
;
16198 *ops
= base_breakpoint_ops
;
16199 ops
->insert_location
= insert_catch_vfork
;
16200 ops
->remove_location
= remove_catch_vfork
;
16201 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16202 ops
->print_it
= print_it_catch_vfork
;
16203 ops
->print_one
= print_one_catch_vfork
;
16204 ops
->print_mention
= print_mention_catch_vfork
;
16205 ops
->print_recreate
= print_recreate_catch_vfork
;
16207 /* Exec catchpoints. */
16208 ops
= &catch_exec_breakpoint_ops
;
16209 *ops
= base_breakpoint_ops
;
16210 ops
->dtor
= dtor_catch_exec
;
16211 ops
->insert_location
= insert_catch_exec
;
16212 ops
->remove_location
= remove_catch_exec
;
16213 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16214 ops
->print_it
= print_it_catch_exec
;
16215 ops
->print_one
= print_one_catch_exec
;
16216 ops
->print_mention
= print_mention_catch_exec
;
16217 ops
->print_recreate
= print_recreate_catch_exec
;
16219 /* Syscall catchpoints. */
16220 ops
= &catch_syscall_breakpoint_ops
;
16221 *ops
= base_breakpoint_ops
;
16222 ops
->dtor
= dtor_catch_syscall
;
16223 ops
->insert_location
= insert_catch_syscall
;
16224 ops
->remove_location
= remove_catch_syscall
;
16225 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16226 ops
->print_it
= print_it_catch_syscall
;
16227 ops
->print_one
= print_one_catch_syscall
;
16228 ops
->print_mention
= print_mention_catch_syscall
;
16229 ops
->print_recreate
= print_recreate_catch_syscall
;
16231 /* Solib-related catchpoints. */
16232 ops
= &catch_solib_breakpoint_ops
;
16233 *ops
= base_breakpoint_ops
;
16234 ops
->dtor
= dtor_catch_solib
;
16235 ops
->insert_location
= insert_catch_solib
;
16236 ops
->remove_location
= remove_catch_solib
;
16237 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16238 ops
->check_status
= check_status_catch_solib
;
16239 ops
->print_it
= print_it_catch_solib
;
16240 ops
->print_one
= print_one_catch_solib
;
16241 ops
->print_mention
= print_mention_catch_solib
;
16242 ops
->print_recreate
= print_recreate_catch_solib
;
16244 ops
= &dprintf_breakpoint_ops
;
16245 *ops
= bkpt_base_breakpoint_ops
;
16246 ops
->re_set
= dprintf_re_set
;
16247 ops
->resources_needed
= bkpt_resources_needed
;
16248 ops
->print_it
= bkpt_print_it
;
16249 ops
->print_mention
= bkpt_print_mention
;
16250 ops
->print_recreate
= dprintf_print_recreate
;
16251 ops
->after_condition_true
= dprintf_after_condition_true
;
16252 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16255 /* Chain containing all defined "enable breakpoint" subcommands. */
16257 static struct cmd_list_element
*enablebreaklist
= NULL
;
16260 _initialize_breakpoint (void)
16262 struct cmd_list_element
*c
;
16264 initialize_breakpoint_ops ();
16266 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16267 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16268 observer_attach_inferior_exit (clear_syscall_counts
);
16269 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16271 breakpoint_objfile_key
16272 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16274 catch_syscall_inferior_data
16275 = register_inferior_data_with_cleanup (NULL
,
16276 catch_syscall_inferior_data_cleanup
);
16278 breakpoint_chain
= 0;
16279 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16280 before a breakpoint is set. */
16281 breakpoint_count
= 0;
16283 tracepoint_count
= 0;
16285 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16286 Set ignore-count of breakpoint number N to COUNT.\n\
16287 Usage is `ignore N COUNT'."));
16289 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16291 add_com ("commands", class_breakpoint
, commands_command
, _("\
16292 Set commands to be executed when a breakpoint is hit.\n\
16293 Give breakpoint number as argument after \"commands\".\n\
16294 With no argument, the targeted breakpoint is the last one set.\n\
16295 The commands themselves follow starting on the next line.\n\
16296 Type a line containing \"end\" to indicate the end of them.\n\
16297 Give \"silent\" as the first line to make the breakpoint silent;\n\
16298 then no output is printed when it is hit, except what the commands print."));
16300 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16301 Specify breakpoint number N to break only if COND is true.\n\
16302 Usage is `condition N COND', where N is an integer and COND is an\n\
16303 expression to be evaluated whenever breakpoint N is reached."));
16304 set_cmd_completer (c
, condition_completer
);
16306 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16307 Set a temporary breakpoint.\n\
16308 Like \"break\" except the breakpoint is only temporary,\n\
16309 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16310 by using \"enable delete\" on the breakpoint number.\n\
16312 BREAK_ARGS_HELP ("tbreak")));
16313 set_cmd_completer (c
, location_completer
);
16315 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16316 Set a hardware assisted breakpoint.\n\
16317 Like \"break\" except the breakpoint requires hardware support,\n\
16318 some target hardware may not have this support.\n\
16320 BREAK_ARGS_HELP ("hbreak")));
16321 set_cmd_completer (c
, location_completer
);
16323 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16324 Set a temporary hardware assisted breakpoint.\n\
16325 Like \"hbreak\" except the breakpoint is only temporary,\n\
16326 so it will be deleted when hit.\n\
16328 BREAK_ARGS_HELP ("thbreak")));
16329 set_cmd_completer (c
, location_completer
);
16331 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16332 Enable some breakpoints.\n\
16333 Give breakpoint numbers (separated by spaces) as arguments.\n\
16334 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16335 This is used to cancel the effect of the \"disable\" command.\n\
16336 With a subcommand you can enable temporarily."),
16337 &enablelist
, "enable ", 1, &cmdlist
);
16339 add_com ("ab", class_breakpoint
, enable_command
, _("\
16340 Enable some breakpoints.\n\
16341 Give breakpoint numbers (separated by spaces) as arguments.\n\
16342 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16343 This is used to cancel the effect of the \"disable\" command.\n\
16344 With a subcommand you can enable temporarily."));
16346 add_com_alias ("en", "enable", class_breakpoint
, 1);
16348 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16349 Enable some breakpoints.\n\
16350 Give breakpoint numbers (separated by spaces) as arguments.\n\
16351 This is used to cancel the effect of the \"disable\" command.\n\
16352 May be abbreviated to simply \"enable\".\n"),
16353 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16355 add_cmd ("once", no_class
, enable_once_command
, _("\
16356 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16357 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16360 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16361 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16362 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16365 add_cmd ("count", no_class
, enable_count_command
, _("\
16366 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16367 If a breakpoint is hit while enabled in this fashion,\n\
16368 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16371 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16372 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16373 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16376 add_cmd ("once", no_class
, enable_once_command
, _("\
16377 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16378 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16381 add_cmd ("count", no_class
, enable_count_command
, _("\
16382 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16383 If a breakpoint is hit while enabled in this fashion,\n\
16384 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16387 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16388 Disable some breakpoints.\n\
16389 Arguments are breakpoint numbers with spaces in between.\n\
16390 To disable all breakpoints, give no argument.\n\
16391 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16392 &disablelist
, "disable ", 1, &cmdlist
);
16393 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16394 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16396 add_com ("sb", class_breakpoint
, disable_command
, _("\
16397 Disable some breakpoints.\n\
16398 Arguments are breakpoint numbers with spaces in between.\n\
16399 To disable all breakpoints, give no argument.\n\
16400 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16402 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16403 Disable some breakpoints.\n\
16404 Arguments are breakpoint numbers with spaces in between.\n\
16405 To disable all breakpoints, give no argument.\n\
16406 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16407 This command may be abbreviated \"disable\"."),
16410 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16411 Delete some breakpoints or auto-display expressions.\n\
16412 Arguments are breakpoint numbers with spaces in between.\n\
16413 To delete all breakpoints, give no argument.\n\
16415 Also a prefix command for deletion of other GDB objects.\n\
16416 The \"unset\" command is also an alias for \"delete\"."),
16417 &deletelist
, "delete ", 1, &cmdlist
);
16418 add_com_alias ("d", "delete", class_breakpoint
, 1);
16419 add_com_alias ("del", "delete", class_breakpoint
, 1);
16421 add_com ("db", class_breakpoint
, delete_command
, _("\
16422 Delete some breakpoints.\n\
16423 Arguments are breakpoint numbers with spaces in between.\n\
16424 To delete all breakpoints, give no argument.\n"));
16426 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16427 Delete some breakpoints or auto-display expressions.\n\
16428 Arguments are breakpoint numbers with spaces in between.\n\
16429 To delete all breakpoints, give no argument.\n\
16430 This command may be abbreviated \"delete\"."),
16433 add_com ("clear", class_breakpoint
, clear_command
, _("\
16434 Clear breakpoint at specified line or function.\n\
16435 Argument may be line number, function name, or \"*\" and an address.\n\
16436 If line number is specified, all breakpoints in that line are cleared.\n\
16437 If function is specified, breakpoints at beginning of function are cleared.\n\
16438 If an address is specified, breakpoints at that address are cleared.\n\
16440 With no argument, clears all breakpoints in the line that the selected frame\n\
16441 is executing in.\n\
16443 See also the \"delete\" command which clears breakpoints by number."));
16444 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16446 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16447 Set breakpoint at specified line or function.\n"
16448 BREAK_ARGS_HELP ("break")));
16449 set_cmd_completer (c
, location_completer
);
16451 add_com_alias ("b", "break", class_run
, 1);
16452 add_com_alias ("br", "break", class_run
, 1);
16453 add_com_alias ("bre", "break", class_run
, 1);
16454 add_com_alias ("brea", "break", class_run
, 1);
16457 add_com_alias ("ba", "break", class_breakpoint
, 1);
16461 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16462 Break in function/address or break at a line in the current file."),
16463 &stoplist
, "stop ", 1, &cmdlist
);
16464 add_cmd ("in", class_breakpoint
, stopin_command
,
16465 _("Break in function or address."), &stoplist
);
16466 add_cmd ("at", class_breakpoint
, stopat_command
,
16467 _("Break at a line in the current file."), &stoplist
);
16468 add_com ("status", class_info
, breakpoints_info
, _("\
16469 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16470 The \"Type\" column indicates one of:\n\
16471 \tbreakpoint - normal breakpoint\n\
16472 \twatchpoint - watchpoint\n\
16473 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16474 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16475 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16476 address and file/line number respectively.\n\
16478 Convenience variable \"$_\" and default examine address for \"x\"\n\
16479 are set to the address of the last breakpoint listed unless the command\n\
16480 is prefixed with \"server \".\n\n\
16481 Convenience variable \"$bpnum\" contains the number of the last\n\
16482 breakpoint set."));
16485 add_info ("breakpoints", breakpoints_info
, _("\
16486 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16487 The \"Type\" column indicates one of:\n\
16488 \tbreakpoint - normal breakpoint\n\
16489 \twatchpoint - watchpoint\n\
16490 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16491 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16492 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16493 address and file/line number respectively.\n\
16495 Convenience variable \"$_\" and default examine address for \"x\"\n\
16496 are set to the address of the last breakpoint listed unless the command\n\
16497 is prefixed with \"server \".\n\n\
16498 Convenience variable \"$bpnum\" contains the number of the last\n\
16499 breakpoint set."));
16501 add_info_alias ("b", "breakpoints", 1);
16504 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16505 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16506 The \"Type\" column indicates one of:\n\
16507 \tbreakpoint - normal breakpoint\n\
16508 \twatchpoint - watchpoint\n\
16509 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16510 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16511 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16512 address and file/line number respectively.\n\
16514 Convenience variable \"$_\" and default examine address for \"x\"\n\
16515 are set to the address of the last breakpoint listed unless the command\n\
16516 is prefixed with \"server \".\n\n\
16517 Convenience variable \"$bpnum\" contains the number of the last\n\
16518 breakpoint set."));
16520 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16521 Status of all breakpoints, or breakpoint number NUMBER.\n\
16522 The \"Type\" column indicates one of:\n\
16523 \tbreakpoint - normal breakpoint\n\
16524 \twatchpoint - watchpoint\n\
16525 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16526 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16527 \tuntil - internal breakpoint used by the \"until\" command\n\
16528 \tfinish - internal breakpoint used by the \"finish\" command\n\
16529 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16530 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16531 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16532 address and file/line number respectively.\n\
16534 Convenience variable \"$_\" and default examine address for \"x\"\n\
16535 are set to the address of the last breakpoint listed unless the command\n\
16536 is prefixed with \"server \".\n\n\
16537 Convenience variable \"$bpnum\" contains the number of the last\n\
16539 &maintenanceinfolist
);
16541 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16542 Set catchpoints to catch events."),
16543 &catch_cmdlist
, "catch ",
16544 0/*allow-unknown*/, &cmdlist
);
16546 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16547 Set temporary catchpoints to catch events."),
16548 &tcatch_cmdlist
, "tcatch ",
16549 0/*allow-unknown*/, &cmdlist
);
16551 add_catch_command ("fork", _("Catch calls to fork."),
16552 catch_fork_command_1
,
16554 (void *) (uintptr_t) catch_fork_permanent
,
16555 (void *) (uintptr_t) catch_fork_temporary
);
16556 add_catch_command ("vfork", _("Catch calls to vfork."),
16557 catch_fork_command_1
,
16559 (void *) (uintptr_t) catch_vfork_permanent
,
16560 (void *) (uintptr_t) catch_vfork_temporary
);
16561 add_catch_command ("exec", _("Catch calls to exec."),
16562 catch_exec_command_1
,
16566 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16567 Usage: catch load [REGEX]\n\
16568 If REGEX is given, only stop for libraries matching the regular expression."),
16569 catch_load_command_1
,
16573 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16574 Usage: catch unload [REGEX]\n\
16575 If REGEX is given, only stop for libraries matching the regular expression."),
16576 catch_unload_command_1
,
16580 add_catch_command ("syscall", _("\
16581 Catch system calls by their names and/or numbers.\n\
16582 Arguments say which system calls to catch. If no arguments\n\
16583 are given, every system call will be caught.\n\
16584 Arguments, if given, should be one or more system call names\n\
16585 (if your system supports that), or system call numbers."),
16586 catch_syscall_command_1
,
16587 catch_syscall_completer
,
16591 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16592 Set a watchpoint for an expression.\n\
16593 Usage: watch [-l|-location] EXPRESSION\n\
16594 A watchpoint stops execution of your program whenever the value of\n\
16595 an expression changes.\n\
16596 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16597 the memory to which it refers."));
16598 set_cmd_completer (c
, expression_completer
);
16600 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16601 Set a read watchpoint for an expression.\n\
16602 Usage: rwatch [-l|-location] EXPRESSION\n\
16603 A watchpoint stops execution of your program whenever the value of\n\
16604 an expression is read.\n\
16605 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16606 the memory to which it refers."));
16607 set_cmd_completer (c
, expression_completer
);
16609 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16610 Set a watchpoint for an expression.\n\
16611 Usage: awatch [-l|-location] EXPRESSION\n\
16612 A watchpoint stops execution of your program whenever the value of\n\
16613 an expression is either read or written.\n\
16614 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16615 the memory to which it refers."));
16616 set_cmd_completer (c
, expression_completer
);
16618 add_info ("watchpoints", watchpoints_info
, _("\
16619 Status of specified watchpoints (all watchpoints if no argument)."));
16621 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16622 respond to changes - contrary to the description. */
16623 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16624 &can_use_hw_watchpoints
, _("\
16625 Set debugger's willingness to use watchpoint hardware."), _("\
16626 Show debugger's willingness to use watchpoint hardware."), _("\
16627 If zero, gdb will not use hardware for new watchpoints, even if\n\
16628 such is available. (However, any hardware watchpoints that were\n\
16629 created before setting this to nonzero, will continue to use watchpoint\n\
16632 show_can_use_hw_watchpoints
,
16633 &setlist
, &showlist
);
16635 can_use_hw_watchpoints
= 1;
16637 /* Tracepoint manipulation commands. */
16639 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16640 Set a tracepoint at specified line or function.\n\
16642 BREAK_ARGS_HELP ("trace") "\n\
16643 Do \"help tracepoints\" for info on other tracepoint commands."));
16644 set_cmd_completer (c
, location_completer
);
16646 add_com_alias ("tp", "trace", class_alias
, 0);
16647 add_com_alias ("tr", "trace", class_alias
, 1);
16648 add_com_alias ("tra", "trace", class_alias
, 1);
16649 add_com_alias ("trac", "trace", class_alias
, 1);
16651 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16652 Set a fast tracepoint at specified line or function.\n\
16654 BREAK_ARGS_HELP ("ftrace") "\n\
16655 Do \"help tracepoints\" for info on other tracepoint commands."));
16656 set_cmd_completer (c
, location_completer
);
16658 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16659 Set a static tracepoint at specified line, function or marker.\n\
16661 strace [LOCATION] [if CONDITION]\n\
16662 LOCATION may be a line number, function name, \"*\" and an address,\n\
16663 or -m MARKER_ID.\n\
16664 If a line number is specified, probe the marker at start of code\n\
16665 for that line. If a function is specified, probe the marker at start\n\
16666 of code for that function. If an address is specified, probe the marker\n\
16667 at that exact address. If a marker id is specified, probe the marker\n\
16668 with that name. With no LOCATION, uses current execution address of\n\
16669 the selected stack frame.\n\
16670 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16671 This collects arbitrary user data passed in the probe point call to the\n\
16672 tracing library. You can inspect it when analyzing the trace buffer,\n\
16673 by printing the $_sdata variable like any other convenience variable.\n\
16675 CONDITION is a boolean expression.\n\
16677 Multiple tracepoints at one place are permitted, and useful if their\n\
16678 conditions are different.\n\
16680 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16681 Do \"help tracepoints\" for info on other tracepoint commands."));
16682 set_cmd_completer (c
, location_completer
);
16684 add_info ("tracepoints", tracepoints_info
, _("\
16685 Status of specified tracepoints (all tracepoints if no argument).\n\
16686 Convenience variable \"$tpnum\" contains the number of the\n\
16687 last tracepoint set."));
16689 add_info_alias ("tp", "tracepoints", 1);
16691 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16692 Delete specified tracepoints.\n\
16693 Arguments are tracepoint numbers, separated by spaces.\n\
16694 No argument means delete all tracepoints."),
16696 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16698 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16699 Disable specified tracepoints.\n\
16700 Arguments are tracepoint numbers, separated by spaces.\n\
16701 No argument means disable all tracepoints."),
16703 deprecate_cmd (c
, "disable");
16705 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16706 Enable specified tracepoints.\n\
16707 Arguments are tracepoint numbers, separated by spaces.\n\
16708 No argument means enable all tracepoints."),
16710 deprecate_cmd (c
, "enable");
16712 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16713 Set the passcount for a tracepoint.\n\
16714 The trace will end when the tracepoint has been passed 'count' times.\n\
16715 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16716 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16718 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16719 _("Save breakpoint definitions as a script."),
16720 &save_cmdlist
, "save ",
16721 0/*allow-unknown*/, &cmdlist
);
16723 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16724 Save current breakpoint definitions as a script.\n\
16725 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16726 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16727 session to restore them."),
16729 set_cmd_completer (c
, filename_completer
);
16731 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16732 Save current tracepoint definitions as a script.\n\
16733 Use the 'source' command in another debug session to restore them."),
16735 set_cmd_completer (c
, filename_completer
);
16737 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16738 deprecate_cmd (c
, "save tracepoints");
16740 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16741 Breakpoint specific settings\n\
16742 Configure various breakpoint-specific variables such as\n\
16743 pending breakpoint behavior"),
16744 &breakpoint_set_cmdlist
, "set breakpoint ",
16745 0/*allow-unknown*/, &setlist
);
16746 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16747 Breakpoint specific settings\n\
16748 Configure various breakpoint-specific variables such as\n\
16749 pending breakpoint behavior"),
16750 &breakpoint_show_cmdlist
, "show breakpoint ",
16751 0/*allow-unknown*/, &showlist
);
16753 add_setshow_auto_boolean_cmd ("pending", no_class
,
16754 &pending_break_support
, _("\
16755 Set debugger's behavior regarding pending breakpoints."), _("\
16756 Show debugger's behavior regarding pending breakpoints."), _("\
16757 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16758 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16759 an error. If auto, an unrecognized breakpoint location results in a\n\
16760 user-query to see if a pending breakpoint should be created."),
16762 show_pending_break_support
,
16763 &breakpoint_set_cmdlist
,
16764 &breakpoint_show_cmdlist
);
16766 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16768 add_setshow_boolean_cmd ("auto-hw", no_class
,
16769 &automatic_hardware_breakpoints
, _("\
16770 Set automatic usage of hardware breakpoints."), _("\
16771 Show automatic usage of hardware breakpoints."), _("\
16772 If set, the debugger will automatically use hardware breakpoints for\n\
16773 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16774 a warning will be emitted for such breakpoints."),
16776 show_automatic_hardware_breakpoints
,
16777 &breakpoint_set_cmdlist
,
16778 &breakpoint_show_cmdlist
);
16780 add_setshow_boolean_cmd ("always-inserted", class_support
,
16781 &always_inserted_mode
, _("\
16782 Set mode for inserting breakpoints."), _("\
16783 Show mode for inserting breakpoints."), _("\
16784 When this mode is on, breakpoints are inserted immediately as soon as\n\
16785 they're created, kept inserted even when execution stops, and removed\n\
16786 only when the user deletes them. When this mode is off (the default),\n\
16787 breakpoints are inserted only when execution continues, and removed\n\
16788 when execution stops."),
16790 &show_always_inserted_mode
,
16791 &breakpoint_set_cmdlist
,
16792 &breakpoint_show_cmdlist
);
16794 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16795 condition_evaluation_enums
,
16796 &condition_evaluation_mode_1
, _("\
16797 Set mode of breakpoint condition evaluation."), _("\
16798 Show mode of breakpoint condition evaluation."), _("\
16799 When this is set to \"host\", breakpoint conditions will be\n\
16800 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16801 breakpoint conditions will be downloaded to the target (if the target\n\
16802 supports such feature) and conditions will be evaluated on the target's side.\n\
16803 If this is set to \"auto\" (default), this will be automatically set to\n\
16804 \"target\" if it supports condition evaluation, otherwise it will\n\
16805 be set to \"gdb\""),
16806 &set_condition_evaluation_mode
,
16807 &show_condition_evaluation_mode
,
16808 &breakpoint_set_cmdlist
,
16809 &breakpoint_show_cmdlist
);
16811 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16812 Set a breakpoint for an address range.\n\
16813 break-range START-LOCATION, END-LOCATION\n\
16814 where START-LOCATION and END-LOCATION can be one of the following:\n\
16815 LINENUM, for that line in the current file,\n\
16816 FILE:LINENUM, for that line in that file,\n\
16817 +OFFSET, for that number of lines after the current line\n\
16818 or the start of the range\n\
16819 FUNCTION, for the first line in that function,\n\
16820 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16821 *ADDRESS, for the instruction at that address.\n\
16823 The breakpoint will stop execution of the inferior whenever it executes\n\
16824 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16825 range (including START-LOCATION and END-LOCATION)."));
16827 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16828 Set a dynamic printf at specified line or function.\n\
16829 dprintf location,format string,arg1,arg2,...\n\
16830 location may be a line number, function name, or \"*\" and an address.\n\
16831 If a line number is specified, break at start of code for that line.\n\
16832 If a function is specified, break at start of code for that function."));
16833 set_cmd_completer (c
, location_completer
);
16835 add_setshow_enum_cmd ("dprintf-style", class_support
,
16836 dprintf_style_enums
, &dprintf_style
, _("\
16837 Set the style of usage for dynamic printf."), _("\
16838 Show the style of usage for dynamic printf."), _("\
16839 This setting chooses how GDB will do a dynamic printf.\n\
16840 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16841 console, as with the \"printf\" command.\n\
16842 If the value is \"call\", the print is done by calling a function in your\n\
16843 program; by default printf(), but you can choose a different function or\n\
16844 output stream by setting dprintf-function and dprintf-channel."),
16845 update_dprintf_commands
, NULL
,
16846 &setlist
, &showlist
);
16848 dprintf_function
= xstrdup ("printf");
16849 add_setshow_string_cmd ("dprintf-function", class_support
,
16850 &dprintf_function
, _("\
16851 Set the function to use for dynamic printf"), _("\
16852 Show the function to use for dynamic printf"), NULL
,
16853 update_dprintf_commands
, NULL
,
16854 &setlist
, &showlist
);
16856 dprintf_channel
= xstrdup ("");
16857 add_setshow_string_cmd ("dprintf-channel", class_support
,
16858 &dprintf_channel
, _("\
16859 Set the channel to use for dynamic printf"), _("\
16860 Show the channel to use for dynamic printf"), NULL
,
16861 update_dprintf_commands
, NULL
,
16862 &setlist
, &showlist
);
16864 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16865 &disconnected_dprintf
, _("\
16866 Set whether dprintf continues after GDB disconnects."), _("\
16867 Show whether dprintf continues after GDB disconnects."), _("\
16868 Use this to let dprintf commands continue to hit and produce output\n\
16869 even if GDB disconnects or detaches from the target."),
16872 &setlist
, &showlist
);
16874 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16875 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16876 (target agent only) This is useful for formatted output in user-defined commands."));
16878 automatic_hardware_breakpoints
= 1;
16880 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16881 observer_attach_thread_exit (remove_threaded_breakpoints
);