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"
40 #include "gdb-demangle.h"
41 #include "filenames.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
62 #include "xml-syscall.h"
63 #include "parser-defs.h"
64 #include "gdb_regex.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
71 #include "dummy-frame.h"
75 /* readline include files */
76 #include "readline/readline.h"
77 #include "readline/history.h"
79 /* readline defines this. */
82 #include "mi/mi-common.h"
83 #include "extension.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint
*);
115 static void create_sals_from_address_default (char **,
116 struct linespec_result
*,
120 static void create_breakpoints_sal_default (struct gdbarch
*,
121 struct linespec_result
*,
122 char *, char *, enum bptype
,
123 enum bpdisp
, int, int,
125 const struct breakpoint_ops
*,
126 int, int, int, unsigned);
128 static void decode_linespec_default (struct breakpoint
*, char **,
129 struct symtabs_and_lines
*);
131 static void clear_command (char *, int);
133 static void catch_command (char *, int);
135 static int can_use_hardware_watchpoint (struct value
*);
137 static void break_command_1 (char *, int, int);
139 static void mention (struct breakpoint
*);
141 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
143 const struct breakpoint_ops
*);
144 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
145 const struct symtab_and_line
*);
147 /* This function is used in gdbtk sources and thus can not be made
149 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
150 struct symtab_and_line
,
152 const struct breakpoint_ops
*);
154 static struct breakpoint
*
155 momentary_breakpoint_from_master (struct breakpoint
*orig
,
157 const struct breakpoint_ops
*ops
);
159 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
161 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
165 static void describe_other_breakpoints (struct gdbarch
*,
166 struct program_space
*, CORE_ADDR
,
167 struct obj_section
*, int);
169 static int watchpoint_locations_match (struct bp_location
*loc1
,
170 struct bp_location
*loc2
);
172 static int breakpoint_location_address_match (struct bp_location
*bl
,
173 struct address_space
*aspace
,
176 static void breakpoints_info (char *, int);
178 static void watchpoints_info (char *, int);
180 static int breakpoint_1 (char *, int,
181 int (*) (const struct breakpoint
*));
183 static int breakpoint_cond_eval (void *);
185 static void cleanup_executing_breakpoints (void *);
187 static void commands_command (char *, int);
189 static void condition_command (char *, int);
198 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
199 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
201 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
203 static int watchpoint_check (void *);
205 static void maintenance_info_breakpoints (char *, int);
207 static int hw_breakpoint_used_count (void);
209 static int hw_watchpoint_use_count (struct breakpoint
*);
211 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
213 int *other_type_used
);
215 static void hbreak_command (char *, int);
217 static void thbreak_command (char *, int);
219 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
222 static void stop_command (char *arg
, int from_tty
);
224 static void stopin_command (char *arg
, int from_tty
);
226 static void stopat_command (char *arg
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void detach_single_step_breakpoints (void);
232 static void free_bp_location (struct bp_location
*loc
);
233 static void incref_bp_location (struct bp_location
*loc
);
234 static void decref_bp_location (struct bp_location
**loc
);
236 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
238 static void update_global_location_list (int);
240 static void update_global_location_list_nothrow (int);
242 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
244 static void insert_breakpoint_locations (void);
246 static int syscall_catchpoint_p (struct breakpoint
*b
);
248 static void tracepoints_info (char *, int);
250 static void delete_trace_command (char *, int);
252 static void enable_trace_command (char *, int);
254 static void disable_trace_command (char *, int);
256 static void trace_pass_command (char *, int);
258 static void set_tracepoint_count (int num
);
260 static int is_masked_watchpoint (const struct breakpoint
*b
);
262 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
264 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
267 static int strace_marker_p (struct breakpoint
*b
);
269 /* The abstract base class all breakpoint_ops structures inherit
271 struct breakpoint_ops base_breakpoint_ops
;
273 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
274 that are implemented on top of software or hardware breakpoints
275 (user breakpoints, internal and momentary breakpoints, etc.). */
276 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
278 /* Internal breakpoints class type. */
279 static struct breakpoint_ops internal_breakpoint_ops
;
281 /* Momentary breakpoints class type. */
282 static struct breakpoint_ops momentary_breakpoint_ops
;
284 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
285 static struct breakpoint_ops longjmp_breakpoint_ops
;
287 /* The breakpoint_ops structure to be used in regular user created
289 struct breakpoint_ops bkpt_breakpoint_ops
;
291 /* Breakpoints set on probes. */
292 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
294 /* Dynamic printf class type. */
295 struct breakpoint_ops dprintf_breakpoint_ops
;
297 /* One (or perhaps two) breakpoints used for software single
300 static void *single_step_breakpoints
[2];
301 static struct gdbarch
*single_step_gdbarch
[2];
303 /* The style in which to perform a dynamic printf. This is a user
304 option because different output options have different tradeoffs;
305 if GDB does the printing, there is better error handling if there
306 is a problem with any of the arguments, but using an inferior
307 function lets you have special-purpose printers and sending of
308 output to the same place as compiled-in print functions. */
310 static const char dprintf_style_gdb
[] = "gdb";
311 static const char dprintf_style_call
[] = "call";
312 static const char dprintf_style_agent
[] = "agent";
313 static const char *const dprintf_style_enums
[] = {
319 static const char *dprintf_style
= dprintf_style_gdb
;
321 /* The function to use for dynamic printf if the preferred style is to
322 call into the inferior. The value is simply a string that is
323 copied into the command, so it can be anything that GDB can
324 evaluate to a callable address, not necessarily a function name. */
326 static char *dprintf_function
= "";
328 /* The channel to use for dynamic printf if the preferred style is to
329 call into the inferior; if a nonempty string, it will be passed to
330 the call as the first argument, with the format string as the
331 second. As with the dprintf function, this can be anything that
332 GDB knows how to evaluate, so in addition to common choices like
333 "stderr", this could be an app-specific expression like
334 "mystreams[curlogger]". */
336 static char *dprintf_channel
= "";
338 /* True if dprintf commands should continue to operate even if GDB
340 static int disconnected_dprintf
= 1;
342 /* A reference-counted struct command_line. This lets multiple
343 breakpoints share a single command list. */
344 struct counted_command_line
346 /* The reference count. */
349 /* The command list. */
350 struct command_line
*commands
;
353 struct command_line
*
354 breakpoint_commands (struct breakpoint
*b
)
356 return b
->commands
? b
->commands
->commands
: NULL
;
359 /* Flag indicating that a command has proceeded the inferior past the
360 current breakpoint. */
362 static int breakpoint_proceeded
;
365 bpdisp_text (enum bpdisp disp
)
367 /* NOTE: the following values are a part of MI protocol and
368 represent values of 'disp' field returned when inferior stops at
370 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
372 return bpdisps
[(int) disp
];
375 /* Prototypes for exported functions. */
376 /* If FALSE, gdb will not use hardware support for watchpoints, even
377 if such is available. */
378 static int can_use_hw_watchpoints
;
381 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
382 struct cmd_list_element
*c
,
385 fprintf_filtered (file
,
386 _("Debugger's willingness to use "
387 "watchpoint hardware is %s.\n"),
391 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
392 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
393 for unrecognized breakpoint locations.
394 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
395 static enum auto_boolean pending_break_support
;
397 show_pending_break_support (struct ui_file
*file
, int from_tty
,
398 struct cmd_list_element
*c
,
401 fprintf_filtered (file
,
402 _("Debugger's behavior regarding "
403 "pending breakpoints is %s.\n"),
407 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
408 set with "break" but falling in read-only memory.
409 If 0, gdb will warn about such breakpoints, but won't automatically
410 use hardware breakpoints. */
411 static int automatic_hardware_breakpoints
;
413 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
414 struct cmd_list_element
*c
,
417 fprintf_filtered (file
,
418 _("Automatic usage of hardware breakpoints is %s.\n"),
422 /* If on, gdb will keep breakpoints inserted even as inferior is
423 stopped, and immediately insert any new breakpoints. If off, gdb
424 will insert breakpoints into inferior only when resuming it, and
425 will remove breakpoints upon stop. If auto, GDB will behave as ON
426 if in non-stop mode, and as OFF if all-stop mode.*/
428 static enum auto_boolean always_inserted_mode
= AUTO_BOOLEAN_AUTO
;
431 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
432 struct cmd_list_element
*c
, const char *value
)
434 if (always_inserted_mode
== AUTO_BOOLEAN_AUTO
)
435 fprintf_filtered (file
,
436 _("Always inserted breakpoint "
437 "mode is %s (currently %s).\n"),
439 breakpoints_always_inserted_mode () ? "on" : "off");
441 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
446 breakpoints_always_inserted_mode (void)
448 return (always_inserted_mode
== AUTO_BOOLEAN_TRUE
449 || (always_inserted_mode
== AUTO_BOOLEAN_AUTO
&& non_stop
));
452 static const char condition_evaluation_both
[] = "host or target";
454 /* Modes for breakpoint condition evaluation. */
455 static const char condition_evaluation_auto
[] = "auto";
456 static const char condition_evaluation_host
[] = "host";
457 static const char condition_evaluation_target
[] = "target";
458 static const char *const condition_evaluation_enums
[] = {
459 condition_evaluation_auto
,
460 condition_evaluation_host
,
461 condition_evaluation_target
,
465 /* Global that holds the current mode for breakpoint condition evaluation. */
466 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
468 /* Global that we use to display information to the user (gets its value from
469 condition_evaluation_mode_1. */
470 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
472 /* Translate a condition evaluation mode MODE into either "host"
473 or "target". This is used mostly to translate from "auto" to the
474 real setting that is being used. It returns the translated
478 translate_condition_evaluation_mode (const char *mode
)
480 if (mode
== condition_evaluation_auto
)
482 if (target_supports_evaluation_of_breakpoint_conditions ())
483 return condition_evaluation_target
;
485 return condition_evaluation_host
;
491 /* Discovers what condition_evaluation_auto translates to. */
494 breakpoint_condition_evaluation_mode (void)
496 return translate_condition_evaluation_mode (condition_evaluation_mode
);
499 /* Return true if GDB should evaluate breakpoint conditions or false
503 gdb_evaluates_breakpoint_condition_p (void)
505 const char *mode
= breakpoint_condition_evaluation_mode ();
507 return (mode
== condition_evaluation_host
);
510 void _initialize_breakpoint (void);
512 /* Are we executing breakpoint commands? */
513 static int executing_breakpoint_commands
;
515 /* Are overlay event breakpoints enabled? */
516 static int overlay_events_enabled
;
518 /* See description in breakpoint.h. */
519 int target_exact_watchpoints
= 0;
521 /* Walk the following statement or block through all breakpoints.
522 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
523 current breakpoint. */
525 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
527 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
528 for (B = breakpoint_chain; \
529 B ? (TMP=B->next, 1): 0; \
532 /* Similar iterator for the low-level breakpoints. SAFE variant is
533 not provided so update_global_location_list must not be called
534 while executing the block of ALL_BP_LOCATIONS. */
536 #define ALL_BP_LOCATIONS(B,BP_TMP) \
537 for (BP_TMP = bp_location; \
538 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
541 /* Iterates through locations with address ADDRESS for the currently selected
542 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
543 to where the loop should start from.
544 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
545 appropriate location to start with. */
547 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
548 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
549 BP_LOCP_TMP = BP_LOCP_START; \
551 && (BP_LOCP_TMP < bp_location + bp_location_count \
552 && (*BP_LOCP_TMP)->address == ADDRESS); \
555 /* Iterator for tracepoints only. */
557 #define ALL_TRACEPOINTS(B) \
558 for (B = breakpoint_chain; B; B = B->next) \
559 if (is_tracepoint (B))
561 /* Chains of all breakpoints defined. */
563 struct breakpoint
*breakpoint_chain
;
565 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
567 static struct bp_location
**bp_location
;
569 /* Number of elements of BP_LOCATION. */
571 static unsigned bp_location_count
;
573 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
574 ADDRESS for the current elements of BP_LOCATION which get a valid
575 result from bp_location_has_shadow. You can use it for roughly
576 limiting the subrange of BP_LOCATION to scan for shadow bytes for
577 an address you need to read. */
579 static CORE_ADDR bp_location_placed_address_before_address_max
;
581 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
582 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
583 BP_LOCATION which get a valid result from bp_location_has_shadow.
584 You can use it for roughly limiting the subrange of BP_LOCATION to
585 scan for shadow bytes for an address you need to read. */
587 static CORE_ADDR bp_location_shadow_len_after_address_max
;
589 /* The locations that no longer correspond to any breakpoint, unlinked
590 from bp_location array, but for which a hit may still be reported
592 VEC(bp_location_p
) *moribund_locations
= NULL
;
594 /* Number of last breakpoint made. */
596 static int breakpoint_count
;
598 /* The value of `breakpoint_count' before the last command that
599 created breakpoints. If the last (break-like) command created more
600 than one breakpoint, then the difference between BREAKPOINT_COUNT
601 and PREV_BREAKPOINT_COUNT is more than one. */
602 static int prev_breakpoint_count
;
604 /* Number of last tracepoint made. */
606 static int tracepoint_count
;
608 static struct cmd_list_element
*breakpoint_set_cmdlist
;
609 static struct cmd_list_element
*breakpoint_show_cmdlist
;
610 struct cmd_list_element
*save_cmdlist
;
612 /* Return whether a breakpoint is an active enabled breakpoint. */
614 breakpoint_enabled (struct breakpoint
*b
)
616 return (b
->enable_state
== bp_enabled
);
619 /* Set breakpoint count to NUM. */
622 set_breakpoint_count (int num
)
624 prev_breakpoint_count
= breakpoint_count
;
625 breakpoint_count
= num
;
626 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
629 /* Used by `start_rbreak_breakpoints' below, to record the current
630 breakpoint count before "rbreak" creates any breakpoint. */
631 static int rbreak_start_breakpoint_count
;
633 /* Called at the start an "rbreak" command to record the first
637 start_rbreak_breakpoints (void)
639 rbreak_start_breakpoint_count
= breakpoint_count
;
642 /* Called at the end of an "rbreak" command to record the last
646 end_rbreak_breakpoints (void)
648 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
651 /* Used in run_command to zero the hit count when a new run starts. */
654 clear_breakpoint_hit_counts (void)
656 struct breakpoint
*b
;
662 /* Allocate a new counted_command_line with reference count of 1.
663 The new structure owns COMMANDS. */
665 static struct counted_command_line
*
666 alloc_counted_command_line (struct command_line
*commands
)
668 struct counted_command_line
*result
669 = xmalloc (sizeof (struct counted_command_line
));
672 result
->commands
= commands
;
676 /* Increment reference count. This does nothing if CMD is NULL. */
679 incref_counted_command_line (struct counted_command_line
*cmd
)
685 /* Decrement reference count. If the reference count reaches 0,
686 destroy the counted_command_line. Sets *CMDP to NULL. This does
687 nothing if *CMDP is NULL. */
690 decref_counted_command_line (struct counted_command_line
**cmdp
)
694 if (--(*cmdp
)->refc
== 0)
696 free_command_lines (&(*cmdp
)->commands
);
703 /* A cleanup function that calls decref_counted_command_line. */
706 do_cleanup_counted_command_line (void *arg
)
708 decref_counted_command_line (arg
);
711 /* Create a cleanup that calls decref_counted_command_line on the
714 static struct cleanup
*
715 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
717 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
721 /* Return the breakpoint with the specified number, or NULL
722 if the number does not refer to an existing breakpoint. */
725 get_breakpoint (int num
)
727 struct breakpoint
*b
;
730 if (b
->number
== num
)
738 /* Mark locations as "conditions have changed" in case the target supports
739 evaluating conditions on its side. */
742 mark_breakpoint_modified (struct breakpoint
*b
)
744 struct bp_location
*loc
;
746 /* This is only meaningful if the target is
747 evaluating conditions and if the user has
748 opted for condition evaluation on the target's
750 if (gdb_evaluates_breakpoint_condition_p ()
751 || !target_supports_evaluation_of_breakpoint_conditions ())
754 if (!is_breakpoint (b
))
757 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
758 loc
->condition_changed
= condition_modified
;
761 /* Mark location as "conditions have changed" in case the target supports
762 evaluating conditions on its side. */
765 mark_breakpoint_location_modified (struct bp_location
*loc
)
767 /* This is only meaningful if the target is
768 evaluating conditions and if the user has
769 opted for condition evaluation on the target's
771 if (gdb_evaluates_breakpoint_condition_p ()
772 || !target_supports_evaluation_of_breakpoint_conditions ())
776 if (!is_breakpoint (loc
->owner
))
779 loc
->condition_changed
= condition_modified
;
782 /* Sets the condition-evaluation mode using the static global
783 condition_evaluation_mode. */
786 set_condition_evaluation_mode (char *args
, int from_tty
,
787 struct cmd_list_element
*c
)
789 const char *old_mode
, *new_mode
;
791 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
792 && !target_supports_evaluation_of_breakpoint_conditions ())
794 condition_evaluation_mode_1
= condition_evaluation_mode
;
795 warning (_("Target does not support breakpoint condition evaluation.\n"
796 "Using host evaluation mode instead."));
800 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
801 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
803 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
804 settings was "auto". */
805 condition_evaluation_mode
= condition_evaluation_mode_1
;
807 /* Only update the mode if the user picked a different one. */
808 if (new_mode
!= old_mode
)
810 struct bp_location
*loc
, **loc_tmp
;
811 /* If the user switched to a different evaluation mode, we
812 need to synch the changes with the target as follows:
814 "host" -> "target": Send all (valid) conditions to the target.
815 "target" -> "host": Remove all the conditions from the target.
818 if (new_mode
== condition_evaluation_target
)
820 /* Mark everything modified and synch conditions with the
822 ALL_BP_LOCATIONS (loc
, loc_tmp
)
823 mark_breakpoint_location_modified (loc
);
827 /* Manually mark non-duplicate locations to synch conditions
828 with the target. We do this to remove all the conditions the
829 target knows about. */
830 ALL_BP_LOCATIONS (loc
, loc_tmp
)
831 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
832 loc
->needs_update
= 1;
836 update_global_location_list (1);
842 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
843 what "auto" is translating to. */
846 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
847 struct cmd_list_element
*c
, const char *value
)
849 if (condition_evaluation_mode
== condition_evaluation_auto
)
850 fprintf_filtered (file
,
851 _("Breakpoint condition evaluation "
852 "mode is %s (currently %s).\n"),
854 breakpoint_condition_evaluation_mode ());
856 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
860 /* A comparison function for bp_location AP and BP that is used by
861 bsearch. This comparison function only cares about addresses, unlike
862 the more general bp_location_compare function. */
865 bp_location_compare_addrs (const void *ap
, const void *bp
)
867 struct bp_location
*a
= *(void **) ap
;
868 struct bp_location
*b
= *(void **) bp
;
870 if (a
->address
== b
->address
)
873 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
876 /* Helper function to skip all bp_locations with addresses
877 less than ADDRESS. It returns the first bp_location that
878 is greater than or equal to ADDRESS. If none is found, just
881 static struct bp_location
**
882 get_first_locp_gte_addr (CORE_ADDR address
)
884 struct bp_location dummy_loc
;
885 struct bp_location
*dummy_locp
= &dummy_loc
;
886 struct bp_location
**locp_found
= NULL
;
888 /* Initialize the dummy location's address field. */
889 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
890 dummy_loc
.address
= address
;
892 /* Find a close match to the first location at ADDRESS. */
893 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
894 sizeof (struct bp_location
**),
895 bp_location_compare_addrs
);
897 /* Nothing was found, nothing left to do. */
898 if (locp_found
== NULL
)
901 /* We may have found a location that is at ADDRESS but is not the first in the
902 location's list. Go backwards (if possible) and locate the first one. */
903 while ((locp_found
- 1) >= bp_location
904 && (*(locp_found
- 1))->address
== address
)
911 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
914 xfree (b
->cond_string
);
915 b
->cond_string
= NULL
;
917 if (is_watchpoint (b
))
919 struct watchpoint
*w
= (struct watchpoint
*) b
;
926 struct bp_location
*loc
;
928 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
933 /* No need to free the condition agent expression
934 bytecode (if we have one). We will handle this
935 when we go through update_global_location_list. */
942 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
946 const char *arg
= exp
;
948 /* I don't know if it matters whether this is the string the user
949 typed in or the decompiled expression. */
950 b
->cond_string
= xstrdup (arg
);
951 b
->condition_not_parsed
= 0;
953 if (is_watchpoint (b
))
955 struct watchpoint
*w
= (struct watchpoint
*) b
;
957 innermost_block
= NULL
;
959 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
961 error (_("Junk at end of expression"));
962 w
->cond_exp_valid_block
= innermost_block
;
966 struct bp_location
*loc
;
968 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
972 parse_exp_1 (&arg
, loc
->address
,
973 block_for_pc (loc
->address
), 0);
975 error (_("Junk at end of expression"));
979 mark_breakpoint_modified (b
);
981 observer_notify_breakpoint_modified (b
);
984 /* Completion for the "condition" command. */
986 static VEC (char_ptr
) *
987 condition_completer (struct cmd_list_element
*cmd
,
988 const char *text
, const char *word
)
992 text
= skip_spaces_const (text
);
993 space
= skip_to_space_const (text
);
997 struct breakpoint
*b
;
998 VEC (char_ptr
) *result
= NULL
;
1002 /* We don't support completion of history indices. */
1003 if (isdigit (text
[1]))
1005 return complete_internalvar (&text
[1]);
1008 /* We're completing the breakpoint number. */
1009 len
= strlen (text
);
1015 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1017 if (strncmp (number
, text
, len
) == 0)
1018 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1024 /* We're completing the expression part. */
1025 text
= skip_spaces_const (space
);
1026 return expression_completer (cmd
, text
, word
);
1029 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1032 condition_command (char *arg
, int from_tty
)
1034 struct breakpoint
*b
;
1039 error_no_arg (_("breakpoint number"));
1042 bnum
= get_number (&p
);
1044 error (_("Bad breakpoint argument: '%s'"), arg
);
1047 if (b
->number
== bnum
)
1049 /* Check if this breakpoint has a "stop" method implemented in an
1050 extension language. This method and conditions entered into GDB
1051 from the CLI are mutually exclusive. */
1052 const struct extension_language_defn
*extlang
1053 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1055 if (extlang
!= NULL
)
1057 error (_("Only one stop condition allowed. There is currently"
1058 " a %s stop condition defined for this breakpoint."),
1059 ext_lang_capitalized_name (extlang
));
1061 set_breakpoint_condition (b
, p
, from_tty
);
1063 if (is_breakpoint (b
))
1064 update_global_location_list (1);
1069 error (_("No breakpoint number %d."), bnum
);
1072 /* Check that COMMAND do not contain commands that are suitable
1073 only for tracepoints and not suitable for ordinary breakpoints.
1074 Throw if any such commands is found. */
1077 check_no_tracepoint_commands (struct command_line
*commands
)
1079 struct command_line
*c
;
1081 for (c
= commands
; c
; c
= c
->next
)
1085 if (c
->control_type
== while_stepping_control
)
1086 error (_("The 'while-stepping' command can "
1087 "only be used for tracepoints"));
1089 for (i
= 0; i
< c
->body_count
; ++i
)
1090 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1092 /* Not that command parsing removes leading whitespace and comment
1093 lines and also empty lines. So, we only need to check for
1094 command directly. */
1095 if (strstr (c
->line
, "collect ") == c
->line
)
1096 error (_("The 'collect' command can only be used for tracepoints"));
1098 if (strstr (c
->line
, "teval ") == c
->line
)
1099 error (_("The 'teval' command can only be used for tracepoints"));
1103 /* Encapsulate tests for different types of tracepoints. */
1106 is_tracepoint_type (enum bptype type
)
1108 return (type
== bp_tracepoint
1109 || type
== bp_fast_tracepoint
1110 || type
== bp_static_tracepoint
);
1114 is_tracepoint (const struct breakpoint
*b
)
1116 return is_tracepoint_type (b
->type
);
1119 /* A helper function that validates that COMMANDS are valid for a
1120 breakpoint. This function will throw an exception if a problem is
1124 validate_commands_for_breakpoint (struct breakpoint
*b
,
1125 struct command_line
*commands
)
1127 if (is_tracepoint (b
))
1129 struct tracepoint
*t
= (struct tracepoint
*) b
;
1130 struct command_line
*c
;
1131 struct command_line
*while_stepping
= 0;
1133 /* Reset the while-stepping step count. The previous commands
1134 might have included a while-stepping action, while the new
1138 /* We need to verify that each top-level element of commands is
1139 valid for tracepoints, that there's at most one
1140 while-stepping element, and that the while-stepping's body
1141 has valid tracing commands excluding nested while-stepping.
1142 We also need to validate the tracepoint action line in the
1143 context of the tracepoint --- validate_actionline actually
1144 has side effects, like setting the tracepoint's
1145 while-stepping STEP_COUNT, in addition to checking if the
1146 collect/teval actions parse and make sense in the
1147 tracepoint's context. */
1148 for (c
= commands
; c
; c
= c
->next
)
1150 if (c
->control_type
== while_stepping_control
)
1152 if (b
->type
== bp_fast_tracepoint
)
1153 error (_("The 'while-stepping' command "
1154 "cannot be used for fast tracepoint"));
1155 else if (b
->type
== bp_static_tracepoint
)
1156 error (_("The 'while-stepping' command "
1157 "cannot be used for static tracepoint"));
1160 error (_("The 'while-stepping' command "
1161 "can be used only once"));
1166 validate_actionline (c
->line
, b
);
1170 struct command_line
*c2
;
1172 gdb_assert (while_stepping
->body_count
== 1);
1173 c2
= while_stepping
->body_list
[0];
1174 for (; c2
; c2
= c2
->next
)
1176 if (c2
->control_type
== while_stepping_control
)
1177 error (_("The 'while-stepping' command cannot be nested"));
1183 check_no_tracepoint_commands (commands
);
1187 /* Return a vector of all the static tracepoints set at ADDR. The
1188 caller is responsible for releasing the vector. */
1191 static_tracepoints_here (CORE_ADDR addr
)
1193 struct breakpoint
*b
;
1194 VEC(breakpoint_p
) *found
= 0;
1195 struct bp_location
*loc
;
1198 if (b
->type
== bp_static_tracepoint
)
1200 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1201 if (loc
->address
== addr
)
1202 VEC_safe_push(breakpoint_p
, found
, b
);
1208 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1209 validate that only allowed commands are included. */
1212 breakpoint_set_commands (struct breakpoint
*b
,
1213 struct command_line
*commands
)
1215 validate_commands_for_breakpoint (b
, commands
);
1217 decref_counted_command_line (&b
->commands
);
1218 b
->commands
= alloc_counted_command_line (commands
);
1219 observer_notify_breakpoint_modified (b
);
1222 /* Set the internal `silent' flag on the breakpoint. Note that this
1223 is not the same as the "silent" that may appear in the breakpoint's
1227 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1229 int old_silent
= b
->silent
;
1232 if (old_silent
!= silent
)
1233 observer_notify_breakpoint_modified (b
);
1236 /* Set the thread for this breakpoint. If THREAD is -1, make the
1237 breakpoint work for any thread. */
1240 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1242 int old_thread
= b
->thread
;
1245 if (old_thread
!= thread
)
1246 observer_notify_breakpoint_modified (b
);
1249 /* Set the task for this breakpoint. If TASK is 0, make the
1250 breakpoint work for any task. */
1253 breakpoint_set_task (struct breakpoint
*b
, int task
)
1255 int old_task
= b
->task
;
1258 if (old_task
!= task
)
1259 observer_notify_breakpoint_modified (b
);
1263 check_tracepoint_command (char *line
, void *closure
)
1265 struct breakpoint
*b
= closure
;
1267 validate_actionline (line
, b
);
1270 /* A structure used to pass information through
1271 map_breakpoint_numbers. */
1273 struct commands_info
1275 /* True if the command was typed at a tty. */
1278 /* The breakpoint range spec. */
1281 /* Non-NULL if the body of the commands are being read from this
1282 already-parsed command. */
1283 struct command_line
*control
;
1285 /* The command lines read from the user, or NULL if they have not
1287 struct counted_command_line
*cmd
;
1290 /* A callback for map_breakpoint_numbers that sets the commands for
1291 commands_command. */
1294 do_map_commands_command (struct breakpoint
*b
, void *data
)
1296 struct commands_info
*info
= data
;
1298 if (info
->cmd
== NULL
)
1300 struct command_line
*l
;
1302 if (info
->control
!= NULL
)
1303 l
= copy_command_lines (info
->control
->body_list
[0]);
1306 struct cleanup
*old_chain
;
1309 str
= xstrprintf (_("Type commands for breakpoint(s) "
1310 "%s, one per line."),
1313 old_chain
= make_cleanup (xfree
, str
);
1315 l
= read_command_lines (str
,
1318 ? check_tracepoint_command
: 0),
1321 do_cleanups (old_chain
);
1324 info
->cmd
= alloc_counted_command_line (l
);
1327 /* If a breakpoint was on the list more than once, we don't need to
1329 if (b
->commands
!= info
->cmd
)
1331 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1332 incref_counted_command_line (info
->cmd
);
1333 decref_counted_command_line (&b
->commands
);
1334 b
->commands
= info
->cmd
;
1335 observer_notify_breakpoint_modified (b
);
1340 commands_command_1 (char *arg
, int from_tty
,
1341 struct command_line
*control
)
1343 struct cleanup
*cleanups
;
1344 struct commands_info info
;
1346 info
.from_tty
= from_tty
;
1347 info
.control
= control
;
1349 /* If we read command lines from the user, then `info' will hold an
1350 extra reference to the commands that we must clean up. */
1351 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1353 if (arg
== NULL
|| !*arg
)
1355 if (breakpoint_count
- prev_breakpoint_count
> 1)
1356 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1358 else if (breakpoint_count
> 0)
1359 arg
= xstrprintf ("%d", breakpoint_count
);
1362 /* So that we don't try to free the incoming non-NULL
1363 argument in the cleanup below. Mapping breakpoint
1364 numbers will fail in this case. */
1369 /* The command loop has some static state, so we need to preserve
1371 arg
= xstrdup (arg
);
1374 make_cleanup (xfree
, arg
);
1378 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1380 if (info
.cmd
== NULL
)
1381 error (_("No breakpoints specified."));
1383 do_cleanups (cleanups
);
1387 commands_command (char *arg
, int from_tty
)
1389 commands_command_1 (arg
, from_tty
, NULL
);
1392 /* Like commands_command, but instead of reading the commands from
1393 input stream, takes them from an already parsed command structure.
1395 This is used by cli-script.c to DTRT with breakpoint commands
1396 that are part of if and while bodies. */
1397 enum command_control_type
1398 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1400 commands_command_1 (arg
, 0, cmd
);
1401 return simple_control
;
1404 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1407 bp_location_has_shadow (struct bp_location
*bl
)
1409 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1413 if (bl
->target_info
.shadow_len
== 0)
1414 /* BL isn't valid, or doesn't shadow memory. */
1419 /* Update BUF, which is LEN bytes read from the target address
1420 MEMADDR, by replacing a memory breakpoint with its shadowed
1423 If READBUF is not NULL, this buffer must not overlap with the of
1424 the breakpoint location's shadow_contents buffer. Otherwise, a
1425 failed assertion internal error will be raised. */
1428 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1429 const gdb_byte
*writebuf_org
,
1430 ULONGEST memaddr
, LONGEST len
,
1431 struct bp_target_info
*target_info
,
1432 struct gdbarch
*gdbarch
)
1434 /* Now do full processing of the found relevant range of elements. */
1435 CORE_ADDR bp_addr
= 0;
1439 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1440 current_program_space
->aspace
, 0))
1442 /* The breakpoint is inserted in a different address space. */
1446 /* Addresses and length of the part of the breakpoint that
1448 bp_addr
= target_info
->placed_address
;
1449 bp_size
= target_info
->shadow_len
;
1451 if (bp_addr
+ bp_size
<= memaddr
)
1453 /* The breakpoint is entirely before the chunk of memory we are
1458 if (bp_addr
>= memaddr
+ len
)
1460 /* The breakpoint is entirely after the chunk of memory we are
1465 /* Offset within shadow_contents. */
1466 if (bp_addr
< memaddr
)
1468 /* Only copy the second part of the breakpoint. */
1469 bp_size
-= memaddr
- bp_addr
;
1470 bptoffset
= memaddr
- bp_addr
;
1474 if (bp_addr
+ bp_size
> memaddr
+ len
)
1476 /* Only copy the first part of the breakpoint. */
1477 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1480 if (readbuf
!= NULL
)
1482 /* Verify that the readbuf buffer does not overlap with the
1483 shadow_contents buffer. */
1484 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1485 || readbuf
>= (target_info
->shadow_contents
1486 + target_info
->shadow_len
));
1488 /* Update the read buffer with this inserted breakpoint's
1490 memcpy (readbuf
+ bp_addr
- memaddr
,
1491 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1495 const unsigned char *bp
;
1496 CORE_ADDR placed_address
= target_info
->placed_address
;
1497 int placed_size
= target_info
->placed_size
;
1499 /* Update the shadow with what we want to write to memory. */
1500 memcpy (target_info
->shadow_contents
+ bptoffset
,
1501 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1503 /* Determine appropriate breakpoint contents and size for this
1505 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1507 /* Update the final write buffer with this inserted
1508 breakpoint's INSN. */
1509 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1513 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1514 by replacing any memory breakpoints with their shadowed contents.
1516 If READBUF is not NULL, this buffer must not overlap with any of
1517 the breakpoint location's shadow_contents buffers. Otherwise,
1518 a failed assertion internal error will be raised.
1520 The range of shadowed area by each bp_location is:
1521 bl->address - bp_location_placed_address_before_address_max
1522 up to bl->address + bp_location_shadow_len_after_address_max
1523 The range we were requested to resolve shadows for is:
1524 memaddr ... memaddr + len
1525 Thus the safe cutoff boundaries for performance optimization are
1526 memaddr + len <= (bl->address
1527 - bp_location_placed_address_before_address_max)
1529 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1532 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1533 const gdb_byte
*writebuf_org
,
1534 ULONGEST memaddr
, LONGEST len
)
1536 /* Left boundary, right boundary and median element of our binary
1538 unsigned bc_l
, bc_r
, bc
;
1541 /* Find BC_L which is a leftmost element which may affect BUF
1542 content. It is safe to report lower value but a failure to
1543 report higher one. */
1546 bc_r
= bp_location_count
;
1547 while (bc_l
+ 1 < bc_r
)
1549 struct bp_location
*bl
;
1551 bc
= (bc_l
+ bc_r
) / 2;
1552 bl
= bp_location
[bc
];
1554 /* Check first BL->ADDRESS will not overflow due to the added
1555 constant. Then advance the left boundary only if we are sure
1556 the BC element can in no way affect the BUF content (MEMADDR
1557 to MEMADDR + LEN range).
1559 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1560 offset so that we cannot miss a breakpoint with its shadow
1561 range tail still reaching MEMADDR. */
1563 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1565 && (bl
->address
+ bp_location_shadow_len_after_address_max
1572 /* Due to the binary search above, we need to make sure we pick the
1573 first location that's at BC_L's address. E.g., if there are
1574 multiple locations at the same address, BC_L may end up pointing
1575 at a duplicate location, and miss the "master"/"inserted"
1576 location. Say, given locations L1, L2 and L3 at addresses A and
1579 L1@A, L2@A, L3@B, ...
1581 BC_L could end up pointing at location L2, while the "master"
1582 location could be L1. Since the `loc->inserted' flag is only set
1583 on "master" locations, we'd forget to restore the shadow of L1
1586 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1589 /* Now do full processing of the found relevant range of elements. */
1591 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1593 struct bp_location
*bl
= bp_location
[bc
];
1594 CORE_ADDR bp_addr
= 0;
1598 /* bp_location array has BL->OWNER always non-NULL. */
1599 if (bl
->owner
->type
== bp_none
)
1600 warning (_("reading through apparently deleted breakpoint #%d?"),
1603 /* Performance optimization: any further element can no longer affect BUF
1606 if (bl
->address
>= bp_location_placed_address_before_address_max
1607 && memaddr
+ len
<= (bl
->address
1608 - bp_location_placed_address_before_address_max
))
1611 if (!bp_location_has_shadow (bl
))
1614 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1615 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1618 /* Now process single-step breakpoints. These are not found in the
1619 bp_location array. */
1620 for (i
= 0; i
< 2; i
++)
1622 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
1626 struct gdbarch
*gdbarch
= single_step_gdbarch
[i
];
1628 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1629 memaddr
, len
, bp_tgt
, gdbarch
);
1636 /* Return true if BPT is either a software breakpoint or a hardware
1640 is_breakpoint (const struct breakpoint
*bpt
)
1642 return (bpt
->type
== bp_breakpoint
1643 || bpt
->type
== bp_hardware_breakpoint
1644 || bpt
->type
== bp_dprintf
);
1647 /* Return true if BPT is of any hardware watchpoint kind. */
1650 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1652 return (bpt
->type
== bp_hardware_watchpoint
1653 || bpt
->type
== bp_read_watchpoint
1654 || bpt
->type
== bp_access_watchpoint
);
1657 /* Return true if BPT is of any watchpoint kind, hardware or
1661 is_watchpoint (const struct breakpoint
*bpt
)
1663 return (is_hardware_watchpoint (bpt
)
1664 || bpt
->type
== bp_watchpoint
);
1667 /* Returns true if the current thread and its running state are safe
1668 to evaluate or update watchpoint B. Watchpoints on local
1669 expressions need to be evaluated in the context of the thread that
1670 was current when the watchpoint was created, and, that thread needs
1671 to be stopped to be able to select the correct frame context.
1672 Watchpoints on global expressions can be evaluated on any thread,
1673 and in any state. It is presently left to the target allowing
1674 memory accesses when threads are running. */
1677 watchpoint_in_thread_scope (struct watchpoint
*b
)
1679 return (b
->base
.pspace
== current_program_space
1680 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1681 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1682 && !is_executing (inferior_ptid
))));
1685 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1686 associated bp_watchpoint_scope breakpoint. */
1689 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1691 struct breakpoint
*b
= &w
->base
;
1693 if (b
->related_breakpoint
!= b
)
1695 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1696 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1697 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1698 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1699 b
->related_breakpoint
= b
;
1701 b
->disposition
= disp_del_at_next_stop
;
1704 /* Assuming that B is a watchpoint:
1705 - Reparse watchpoint expression, if REPARSE is non-zero
1706 - Evaluate expression and store the result in B->val
1707 - Evaluate the condition if there is one, and store the result
1709 - Update the list of values that must be watched in B->loc.
1711 If the watchpoint disposition is disp_del_at_next_stop, then do
1712 nothing. If this is local watchpoint that is out of scope, delete
1715 Even with `set breakpoint always-inserted on' the watchpoints are
1716 removed + inserted on each stop here. Normal breakpoints must
1717 never be removed because they might be missed by a running thread
1718 when debugging in non-stop mode. On the other hand, hardware
1719 watchpoints (is_hardware_watchpoint; processed here) are specific
1720 to each LWP since they are stored in each LWP's hardware debug
1721 registers. Therefore, such LWP must be stopped first in order to
1722 be able to modify its hardware watchpoints.
1724 Hardware watchpoints must be reset exactly once after being
1725 presented to the user. It cannot be done sooner, because it would
1726 reset the data used to present the watchpoint hit to the user. And
1727 it must not be done later because it could display the same single
1728 watchpoint hit during multiple GDB stops. Note that the latter is
1729 relevant only to the hardware watchpoint types bp_read_watchpoint
1730 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1731 not user-visible - its hit is suppressed if the memory content has
1734 The following constraints influence the location where we can reset
1735 hardware watchpoints:
1737 * target_stopped_by_watchpoint and target_stopped_data_address are
1738 called several times when GDB stops.
1741 * Multiple hardware watchpoints can be hit at the same time,
1742 causing GDB to stop. GDB only presents one hardware watchpoint
1743 hit at a time as the reason for stopping, and all the other hits
1744 are presented later, one after the other, each time the user
1745 requests the execution to be resumed. Execution is not resumed
1746 for the threads still having pending hit event stored in
1747 LWP_INFO->STATUS. While the watchpoint is already removed from
1748 the inferior on the first stop the thread hit event is kept being
1749 reported from its cached value by linux_nat_stopped_data_address
1750 until the real thread resume happens after the watchpoint gets
1751 presented and thus its LWP_INFO->STATUS gets reset.
1753 Therefore the hardware watchpoint hit can get safely reset on the
1754 watchpoint removal from inferior. */
1757 update_watchpoint (struct watchpoint
*b
, int reparse
)
1759 int within_current_scope
;
1760 struct frame_id saved_frame_id
;
1763 /* If this is a local watchpoint, we only want to check if the
1764 watchpoint frame is in scope if the current thread is the thread
1765 that was used to create the watchpoint. */
1766 if (!watchpoint_in_thread_scope (b
))
1769 if (b
->base
.disposition
== disp_del_at_next_stop
)
1774 /* Determine if the watchpoint is within scope. */
1775 if (b
->exp_valid_block
== NULL
)
1776 within_current_scope
= 1;
1779 struct frame_info
*fi
= get_current_frame ();
1780 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1781 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1783 /* If we're in a function epilogue, unwinding may not work
1784 properly, so do not attempt to recreate locations at this
1785 point. See similar comments in watchpoint_check. */
1786 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1789 /* Save the current frame's ID so we can restore it after
1790 evaluating the watchpoint expression on its own frame. */
1791 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1792 took a frame parameter, so that we didn't have to change the
1795 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1797 fi
= frame_find_by_id (b
->watchpoint_frame
);
1798 within_current_scope
= (fi
!= NULL
);
1799 if (within_current_scope
)
1803 /* We don't free locations. They are stored in the bp_location array
1804 and update_global_location_list will eventually delete them and
1805 remove breakpoints if needed. */
1808 if (within_current_scope
&& reparse
)
1817 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1818 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1819 /* If the meaning of expression itself changed, the old value is
1820 no longer relevant. We don't want to report a watchpoint hit
1821 to the user when the old value and the new value may actually
1822 be completely different objects. */
1823 value_free (b
->val
);
1827 /* Note that unlike with breakpoints, the watchpoint's condition
1828 expression is stored in the breakpoint object, not in the
1829 locations (re)created below. */
1830 if (b
->base
.cond_string
!= NULL
)
1832 if (b
->cond_exp
!= NULL
)
1834 xfree (b
->cond_exp
);
1838 s
= b
->base
.cond_string
;
1839 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1843 /* If we failed to parse the expression, for example because
1844 it refers to a global variable in a not-yet-loaded shared library,
1845 don't try to insert watchpoint. We don't automatically delete
1846 such watchpoint, though, since failure to parse expression
1847 is different from out-of-scope watchpoint. */
1848 if (!target_has_execution
)
1850 /* Without execution, memory can't change. No use to try and
1851 set watchpoint locations. The watchpoint will be reset when
1852 the target gains execution, through breakpoint_re_set. */
1853 if (!can_use_hw_watchpoints
)
1855 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1856 b
->base
.type
= bp_watchpoint
;
1858 error (_("Can't set read/access watchpoint when "
1859 "hardware watchpoints are disabled."));
1862 else if (within_current_scope
&& b
->exp
)
1865 struct value
*val_chain
, *v
, *result
, *next
;
1866 struct program_space
*frame_pspace
;
1868 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1870 /* Avoid setting b->val if it's already set. The meaning of
1871 b->val is 'the last value' user saw, and we should update
1872 it only if we reported that last value to user. As it
1873 happens, the code that reports it updates b->val directly.
1874 We don't keep track of the memory value for masked
1876 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1882 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1884 /* Look at each value on the value chain. */
1885 for (v
= val_chain
; v
; v
= value_next (v
))
1887 /* If it's a memory location, and GDB actually needed
1888 its contents to evaluate the expression, then we
1889 must watch it. If the first value returned is
1890 still lazy, that means an error occurred reading it;
1891 watch it anyway in case it becomes readable. */
1892 if (VALUE_LVAL (v
) == lval_memory
1893 && (v
== val_chain
|| ! value_lazy (v
)))
1895 struct type
*vtype
= check_typedef (value_type (v
));
1897 /* We only watch structs and arrays if user asked
1898 for it explicitly, never if they just happen to
1899 appear in the middle of some value chain. */
1901 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1902 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1906 struct bp_location
*loc
, **tmp
;
1908 addr
= value_address (v
);
1910 if (b
->base
.type
== bp_read_watchpoint
)
1912 else if (b
->base
.type
== bp_access_watchpoint
)
1915 loc
= allocate_bp_location (&b
->base
);
1916 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1919 loc
->gdbarch
= get_type_arch (value_type (v
));
1921 loc
->pspace
= frame_pspace
;
1922 loc
->address
= addr
;
1923 loc
->length
= TYPE_LENGTH (value_type (v
));
1924 loc
->watchpoint_type
= type
;
1929 /* Change the type of breakpoint between hardware assisted or
1930 an ordinary watchpoint depending on the hardware support
1931 and free hardware slots. REPARSE is set when the inferior
1936 enum bp_loc_type loc_type
;
1937 struct bp_location
*bl
;
1939 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1943 int i
, target_resources_ok
, other_type_used
;
1946 /* Use an exact watchpoint when there's only one memory region to be
1947 watched, and only one debug register is needed to watch it. */
1948 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1950 /* We need to determine how many resources are already
1951 used for all other hardware watchpoints plus this one
1952 to see if we still have enough resources to also fit
1953 this watchpoint in as well. */
1955 /* If this is a software watchpoint, we try to turn it
1956 to a hardware one -- count resources as if B was of
1957 hardware watchpoint type. */
1958 type
= b
->base
.type
;
1959 if (type
== bp_watchpoint
)
1960 type
= bp_hardware_watchpoint
;
1962 /* This watchpoint may or may not have been placed on
1963 the list yet at this point (it won't be in the list
1964 if we're trying to create it for the first time,
1965 through watch_command), so always account for it
1968 /* Count resources used by all watchpoints except B. */
1969 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1971 /* Add in the resources needed for B. */
1972 i
+= hw_watchpoint_use_count (&b
->base
);
1975 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1976 if (target_resources_ok
<= 0)
1978 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1980 if (target_resources_ok
== 0 && !sw_mode
)
1981 error (_("Target does not support this type of "
1982 "hardware watchpoint."));
1983 else if (target_resources_ok
< 0 && !sw_mode
)
1984 error (_("There are not enough available hardware "
1985 "resources for this watchpoint."));
1987 /* Downgrade to software watchpoint. */
1988 b
->base
.type
= bp_watchpoint
;
1992 /* If this was a software watchpoint, we've just
1993 found we have enough resources to turn it to a
1994 hardware watchpoint. Otherwise, this is a
1996 b
->base
.type
= type
;
1999 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2001 if (!can_use_hw_watchpoints
)
2002 error (_("Can't set read/access watchpoint when "
2003 "hardware watchpoints are disabled."));
2005 error (_("Expression cannot be implemented with "
2006 "read/access watchpoint."));
2009 b
->base
.type
= bp_watchpoint
;
2011 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2012 : bp_loc_hardware_watchpoint
);
2013 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2014 bl
->loc_type
= loc_type
;
2017 for (v
= val_chain
; v
; v
= next
)
2019 next
= value_next (v
);
2024 /* If a software watchpoint is not watching any memory, then the
2025 above left it without any location set up. But,
2026 bpstat_stop_status requires a location to be able to report
2027 stops, so make sure there's at least a dummy one. */
2028 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2030 struct breakpoint
*base
= &b
->base
;
2031 base
->loc
= allocate_bp_location (base
);
2032 base
->loc
->pspace
= frame_pspace
;
2033 base
->loc
->address
= -1;
2034 base
->loc
->length
= -1;
2035 base
->loc
->watchpoint_type
= -1;
2038 else if (!within_current_scope
)
2040 printf_filtered (_("\
2041 Watchpoint %d deleted because the program has left the block\n\
2042 in which its expression is valid.\n"),
2044 watchpoint_del_at_next_stop (b
);
2047 /* Restore the selected frame. */
2049 select_frame (frame_find_by_id (saved_frame_id
));
2053 /* Returns 1 iff breakpoint location should be
2054 inserted in the inferior. We don't differentiate the type of BL's owner
2055 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2056 breakpoint_ops is not defined, because in insert_bp_location,
2057 tracepoint's insert_location will not be called. */
2059 should_be_inserted (struct bp_location
*bl
)
2061 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2064 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2067 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2070 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2073 /* This is set for example, when we're attached to the parent of a
2074 vfork, and have detached from the child. The child is running
2075 free, and we expect it to do an exec or exit, at which point the
2076 OS makes the parent schedulable again (and the target reports
2077 that the vfork is done). Until the child is done with the shared
2078 memory region, do not insert breakpoints in the parent, otherwise
2079 the child could still trip on the parent's breakpoints. Since
2080 the parent is blocked anyway, it won't miss any breakpoint. */
2081 if (bl
->pspace
->breakpoints_not_allowed
)
2084 /* Don't insert a breakpoint if we're trying to step past its
2086 if ((bl
->loc_type
== bp_loc_software_breakpoint
2087 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2088 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2095 /* Same as should_be_inserted but does the check assuming
2096 that the location is not duplicated. */
2099 unduplicated_should_be_inserted (struct bp_location
*bl
)
2102 const int save_duplicate
= bl
->duplicate
;
2105 result
= should_be_inserted (bl
);
2106 bl
->duplicate
= save_duplicate
;
2110 /* Parses a conditional described by an expression COND into an
2111 agent expression bytecode suitable for evaluation
2112 by the bytecode interpreter. Return NULL if there was
2113 any error during parsing. */
2115 static struct agent_expr
*
2116 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2118 struct agent_expr
*aexpr
= NULL
;
2119 volatile struct gdb_exception ex
;
2124 /* We don't want to stop processing, so catch any errors
2125 that may show up. */
2126 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2128 aexpr
= gen_eval_for_expr (scope
, cond
);
2133 /* If we got here, it means the condition could not be parsed to a valid
2134 bytecode expression and thus can't be evaluated on the target's side.
2135 It's no use iterating through the conditions. */
2139 /* We have a valid agent expression. */
2143 /* Based on location BL, create a list of breakpoint conditions to be
2144 passed on to the target. If we have duplicated locations with different
2145 conditions, we will add such conditions to the list. The idea is that the
2146 target will evaluate the list of conditions and will only notify GDB when
2147 one of them is true. */
2150 build_target_condition_list (struct bp_location
*bl
)
2152 struct bp_location
**locp
= NULL
, **loc2p
;
2153 int null_condition_or_parse_error
= 0;
2154 int modified
= bl
->needs_update
;
2155 struct bp_location
*loc
;
2157 /* Release conditions left over from a previous insert. */
2158 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2160 /* This is only meaningful if the target is
2161 evaluating conditions and if the user has
2162 opted for condition evaluation on the target's
2164 if (gdb_evaluates_breakpoint_condition_p ()
2165 || !target_supports_evaluation_of_breakpoint_conditions ())
2168 /* Do a first pass to check for locations with no assigned
2169 conditions or conditions that fail to parse to a valid agent expression
2170 bytecode. If any of these happen, then it's no use to send conditions
2171 to the target since this location will always trigger and generate a
2172 response back to GDB. */
2173 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2176 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2180 struct agent_expr
*aexpr
;
2182 /* Re-parse the conditions since something changed. In that
2183 case we already freed the condition bytecodes (see
2184 force_breakpoint_reinsertion). We just
2185 need to parse the condition to bytecodes again. */
2186 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2187 loc
->cond_bytecode
= aexpr
;
2189 /* Check if we managed to parse the conditional expression
2190 correctly. If not, we will not send this condition
2196 /* If we have a NULL bytecode expression, it means something
2197 went wrong or we have a null condition expression. */
2198 if (!loc
->cond_bytecode
)
2200 null_condition_or_parse_error
= 1;
2206 /* If any of these happened, it means we will have to evaluate the conditions
2207 for the location's address on gdb's side. It is no use keeping bytecodes
2208 for all the other duplicate locations, thus we free all of them here.
2210 This is so we have a finer control over which locations' conditions are
2211 being evaluated by GDB or the remote stub. */
2212 if (null_condition_or_parse_error
)
2214 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2217 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2219 /* Only go as far as the first NULL bytecode is
2221 if (!loc
->cond_bytecode
)
2224 free_agent_expr (loc
->cond_bytecode
);
2225 loc
->cond_bytecode
= NULL
;
2230 /* No NULL conditions or failed bytecode generation. Build a condition list
2231 for this location's address. */
2232 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2236 && is_breakpoint (loc
->owner
)
2237 && loc
->pspace
->num
== bl
->pspace
->num
2238 && loc
->owner
->enable_state
== bp_enabled
2240 /* Add the condition to the vector. This will be used later to send the
2241 conditions to the target. */
2242 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2243 loc
->cond_bytecode
);
2249 /* Parses a command described by string CMD into an agent expression
2250 bytecode suitable for evaluation by the bytecode interpreter.
2251 Return NULL if there was any error during parsing. */
2253 static struct agent_expr
*
2254 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2256 struct cleanup
*old_cleanups
= 0;
2257 struct expression
*expr
, **argvec
;
2258 struct agent_expr
*aexpr
= NULL
;
2259 volatile struct gdb_exception ex
;
2260 const char *cmdrest
;
2261 const char *format_start
, *format_end
;
2262 struct format_piece
*fpieces
;
2264 struct gdbarch
*gdbarch
= get_current_arch ();
2271 if (*cmdrest
== ',')
2273 cmdrest
= skip_spaces_const (cmdrest
);
2275 if (*cmdrest
++ != '"')
2276 error (_("No format string following the location"));
2278 format_start
= cmdrest
;
2280 fpieces
= parse_format_string (&cmdrest
);
2282 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2284 format_end
= cmdrest
;
2286 if (*cmdrest
++ != '"')
2287 error (_("Bad format string, non-terminated '\"'."));
2289 cmdrest
= skip_spaces_const (cmdrest
);
2291 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2292 error (_("Invalid argument syntax"));
2294 if (*cmdrest
== ',')
2296 cmdrest
= skip_spaces_const (cmdrest
);
2298 /* For each argument, make an expression. */
2300 argvec
= (struct expression
**) alloca (strlen (cmd
)
2301 * sizeof (struct expression
*));
2304 while (*cmdrest
!= '\0')
2309 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2310 argvec
[nargs
++] = expr
;
2312 if (*cmdrest
== ',')
2316 /* We don't want to stop processing, so catch any errors
2317 that may show up. */
2318 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2320 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2321 format_start
, format_end
- format_start
,
2322 fpieces
, nargs
, argvec
);
2325 do_cleanups (old_cleanups
);
2329 /* If we got here, it means the command could not be parsed to a valid
2330 bytecode expression and thus can't be evaluated on the target's side.
2331 It's no use iterating through the other commands. */
2335 /* We have a valid agent expression, return it. */
2339 /* Based on location BL, create a list of breakpoint commands to be
2340 passed on to the target. If we have duplicated locations with
2341 different commands, we will add any such to the list. */
2344 build_target_command_list (struct bp_location
*bl
)
2346 struct bp_location
**locp
= NULL
, **loc2p
;
2347 int null_command_or_parse_error
= 0;
2348 int modified
= bl
->needs_update
;
2349 struct bp_location
*loc
;
2351 /* Release commands left over from a previous insert. */
2352 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2354 /* For now, limit to agent-style dprintf breakpoints. */
2355 if (bl
->owner
->type
!= bp_dprintf
2356 || strcmp (dprintf_style
, dprintf_style_agent
) != 0)
2359 if (!target_can_run_breakpoint_commands ())
2362 /* Do a first pass to check for locations with no assigned
2363 conditions or conditions that fail to parse to a valid agent expression
2364 bytecode. If any of these happen, then it's no use to send conditions
2365 to the target since this location will always trigger and generate a
2366 response back to GDB. */
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2370 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2374 struct agent_expr
*aexpr
;
2376 /* Re-parse the commands since something changed. In that
2377 case we already freed the command bytecodes (see
2378 force_breakpoint_reinsertion). We just
2379 need to parse the command to bytecodes again. */
2380 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2381 loc
->owner
->extra_string
);
2382 loc
->cmd_bytecode
= aexpr
;
2388 /* If we have a NULL bytecode expression, it means something
2389 went wrong or we have a null command expression. */
2390 if (!loc
->cmd_bytecode
)
2392 null_command_or_parse_error
= 1;
2398 /* If anything failed, then we're not doing target-side commands,
2400 if (null_command_or_parse_error
)
2402 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2405 if (is_breakpoint (loc
->owner
)
2406 && loc
->pspace
->num
== bl
->pspace
->num
)
2408 /* Only go as far as the first NULL bytecode is
2410 if (loc
->cmd_bytecode
== NULL
)
2413 free_agent_expr (loc
->cmd_bytecode
);
2414 loc
->cmd_bytecode
= NULL
;
2419 /* No NULL commands or failed bytecode generation. Build a command list
2420 for this location's address. */
2421 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2424 if (loc
->owner
->extra_string
2425 && is_breakpoint (loc
->owner
)
2426 && loc
->pspace
->num
== bl
->pspace
->num
2427 && loc
->owner
->enable_state
== bp_enabled
2429 /* Add the command to the vector. This will be used later
2430 to send the commands to the target. */
2431 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2435 bl
->target_info
.persist
= 0;
2436 /* Maybe flag this location as persistent. */
2437 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2438 bl
->target_info
.persist
= 1;
2441 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2442 location. Any error messages are printed to TMP_ERROR_STREAM; and
2443 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2444 Returns 0 for success, 1 if the bp_location type is not supported or
2447 NOTE drow/2003-09-09: This routine could be broken down to an
2448 object-style method for each breakpoint or catchpoint type. */
2450 insert_bp_location (struct bp_location
*bl
,
2451 struct ui_file
*tmp_error_stream
,
2452 int *disabled_breaks
,
2453 int *hw_breakpoint_error
,
2454 int *hw_bp_error_explained_already
)
2456 enum errors bp_err
= GDB_NO_ERROR
;
2457 const char *bp_err_message
= NULL
;
2458 volatile struct gdb_exception e
;
2460 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2463 /* Note we don't initialize bl->target_info, as that wipes out
2464 the breakpoint location's shadow_contents if the breakpoint
2465 is still inserted at that location. This in turn breaks
2466 target_read_memory which depends on these buffers when
2467 a memory read is requested at the breakpoint location:
2468 Once the target_info has been wiped, we fail to see that
2469 we have a breakpoint inserted at that address and thus
2470 read the breakpoint instead of returning the data saved in
2471 the breakpoint location's shadow contents. */
2472 bl
->target_info
.placed_address
= bl
->address
;
2473 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2474 bl
->target_info
.length
= bl
->length
;
2476 /* When working with target-side conditions, we must pass all the conditions
2477 for the same breakpoint address down to the target since GDB will not
2478 insert those locations. With a list of breakpoint conditions, the target
2479 can decide when to stop and notify GDB. */
2481 if (is_breakpoint (bl
->owner
))
2483 build_target_condition_list (bl
);
2484 build_target_command_list (bl
);
2485 /* Reset the modification marker. */
2486 bl
->needs_update
= 0;
2489 if (bl
->loc_type
== bp_loc_software_breakpoint
2490 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2492 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2494 /* If the explicitly specified breakpoint type
2495 is not hardware breakpoint, check the memory map to see
2496 if the breakpoint address is in read only memory or not.
2498 Two important cases are:
2499 - location type is not hardware breakpoint, memory
2500 is readonly. We change the type of the location to
2501 hardware breakpoint.
2502 - location type is hardware breakpoint, memory is
2503 read-write. This means we've previously made the
2504 location hardware one, but then the memory map changed,
2507 When breakpoints are removed, remove_breakpoints will use
2508 location types we've just set here, the only possible
2509 problem is that memory map has changed during running
2510 program, but it's not going to work anyway with current
2512 struct mem_region
*mr
2513 = lookup_mem_region (bl
->target_info
.placed_address
);
2517 if (automatic_hardware_breakpoints
)
2519 enum bp_loc_type new_type
;
2521 if (mr
->attrib
.mode
!= MEM_RW
)
2522 new_type
= bp_loc_hardware_breakpoint
;
2524 new_type
= bp_loc_software_breakpoint
;
2526 if (new_type
!= bl
->loc_type
)
2528 static int said
= 0;
2530 bl
->loc_type
= new_type
;
2533 fprintf_filtered (gdb_stdout
,
2534 _("Note: automatically using "
2535 "hardware breakpoints for "
2536 "read-only addresses.\n"));
2541 else if (bl
->loc_type
== bp_loc_software_breakpoint
2542 && mr
->attrib
.mode
!= MEM_RW
)
2543 warning (_("cannot set software breakpoint "
2544 "at readonly address %s"),
2545 paddress (bl
->gdbarch
, bl
->address
));
2549 /* First check to see if we have to handle an overlay. */
2550 if (overlay_debugging
== ovly_off
2551 || bl
->section
== NULL
2552 || !(section_is_overlay (bl
->section
)))
2554 /* No overlay handling: just set the breakpoint. */
2555 TRY_CATCH (e
, RETURN_MASK_ALL
)
2559 val
= bl
->owner
->ops
->insert_location (bl
);
2561 bp_err
= GENERIC_ERROR
;
2566 bp_err_message
= e
.message
;
2571 /* This breakpoint is in an overlay section.
2572 Shall we set a breakpoint at the LMA? */
2573 if (!overlay_events_enabled
)
2575 /* Yes -- overlay event support is not active,
2576 so we must try to set a breakpoint at the LMA.
2577 This will not work for a hardware breakpoint. */
2578 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2579 warning (_("hardware breakpoint %d not supported in overlay!"),
2583 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2585 /* Set a software (trap) breakpoint at the LMA. */
2586 bl
->overlay_target_info
= bl
->target_info
;
2587 bl
->overlay_target_info
.placed_address
= addr
;
2589 /* No overlay handling: just set the breakpoint. */
2590 TRY_CATCH (e
, RETURN_MASK_ALL
)
2594 val
= target_insert_breakpoint (bl
->gdbarch
,
2595 &bl
->overlay_target_info
);
2597 bp_err
= GENERIC_ERROR
;
2602 bp_err_message
= e
.message
;
2605 if (bp_err
!= GDB_NO_ERROR
)
2606 fprintf_unfiltered (tmp_error_stream
,
2607 "Overlay breakpoint %d "
2608 "failed: in ROM?\n",
2612 /* Shall we set a breakpoint at the VMA? */
2613 if (section_is_mapped (bl
->section
))
2615 /* Yes. This overlay section is mapped into memory. */
2616 TRY_CATCH (e
, RETURN_MASK_ALL
)
2620 val
= bl
->owner
->ops
->insert_location (bl
);
2622 bp_err
= GENERIC_ERROR
;
2627 bp_err_message
= e
.message
;
2632 /* No. This breakpoint will not be inserted.
2633 No error, but do not mark the bp as 'inserted'. */
2638 if (bp_err
!= GDB_NO_ERROR
)
2640 /* Can't set the breakpoint. */
2642 /* In some cases, we might not be able to insert a
2643 breakpoint in a shared library that has already been
2644 removed, but we have not yet processed the shlib unload
2645 event. Unfortunately, some targets that implement
2646 breakpoint insertion themselves can't tell why the
2647 breakpoint insertion failed (e.g., the remote target
2648 doesn't define error codes), so we must treat generic
2649 errors as memory errors. */
2650 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2651 && bl
->loc_type
== bp_loc_software_breakpoint
2652 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2653 || userloaded_objfile_contains_address_p (bl
->pspace
,
2656 /* See also: disable_breakpoints_in_shlibs. */
2657 bl
->shlib_disabled
= 1;
2658 observer_notify_breakpoint_modified (bl
->owner
);
2659 if (!*disabled_breaks
)
2661 fprintf_unfiltered (tmp_error_stream
,
2662 "Cannot insert breakpoint %d.\n",
2664 fprintf_unfiltered (tmp_error_stream
,
2665 "Temporarily disabling shared "
2666 "library breakpoints:\n");
2668 *disabled_breaks
= 1;
2669 fprintf_unfiltered (tmp_error_stream
,
2670 "breakpoint #%d\n", bl
->owner
->number
);
2675 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2677 *hw_breakpoint_error
= 1;
2678 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2679 fprintf_unfiltered (tmp_error_stream
,
2680 "Cannot insert hardware breakpoint %d%s",
2681 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2682 if (bp_err_message
!= NULL
)
2683 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2687 if (bp_err_message
== NULL
)
2690 = memory_error_message (TARGET_XFER_E_IO
,
2691 bl
->gdbarch
, bl
->address
);
2692 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2694 fprintf_unfiltered (tmp_error_stream
,
2695 "Cannot insert breakpoint %d.\n"
2697 bl
->owner
->number
, message
);
2698 do_cleanups (old_chain
);
2702 fprintf_unfiltered (tmp_error_stream
,
2703 "Cannot insert breakpoint %d: %s\n",
2718 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2719 /* NOTE drow/2003-09-08: This state only exists for removing
2720 watchpoints. It's not clear that it's necessary... */
2721 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2725 gdb_assert (bl
->owner
->ops
!= NULL
2726 && bl
->owner
->ops
->insert_location
!= NULL
);
2728 val
= bl
->owner
->ops
->insert_location (bl
);
2730 /* If trying to set a read-watchpoint, and it turns out it's not
2731 supported, try emulating one with an access watchpoint. */
2732 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2734 struct bp_location
*loc
, **loc_temp
;
2736 /* But don't try to insert it, if there's already another
2737 hw_access location that would be considered a duplicate
2739 ALL_BP_LOCATIONS (loc
, loc_temp
)
2741 && loc
->watchpoint_type
== hw_access
2742 && watchpoint_locations_match (bl
, loc
))
2746 bl
->target_info
= loc
->target_info
;
2747 bl
->watchpoint_type
= hw_access
;
2754 bl
->watchpoint_type
= hw_access
;
2755 val
= bl
->owner
->ops
->insert_location (bl
);
2758 /* Back to the original value. */
2759 bl
->watchpoint_type
= hw_read
;
2763 bl
->inserted
= (val
== 0);
2766 else if (bl
->owner
->type
== bp_catchpoint
)
2770 gdb_assert (bl
->owner
->ops
!= NULL
2771 && bl
->owner
->ops
->insert_location
!= NULL
);
2773 val
= bl
->owner
->ops
->insert_location (bl
);
2776 bl
->owner
->enable_state
= bp_disabled
;
2780 Error inserting catchpoint %d: Your system does not support this type\n\
2781 of catchpoint."), bl
->owner
->number
);
2783 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2786 bl
->inserted
= (val
== 0);
2788 /* We've already printed an error message if there was a problem
2789 inserting this catchpoint, and we've disabled the catchpoint,
2790 so just return success. */
2797 /* This function is called when program space PSPACE is about to be
2798 deleted. It takes care of updating breakpoints to not reference
2802 breakpoint_program_space_exit (struct program_space
*pspace
)
2804 struct breakpoint
*b
, *b_temp
;
2805 struct bp_location
*loc
, **loc_temp
;
2807 /* Remove any breakpoint that was set through this program space. */
2808 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2810 if (b
->pspace
== pspace
)
2811 delete_breakpoint (b
);
2814 /* Breakpoints set through other program spaces could have locations
2815 bound to PSPACE as well. Remove those. */
2816 ALL_BP_LOCATIONS (loc
, loc_temp
)
2818 struct bp_location
*tmp
;
2820 if (loc
->pspace
== pspace
)
2822 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2823 if (loc
->owner
->loc
== loc
)
2824 loc
->owner
->loc
= loc
->next
;
2826 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2827 if (tmp
->next
== loc
)
2829 tmp
->next
= loc
->next
;
2835 /* Now update the global location list to permanently delete the
2836 removed locations above. */
2837 update_global_location_list (0);
2840 /* Make sure all breakpoints are inserted in inferior.
2841 Throws exception on any error.
2842 A breakpoint that is already inserted won't be inserted
2843 again, so calling this function twice is safe. */
2845 insert_breakpoints (void)
2847 struct breakpoint
*bpt
;
2849 ALL_BREAKPOINTS (bpt
)
2850 if (is_hardware_watchpoint (bpt
))
2852 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2854 update_watchpoint (w
, 0 /* don't reparse. */);
2857 update_global_location_list (1);
2859 /* update_global_location_list does not insert breakpoints when
2860 always_inserted_mode is not enabled. Explicitly insert them
2862 if (!breakpoints_always_inserted_mode ())
2863 insert_breakpoint_locations ();
2866 /* Invoke CALLBACK for each of bp_location. */
2869 iterate_over_bp_locations (walk_bp_location_callback callback
)
2871 struct bp_location
*loc
, **loc_tmp
;
2873 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2875 callback (loc
, NULL
);
2879 /* This is used when we need to synch breakpoint conditions between GDB and the
2880 target. It is the case with deleting and disabling of breakpoints when using
2881 always-inserted mode. */
2884 update_inserted_breakpoint_locations (void)
2886 struct bp_location
*bl
, **blp_tmp
;
2889 int disabled_breaks
= 0;
2890 int hw_breakpoint_error
= 0;
2891 int hw_bp_details_reported
= 0;
2893 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2894 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2896 /* Explicitly mark the warning -- this will only be printed if
2897 there was an error. */
2898 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2900 save_current_space_and_thread ();
2902 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2904 /* We only want to update software breakpoints and hardware
2906 if (!is_breakpoint (bl
->owner
))
2909 /* We only want to update locations that are already inserted
2910 and need updating. This is to avoid unwanted insertion during
2911 deletion of breakpoints. */
2912 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2915 switch_to_program_space_and_thread (bl
->pspace
);
2917 /* For targets that support global breakpoints, there's no need
2918 to select an inferior to insert breakpoint to. In fact, even
2919 if we aren't attached to any process yet, we should still
2920 insert breakpoints. */
2921 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2922 && ptid_equal (inferior_ptid
, null_ptid
))
2925 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2926 &hw_breakpoint_error
, &hw_bp_details_reported
);
2933 target_terminal_ours_for_output ();
2934 error_stream (tmp_error_stream
);
2937 do_cleanups (cleanups
);
2940 /* Used when starting or continuing the program. */
2943 insert_breakpoint_locations (void)
2945 struct breakpoint
*bpt
;
2946 struct bp_location
*bl
, **blp_tmp
;
2949 int disabled_breaks
= 0;
2950 int hw_breakpoint_error
= 0;
2951 int hw_bp_error_explained_already
= 0;
2953 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2954 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2956 /* Explicitly mark the warning -- this will only be printed if
2957 there was an error. */
2958 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2960 save_current_space_and_thread ();
2962 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2964 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2967 /* There is no point inserting thread-specific breakpoints if
2968 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2969 has BL->OWNER always non-NULL. */
2970 if (bl
->owner
->thread
!= -1
2971 && !valid_thread_id (bl
->owner
->thread
))
2974 switch_to_program_space_and_thread (bl
->pspace
);
2976 /* For targets that support global breakpoints, there's no need
2977 to select an inferior to insert breakpoint to. In fact, even
2978 if we aren't attached to any process yet, we should still
2979 insert breakpoints. */
2980 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2981 && ptid_equal (inferior_ptid
, null_ptid
))
2984 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2985 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2990 /* If we failed to insert all locations of a watchpoint, remove
2991 them, as half-inserted watchpoint is of limited use. */
2992 ALL_BREAKPOINTS (bpt
)
2994 int some_failed
= 0;
2995 struct bp_location
*loc
;
2997 if (!is_hardware_watchpoint (bpt
))
3000 if (!breakpoint_enabled (bpt
))
3003 if (bpt
->disposition
== disp_del_at_next_stop
)
3006 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3007 if (!loc
->inserted
&& should_be_inserted (loc
))
3014 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3016 remove_breakpoint (loc
, mark_uninserted
);
3018 hw_breakpoint_error
= 1;
3019 fprintf_unfiltered (tmp_error_stream
,
3020 "Could not insert hardware watchpoint %d.\n",
3028 /* If a hardware breakpoint or watchpoint was inserted, add a
3029 message about possibly exhausted resources. */
3030 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3032 fprintf_unfiltered (tmp_error_stream
,
3033 "Could not insert hardware breakpoints:\n\
3034 You may have requested too many hardware breakpoints/watchpoints.\n");
3036 target_terminal_ours_for_output ();
3037 error_stream (tmp_error_stream
);
3040 do_cleanups (cleanups
);
3043 /* Used when the program stops.
3044 Returns zero if successful, or non-zero if there was a problem
3045 removing a breakpoint location. */
3048 remove_breakpoints (void)
3050 struct bp_location
*bl
, **blp_tmp
;
3053 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3055 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3056 val
|= remove_breakpoint (bl
, mark_uninserted
);
3061 /* When a thread exits, remove breakpoints that are related to
3065 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3067 struct breakpoint
*b
, *b_tmp
;
3069 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3071 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3073 b
->disposition
= disp_del_at_next_stop
;
3075 printf_filtered (_("\
3076 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3077 b
->number
, tp
->num
);
3079 /* Hide it from the user. */
3085 /* Remove breakpoints of process PID. */
3088 remove_breakpoints_pid (int pid
)
3090 struct bp_location
*bl
, **blp_tmp
;
3092 struct inferior
*inf
= find_inferior_pid (pid
);
3094 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3096 if (bl
->pspace
!= inf
->pspace
)
3099 if (bl
->owner
->type
== bp_dprintf
)
3104 val
= remove_breakpoint (bl
, mark_uninserted
);
3113 reattach_breakpoints (int pid
)
3115 struct cleanup
*old_chain
;
3116 struct bp_location
*bl
, **blp_tmp
;
3118 struct ui_file
*tmp_error_stream
;
3119 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3120 struct inferior
*inf
;
3121 struct thread_info
*tp
;
3123 tp
= any_live_thread_of_process (pid
);
3127 inf
= find_inferior_pid (pid
);
3128 old_chain
= save_inferior_ptid ();
3130 inferior_ptid
= tp
->ptid
;
3132 tmp_error_stream
= mem_fileopen ();
3133 make_cleanup_ui_file_delete (tmp_error_stream
);
3135 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3137 if (bl
->pspace
!= inf
->pspace
)
3143 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3146 do_cleanups (old_chain
);
3151 do_cleanups (old_chain
);
3155 static int internal_breakpoint_number
= -1;
3157 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3158 If INTERNAL is non-zero, the breakpoint number will be populated
3159 from internal_breakpoint_number and that variable decremented.
3160 Otherwise the breakpoint number will be populated from
3161 breakpoint_count and that value incremented. Internal breakpoints
3162 do not set the internal var bpnum. */
3164 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3167 b
->number
= internal_breakpoint_number
--;
3170 set_breakpoint_count (breakpoint_count
+ 1);
3171 b
->number
= breakpoint_count
;
3175 static struct breakpoint
*
3176 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3177 CORE_ADDR address
, enum bptype type
,
3178 const struct breakpoint_ops
*ops
)
3180 struct symtab_and_line sal
;
3181 struct breakpoint
*b
;
3183 init_sal (&sal
); /* Initialize to zeroes. */
3186 sal
.section
= find_pc_overlay (sal
.pc
);
3187 sal
.pspace
= current_program_space
;
3189 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3190 b
->number
= internal_breakpoint_number
--;
3191 b
->disposition
= disp_donttouch
;
3196 static const char *const longjmp_names
[] =
3198 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3200 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3202 /* Per-objfile data private to breakpoint.c. */
3203 struct breakpoint_objfile_data
3205 /* Minimal symbol for "_ovly_debug_event" (if any). */
3206 struct bound_minimal_symbol overlay_msym
;
3208 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3209 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3211 /* True if we have looked for longjmp probes. */
3212 int longjmp_searched
;
3214 /* SystemTap probe points for longjmp (if any). */
3215 VEC (probe_p
) *longjmp_probes
;
3217 /* Minimal symbol for "std::terminate()" (if any). */
3218 struct bound_minimal_symbol terminate_msym
;
3220 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3221 struct bound_minimal_symbol exception_msym
;
3223 /* True if we have looked for exception probes. */
3224 int exception_searched
;
3226 /* SystemTap probe points for unwinding (if any). */
3227 VEC (probe_p
) *exception_probes
;
3230 static const struct objfile_data
*breakpoint_objfile_key
;
3232 /* Minimal symbol not found sentinel. */
3233 static struct minimal_symbol msym_not_found
;
3235 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3238 msym_not_found_p (const struct minimal_symbol
*msym
)
3240 return msym
== &msym_not_found
;
3243 /* Return per-objfile data needed by breakpoint.c.
3244 Allocate the data if necessary. */
3246 static struct breakpoint_objfile_data
*
3247 get_breakpoint_objfile_data (struct objfile
*objfile
)
3249 struct breakpoint_objfile_data
*bp_objfile_data
;
3251 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3252 if (bp_objfile_data
== NULL
)
3254 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3255 sizeof (*bp_objfile_data
));
3257 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3258 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3260 return bp_objfile_data
;
3264 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3266 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3268 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3269 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3273 create_overlay_event_breakpoint (void)
3275 struct objfile
*objfile
;
3276 const char *const func_name
= "_ovly_debug_event";
3278 ALL_OBJFILES (objfile
)
3280 struct breakpoint
*b
;
3281 struct breakpoint_objfile_data
*bp_objfile_data
;
3284 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3286 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3289 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3291 struct bound_minimal_symbol m
;
3293 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3294 if (m
.minsym
== NULL
)
3296 /* Avoid future lookups in this objfile. */
3297 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3300 bp_objfile_data
->overlay_msym
= m
;
3303 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3304 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3306 &internal_breakpoint_ops
);
3307 b
->addr_string
= xstrdup (func_name
);
3309 if (overlay_debugging
== ovly_auto
)
3311 b
->enable_state
= bp_enabled
;
3312 overlay_events_enabled
= 1;
3316 b
->enable_state
= bp_disabled
;
3317 overlay_events_enabled
= 0;
3320 update_global_location_list (1);
3324 create_longjmp_master_breakpoint (void)
3326 struct program_space
*pspace
;
3327 struct cleanup
*old_chain
;
3329 old_chain
= save_current_program_space ();
3331 ALL_PSPACES (pspace
)
3333 struct objfile
*objfile
;
3335 set_current_program_space (pspace
);
3337 ALL_OBJFILES (objfile
)
3340 struct gdbarch
*gdbarch
;
3341 struct breakpoint_objfile_data
*bp_objfile_data
;
3343 gdbarch
= get_objfile_arch (objfile
);
3345 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3347 if (!bp_objfile_data
->longjmp_searched
)
3351 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3354 /* We are only interested in checking one element. */
3355 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3357 if (!can_evaluate_probe_arguments (p
))
3359 /* We cannot use the probe interface here, because it does
3360 not know how to evaluate arguments. */
3361 VEC_free (probe_p
, ret
);
3365 bp_objfile_data
->longjmp_probes
= ret
;
3366 bp_objfile_data
->longjmp_searched
= 1;
3369 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3372 struct probe
*probe
;
3373 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3376 VEC_iterate (probe_p
,
3377 bp_objfile_data
->longjmp_probes
,
3381 struct breakpoint
*b
;
3383 b
= create_internal_breakpoint (gdbarch
,
3384 get_probe_address (probe
,
3387 &internal_breakpoint_ops
);
3388 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3389 b
->enable_state
= bp_disabled
;
3395 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3398 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3400 struct breakpoint
*b
;
3401 const char *func_name
;
3404 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3407 func_name
= longjmp_names
[i
];
3408 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3410 struct bound_minimal_symbol m
;
3412 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3413 if (m
.minsym
== NULL
)
3415 /* Prevent future lookups in this objfile. */
3416 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3419 bp_objfile_data
->longjmp_msym
[i
] = m
;
3422 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3423 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3424 &internal_breakpoint_ops
);
3425 b
->addr_string
= xstrdup (func_name
);
3426 b
->enable_state
= bp_disabled
;
3430 update_global_location_list (1);
3432 do_cleanups (old_chain
);
3435 /* Create a master std::terminate breakpoint. */
3437 create_std_terminate_master_breakpoint (void)
3439 struct program_space
*pspace
;
3440 struct cleanup
*old_chain
;
3441 const char *const func_name
= "std::terminate()";
3443 old_chain
= save_current_program_space ();
3445 ALL_PSPACES (pspace
)
3447 struct objfile
*objfile
;
3450 set_current_program_space (pspace
);
3452 ALL_OBJFILES (objfile
)
3454 struct breakpoint
*b
;
3455 struct breakpoint_objfile_data
*bp_objfile_data
;
3457 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3459 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3462 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3464 struct bound_minimal_symbol m
;
3466 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3467 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3468 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3470 /* Prevent future lookups in this objfile. */
3471 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3474 bp_objfile_data
->terminate_msym
= m
;
3477 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3478 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3479 bp_std_terminate_master
,
3480 &internal_breakpoint_ops
);
3481 b
->addr_string
= xstrdup (func_name
);
3482 b
->enable_state
= bp_disabled
;
3486 update_global_location_list (1);
3488 do_cleanups (old_chain
);
3491 /* Install a master breakpoint on the unwinder's debug hook. */
3494 create_exception_master_breakpoint (void)
3496 struct objfile
*objfile
;
3497 const char *const func_name
= "_Unwind_DebugHook";
3499 ALL_OBJFILES (objfile
)
3501 struct breakpoint
*b
;
3502 struct gdbarch
*gdbarch
;
3503 struct breakpoint_objfile_data
*bp_objfile_data
;
3506 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3508 /* We prefer the SystemTap probe point if it exists. */
3509 if (!bp_objfile_data
->exception_searched
)
3513 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3517 /* We are only interested in checking one element. */
3518 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3520 if (!can_evaluate_probe_arguments (p
))
3522 /* We cannot use the probe interface here, because it does
3523 not know how to evaluate arguments. */
3524 VEC_free (probe_p
, ret
);
3528 bp_objfile_data
->exception_probes
= ret
;
3529 bp_objfile_data
->exception_searched
= 1;
3532 if (bp_objfile_data
->exception_probes
!= NULL
)
3534 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3536 struct probe
*probe
;
3539 VEC_iterate (probe_p
,
3540 bp_objfile_data
->exception_probes
,
3544 struct breakpoint
*b
;
3546 b
= create_internal_breakpoint (gdbarch
,
3547 get_probe_address (probe
,
3549 bp_exception_master
,
3550 &internal_breakpoint_ops
);
3551 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3552 b
->enable_state
= bp_disabled
;
3558 /* Otherwise, try the hook function. */
3560 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3563 gdbarch
= get_objfile_arch (objfile
);
3565 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3567 struct bound_minimal_symbol debug_hook
;
3569 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3570 if (debug_hook
.minsym
== NULL
)
3572 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3576 bp_objfile_data
->exception_msym
= debug_hook
;
3579 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3580 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3582 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3583 &internal_breakpoint_ops
);
3584 b
->addr_string
= xstrdup (func_name
);
3585 b
->enable_state
= bp_disabled
;
3588 update_global_location_list (1);
3592 update_breakpoints_after_exec (void)
3594 struct breakpoint
*b
, *b_tmp
;
3595 struct bp_location
*bploc
, **bplocp_tmp
;
3597 /* We're about to delete breakpoints from GDB's lists. If the
3598 INSERTED flag is true, GDB will try to lift the breakpoints by
3599 writing the breakpoints' "shadow contents" back into memory. The
3600 "shadow contents" are NOT valid after an exec, so GDB should not
3601 do that. Instead, the target is responsible from marking
3602 breakpoints out as soon as it detects an exec. We don't do that
3603 here instead, because there may be other attempts to delete
3604 breakpoints after detecting an exec and before reaching here. */
3605 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3606 if (bploc
->pspace
== current_program_space
)
3607 gdb_assert (!bploc
->inserted
);
3609 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3611 if (b
->pspace
!= current_program_space
)
3614 /* Solib breakpoints must be explicitly reset after an exec(). */
3615 if (b
->type
== bp_shlib_event
)
3617 delete_breakpoint (b
);
3621 /* JIT breakpoints must be explicitly reset after an exec(). */
3622 if (b
->type
== bp_jit_event
)
3624 delete_breakpoint (b
);
3628 /* Thread event breakpoints must be set anew after an exec(),
3629 as must overlay event and longjmp master breakpoints. */
3630 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3631 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3632 || b
->type
== bp_exception_master
)
3634 delete_breakpoint (b
);
3638 /* Step-resume breakpoints are meaningless after an exec(). */
3639 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3641 delete_breakpoint (b
);
3645 /* Longjmp and longjmp-resume breakpoints are also meaningless
3647 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3648 || b
->type
== bp_longjmp_call_dummy
3649 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3651 delete_breakpoint (b
);
3655 if (b
->type
== bp_catchpoint
)
3657 /* For now, none of the bp_catchpoint breakpoints need to
3658 do anything at this point. In the future, if some of
3659 the catchpoints need to something, we will need to add
3660 a new method, and call this method from here. */
3664 /* bp_finish is a special case. The only way we ought to be able
3665 to see one of these when an exec() has happened, is if the user
3666 caught a vfork, and then said "finish". Ordinarily a finish just
3667 carries them to the call-site of the current callee, by setting
3668 a temporary bp there and resuming. But in this case, the finish
3669 will carry them entirely through the vfork & exec.
3671 We don't want to allow a bp_finish to remain inserted now. But
3672 we can't safely delete it, 'cause finish_command has a handle to
3673 the bp on a bpstat, and will later want to delete it. There's a
3674 chance (and I've seen it happen) that if we delete the bp_finish
3675 here, that its storage will get reused by the time finish_command
3676 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3677 We really must allow finish_command to delete a bp_finish.
3679 In the absence of a general solution for the "how do we know
3680 it's safe to delete something others may have handles to?"
3681 problem, what we'll do here is just uninsert the bp_finish, and
3682 let finish_command delete it.
3684 (We know the bp_finish is "doomed" in the sense that it's
3685 momentary, and will be deleted as soon as finish_command sees
3686 the inferior stopped. So it doesn't matter that the bp's
3687 address is probably bogus in the new a.out, unlike e.g., the
3688 solib breakpoints.) */
3690 if (b
->type
== bp_finish
)
3695 /* Without a symbolic address, we have little hope of the
3696 pre-exec() address meaning the same thing in the post-exec()
3698 if (b
->addr_string
== NULL
)
3700 delete_breakpoint (b
);
3704 /* FIXME what about longjmp breakpoints? Re-create them here? */
3705 create_overlay_event_breakpoint ();
3706 create_longjmp_master_breakpoint ();
3707 create_std_terminate_master_breakpoint ();
3708 create_exception_master_breakpoint ();
3712 detach_breakpoints (ptid_t ptid
)
3714 struct bp_location
*bl
, **blp_tmp
;
3716 struct cleanup
*old_chain
= save_inferior_ptid ();
3717 struct inferior
*inf
= current_inferior ();
3719 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3720 error (_("Cannot detach breakpoints of inferior_ptid"));
3722 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3723 inferior_ptid
= ptid
;
3724 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3726 if (bl
->pspace
!= inf
->pspace
)
3729 /* This function must physically remove breakpoints locations
3730 from the specified ptid, without modifying the breakpoint
3731 package's state. Locations of type bp_loc_other are only
3732 maintained at GDB side. So, there is no need to remove
3733 these bp_loc_other locations. Moreover, removing these
3734 would modify the breakpoint package's state. */
3735 if (bl
->loc_type
== bp_loc_other
)
3739 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3742 /* Detach single-step breakpoints as well. */
3743 detach_single_step_breakpoints ();
3745 do_cleanups (old_chain
);
3749 /* Remove the breakpoint location BL from the current address space.
3750 Note that this is used to detach breakpoints from a child fork.
3751 When we get here, the child isn't in the inferior list, and neither
3752 do we have objects to represent its address space --- we should
3753 *not* look at bl->pspace->aspace here. */
3756 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3760 /* BL is never in moribund_locations by our callers. */
3761 gdb_assert (bl
->owner
!= NULL
);
3763 if (bl
->owner
->enable_state
== bp_permanent
)
3764 /* Permanent breakpoints cannot be inserted or removed. */
3767 /* The type of none suggests that owner is actually deleted.
3768 This should not ever happen. */
3769 gdb_assert (bl
->owner
->type
!= bp_none
);
3771 if (bl
->loc_type
== bp_loc_software_breakpoint
3772 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3774 /* "Normal" instruction breakpoint: either the standard
3775 trap-instruction bp (bp_breakpoint), or a
3776 bp_hardware_breakpoint. */
3778 /* First check to see if we have to handle an overlay. */
3779 if (overlay_debugging
== ovly_off
3780 || bl
->section
== NULL
3781 || !(section_is_overlay (bl
->section
)))
3783 /* No overlay handling: just remove the breakpoint. */
3785 /* If we're trying to uninsert a memory breakpoint that we
3786 know is set in a dynamic object that is marked
3787 shlib_disabled, then either the dynamic object was
3788 removed with "remove-symbol-file" or with
3789 "nosharedlibrary". In the former case, we don't know
3790 whether another dynamic object might have loaded over the
3791 breakpoint's address -- the user might well let us know
3792 about it next with add-symbol-file (the whole point of
3793 OBJF_USERLOADED is letting the user manually maintain a
3794 list of dynamically loaded objects). If we have the
3795 breakpoint's shadow memory, that is, this is a software
3796 breakpoint managed by GDB, check whether the breakpoint
3797 is still inserted in memory, to avoid overwriting wrong
3798 code with stale saved shadow contents. Note that HW
3799 breakpoints don't have shadow memory, as they're
3800 implemented using a mechanism that is not dependent on
3801 being able to modify the target's memory, and as such
3802 they should always be removed. */
3803 if (bl
->shlib_disabled
3804 && bl
->target_info
.shadow_len
!= 0
3805 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3808 val
= bl
->owner
->ops
->remove_location (bl
);
3812 /* This breakpoint is in an overlay section.
3813 Did we set a breakpoint at the LMA? */
3814 if (!overlay_events_enabled
)
3816 /* Yes -- overlay event support is not active, so we
3817 should have set a breakpoint at the LMA. Remove it.
3819 /* Ignore any failures: if the LMA is in ROM, we will
3820 have already warned when we failed to insert it. */
3821 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3822 target_remove_hw_breakpoint (bl
->gdbarch
,
3823 &bl
->overlay_target_info
);
3825 target_remove_breakpoint (bl
->gdbarch
,
3826 &bl
->overlay_target_info
);
3828 /* Did we set a breakpoint at the VMA?
3829 If so, we will have marked the breakpoint 'inserted'. */
3832 /* Yes -- remove it. Previously we did not bother to
3833 remove the breakpoint if the section had been
3834 unmapped, but let's not rely on that being safe. We
3835 don't know what the overlay manager might do. */
3837 /* However, we should remove *software* breakpoints only
3838 if the section is still mapped, or else we overwrite
3839 wrong code with the saved shadow contents. */
3840 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3841 || section_is_mapped (bl
->section
))
3842 val
= bl
->owner
->ops
->remove_location (bl
);
3848 /* No -- not inserted, so no need to remove. No error. */
3853 /* In some cases, we might not be able to remove a breakpoint in
3854 a shared library that has already been removed, but we have
3855 not yet processed the shlib unload event. Similarly for an
3856 unloaded add-symbol-file object - the user might not yet have
3857 had the chance to remove-symbol-file it. shlib_disabled will
3858 be set if the library/object has already been removed, but
3859 the breakpoint hasn't been uninserted yet, e.g., after
3860 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3861 always-inserted mode. */
3863 && (bl
->loc_type
== bp_loc_software_breakpoint
3864 && (bl
->shlib_disabled
3865 || solib_name_from_address (bl
->pspace
, bl
->address
)
3866 || userloaded_objfile_contains_address_p (bl
->pspace
,
3872 bl
->inserted
= (is
== mark_inserted
);
3874 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3876 gdb_assert (bl
->owner
->ops
!= NULL
3877 && bl
->owner
->ops
->remove_location
!= NULL
);
3879 bl
->inserted
= (is
== mark_inserted
);
3880 bl
->owner
->ops
->remove_location (bl
);
3882 /* Failure to remove any of the hardware watchpoints comes here. */
3883 if ((is
== mark_uninserted
) && (bl
->inserted
))
3884 warning (_("Could not remove hardware watchpoint %d."),
3887 else if (bl
->owner
->type
== bp_catchpoint
3888 && breakpoint_enabled (bl
->owner
)
3891 gdb_assert (bl
->owner
->ops
!= NULL
3892 && bl
->owner
->ops
->remove_location
!= NULL
);
3894 val
= bl
->owner
->ops
->remove_location (bl
);
3898 bl
->inserted
= (is
== mark_inserted
);
3905 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3908 struct cleanup
*old_chain
;
3910 /* BL is never in moribund_locations by our callers. */
3911 gdb_assert (bl
->owner
!= NULL
);
3913 if (bl
->owner
->enable_state
== bp_permanent
)
3914 /* Permanent breakpoints cannot be inserted or removed. */
3917 /* The type of none suggests that owner is actually deleted.
3918 This should not ever happen. */
3919 gdb_assert (bl
->owner
->type
!= bp_none
);
3921 old_chain
= save_current_space_and_thread ();
3923 switch_to_program_space_and_thread (bl
->pspace
);
3925 ret
= remove_breakpoint_1 (bl
, is
);
3927 do_cleanups (old_chain
);
3931 /* Clear the "inserted" flag in all breakpoints. */
3934 mark_breakpoints_out (void)
3936 struct bp_location
*bl
, **blp_tmp
;
3938 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3939 if (bl
->pspace
== current_program_space
)
3943 /* Clear the "inserted" flag in all breakpoints and delete any
3944 breakpoints which should go away between runs of the program.
3946 Plus other such housekeeping that has to be done for breakpoints
3949 Note: this function gets called at the end of a run (by
3950 generic_mourn_inferior) and when a run begins (by
3951 init_wait_for_inferior). */
3956 breakpoint_init_inferior (enum inf_context context
)
3958 struct breakpoint
*b
, *b_tmp
;
3959 struct bp_location
*bl
, **blp_tmp
;
3961 struct program_space
*pspace
= current_program_space
;
3963 /* If breakpoint locations are shared across processes, then there's
3965 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3968 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3970 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3971 if (bl
->pspace
== pspace
3972 && bl
->owner
->enable_state
!= bp_permanent
)
3976 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3978 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3984 case bp_longjmp_call_dummy
:
3986 /* If the call dummy breakpoint is at the entry point it will
3987 cause problems when the inferior is rerun, so we better get
3990 case bp_watchpoint_scope
:
3992 /* Also get rid of scope breakpoints. */
3994 case bp_shlib_event
:
3996 /* Also remove solib event breakpoints. Their addresses may
3997 have changed since the last time we ran the program.
3998 Actually we may now be debugging against different target;
3999 and so the solib backend that installed this breakpoint may
4000 not be used in by the target. E.g.,
4002 (gdb) file prog-linux
4003 (gdb) run # native linux target
4006 (gdb) file prog-win.exe
4007 (gdb) tar rem :9999 # remote Windows gdbserver.
4010 case bp_step_resume
:
4012 /* Also remove step-resume breakpoints. */
4014 delete_breakpoint (b
);
4018 case bp_hardware_watchpoint
:
4019 case bp_read_watchpoint
:
4020 case bp_access_watchpoint
:
4022 struct watchpoint
*w
= (struct watchpoint
*) b
;
4024 /* Likewise for watchpoints on local expressions. */
4025 if (w
->exp_valid_block
!= NULL
)
4026 delete_breakpoint (b
);
4027 else if (context
== inf_starting
)
4029 /* Reset val field to force reread of starting value in
4030 insert_breakpoints. */
4032 value_free (w
->val
);
4043 /* Get rid of the moribund locations. */
4044 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4045 decref_bp_location (&bl
);
4046 VEC_free (bp_location_p
, moribund_locations
);
4049 /* These functions concern about actual breakpoints inserted in the
4050 target --- to e.g. check if we need to do decr_pc adjustment or if
4051 we need to hop over the bkpt --- so we check for address space
4052 match, not program space. */
4054 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4055 exists at PC. It returns ordinary_breakpoint_here if it's an
4056 ordinary breakpoint, or permanent_breakpoint_here if it's a
4057 permanent breakpoint.
4058 - When continuing from a location with an ordinary breakpoint, we
4059 actually single step once before calling insert_breakpoints.
4060 - When continuing from a location with a permanent breakpoint, we
4061 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4062 the target, to advance the PC past the breakpoint. */
4064 enum breakpoint_here
4065 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4067 struct bp_location
*bl
, **blp_tmp
;
4068 int any_breakpoint_here
= 0;
4070 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4072 if (bl
->loc_type
!= bp_loc_software_breakpoint
4073 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4076 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4077 if ((breakpoint_enabled (bl
->owner
)
4078 || bl
->owner
->enable_state
== bp_permanent
)
4079 && breakpoint_location_address_match (bl
, aspace
, pc
))
4081 if (overlay_debugging
4082 && section_is_overlay (bl
->section
)
4083 && !section_is_mapped (bl
->section
))
4084 continue; /* unmapped overlay -- can't be a match */
4085 else if (bl
->owner
->enable_state
== bp_permanent
)
4086 return permanent_breakpoint_here
;
4088 any_breakpoint_here
= 1;
4092 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4095 /* Return true if there's a moribund breakpoint at PC. */
4098 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4100 struct bp_location
*loc
;
4103 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4104 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4110 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4111 inserted using regular breakpoint_chain / bp_location array
4112 mechanism. This does not check for single-step breakpoints, which
4113 are inserted and removed using direct target manipulation. */
4116 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
4119 struct bp_location
*bl
, **blp_tmp
;
4121 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4123 if (bl
->loc_type
!= bp_loc_software_breakpoint
4124 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4128 && breakpoint_location_address_match (bl
, aspace
, pc
))
4130 if (overlay_debugging
4131 && section_is_overlay (bl
->section
)
4132 && !section_is_mapped (bl
->section
))
4133 continue; /* unmapped overlay -- can't be a match */
4141 /* Returns non-zero iff there's either regular breakpoint
4142 or a single step breakpoint inserted at PC. */
4145 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4147 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
4150 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4156 /* This function returns non-zero iff there is a software breakpoint
4160 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4163 struct bp_location
*bl
, **blp_tmp
;
4165 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4167 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4171 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4174 if (overlay_debugging
4175 && section_is_overlay (bl
->section
)
4176 && !section_is_mapped (bl
->section
))
4177 continue; /* unmapped overlay -- can't be a match */
4183 /* Also check for software single-step breakpoints. */
4184 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4191 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4192 CORE_ADDR addr
, ULONGEST len
)
4194 struct breakpoint
*bpt
;
4196 ALL_BREAKPOINTS (bpt
)
4198 struct bp_location
*loc
;
4200 if (bpt
->type
!= bp_hardware_watchpoint
4201 && bpt
->type
!= bp_access_watchpoint
)
4204 if (!breakpoint_enabled (bpt
))
4207 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4208 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4212 /* Check for intersection. */
4213 l
= max (loc
->address
, addr
);
4214 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4222 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4223 PC is valid for process/thread PTID. */
4226 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4229 struct bp_location
*bl
, **blp_tmp
;
4230 /* The thread and task IDs associated to PTID, computed lazily. */
4234 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4236 if (bl
->loc_type
!= bp_loc_software_breakpoint
4237 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4240 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4241 if (!breakpoint_enabled (bl
->owner
)
4242 && bl
->owner
->enable_state
!= bp_permanent
)
4245 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4248 if (bl
->owner
->thread
!= -1)
4250 /* This is a thread-specific breakpoint. Check that ptid
4251 matches that thread. If thread hasn't been computed yet,
4252 it is now time to do so. */
4254 thread
= pid_to_thread_id (ptid
);
4255 if (bl
->owner
->thread
!= thread
)
4259 if (bl
->owner
->task
!= 0)
4261 /* This is a task-specific breakpoint. Check that ptid
4262 matches that task. If task hasn't been computed yet,
4263 it is now time to do so. */
4265 task
= ada_get_task_number (ptid
);
4266 if (bl
->owner
->task
!= task
)
4270 if (overlay_debugging
4271 && section_is_overlay (bl
->section
)
4272 && !section_is_mapped (bl
->section
))
4273 continue; /* unmapped overlay -- can't be a match */
4282 /* bpstat stuff. External routines' interfaces are documented
4286 is_catchpoint (struct breakpoint
*ep
)
4288 return (ep
->type
== bp_catchpoint
);
4291 /* Frees any storage that is part of a bpstat. Does not walk the
4295 bpstat_free (bpstat bs
)
4297 if (bs
->old_val
!= NULL
)
4298 value_free (bs
->old_val
);
4299 decref_counted_command_line (&bs
->commands
);
4300 decref_bp_location (&bs
->bp_location_at
);
4304 /* Clear a bpstat so that it says we are not at any breakpoint.
4305 Also free any storage that is part of a bpstat. */
4308 bpstat_clear (bpstat
*bsp
)
4325 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4326 is part of the bpstat is copied as well. */
4329 bpstat_copy (bpstat bs
)
4333 bpstat retval
= NULL
;
4338 for (; bs
!= NULL
; bs
= bs
->next
)
4340 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4341 memcpy (tmp
, bs
, sizeof (*tmp
));
4342 incref_counted_command_line (tmp
->commands
);
4343 incref_bp_location (tmp
->bp_location_at
);
4344 if (bs
->old_val
!= NULL
)
4346 tmp
->old_val
= value_copy (bs
->old_val
);
4347 release_value (tmp
->old_val
);
4351 /* This is the first thing in the chain. */
4361 /* Find the bpstat associated with this breakpoint. */
4364 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4369 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4371 if (bsp
->breakpoint_at
== breakpoint
)
4377 /* See breakpoint.h. */
4380 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4382 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4384 if (bsp
->breakpoint_at
== NULL
)
4386 /* A moribund location can never explain a signal other than
4388 if (sig
== GDB_SIGNAL_TRAP
)
4393 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4402 /* Put in *NUM the breakpoint number of the first breakpoint we are
4403 stopped at. *BSP upon return is a bpstat which points to the
4404 remaining breakpoints stopped at (but which is not guaranteed to be
4405 good for anything but further calls to bpstat_num).
4407 Return 0 if passed a bpstat which does not indicate any breakpoints.
4408 Return -1 if stopped at a breakpoint that has been deleted since
4410 Return 1 otherwise. */
4413 bpstat_num (bpstat
*bsp
, int *num
)
4415 struct breakpoint
*b
;
4418 return 0; /* No more breakpoint values */
4420 /* We assume we'll never have several bpstats that correspond to a
4421 single breakpoint -- otherwise, this function might return the
4422 same number more than once and this will look ugly. */
4423 b
= (*bsp
)->breakpoint_at
;
4424 *bsp
= (*bsp
)->next
;
4426 return -1; /* breakpoint that's been deleted since */
4428 *num
= b
->number
; /* We have its number */
4432 /* See breakpoint.h. */
4435 bpstat_clear_actions (void)
4437 struct thread_info
*tp
;
4440 if (ptid_equal (inferior_ptid
, null_ptid
))
4443 tp
= find_thread_ptid (inferior_ptid
);
4447 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4449 decref_counted_command_line (&bs
->commands
);
4451 if (bs
->old_val
!= NULL
)
4453 value_free (bs
->old_val
);
4459 /* Called when a command is about to proceed the inferior. */
4462 breakpoint_about_to_proceed (void)
4464 if (!ptid_equal (inferior_ptid
, null_ptid
))
4466 struct thread_info
*tp
= inferior_thread ();
4468 /* Allow inferior function calls in breakpoint commands to not
4469 interrupt the command list. When the call finishes
4470 successfully, the inferior will be standing at the same
4471 breakpoint as if nothing happened. */
4472 if (tp
->control
.in_infcall
)
4476 breakpoint_proceeded
= 1;
4479 /* Stub for cleaning up our state if we error-out of a breakpoint
4482 cleanup_executing_breakpoints (void *ignore
)
4484 executing_breakpoint_commands
= 0;
4487 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4488 or its equivalent. */
4491 command_line_is_silent (struct command_line
*cmd
)
4493 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4494 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4497 /* Execute all the commands associated with all the breakpoints at
4498 this location. Any of these commands could cause the process to
4499 proceed beyond this point, etc. We look out for such changes by
4500 checking the global "breakpoint_proceeded" after each command.
4502 Returns true if a breakpoint command resumed the inferior. In that
4503 case, it is the caller's responsibility to recall it again with the
4504 bpstat of the current thread. */
4507 bpstat_do_actions_1 (bpstat
*bsp
)
4510 struct cleanup
*old_chain
;
4513 /* Avoid endless recursion if a `source' command is contained
4515 if (executing_breakpoint_commands
)
4518 executing_breakpoint_commands
= 1;
4519 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4521 prevent_dont_repeat ();
4523 /* This pointer will iterate over the list of bpstat's. */
4526 breakpoint_proceeded
= 0;
4527 for (; bs
!= NULL
; bs
= bs
->next
)
4529 struct counted_command_line
*ccmd
;
4530 struct command_line
*cmd
;
4531 struct cleanup
*this_cmd_tree_chain
;
4533 /* Take ownership of the BSP's command tree, if it has one.
4535 The command tree could legitimately contain commands like
4536 'step' and 'next', which call clear_proceed_status, which
4537 frees stop_bpstat's command tree. To make sure this doesn't
4538 free the tree we're executing out from under us, we need to
4539 take ownership of the tree ourselves. Since a given bpstat's
4540 commands are only executed once, we don't need to copy it; we
4541 can clear the pointer in the bpstat, and make sure we free
4542 the tree when we're done. */
4543 ccmd
= bs
->commands
;
4544 bs
->commands
= NULL
;
4545 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4546 cmd
= ccmd
? ccmd
->commands
: NULL
;
4547 if (command_line_is_silent (cmd
))
4549 /* The action has been already done by bpstat_stop_status. */
4555 execute_control_command (cmd
);
4557 if (breakpoint_proceeded
)
4563 /* We can free this command tree now. */
4564 do_cleanups (this_cmd_tree_chain
);
4566 if (breakpoint_proceeded
)
4568 if (target_can_async_p ())
4569 /* If we are in async mode, then the target might be still
4570 running, not stopped at any breakpoint, so nothing for
4571 us to do here -- just return to the event loop. */
4574 /* In sync mode, when execute_control_command returns
4575 we're already standing on the next breakpoint.
4576 Breakpoint commands for that stop were not run, since
4577 execute_command does not run breakpoint commands --
4578 only command_line_handler does, but that one is not
4579 involved in execution of breakpoint commands. So, we
4580 can now execute breakpoint commands. It should be
4581 noted that making execute_command do bpstat actions is
4582 not an option -- in this case we'll have recursive
4583 invocation of bpstat for each breakpoint with a
4584 command, and can easily blow up GDB stack. Instead, we
4585 return true, which will trigger the caller to recall us
4586 with the new stop_bpstat. */
4591 do_cleanups (old_chain
);
4596 bpstat_do_actions (void)
4598 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4600 /* Do any commands attached to breakpoint we are stopped at. */
4601 while (!ptid_equal (inferior_ptid
, null_ptid
)
4602 && target_has_execution
4603 && !is_exited (inferior_ptid
)
4604 && !is_executing (inferior_ptid
))
4605 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4606 and only return when it is stopped at the next breakpoint, we
4607 keep doing breakpoint actions until it returns false to
4608 indicate the inferior was not resumed. */
4609 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4612 discard_cleanups (cleanup_if_error
);
4615 /* Print out the (old or new) value associated with a watchpoint. */
4618 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4621 fprintf_unfiltered (stream
, _("<unreadable>"));
4624 struct value_print_options opts
;
4625 get_user_print_options (&opts
);
4626 value_print (val
, stream
, &opts
);
4630 /* Generic routine for printing messages indicating why we
4631 stopped. The behavior of this function depends on the value
4632 'print_it' in the bpstat structure. Under some circumstances we
4633 may decide not to print anything here and delegate the task to
4636 static enum print_stop_action
4637 print_bp_stop_message (bpstat bs
)
4639 switch (bs
->print_it
)
4642 /* Nothing should be printed for this bpstat entry. */
4643 return PRINT_UNKNOWN
;
4647 /* We still want to print the frame, but we already printed the
4648 relevant messages. */
4649 return PRINT_SRC_AND_LOC
;
4652 case print_it_normal
:
4654 struct breakpoint
*b
= bs
->breakpoint_at
;
4656 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4657 which has since been deleted. */
4659 return PRINT_UNKNOWN
;
4661 /* Normal case. Call the breakpoint's print_it method. */
4662 return b
->ops
->print_it (bs
);
4667 internal_error (__FILE__
, __LINE__
,
4668 _("print_bp_stop_message: unrecognized enum value"));
4673 /* A helper function that prints a shared library stopped event. */
4676 print_solib_event (int is_catchpoint
)
4679 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4681 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4685 if (any_added
|| any_deleted
)
4686 ui_out_text (current_uiout
,
4687 _("Stopped due to shared library event:\n"));
4689 ui_out_text (current_uiout
,
4690 _("Stopped due to shared library event (no "
4691 "libraries added or removed)\n"));
4694 if (ui_out_is_mi_like_p (current_uiout
))
4695 ui_out_field_string (current_uiout
, "reason",
4696 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4700 struct cleanup
*cleanup
;
4704 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4705 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4708 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4713 ui_out_text (current_uiout
, " ");
4714 ui_out_field_string (current_uiout
, "library", name
);
4715 ui_out_text (current_uiout
, "\n");
4718 do_cleanups (cleanup
);
4723 struct so_list
*iter
;
4725 struct cleanup
*cleanup
;
4727 ui_out_text (current_uiout
, _(" Inferior loaded "));
4728 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4731 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4736 ui_out_text (current_uiout
, " ");
4737 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4738 ui_out_text (current_uiout
, "\n");
4741 do_cleanups (cleanup
);
4745 /* Print a message indicating what happened. This is called from
4746 normal_stop(). The input to this routine is the head of the bpstat
4747 list - a list of the eventpoints that caused this stop. KIND is
4748 the target_waitkind for the stopping event. This
4749 routine calls the generic print routine for printing a message
4750 about reasons for stopping. This will print (for example) the
4751 "Breakpoint n," part of the output. The return value of this
4754 PRINT_UNKNOWN: Means we printed nothing.
4755 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4756 code to print the location. An example is
4757 "Breakpoint 1, " which should be followed by
4759 PRINT_SRC_ONLY: Means we printed something, but there is no need
4760 to also print the location part of the message.
4761 An example is the catch/throw messages, which
4762 don't require a location appended to the end.
4763 PRINT_NOTHING: We have done some printing and we don't need any
4764 further info to be printed. */
4766 enum print_stop_action
4767 bpstat_print (bpstat bs
, int kind
)
4771 /* Maybe another breakpoint in the chain caused us to stop.
4772 (Currently all watchpoints go on the bpstat whether hit or not.
4773 That probably could (should) be changed, provided care is taken
4774 with respect to bpstat_explains_signal). */
4775 for (; bs
; bs
= bs
->next
)
4777 val
= print_bp_stop_message (bs
);
4778 if (val
== PRINT_SRC_ONLY
4779 || val
== PRINT_SRC_AND_LOC
4780 || val
== PRINT_NOTHING
)
4784 /* If we had hit a shared library event breakpoint,
4785 print_bp_stop_message would print out this message. If we hit an
4786 OS-level shared library event, do the same thing. */
4787 if (kind
== TARGET_WAITKIND_LOADED
)
4789 print_solib_event (0);
4790 return PRINT_NOTHING
;
4793 /* We reached the end of the chain, or we got a null BS to start
4794 with and nothing was printed. */
4795 return PRINT_UNKNOWN
;
4798 /* Evaluate the expression EXP and return 1 if value is zero.
4799 This returns the inverse of the condition because it is called
4800 from catch_errors which returns 0 if an exception happened, and if an
4801 exception happens we want execution to stop.
4802 The argument is a "struct expression *" that has been cast to a
4803 "void *" to make it pass through catch_errors. */
4806 breakpoint_cond_eval (void *exp
)
4808 struct value
*mark
= value_mark ();
4809 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4811 value_free_to_mark (mark
);
4815 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4818 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4822 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4824 **bs_link_pointer
= bs
;
4825 *bs_link_pointer
= &bs
->next
;
4826 bs
->breakpoint_at
= bl
->owner
;
4827 bs
->bp_location_at
= bl
;
4828 incref_bp_location (bl
);
4829 /* If the condition is false, etc., don't do the commands. */
4830 bs
->commands
= NULL
;
4832 bs
->print_it
= print_it_normal
;
4836 /* The target has stopped with waitstatus WS. Check if any hardware
4837 watchpoints have triggered, according to the target. */
4840 watchpoints_triggered (struct target_waitstatus
*ws
)
4842 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4844 struct breakpoint
*b
;
4846 if (!stopped_by_watchpoint
)
4848 /* We were not stopped by a watchpoint. Mark all watchpoints
4849 as not triggered. */
4851 if (is_hardware_watchpoint (b
))
4853 struct watchpoint
*w
= (struct watchpoint
*) b
;
4855 w
->watchpoint_triggered
= watch_triggered_no
;
4861 if (!target_stopped_data_address (¤t_target
, &addr
))
4863 /* We were stopped by a watchpoint, but we don't know where.
4864 Mark all watchpoints as unknown. */
4866 if (is_hardware_watchpoint (b
))
4868 struct watchpoint
*w
= (struct watchpoint
*) b
;
4870 w
->watchpoint_triggered
= watch_triggered_unknown
;
4876 /* The target could report the data address. Mark watchpoints
4877 affected by this data address as triggered, and all others as not
4881 if (is_hardware_watchpoint (b
))
4883 struct watchpoint
*w
= (struct watchpoint
*) b
;
4884 struct bp_location
*loc
;
4886 w
->watchpoint_triggered
= watch_triggered_no
;
4887 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4889 if (is_masked_watchpoint (b
))
4891 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4892 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4894 if (newaddr
== start
)
4896 w
->watchpoint_triggered
= watch_triggered_yes
;
4900 /* Exact match not required. Within range is sufficient. */
4901 else if (target_watchpoint_addr_within_range (¤t_target
,
4905 w
->watchpoint_triggered
= watch_triggered_yes
;
4914 /* Possible return values for watchpoint_check (this can't be an enum
4915 because of check_errors). */
4916 /* The watchpoint has been deleted. */
4917 #define WP_DELETED 1
4918 /* The value has changed. */
4919 #define WP_VALUE_CHANGED 2
4920 /* The value has not changed. */
4921 #define WP_VALUE_NOT_CHANGED 3
4922 /* Ignore this watchpoint, no matter if the value changed or not. */
4925 #define BP_TEMPFLAG 1
4926 #define BP_HARDWAREFLAG 2
4928 /* Evaluate watchpoint condition expression and check if its value
4931 P should be a pointer to struct bpstat, but is defined as a void *
4932 in order for this function to be usable with catch_errors. */
4935 watchpoint_check (void *p
)
4937 bpstat bs
= (bpstat
) p
;
4938 struct watchpoint
*b
;
4939 struct frame_info
*fr
;
4940 int within_current_scope
;
4942 /* BS is built from an existing struct breakpoint. */
4943 gdb_assert (bs
->breakpoint_at
!= NULL
);
4944 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4946 /* If this is a local watchpoint, we only want to check if the
4947 watchpoint frame is in scope if the current thread is the thread
4948 that was used to create the watchpoint. */
4949 if (!watchpoint_in_thread_scope (b
))
4952 if (b
->exp_valid_block
== NULL
)
4953 within_current_scope
= 1;
4956 struct frame_info
*frame
= get_current_frame ();
4957 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4958 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4960 /* in_function_epilogue_p() returns a non-zero value if we're
4961 still in the function but the stack frame has already been
4962 invalidated. Since we can't rely on the values of local
4963 variables after the stack has been destroyed, we are treating
4964 the watchpoint in that state as `not changed' without further
4965 checking. Don't mark watchpoints as changed if the current
4966 frame is in an epilogue - even if they are in some other
4967 frame, our view of the stack is likely to be wrong and
4968 frame_find_by_id could error out. */
4969 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4972 fr
= frame_find_by_id (b
->watchpoint_frame
);
4973 within_current_scope
= (fr
!= NULL
);
4975 /* If we've gotten confused in the unwinder, we might have
4976 returned a frame that can't describe this variable. */
4977 if (within_current_scope
)
4979 struct symbol
*function
;
4981 function
= get_frame_function (fr
);
4982 if (function
== NULL
4983 || !contained_in (b
->exp_valid_block
,
4984 SYMBOL_BLOCK_VALUE (function
)))
4985 within_current_scope
= 0;
4988 if (within_current_scope
)
4989 /* If we end up stopping, the current frame will get selected
4990 in normal_stop. So this call to select_frame won't affect
4995 if (within_current_scope
)
4997 /* We use value_{,free_to_}mark because it could be a *long*
4998 time before we return to the command level and call
4999 free_all_values. We can't call free_all_values because we
5000 might be in the middle of evaluating a function call. */
5004 struct value
*new_val
;
5006 if (is_masked_watchpoint (&b
->base
))
5007 /* Since we don't know the exact trigger address (from
5008 stopped_data_address), just tell the user we've triggered
5009 a mask watchpoint. */
5010 return WP_VALUE_CHANGED
;
5012 mark
= value_mark ();
5013 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5015 /* We use value_equal_contents instead of value_equal because
5016 the latter coerces an array to a pointer, thus comparing just
5017 the address of the array instead of its contents. This is
5018 not what we want. */
5019 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5020 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5022 if (new_val
!= NULL
)
5024 release_value (new_val
);
5025 value_free_to_mark (mark
);
5027 bs
->old_val
= b
->val
;
5030 return WP_VALUE_CHANGED
;
5034 /* Nothing changed. */
5035 value_free_to_mark (mark
);
5036 return WP_VALUE_NOT_CHANGED
;
5041 struct ui_out
*uiout
= current_uiout
;
5043 /* This seems like the only logical thing to do because
5044 if we temporarily ignored the watchpoint, then when
5045 we reenter the block in which it is valid it contains
5046 garbage (in the case of a function, it may have two
5047 garbage values, one before and one after the prologue).
5048 So we can't even detect the first assignment to it and
5049 watch after that (since the garbage may or may not equal
5050 the first value assigned). */
5051 /* We print all the stop information in
5052 breakpoint_ops->print_it, but in this case, by the time we
5053 call breakpoint_ops->print_it this bp will be deleted
5054 already. So we have no choice but print the information
5056 if (ui_out_is_mi_like_p (uiout
))
5058 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5059 ui_out_text (uiout
, "\nWatchpoint ");
5060 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5062 " deleted because the program has left the block in\n\
5063 which its expression is valid.\n");
5065 /* Make sure the watchpoint's commands aren't executed. */
5066 decref_counted_command_line (&b
->base
.commands
);
5067 watchpoint_del_at_next_stop (b
);
5073 /* Return true if it looks like target has stopped due to hitting
5074 breakpoint location BL. This function does not check if we should
5075 stop, only if BL explains the stop. */
5078 bpstat_check_location (const struct bp_location
*bl
,
5079 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5080 const struct target_waitstatus
*ws
)
5082 struct breakpoint
*b
= bl
->owner
;
5084 /* BL is from an existing breakpoint. */
5085 gdb_assert (b
!= NULL
);
5087 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5090 /* Determine if the watched values have actually changed, and we
5091 should stop. If not, set BS->stop to 0. */
5094 bpstat_check_watchpoint (bpstat bs
)
5096 const struct bp_location
*bl
;
5097 struct watchpoint
*b
;
5099 /* BS is built for existing struct breakpoint. */
5100 bl
= bs
->bp_location_at
;
5101 gdb_assert (bl
!= NULL
);
5102 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5103 gdb_assert (b
!= NULL
);
5106 int must_check_value
= 0;
5108 if (b
->base
.type
== bp_watchpoint
)
5109 /* For a software watchpoint, we must always check the
5111 must_check_value
= 1;
5112 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5113 /* We have a hardware watchpoint (read, write, or access)
5114 and the target earlier reported an address watched by
5116 must_check_value
= 1;
5117 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5118 && b
->base
.type
== bp_hardware_watchpoint
)
5119 /* We were stopped by a hardware watchpoint, but the target could
5120 not report the data address. We must check the watchpoint's
5121 value. Access and read watchpoints are out of luck; without
5122 a data address, we can't figure it out. */
5123 must_check_value
= 1;
5125 if (must_check_value
)
5128 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5130 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5131 int e
= catch_errors (watchpoint_check
, bs
, message
,
5133 do_cleanups (cleanups
);
5137 /* We've already printed what needs to be printed. */
5138 bs
->print_it
= print_it_done
;
5142 bs
->print_it
= print_it_noop
;
5145 case WP_VALUE_CHANGED
:
5146 if (b
->base
.type
== bp_read_watchpoint
)
5148 /* There are two cases to consider here:
5150 1. We're watching the triggered memory for reads.
5151 In that case, trust the target, and always report
5152 the watchpoint hit to the user. Even though
5153 reads don't cause value changes, the value may
5154 have changed since the last time it was read, and
5155 since we're not trapping writes, we will not see
5156 those, and as such we should ignore our notion of
5159 2. We're watching the triggered memory for both
5160 reads and writes. There are two ways this may
5163 2.1. This is a target that can't break on data
5164 reads only, but can break on accesses (reads or
5165 writes), such as e.g., x86. We detect this case
5166 at the time we try to insert read watchpoints.
5168 2.2. Otherwise, the target supports read
5169 watchpoints, but, the user set an access or write
5170 watchpoint watching the same memory as this read
5173 If we're watching memory writes as well as reads,
5174 ignore watchpoint hits when we find that the
5175 value hasn't changed, as reads don't cause
5176 changes. This still gives false positives when
5177 the program writes the same value to memory as
5178 what there was already in memory (we will confuse
5179 it for a read), but it's much better than
5182 int other_write_watchpoint
= 0;
5184 if (bl
->watchpoint_type
== hw_read
)
5186 struct breakpoint
*other_b
;
5188 ALL_BREAKPOINTS (other_b
)
5189 if (other_b
->type
== bp_hardware_watchpoint
5190 || other_b
->type
== bp_access_watchpoint
)
5192 struct watchpoint
*other_w
=
5193 (struct watchpoint
*) other_b
;
5195 if (other_w
->watchpoint_triggered
5196 == watch_triggered_yes
)
5198 other_write_watchpoint
= 1;
5204 if (other_write_watchpoint
5205 || bl
->watchpoint_type
== hw_access
)
5207 /* We're watching the same memory for writes,
5208 and the value changed since the last time we
5209 updated it, so this trap must be for a write.
5211 bs
->print_it
= print_it_noop
;
5216 case WP_VALUE_NOT_CHANGED
:
5217 if (b
->base
.type
== bp_hardware_watchpoint
5218 || b
->base
.type
== bp_watchpoint
)
5220 /* Don't stop: write watchpoints shouldn't fire if
5221 the value hasn't changed. */
5222 bs
->print_it
= print_it_noop
;
5230 /* Error from catch_errors. */
5231 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5232 watchpoint_del_at_next_stop (b
);
5233 /* We've already printed what needs to be printed. */
5234 bs
->print_it
= print_it_done
;
5238 else /* must_check_value == 0 */
5240 /* This is a case where some watchpoint(s) triggered, but
5241 not at the address of this watchpoint, or else no
5242 watchpoint triggered after all. So don't print
5243 anything for this watchpoint. */
5244 bs
->print_it
= print_it_noop
;
5250 /* For breakpoints that are currently marked as telling gdb to stop,
5251 check conditions (condition proper, frame, thread and ignore count)
5252 of breakpoint referred to by BS. If we should not stop for this
5253 breakpoint, set BS->stop to 0. */
5256 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5258 const struct bp_location
*bl
;
5259 struct breakpoint
*b
;
5260 int value_is_zero
= 0;
5261 struct expression
*cond
;
5263 gdb_assert (bs
->stop
);
5265 /* BS is built for existing struct breakpoint. */
5266 bl
= bs
->bp_location_at
;
5267 gdb_assert (bl
!= NULL
);
5268 b
= bs
->breakpoint_at
;
5269 gdb_assert (b
!= NULL
);
5271 /* Even if the target evaluated the condition on its end and notified GDB, we
5272 need to do so again since GDB does not know if we stopped due to a
5273 breakpoint or a single step breakpoint. */
5275 if (frame_id_p (b
->frame_id
)
5276 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5282 /* If this is a thread/task-specific breakpoint, don't waste cpu
5283 evaluating the condition if this isn't the specified
5285 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5286 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5293 /* Evaluate extension language breakpoints that have a "stop" method
5295 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5297 if (is_watchpoint (b
))
5299 struct watchpoint
*w
= (struct watchpoint
*) b
;
5306 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5308 int within_current_scope
= 1;
5309 struct watchpoint
* w
;
5311 /* We use value_mark and value_free_to_mark because it could
5312 be a long time before we return to the command level and
5313 call free_all_values. We can't call free_all_values
5314 because we might be in the middle of evaluating a
5316 struct value
*mark
= value_mark ();
5318 if (is_watchpoint (b
))
5319 w
= (struct watchpoint
*) b
;
5323 /* Need to select the frame, with all that implies so that
5324 the conditions will have the right context. Because we
5325 use the frame, we will not see an inlined function's
5326 variables when we arrive at a breakpoint at the start
5327 of the inlined function; the current frame will be the
5329 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5330 select_frame (get_current_frame ());
5333 struct frame_info
*frame
;
5335 /* For local watchpoint expressions, which particular
5336 instance of a local is being watched matters, so we
5337 keep track of the frame to evaluate the expression
5338 in. To evaluate the condition however, it doesn't
5339 really matter which instantiation of the function
5340 where the condition makes sense triggers the
5341 watchpoint. This allows an expression like "watch
5342 global if q > 10" set in `func', catch writes to
5343 global on all threads that call `func', or catch
5344 writes on all recursive calls of `func' by a single
5345 thread. We simply always evaluate the condition in
5346 the innermost frame that's executing where it makes
5347 sense to evaluate the condition. It seems
5349 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5351 select_frame (frame
);
5353 within_current_scope
= 0;
5355 if (within_current_scope
)
5357 = catch_errors (breakpoint_cond_eval
, cond
,
5358 "Error in testing breakpoint condition:\n",
5362 warning (_("Watchpoint condition cannot be tested "
5363 "in the current scope"));
5364 /* If we failed to set the right context for this
5365 watchpoint, unconditionally report it. */
5368 /* FIXME-someday, should give breakpoint #. */
5369 value_free_to_mark (mark
);
5372 if (cond
&& value_is_zero
)
5376 else if (b
->ignore_count
> 0)
5380 /* Increase the hit count even though we don't stop. */
5382 observer_notify_breakpoint_modified (b
);
5387 /* Get a bpstat associated with having just stopped at address
5388 BP_ADDR in thread PTID.
5390 Determine whether we stopped at a breakpoint, etc, or whether we
5391 don't understand this stop. Result is a chain of bpstat's such
5394 if we don't understand the stop, the result is a null pointer.
5396 if we understand why we stopped, the result is not null.
5398 Each element of the chain refers to a particular breakpoint or
5399 watchpoint at which we have stopped. (We may have stopped for
5400 several reasons concurrently.)
5402 Each element of the chain has valid next, breakpoint_at,
5403 commands, FIXME??? fields. */
5406 bpstat_stop_status (struct address_space
*aspace
,
5407 CORE_ADDR bp_addr
, ptid_t ptid
,
5408 const struct target_waitstatus
*ws
)
5410 struct breakpoint
*b
= NULL
;
5411 struct bp_location
*bl
;
5412 struct bp_location
*loc
;
5413 /* First item of allocated bpstat's. */
5414 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5415 /* Pointer to the last thing in the chain currently. */
5418 int need_remove_insert
;
5421 /* First, build the bpstat chain with locations that explain a
5422 target stop, while being careful to not set the target running,
5423 as that may invalidate locations (in particular watchpoint
5424 locations are recreated). Resuming will happen here with
5425 breakpoint conditions or watchpoint expressions that include
5426 inferior function calls. */
5430 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5433 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5435 /* For hardware watchpoints, we look only at the first
5436 location. The watchpoint_check function will work on the
5437 entire expression, not the individual locations. For
5438 read watchpoints, the watchpoints_triggered function has
5439 checked all locations already. */
5440 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5443 if (!bl
->enabled
|| bl
->shlib_disabled
)
5446 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5449 /* Come here if it's a watchpoint, or if the break address
5452 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5455 /* Assume we stop. Should we find a watchpoint that is not
5456 actually triggered, or if the condition of the breakpoint
5457 evaluates as false, we'll reset 'stop' to 0. */
5461 /* If this is a scope breakpoint, mark the associated
5462 watchpoint as triggered so that we will handle the
5463 out-of-scope event. We'll get to the watchpoint next
5465 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5467 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5469 w
->watchpoint_triggered
= watch_triggered_yes
;
5474 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5476 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5478 bs
= bpstat_alloc (loc
, &bs_link
);
5479 /* For hits of moribund locations, we should just proceed. */
5482 bs
->print_it
= print_it_noop
;
5486 /* A bit of special processing for shlib breakpoints. We need to
5487 process solib loading here, so that the lists of loaded and
5488 unloaded libraries are correct before we handle "catch load" and
5490 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5492 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5494 handle_solib_event ();
5499 /* Now go through the locations that caused the target to stop, and
5500 check whether we're interested in reporting this stop to higher
5501 layers, or whether we should resume the target transparently. */
5505 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5510 b
= bs
->breakpoint_at
;
5511 b
->ops
->check_status (bs
);
5514 bpstat_check_breakpoint_conditions (bs
, ptid
);
5519 observer_notify_breakpoint_modified (b
);
5521 /* We will stop here. */
5522 if (b
->disposition
== disp_disable
)
5524 --(b
->enable_count
);
5525 if (b
->enable_count
<= 0
5526 && b
->enable_state
!= bp_permanent
)
5527 b
->enable_state
= bp_disabled
;
5532 bs
->commands
= b
->commands
;
5533 incref_counted_command_line (bs
->commands
);
5534 if (command_line_is_silent (bs
->commands
5535 ? bs
->commands
->commands
: NULL
))
5538 b
->ops
->after_condition_true (bs
);
5543 /* Print nothing for this entry if we don't stop or don't
5545 if (!bs
->stop
|| !bs
->print
)
5546 bs
->print_it
= print_it_noop
;
5549 /* If we aren't stopping, the value of some hardware watchpoint may
5550 not have changed, but the intermediate memory locations we are
5551 watching may have. Don't bother if we're stopping; this will get
5553 need_remove_insert
= 0;
5554 if (! bpstat_causes_stop (bs_head
))
5555 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5557 && bs
->breakpoint_at
5558 && is_hardware_watchpoint (bs
->breakpoint_at
))
5560 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5562 update_watchpoint (w
, 0 /* don't reparse. */);
5563 need_remove_insert
= 1;
5566 if (need_remove_insert
)
5567 update_global_location_list (1);
5568 else if (removed_any
)
5569 update_global_location_list (0);
5575 handle_jit_event (void)
5577 struct frame_info
*frame
;
5578 struct gdbarch
*gdbarch
;
5580 /* Switch terminal for any messages produced by
5581 breakpoint_re_set. */
5582 target_terminal_ours_for_output ();
5584 frame
= get_current_frame ();
5585 gdbarch
= get_frame_arch (frame
);
5587 jit_event_handler (gdbarch
);
5589 target_terminal_inferior ();
5592 /* Prepare WHAT final decision for infrun. */
5594 /* Decide what infrun needs to do with this bpstat. */
5597 bpstat_what (bpstat bs_head
)
5599 struct bpstat_what retval
;
5603 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5604 retval
.call_dummy
= STOP_NONE
;
5605 retval
.is_longjmp
= 0;
5607 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5609 /* Extract this BS's action. After processing each BS, we check
5610 if its action overrides all we've seem so far. */
5611 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5614 if (bs
->breakpoint_at
== NULL
)
5616 /* I suspect this can happen if it was a momentary
5617 breakpoint which has since been deleted. */
5621 bptype
= bs
->breakpoint_at
->type
;
5628 case bp_hardware_breakpoint
:
5631 case bp_shlib_event
:
5635 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5637 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5640 this_action
= BPSTAT_WHAT_SINGLE
;
5643 case bp_hardware_watchpoint
:
5644 case bp_read_watchpoint
:
5645 case bp_access_watchpoint
:
5649 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5651 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5655 /* There was a watchpoint, but we're not stopping.
5656 This requires no further action. */
5660 case bp_longjmp_call_dummy
:
5662 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5663 retval
.is_longjmp
= bptype
!= bp_exception
;
5665 case bp_longjmp_resume
:
5666 case bp_exception_resume
:
5667 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5668 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5670 case bp_step_resume
:
5672 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5675 /* It is for the wrong frame. */
5676 this_action
= BPSTAT_WHAT_SINGLE
;
5679 case bp_hp_step_resume
:
5681 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5684 /* It is for the wrong frame. */
5685 this_action
= BPSTAT_WHAT_SINGLE
;
5688 case bp_watchpoint_scope
:
5689 case bp_thread_event
:
5690 case bp_overlay_event
:
5691 case bp_longjmp_master
:
5692 case bp_std_terminate_master
:
5693 case bp_exception_master
:
5694 this_action
= BPSTAT_WHAT_SINGLE
;
5700 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5702 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5706 /* There was a catchpoint, but we're not stopping.
5707 This requires no further action. */
5712 this_action
= BPSTAT_WHAT_SINGLE
;
5715 /* Make sure the action is stop (silent or noisy),
5716 so infrun.c pops the dummy frame. */
5717 retval
.call_dummy
= STOP_STACK_DUMMY
;
5718 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5720 case bp_std_terminate
:
5721 /* Make sure the action is stop (silent or noisy),
5722 so infrun.c pops the dummy frame. */
5723 retval
.call_dummy
= STOP_STD_TERMINATE
;
5724 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5727 case bp_fast_tracepoint
:
5728 case bp_static_tracepoint
:
5729 /* Tracepoint hits should not be reported back to GDB, and
5730 if one got through somehow, it should have been filtered
5732 internal_error (__FILE__
, __LINE__
,
5733 _("bpstat_what: tracepoint encountered"));
5735 case bp_gnu_ifunc_resolver
:
5736 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5737 this_action
= BPSTAT_WHAT_SINGLE
;
5739 case bp_gnu_ifunc_resolver_return
:
5740 /* The breakpoint will be removed, execution will restart from the
5741 PC of the former breakpoint. */
5742 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5747 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5749 this_action
= BPSTAT_WHAT_SINGLE
;
5753 internal_error (__FILE__
, __LINE__
,
5754 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5757 retval
.main_action
= max (retval
.main_action
, this_action
);
5760 /* These operations may affect the bs->breakpoint_at state so they are
5761 delayed after MAIN_ACTION is decided above. */
5766 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5768 handle_jit_event ();
5771 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5773 struct breakpoint
*b
= bs
->breakpoint_at
;
5779 case bp_gnu_ifunc_resolver
:
5780 gnu_ifunc_resolver_stop (b
);
5782 case bp_gnu_ifunc_resolver_return
:
5783 gnu_ifunc_resolver_return_stop (b
);
5791 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5792 without hardware support). This isn't related to a specific bpstat,
5793 just to things like whether watchpoints are set. */
5796 bpstat_should_step (void)
5798 struct breakpoint
*b
;
5801 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5807 bpstat_causes_stop (bpstat bs
)
5809 for (; bs
!= NULL
; bs
= bs
->next
)
5818 /* Compute a string of spaces suitable to indent the next line
5819 so it starts at the position corresponding to the table column
5820 named COL_NAME in the currently active table of UIOUT. */
5823 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5825 static char wrap_indent
[80];
5826 int i
, total_width
, width
, align
;
5830 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5832 if (strcmp (text
, col_name
) == 0)
5834 gdb_assert (total_width
< sizeof wrap_indent
);
5835 memset (wrap_indent
, ' ', total_width
);
5836 wrap_indent
[total_width
] = 0;
5841 total_width
+= width
+ 1;
5847 /* Determine if the locations of this breakpoint will have their conditions
5848 evaluated by the target, host or a mix of both. Returns the following:
5850 "host": Host evals condition.
5851 "host or target": Host or Target evals condition.
5852 "target": Target evals condition.
5856 bp_condition_evaluator (struct breakpoint
*b
)
5858 struct bp_location
*bl
;
5859 char host_evals
= 0;
5860 char target_evals
= 0;
5865 if (!is_breakpoint (b
))
5868 if (gdb_evaluates_breakpoint_condition_p ()
5869 || !target_supports_evaluation_of_breakpoint_conditions ())
5870 return condition_evaluation_host
;
5872 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5874 if (bl
->cond_bytecode
)
5880 if (host_evals
&& target_evals
)
5881 return condition_evaluation_both
;
5882 else if (target_evals
)
5883 return condition_evaluation_target
;
5885 return condition_evaluation_host
;
5888 /* Determine the breakpoint location's condition evaluator. This is
5889 similar to bp_condition_evaluator, but for locations. */
5892 bp_location_condition_evaluator (struct bp_location
*bl
)
5894 if (bl
&& !is_breakpoint (bl
->owner
))
5897 if (gdb_evaluates_breakpoint_condition_p ()
5898 || !target_supports_evaluation_of_breakpoint_conditions ())
5899 return condition_evaluation_host
;
5901 if (bl
&& bl
->cond_bytecode
)
5902 return condition_evaluation_target
;
5904 return condition_evaluation_host
;
5907 /* Print the LOC location out of the list of B->LOC locations. */
5910 print_breakpoint_location (struct breakpoint
*b
,
5911 struct bp_location
*loc
)
5913 struct ui_out
*uiout
= current_uiout
;
5914 struct cleanup
*old_chain
= save_current_program_space ();
5916 if (loc
!= NULL
&& loc
->shlib_disabled
)
5920 set_current_program_space (loc
->pspace
);
5922 if (b
->display_canonical
)
5923 ui_out_field_string (uiout
, "what", b
->addr_string
);
5924 else if (loc
&& loc
->symtab
)
5927 = find_pc_sect_function (loc
->address
, loc
->section
);
5930 ui_out_text (uiout
, "in ");
5931 ui_out_field_string (uiout
, "func",
5932 SYMBOL_PRINT_NAME (sym
));
5933 ui_out_text (uiout
, " ");
5934 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5935 ui_out_text (uiout
, "at ");
5937 ui_out_field_string (uiout
, "file",
5938 symtab_to_filename_for_display (loc
->symtab
));
5939 ui_out_text (uiout
, ":");
5941 if (ui_out_is_mi_like_p (uiout
))
5942 ui_out_field_string (uiout
, "fullname",
5943 symtab_to_fullname (loc
->symtab
));
5945 ui_out_field_int (uiout
, "line", loc
->line_number
);
5949 struct ui_file
*stb
= mem_fileopen ();
5950 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5952 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5954 ui_out_field_stream (uiout
, "at", stb
);
5956 do_cleanups (stb_chain
);
5959 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5961 if (loc
&& is_breakpoint (b
)
5962 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5963 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5965 ui_out_text (uiout
, " (");
5966 ui_out_field_string (uiout
, "evaluated-by",
5967 bp_location_condition_evaluator (loc
));
5968 ui_out_text (uiout
, ")");
5971 do_cleanups (old_chain
);
5975 bptype_string (enum bptype type
)
5977 struct ep_type_description
5982 static struct ep_type_description bptypes
[] =
5984 {bp_none
, "?deleted?"},
5985 {bp_breakpoint
, "breakpoint"},
5986 {bp_hardware_breakpoint
, "hw breakpoint"},
5987 {bp_until
, "until"},
5988 {bp_finish
, "finish"},
5989 {bp_watchpoint
, "watchpoint"},
5990 {bp_hardware_watchpoint
, "hw watchpoint"},
5991 {bp_read_watchpoint
, "read watchpoint"},
5992 {bp_access_watchpoint
, "acc watchpoint"},
5993 {bp_longjmp
, "longjmp"},
5994 {bp_longjmp_resume
, "longjmp resume"},
5995 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5996 {bp_exception
, "exception"},
5997 {bp_exception_resume
, "exception resume"},
5998 {bp_step_resume
, "step resume"},
5999 {bp_hp_step_resume
, "high-priority step resume"},
6000 {bp_watchpoint_scope
, "watchpoint scope"},
6001 {bp_call_dummy
, "call dummy"},
6002 {bp_std_terminate
, "std::terminate"},
6003 {bp_shlib_event
, "shlib events"},
6004 {bp_thread_event
, "thread events"},
6005 {bp_overlay_event
, "overlay events"},
6006 {bp_longjmp_master
, "longjmp master"},
6007 {bp_std_terminate_master
, "std::terminate master"},
6008 {bp_exception_master
, "exception master"},
6009 {bp_catchpoint
, "catchpoint"},
6010 {bp_tracepoint
, "tracepoint"},
6011 {bp_fast_tracepoint
, "fast tracepoint"},
6012 {bp_static_tracepoint
, "static tracepoint"},
6013 {bp_dprintf
, "dprintf"},
6014 {bp_jit_event
, "jit events"},
6015 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6016 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6019 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6020 || ((int) type
!= bptypes
[(int) type
].type
))
6021 internal_error (__FILE__
, __LINE__
,
6022 _("bptypes table does not describe type #%d."),
6025 return bptypes
[(int) type
].description
;
6028 /* For MI, output a field named 'thread-groups' with a list as the value.
6029 For CLI, prefix the list with the string 'inf'. */
6032 output_thread_groups (struct ui_out
*uiout
,
6033 const char *field_name
,
6037 struct cleanup
*back_to
;
6038 int is_mi
= ui_out_is_mi_like_p (uiout
);
6042 /* For backward compatibility, don't display inferiors in CLI unless
6043 there are several. Always display them for MI. */
6044 if (!is_mi
&& mi_only
)
6047 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6049 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6055 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6056 ui_out_field_string (uiout
, NULL
, mi_group
);
6061 ui_out_text (uiout
, " inf ");
6063 ui_out_text (uiout
, ", ");
6065 ui_out_text (uiout
, plongest (inf
));
6069 do_cleanups (back_to
);
6072 /* Print B to gdb_stdout. */
6075 print_one_breakpoint_location (struct breakpoint
*b
,
6076 struct bp_location
*loc
,
6078 struct bp_location
**last_loc
,
6081 struct command_line
*l
;
6082 static char bpenables
[] = "nynny";
6084 struct ui_out
*uiout
= current_uiout
;
6085 int header_of_multiple
= 0;
6086 int part_of_multiple
= (loc
!= NULL
);
6087 struct value_print_options opts
;
6089 get_user_print_options (&opts
);
6091 gdb_assert (!loc
|| loc_number
!= 0);
6092 /* See comment in print_one_breakpoint concerning treatment of
6093 breakpoints with single disabled location. */
6096 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6097 header_of_multiple
= 1;
6105 if (part_of_multiple
)
6108 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6109 ui_out_field_string (uiout
, "number", formatted
);
6114 ui_out_field_int (uiout
, "number", b
->number
);
6119 if (part_of_multiple
)
6120 ui_out_field_skip (uiout
, "type");
6122 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6126 if (part_of_multiple
)
6127 ui_out_field_skip (uiout
, "disp");
6129 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6134 if (part_of_multiple
)
6135 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6137 ui_out_field_fmt (uiout
, "enabled", "%c",
6138 bpenables
[(int) b
->enable_state
]);
6139 ui_out_spaces (uiout
, 2);
6143 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6145 /* Although the print_one can possibly print all locations,
6146 calling it here is not likely to get any nice result. So,
6147 make sure there's just one location. */
6148 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6149 b
->ops
->print_one (b
, last_loc
);
6155 internal_error (__FILE__
, __LINE__
,
6156 _("print_one_breakpoint: bp_none encountered\n"));
6160 case bp_hardware_watchpoint
:
6161 case bp_read_watchpoint
:
6162 case bp_access_watchpoint
:
6164 struct watchpoint
*w
= (struct watchpoint
*) b
;
6166 /* Field 4, the address, is omitted (which makes the columns
6167 not line up too nicely with the headers, but the effect
6168 is relatively readable). */
6169 if (opts
.addressprint
)
6170 ui_out_field_skip (uiout
, "addr");
6172 ui_out_field_string (uiout
, "what", w
->exp_string
);
6177 case bp_hardware_breakpoint
:
6181 case bp_longjmp_resume
:
6182 case bp_longjmp_call_dummy
:
6184 case bp_exception_resume
:
6185 case bp_step_resume
:
6186 case bp_hp_step_resume
:
6187 case bp_watchpoint_scope
:
6189 case bp_std_terminate
:
6190 case bp_shlib_event
:
6191 case bp_thread_event
:
6192 case bp_overlay_event
:
6193 case bp_longjmp_master
:
6194 case bp_std_terminate_master
:
6195 case bp_exception_master
:
6197 case bp_fast_tracepoint
:
6198 case bp_static_tracepoint
:
6201 case bp_gnu_ifunc_resolver
:
6202 case bp_gnu_ifunc_resolver_return
:
6203 if (opts
.addressprint
)
6206 if (header_of_multiple
)
6207 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6208 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6209 ui_out_field_string (uiout
, "addr", "<PENDING>");
6211 ui_out_field_core_addr (uiout
, "addr",
6212 loc
->gdbarch
, loc
->address
);
6215 if (!header_of_multiple
)
6216 print_breakpoint_location (b
, loc
);
6223 if (loc
!= NULL
&& !header_of_multiple
)
6225 struct inferior
*inf
;
6226 VEC(int) *inf_num
= NULL
;
6231 if (inf
->pspace
== loc
->pspace
)
6232 VEC_safe_push (int, inf_num
, inf
->num
);
6235 /* For backward compatibility, don't display inferiors in CLI unless
6236 there are several. Always display for MI. */
6238 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6239 && (number_of_program_spaces () > 1
6240 || number_of_inferiors () > 1)
6241 /* LOC is for existing B, it cannot be in
6242 moribund_locations and thus having NULL OWNER. */
6243 && loc
->owner
->type
!= bp_catchpoint
))
6245 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6246 VEC_free (int, inf_num
);
6249 if (!part_of_multiple
)
6251 if (b
->thread
!= -1)
6253 /* FIXME: This seems to be redundant and lost here; see the
6254 "stop only in" line a little further down. */
6255 ui_out_text (uiout
, " thread ");
6256 ui_out_field_int (uiout
, "thread", b
->thread
);
6258 else if (b
->task
!= 0)
6260 ui_out_text (uiout
, " task ");
6261 ui_out_field_int (uiout
, "task", b
->task
);
6265 ui_out_text (uiout
, "\n");
6267 if (!part_of_multiple
)
6268 b
->ops
->print_one_detail (b
, uiout
);
6270 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6273 ui_out_text (uiout
, "\tstop only in stack frame at ");
6274 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6276 ui_out_field_core_addr (uiout
, "frame",
6277 b
->gdbarch
, b
->frame_id
.stack_addr
);
6278 ui_out_text (uiout
, "\n");
6281 if (!part_of_multiple
&& b
->cond_string
)
6284 if (is_tracepoint (b
))
6285 ui_out_text (uiout
, "\ttrace only if ");
6287 ui_out_text (uiout
, "\tstop only if ");
6288 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6290 /* Print whether the target is doing the breakpoint's condition
6291 evaluation. If GDB is doing the evaluation, don't print anything. */
6292 if (is_breakpoint (b
)
6293 && breakpoint_condition_evaluation_mode ()
6294 == condition_evaluation_target
)
6296 ui_out_text (uiout
, " (");
6297 ui_out_field_string (uiout
, "evaluated-by",
6298 bp_condition_evaluator (b
));
6299 ui_out_text (uiout
, " evals)");
6301 ui_out_text (uiout
, "\n");
6304 if (!part_of_multiple
&& b
->thread
!= -1)
6306 /* FIXME should make an annotation for this. */
6307 ui_out_text (uiout
, "\tstop only in thread ");
6308 ui_out_field_int (uiout
, "thread", b
->thread
);
6309 ui_out_text (uiout
, "\n");
6312 if (!part_of_multiple
)
6316 /* FIXME should make an annotation for this. */
6317 if (is_catchpoint (b
))
6318 ui_out_text (uiout
, "\tcatchpoint");
6319 else if (is_tracepoint (b
))
6320 ui_out_text (uiout
, "\ttracepoint");
6322 ui_out_text (uiout
, "\tbreakpoint");
6323 ui_out_text (uiout
, " already hit ");
6324 ui_out_field_int (uiout
, "times", b
->hit_count
);
6325 if (b
->hit_count
== 1)
6326 ui_out_text (uiout
, " time\n");
6328 ui_out_text (uiout
, " times\n");
6332 /* Output the count also if it is zero, but only if this is mi. */
6333 if (ui_out_is_mi_like_p (uiout
))
6334 ui_out_field_int (uiout
, "times", b
->hit_count
);
6338 if (!part_of_multiple
&& b
->ignore_count
)
6341 ui_out_text (uiout
, "\tignore next ");
6342 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6343 ui_out_text (uiout
, " hits\n");
6346 /* Note that an enable count of 1 corresponds to "enable once"
6347 behavior, which is reported by the combination of enablement and
6348 disposition, so we don't need to mention it here. */
6349 if (!part_of_multiple
&& b
->enable_count
> 1)
6352 ui_out_text (uiout
, "\tdisable after ");
6353 /* Tweak the wording to clarify that ignore and enable counts
6354 are distinct, and have additive effect. */
6355 if (b
->ignore_count
)
6356 ui_out_text (uiout
, "additional ");
6358 ui_out_text (uiout
, "next ");
6359 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6360 ui_out_text (uiout
, " hits\n");
6363 if (!part_of_multiple
&& is_tracepoint (b
))
6365 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6367 if (tp
->traceframe_usage
)
6369 ui_out_text (uiout
, "\ttrace buffer usage ");
6370 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6371 ui_out_text (uiout
, " bytes\n");
6375 l
= b
->commands
? b
->commands
->commands
: NULL
;
6376 if (!part_of_multiple
&& l
)
6378 struct cleanup
*script_chain
;
6381 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6382 print_command_lines (uiout
, l
, 4);
6383 do_cleanups (script_chain
);
6386 if (is_tracepoint (b
))
6388 struct tracepoint
*t
= (struct tracepoint
*) b
;
6390 if (!part_of_multiple
&& t
->pass_count
)
6392 annotate_field (10);
6393 ui_out_text (uiout
, "\tpass count ");
6394 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6395 ui_out_text (uiout
, " \n");
6398 /* Don't display it when tracepoint or tracepoint location is
6400 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6402 annotate_field (11);
6404 if (ui_out_is_mi_like_p (uiout
))
6405 ui_out_field_string (uiout
, "installed",
6406 loc
->inserted
? "y" : "n");
6410 ui_out_text (uiout
, "\t");
6412 ui_out_text (uiout
, "\tnot ");
6413 ui_out_text (uiout
, "installed on target\n");
6418 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6420 if (is_watchpoint (b
))
6422 struct watchpoint
*w
= (struct watchpoint
*) b
;
6424 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6426 else if (b
->addr_string
)
6427 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6432 print_one_breakpoint (struct breakpoint
*b
,
6433 struct bp_location
**last_loc
,
6436 struct cleanup
*bkpt_chain
;
6437 struct ui_out
*uiout
= current_uiout
;
6439 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6441 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6442 do_cleanups (bkpt_chain
);
6444 /* If this breakpoint has custom print function,
6445 it's already printed. Otherwise, print individual
6446 locations, if any. */
6447 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6449 /* If breakpoint has a single location that is disabled, we
6450 print it as if it had several locations, since otherwise it's
6451 hard to represent "breakpoint enabled, location disabled"
6454 Note that while hardware watchpoints have several locations
6455 internally, that's not a property exposed to user. */
6457 && !is_hardware_watchpoint (b
)
6458 && (b
->loc
->next
|| !b
->loc
->enabled
))
6460 struct bp_location
*loc
;
6463 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6465 struct cleanup
*inner2
=
6466 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6467 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6468 do_cleanups (inner2
);
6475 breakpoint_address_bits (struct breakpoint
*b
)
6477 int print_address_bits
= 0;
6478 struct bp_location
*loc
;
6480 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6484 /* Software watchpoints that aren't watching memory don't have
6485 an address to print. */
6486 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6489 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6490 if (addr_bit
> print_address_bits
)
6491 print_address_bits
= addr_bit
;
6494 return print_address_bits
;
6497 struct captured_breakpoint_query_args
6503 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6505 struct captured_breakpoint_query_args
*args
= data
;
6506 struct breakpoint
*b
;
6507 struct bp_location
*dummy_loc
= NULL
;
6511 if (args
->bnum
== b
->number
)
6513 print_one_breakpoint (b
, &dummy_loc
, 0);
6521 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6522 char **error_message
)
6524 struct captured_breakpoint_query_args args
;
6527 /* For the moment we don't trust print_one_breakpoint() to not throw
6529 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6530 error_message
, RETURN_MASK_ALL
) < 0)
6536 /* Return true if this breakpoint was set by the user, false if it is
6537 internal or momentary. */
6540 user_breakpoint_p (struct breakpoint
*b
)
6542 return b
->number
> 0;
6545 /* Print information on user settable breakpoint (watchpoint, etc)
6546 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6547 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6548 FILTER is non-NULL, call it on each breakpoint and only include the
6549 ones for which it returns non-zero. Return the total number of
6550 breakpoints listed. */
6553 breakpoint_1 (char *args
, int allflag
,
6554 int (*filter
) (const struct breakpoint
*))
6556 struct breakpoint
*b
;
6557 struct bp_location
*last_loc
= NULL
;
6558 int nr_printable_breakpoints
;
6559 struct cleanup
*bkpttbl_chain
;
6560 struct value_print_options opts
;
6561 int print_address_bits
= 0;
6562 int print_type_col_width
= 14;
6563 struct ui_out
*uiout
= current_uiout
;
6565 get_user_print_options (&opts
);
6567 /* Compute the number of rows in the table, as well as the size
6568 required for address fields. */
6569 nr_printable_breakpoints
= 0;
6572 /* If we have a filter, only list the breakpoints it accepts. */
6573 if (filter
&& !filter (b
))
6576 /* If we have an "args" string, it is a list of breakpoints to
6577 accept. Skip the others. */
6578 if (args
!= NULL
&& *args
!= '\0')
6580 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6582 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6586 if (allflag
|| user_breakpoint_p (b
))
6588 int addr_bit
, type_len
;
6590 addr_bit
= breakpoint_address_bits (b
);
6591 if (addr_bit
> print_address_bits
)
6592 print_address_bits
= addr_bit
;
6594 type_len
= strlen (bptype_string (b
->type
));
6595 if (type_len
> print_type_col_width
)
6596 print_type_col_width
= type_len
;
6598 nr_printable_breakpoints
++;
6602 if (opts
.addressprint
)
6604 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6605 nr_printable_breakpoints
,
6609 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6610 nr_printable_breakpoints
,
6613 if (nr_printable_breakpoints
> 0)
6614 annotate_breakpoints_headers ();
6615 if (nr_printable_breakpoints
> 0)
6617 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6618 if (nr_printable_breakpoints
> 0)
6620 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6621 "type", "Type"); /* 2 */
6622 if (nr_printable_breakpoints
> 0)
6624 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6625 if (nr_printable_breakpoints
> 0)
6627 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6628 if (opts
.addressprint
)
6630 if (nr_printable_breakpoints
> 0)
6632 if (print_address_bits
<= 32)
6633 ui_out_table_header (uiout
, 10, ui_left
,
6634 "addr", "Address"); /* 5 */
6636 ui_out_table_header (uiout
, 18, ui_left
,
6637 "addr", "Address"); /* 5 */
6639 if (nr_printable_breakpoints
> 0)
6641 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6642 ui_out_table_body (uiout
);
6643 if (nr_printable_breakpoints
> 0)
6644 annotate_breakpoints_table ();
6649 /* If we have a filter, only list the breakpoints it accepts. */
6650 if (filter
&& !filter (b
))
6653 /* If we have an "args" string, it is a list of breakpoints to
6654 accept. Skip the others. */
6656 if (args
!= NULL
&& *args
!= '\0')
6658 if (allflag
) /* maintenance info breakpoint */
6660 if (parse_and_eval_long (args
) != b
->number
)
6663 else /* all others */
6665 if (!number_is_in_list (args
, b
->number
))
6669 /* We only print out user settable breakpoints unless the
6671 if (allflag
|| user_breakpoint_p (b
))
6672 print_one_breakpoint (b
, &last_loc
, allflag
);
6675 do_cleanups (bkpttbl_chain
);
6677 if (nr_printable_breakpoints
== 0)
6679 /* If there's a filter, let the caller decide how to report
6683 if (args
== NULL
|| *args
== '\0')
6684 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6686 ui_out_message (uiout
, 0,
6687 "No breakpoint or watchpoint matching '%s'.\n",
6693 if (last_loc
&& !server_command
)
6694 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6697 /* FIXME? Should this be moved up so that it is only called when
6698 there have been breakpoints? */
6699 annotate_breakpoints_table_end ();
6701 return nr_printable_breakpoints
;
6704 /* Display the value of default-collect in a way that is generally
6705 compatible with the breakpoint list. */
6708 default_collect_info (void)
6710 struct ui_out
*uiout
= current_uiout
;
6712 /* If it has no value (which is frequently the case), say nothing; a
6713 message like "No default-collect." gets in user's face when it's
6715 if (!*default_collect
)
6718 /* The following phrase lines up nicely with per-tracepoint collect
6720 ui_out_text (uiout
, "default collect ");
6721 ui_out_field_string (uiout
, "default-collect", default_collect
);
6722 ui_out_text (uiout
, " \n");
6726 breakpoints_info (char *args
, int from_tty
)
6728 breakpoint_1 (args
, 0, NULL
);
6730 default_collect_info ();
6734 watchpoints_info (char *args
, int from_tty
)
6736 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6737 struct ui_out
*uiout
= current_uiout
;
6739 if (num_printed
== 0)
6741 if (args
== NULL
|| *args
== '\0')
6742 ui_out_message (uiout
, 0, "No watchpoints.\n");
6744 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6749 maintenance_info_breakpoints (char *args
, int from_tty
)
6751 breakpoint_1 (args
, 1, NULL
);
6753 default_collect_info ();
6757 breakpoint_has_pc (struct breakpoint
*b
,
6758 struct program_space
*pspace
,
6759 CORE_ADDR pc
, struct obj_section
*section
)
6761 struct bp_location
*bl
= b
->loc
;
6763 for (; bl
; bl
= bl
->next
)
6765 if (bl
->pspace
== pspace
6766 && bl
->address
== pc
6767 && (!overlay_debugging
|| bl
->section
== section
))
6773 /* Print a message describing any user-breakpoints set at PC. This
6774 concerns with logical breakpoints, so we match program spaces, not
6778 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6779 struct program_space
*pspace
, CORE_ADDR pc
,
6780 struct obj_section
*section
, int thread
)
6783 struct breakpoint
*b
;
6786 others
+= (user_breakpoint_p (b
)
6787 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6791 printf_filtered (_("Note: breakpoint "));
6792 else /* if (others == ???) */
6793 printf_filtered (_("Note: breakpoints "));
6795 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6798 printf_filtered ("%d", b
->number
);
6799 if (b
->thread
== -1 && thread
!= -1)
6800 printf_filtered (" (all threads)");
6801 else if (b
->thread
!= -1)
6802 printf_filtered (" (thread %d)", b
->thread
);
6803 printf_filtered ("%s%s ",
6804 ((b
->enable_state
== bp_disabled
6805 || b
->enable_state
== bp_call_disabled
)
6807 : b
->enable_state
== bp_permanent
6811 : ((others
== 1) ? " and" : ""));
6813 printf_filtered (_("also set at pc "));
6814 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6815 printf_filtered (".\n");
6820 /* Return true iff it is meaningful to use the address member of
6821 BPT. For some breakpoint types, the address member is irrelevant
6822 and it makes no sense to attempt to compare it to other addresses
6823 (or use it for any other purpose either).
6825 More specifically, each of the following breakpoint types will
6826 always have a zero valued address and we don't want to mark
6827 breakpoints of any of these types to be a duplicate of an actual
6828 breakpoint at address zero:
6836 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6838 enum bptype type
= bpt
->type
;
6840 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6843 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6844 true if LOC1 and LOC2 represent the same watchpoint location. */
6847 watchpoint_locations_match (struct bp_location
*loc1
,
6848 struct bp_location
*loc2
)
6850 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6851 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6853 /* Both of them must exist. */
6854 gdb_assert (w1
!= NULL
);
6855 gdb_assert (w2
!= NULL
);
6857 /* If the target can evaluate the condition expression in hardware,
6858 then we we need to insert both watchpoints even if they are at
6859 the same place. Otherwise the watchpoint will only trigger when
6860 the condition of whichever watchpoint was inserted evaluates to
6861 true, not giving a chance for GDB to check the condition of the
6862 other watchpoint. */
6864 && target_can_accel_watchpoint_condition (loc1
->address
,
6866 loc1
->watchpoint_type
,
6869 && target_can_accel_watchpoint_condition (loc2
->address
,
6871 loc2
->watchpoint_type
,
6875 /* Note that this checks the owner's type, not the location's. In
6876 case the target does not support read watchpoints, but does
6877 support access watchpoints, we'll have bp_read_watchpoint
6878 watchpoints with hw_access locations. Those should be considered
6879 duplicates of hw_read locations. The hw_read locations will
6880 become hw_access locations later. */
6881 return (loc1
->owner
->type
== loc2
->owner
->type
6882 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6883 && loc1
->address
== loc2
->address
6884 && loc1
->length
== loc2
->length
);
6887 /* See breakpoint.h. */
6890 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6891 struct address_space
*aspace2
, CORE_ADDR addr2
)
6893 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6894 || aspace1
== aspace2
)
6898 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6899 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6900 matches ASPACE2. On targets that have global breakpoints, the address
6901 space doesn't really matter. */
6904 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6905 int len1
, struct address_space
*aspace2
,
6908 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6909 || aspace1
== aspace2
)
6910 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6913 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6914 a ranged breakpoint. In most targets, a match happens only if ASPACE
6915 matches the breakpoint's address space. On targets that have global
6916 breakpoints, the address space doesn't really matter. */
6919 breakpoint_location_address_match (struct bp_location
*bl
,
6920 struct address_space
*aspace
,
6923 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6926 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6927 bl
->address
, bl
->length
,
6931 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6932 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6933 true, otherwise returns false. */
6936 tracepoint_locations_match (struct bp_location
*loc1
,
6937 struct bp_location
*loc2
)
6939 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6940 /* Since tracepoint locations are never duplicated with others', tracepoint
6941 locations at the same address of different tracepoints are regarded as
6942 different locations. */
6943 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6948 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6949 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6950 represent the same location. */
6953 breakpoint_locations_match (struct bp_location
*loc1
,
6954 struct bp_location
*loc2
)
6956 int hw_point1
, hw_point2
;
6958 /* Both of them must not be in moribund_locations. */
6959 gdb_assert (loc1
->owner
!= NULL
);
6960 gdb_assert (loc2
->owner
!= NULL
);
6962 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6963 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6965 if (hw_point1
!= hw_point2
)
6968 return watchpoint_locations_match (loc1
, loc2
);
6969 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6970 return tracepoint_locations_match (loc1
, loc2
);
6972 /* We compare bp_location.length in order to cover ranged breakpoints. */
6973 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6974 loc2
->pspace
->aspace
, loc2
->address
)
6975 && loc1
->length
== loc2
->length
);
6979 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6980 int bnum
, int have_bnum
)
6982 /* The longest string possibly returned by hex_string_custom
6983 is 50 chars. These must be at least that big for safety. */
6987 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6988 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6990 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6991 bnum
, astr1
, astr2
);
6993 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6996 /* Adjust a breakpoint's address to account for architectural
6997 constraints on breakpoint placement. Return the adjusted address.
6998 Note: Very few targets require this kind of adjustment. For most
6999 targets, this function is simply the identity function. */
7002 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7003 CORE_ADDR bpaddr
, enum bptype bptype
)
7005 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7007 /* Very few targets need any kind of breakpoint adjustment. */
7010 else if (bptype
== bp_watchpoint
7011 || bptype
== bp_hardware_watchpoint
7012 || bptype
== bp_read_watchpoint
7013 || bptype
== bp_access_watchpoint
7014 || bptype
== bp_catchpoint
)
7016 /* Watchpoints and the various bp_catch_* eventpoints should not
7017 have their addresses modified. */
7022 CORE_ADDR adjusted_bpaddr
;
7024 /* Some targets have architectural constraints on the placement
7025 of breakpoint instructions. Obtain the adjusted address. */
7026 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7028 /* An adjusted breakpoint address can significantly alter
7029 a user's expectations. Print a warning if an adjustment
7031 if (adjusted_bpaddr
!= bpaddr
)
7032 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7034 return adjusted_bpaddr
;
7039 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7040 struct breakpoint
*owner
)
7042 memset (loc
, 0, sizeof (*loc
));
7044 gdb_assert (ops
!= NULL
);
7049 loc
->cond_bytecode
= NULL
;
7050 loc
->shlib_disabled
= 0;
7053 switch (owner
->type
)
7059 case bp_longjmp_resume
:
7060 case bp_longjmp_call_dummy
:
7062 case bp_exception_resume
:
7063 case bp_step_resume
:
7064 case bp_hp_step_resume
:
7065 case bp_watchpoint_scope
:
7067 case bp_std_terminate
:
7068 case bp_shlib_event
:
7069 case bp_thread_event
:
7070 case bp_overlay_event
:
7072 case bp_longjmp_master
:
7073 case bp_std_terminate_master
:
7074 case bp_exception_master
:
7075 case bp_gnu_ifunc_resolver
:
7076 case bp_gnu_ifunc_resolver_return
:
7078 loc
->loc_type
= bp_loc_software_breakpoint
;
7079 mark_breakpoint_location_modified (loc
);
7081 case bp_hardware_breakpoint
:
7082 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7083 mark_breakpoint_location_modified (loc
);
7085 case bp_hardware_watchpoint
:
7086 case bp_read_watchpoint
:
7087 case bp_access_watchpoint
:
7088 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7093 case bp_fast_tracepoint
:
7094 case bp_static_tracepoint
:
7095 loc
->loc_type
= bp_loc_other
;
7098 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7104 /* Allocate a struct bp_location. */
7106 static struct bp_location
*
7107 allocate_bp_location (struct breakpoint
*bpt
)
7109 return bpt
->ops
->allocate_location (bpt
);
7113 free_bp_location (struct bp_location
*loc
)
7115 loc
->ops
->dtor (loc
);
7119 /* Increment reference count. */
7122 incref_bp_location (struct bp_location
*bl
)
7127 /* Decrement reference count. If the reference count reaches 0,
7128 destroy the bp_location. Sets *BLP to NULL. */
7131 decref_bp_location (struct bp_location
**blp
)
7133 gdb_assert ((*blp
)->refc
> 0);
7135 if (--(*blp
)->refc
== 0)
7136 free_bp_location (*blp
);
7140 /* Add breakpoint B at the end of the global breakpoint chain. */
7143 add_to_breakpoint_chain (struct breakpoint
*b
)
7145 struct breakpoint
*b1
;
7147 /* Add this breakpoint to the end of the chain so that a list of
7148 breakpoints will come out in order of increasing numbers. */
7150 b1
= breakpoint_chain
;
7152 breakpoint_chain
= b
;
7161 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7164 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7165 struct gdbarch
*gdbarch
,
7167 const struct breakpoint_ops
*ops
)
7169 memset (b
, 0, sizeof (*b
));
7171 gdb_assert (ops
!= NULL
);
7175 b
->gdbarch
= gdbarch
;
7176 b
->language
= current_language
->la_language
;
7177 b
->input_radix
= input_radix
;
7179 b
->enable_state
= bp_enabled
;
7182 b
->ignore_count
= 0;
7184 b
->frame_id
= null_frame_id
;
7185 b
->condition_not_parsed
= 0;
7186 b
->py_bp_object
= NULL
;
7187 b
->related_breakpoint
= b
;
7190 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7191 that has type BPTYPE and has no locations as yet. */
7193 static struct breakpoint
*
7194 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7196 const struct breakpoint_ops
*ops
)
7198 struct breakpoint
*b
= XNEW (struct breakpoint
);
7200 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7201 add_to_breakpoint_chain (b
);
7205 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7206 resolutions should be made as the user specified the location explicitly
7210 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7212 gdb_assert (loc
->owner
!= NULL
);
7214 if (loc
->owner
->type
== bp_breakpoint
7215 || loc
->owner
->type
== bp_hardware_breakpoint
7216 || is_tracepoint (loc
->owner
))
7219 const char *function_name
;
7220 CORE_ADDR func_addr
;
7222 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7223 &func_addr
, NULL
, &is_gnu_ifunc
);
7225 if (is_gnu_ifunc
&& !explicit_loc
)
7227 struct breakpoint
*b
= loc
->owner
;
7229 gdb_assert (loc
->pspace
== current_program_space
);
7230 if (gnu_ifunc_resolve_name (function_name
,
7231 &loc
->requested_address
))
7233 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7234 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7235 loc
->requested_address
,
7238 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7239 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7241 /* Create only the whole new breakpoint of this type but do not
7242 mess more complicated breakpoints with multiple locations. */
7243 b
->type
= bp_gnu_ifunc_resolver
;
7244 /* Remember the resolver's address for use by the return
7246 loc
->related_address
= func_addr
;
7251 loc
->function_name
= xstrdup (function_name
);
7255 /* Attempt to determine architecture of location identified by SAL. */
7257 get_sal_arch (struct symtab_and_line sal
)
7260 return get_objfile_arch (sal
.section
->objfile
);
7262 return get_objfile_arch (sal
.symtab
->objfile
);
7267 /* Low level routine for partially initializing a breakpoint of type
7268 BPTYPE. The newly created breakpoint's address, section, source
7269 file name, and line number are provided by SAL.
7271 It is expected that the caller will complete the initialization of
7272 the newly created breakpoint struct as well as output any status
7273 information regarding the creation of a new breakpoint. */
7276 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7277 struct symtab_and_line sal
, enum bptype bptype
,
7278 const struct breakpoint_ops
*ops
)
7280 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7282 add_location_to_breakpoint (b
, &sal
);
7284 if (bptype
!= bp_catchpoint
)
7285 gdb_assert (sal
.pspace
!= NULL
);
7287 /* Store the program space that was used to set the breakpoint,
7288 except for ordinary breakpoints, which are independent of the
7290 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7291 b
->pspace
= sal
.pspace
;
7294 /* set_raw_breakpoint is a low level routine for allocating and
7295 partially initializing a breakpoint of type BPTYPE. The newly
7296 created breakpoint's address, section, source file name, and line
7297 number are provided by SAL. The newly created and partially
7298 initialized breakpoint is added to the breakpoint chain and
7299 is also returned as the value of this function.
7301 It is expected that the caller will complete the initialization of
7302 the newly created breakpoint struct as well as output any status
7303 information regarding the creation of a new breakpoint. In
7304 particular, set_raw_breakpoint does NOT set the breakpoint
7305 number! Care should be taken to not allow an error to occur
7306 prior to completing the initialization of the breakpoint. If this
7307 should happen, a bogus breakpoint will be left on the chain. */
7310 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7311 struct symtab_and_line sal
, enum bptype bptype
,
7312 const struct breakpoint_ops
*ops
)
7314 struct breakpoint
*b
= XNEW (struct breakpoint
);
7316 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7317 add_to_breakpoint_chain (b
);
7322 /* Note that the breakpoint object B describes a permanent breakpoint
7323 instruction, hard-wired into the inferior's code. */
7325 make_breakpoint_permanent (struct breakpoint
*b
)
7327 struct bp_location
*bl
;
7329 b
->enable_state
= bp_permanent
;
7331 /* By definition, permanent breakpoints are already present in the
7332 code. Mark all locations as inserted. For now,
7333 make_breakpoint_permanent is called in just one place, so it's
7334 hard to say if it's reasonable to have permanent breakpoint with
7335 multiple locations or not, but it's easy to implement. */
7336 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7340 /* Call this routine when stepping and nexting to enable a breakpoint
7341 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7342 initiated the operation. */
7345 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7347 struct breakpoint
*b
, *b_tmp
;
7348 int thread
= tp
->num
;
7350 /* To avoid having to rescan all objfile symbols at every step,
7351 we maintain a list of continually-inserted but always disabled
7352 longjmp "master" breakpoints. Here, we simply create momentary
7353 clones of those and enable them for the requested thread. */
7354 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7355 if (b
->pspace
== current_program_space
7356 && (b
->type
== bp_longjmp_master
7357 || b
->type
== bp_exception_master
))
7359 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7360 struct breakpoint
*clone
;
7362 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7363 after their removal. */
7364 clone
= momentary_breakpoint_from_master (b
, type
,
7365 &longjmp_breakpoint_ops
);
7366 clone
->thread
= thread
;
7369 tp
->initiating_frame
= frame
;
7372 /* Delete all longjmp breakpoints from THREAD. */
7374 delete_longjmp_breakpoint (int thread
)
7376 struct breakpoint
*b
, *b_tmp
;
7378 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7379 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7381 if (b
->thread
== thread
)
7382 delete_breakpoint (b
);
7387 delete_longjmp_breakpoint_at_next_stop (int thread
)
7389 struct breakpoint
*b
, *b_tmp
;
7391 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7392 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7394 if (b
->thread
== thread
)
7395 b
->disposition
= disp_del_at_next_stop
;
7399 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7400 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7401 pointer to any of them. Return NULL if this system cannot place longjmp
7405 set_longjmp_breakpoint_for_call_dummy (void)
7407 struct breakpoint
*b
, *retval
= NULL
;
7410 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7412 struct breakpoint
*new_b
;
7414 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7415 &momentary_breakpoint_ops
);
7416 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7418 /* Link NEW_B into the chain of RETVAL breakpoints. */
7420 gdb_assert (new_b
->related_breakpoint
== new_b
);
7423 new_b
->related_breakpoint
= retval
;
7424 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7425 retval
= retval
->related_breakpoint
;
7426 retval
->related_breakpoint
= new_b
;
7432 /* Verify all existing dummy frames and their associated breakpoints for
7433 THREAD. Remove those which can no longer be found in the current frame
7436 You should call this function only at places where it is safe to currently
7437 unwind the whole stack. Failed stack unwind would discard live dummy
7441 check_longjmp_breakpoint_for_call_dummy (int thread
)
7443 struct breakpoint
*b
, *b_tmp
;
7445 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7446 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
7448 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7450 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7451 dummy_b
= dummy_b
->related_breakpoint
;
7452 if (dummy_b
->type
!= bp_call_dummy
7453 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7456 dummy_frame_discard (dummy_b
->frame_id
);
7458 while (b
->related_breakpoint
!= b
)
7460 if (b_tmp
== b
->related_breakpoint
)
7461 b_tmp
= b
->related_breakpoint
->next
;
7462 delete_breakpoint (b
->related_breakpoint
);
7464 delete_breakpoint (b
);
7469 enable_overlay_breakpoints (void)
7471 struct breakpoint
*b
;
7474 if (b
->type
== bp_overlay_event
)
7476 b
->enable_state
= bp_enabled
;
7477 update_global_location_list (1);
7478 overlay_events_enabled
= 1;
7483 disable_overlay_breakpoints (void)
7485 struct breakpoint
*b
;
7488 if (b
->type
== bp_overlay_event
)
7490 b
->enable_state
= bp_disabled
;
7491 update_global_location_list (0);
7492 overlay_events_enabled
= 0;
7496 /* Set an active std::terminate breakpoint for each std::terminate
7497 master breakpoint. */
7499 set_std_terminate_breakpoint (void)
7501 struct breakpoint
*b
, *b_tmp
;
7503 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7504 if (b
->pspace
== current_program_space
7505 && b
->type
== bp_std_terminate_master
)
7507 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7508 &momentary_breakpoint_ops
);
7512 /* Delete all the std::terminate breakpoints. */
7514 delete_std_terminate_breakpoint (void)
7516 struct breakpoint
*b
, *b_tmp
;
7518 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7519 if (b
->type
== bp_std_terminate
)
7520 delete_breakpoint (b
);
7524 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7526 struct breakpoint
*b
;
7528 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7529 &internal_breakpoint_ops
);
7531 b
->enable_state
= bp_enabled
;
7532 /* addr_string has to be used or breakpoint_re_set will delete me. */
7534 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7536 update_global_location_list_nothrow (1);
7542 remove_thread_event_breakpoints (void)
7544 struct breakpoint
*b
, *b_tmp
;
7546 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7547 if (b
->type
== bp_thread_event
7548 && b
->loc
->pspace
== current_program_space
)
7549 delete_breakpoint (b
);
7552 struct lang_and_radix
7558 /* Create a breakpoint for JIT code registration and unregistration. */
7561 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7563 struct breakpoint
*b
;
7565 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7566 &internal_breakpoint_ops
);
7567 update_global_location_list_nothrow (1);
7571 /* Remove JIT code registration and unregistration breakpoint(s). */
7574 remove_jit_event_breakpoints (void)
7576 struct breakpoint
*b
, *b_tmp
;
7578 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7579 if (b
->type
== bp_jit_event
7580 && b
->loc
->pspace
== current_program_space
)
7581 delete_breakpoint (b
);
7585 remove_solib_event_breakpoints (void)
7587 struct breakpoint
*b
, *b_tmp
;
7589 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7590 if (b
->type
== bp_shlib_event
7591 && b
->loc
->pspace
== current_program_space
)
7592 delete_breakpoint (b
);
7596 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7598 struct breakpoint
*b
;
7600 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7601 &internal_breakpoint_ops
);
7602 update_global_location_list_nothrow (1);
7606 /* Disable any breakpoints that are on code in shared libraries. Only
7607 apply to enabled breakpoints, disabled ones can just stay disabled. */
7610 disable_breakpoints_in_shlibs (void)
7612 struct bp_location
*loc
, **locp_tmp
;
7614 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7616 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7617 struct breakpoint
*b
= loc
->owner
;
7619 /* We apply the check to all breakpoints, including disabled for
7620 those with loc->duplicate set. This is so that when breakpoint
7621 becomes enabled, or the duplicate is removed, gdb will try to
7622 insert all breakpoints. If we don't set shlib_disabled here,
7623 we'll try to insert those breakpoints and fail. */
7624 if (((b
->type
== bp_breakpoint
)
7625 || (b
->type
== bp_jit_event
)
7626 || (b
->type
== bp_hardware_breakpoint
)
7627 || (is_tracepoint (b
)))
7628 && loc
->pspace
== current_program_space
7629 && !loc
->shlib_disabled
7630 && solib_name_from_address (loc
->pspace
, loc
->address
)
7633 loc
->shlib_disabled
= 1;
7638 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7639 notification of unloaded_shlib. Only apply to enabled breakpoints,
7640 disabled ones can just stay disabled. */
7643 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7645 struct bp_location
*loc
, **locp_tmp
;
7646 int disabled_shlib_breaks
= 0;
7648 /* SunOS a.out shared libraries are always mapped, so do not
7649 disable breakpoints; they will only be reported as unloaded
7650 through clear_solib when GDB discards its shared library
7651 list. See clear_solib for more information. */
7652 if (exec_bfd
!= NULL
7653 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7656 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7658 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7659 struct breakpoint
*b
= loc
->owner
;
7661 if (solib
->pspace
== loc
->pspace
7662 && !loc
->shlib_disabled
7663 && (((b
->type
== bp_breakpoint
7664 || b
->type
== bp_jit_event
7665 || b
->type
== bp_hardware_breakpoint
)
7666 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7667 || loc
->loc_type
== bp_loc_software_breakpoint
))
7668 || is_tracepoint (b
))
7669 && solib_contains_address_p (solib
, loc
->address
))
7671 loc
->shlib_disabled
= 1;
7672 /* At this point, we cannot rely on remove_breakpoint
7673 succeeding so we must mark the breakpoint as not inserted
7674 to prevent future errors occurring in remove_breakpoints. */
7677 /* This may cause duplicate notifications for the same breakpoint. */
7678 observer_notify_breakpoint_modified (b
);
7680 if (!disabled_shlib_breaks
)
7682 target_terminal_ours_for_output ();
7683 warning (_("Temporarily disabling breakpoints "
7684 "for unloaded shared library \"%s\""),
7687 disabled_shlib_breaks
= 1;
7692 /* Disable any breakpoints and tracepoints in OBJFILE upon
7693 notification of free_objfile. Only apply to enabled breakpoints,
7694 disabled ones can just stay disabled. */
7697 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7699 struct breakpoint
*b
;
7701 if (objfile
== NULL
)
7704 /* OBJF_USERLOADED are dynamic modules manually managed by the user
7705 with add-symbol-file/remove-symbol-file. Similarly to how
7706 breakpoints in shared libraries are handled in response to
7707 "nosharedlibrary", mark breakpoints in OBJF_USERLOADED modules
7708 shlib_disabled so they end up uninserted on the next global
7709 location list update. Shared libraries not loaded by the user
7710 aren't handled here -- they're already handled in
7711 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7712 solib_unloaded observer. We skip objfiles that are not
7713 OBJF_USERLOADED (nor OBJF_SHARED) as those aren't considered
7714 dynamic objects (e.g. the main objfile). */
7715 if ((objfile
->flags
& OBJF_USERLOADED
) == 0)
7720 struct bp_location
*loc
;
7721 int bp_modified
= 0;
7723 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7726 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7728 CORE_ADDR loc_addr
= loc
->address
;
7730 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7731 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7734 if (loc
->shlib_disabled
!= 0)
7737 if (objfile
->pspace
!= loc
->pspace
)
7740 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7741 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7744 if (is_addr_in_objfile (loc_addr
, objfile
))
7746 loc
->shlib_disabled
= 1;
7747 /* At this point, we don't know whether the object was
7748 unmapped from the inferior or not, so leave the
7749 inserted flag alone. We'll handle failure to
7750 uninsert quietly, in case the object was indeed
7753 mark_breakpoint_location_modified (loc
);
7760 observer_notify_breakpoint_modified (b
);
7764 /* FORK & VFORK catchpoints. */
7766 /* An instance of this type is used to represent a fork or vfork
7767 catchpoint. It includes a "struct breakpoint" as a kind of base
7768 class; users downcast to "struct breakpoint *" when needed. A
7769 breakpoint is really of this type iff its ops pointer points to
7770 CATCH_FORK_BREAKPOINT_OPS. */
7772 struct fork_catchpoint
7774 /* The base class. */
7775 struct breakpoint base
;
7777 /* Process id of a child process whose forking triggered this
7778 catchpoint. This field is only valid immediately after this
7779 catchpoint has triggered. */
7780 ptid_t forked_inferior_pid
;
7783 /* Implement the "insert" breakpoint_ops method for fork
7787 insert_catch_fork (struct bp_location
*bl
)
7789 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7792 /* Implement the "remove" breakpoint_ops method for fork
7796 remove_catch_fork (struct bp_location
*bl
)
7798 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7801 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7805 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7806 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7807 const struct target_waitstatus
*ws
)
7809 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7811 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7814 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7818 /* Implement the "print_it" breakpoint_ops method for fork
7821 static enum print_stop_action
7822 print_it_catch_fork (bpstat bs
)
7824 struct ui_out
*uiout
= current_uiout
;
7825 struct breakpoint
*b
= bs
->breakpoint_at
;
7826 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7828 annotate_catchpoint (b
->number
);
7829 if (b
->disposition
== disp_del
)
7830 ui_out_text (uiout
, "\nTemporary catchpoint ");
7832 ui_out_text (uiout
, "\nCatchpoint ");
7833 if (ui_out_is_mi_like_p (uiout
))
7835 ui_out_field_string (uiout
, "reason",
7836 async_reason_lookup (EXEC_ASYNC_FORK
));
7837 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7839 ui_out_field_int (uiout
, "bkptno", b
->number
);
7840 ui_out_text (uiout
, " (forked process ");
7841 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7842 ui_out_text (uiout
, "), ");
7843 return PRINT_SRC_AND_LOC
;
7846 /* Implement the "print_one" breakpoint_ops method for fork
7850 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7852 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7853 struct value_print_options opts
;
7854 struct ui_out
*uiout
= current_uiout
;
7856 get_user_print_options (&opts
);
7858 /* Field 4, the address, is omitted (which makes the columns not
7859 line up too nicely with the headers, but the effect is relatively
7861 if (opts
.addressprint
)
7862 ui_out_field_skip (uiout
, "addr");
7864 ui_out_text (uiout
, "fork");
7865 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7867 ui_out_text (uiout
, ", process ");
7868 ui_out_field_int (uiout
, "what",
7869 ptid_get_pid (c
->forked_inferior_pid
));
7870 ui_out_spaces (uiout
, 1);
7873 if (ui_out_is_mi_like_p (uiout
))
7874 ui_out_field_string (uiout
, "catch-type", "fork");
7877 /* Implement the "print_mention" breakpoint_ops method for fork
7881 print_mention_catch_fork (struct breakpoint
*b
)
7883 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7886 /* Implement the "print_recreate" breakpoint_ops method for fork
7890 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7892 fprintf_unfiltered (fp
, "catch fork");
7893 print_recreate_thread (b
, fp
);
7896 /* The breakpoint_ops structure to be used in fork catchpoints. */
7898 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7900 /* Implement the "insert" breakpoint_ops method for vfork
7904 insert_catch_vfork (struct bp_location
*bl
)
7906 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7909 /* Implement the "remove" breakpoint_ops method for vfork
7913 remove_catch_vfork (struct bp_location
*bl
)
7915 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7918 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7922 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7923 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7924 const struct target_waitstatus
*ws
)
7926 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7928 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7931 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7935 /* Implement the "print_it" breakpoint_ops method for vfork
7938 static enum print_stop_action
7939 print_it_catch_vfork (bpstat bs
)
7941 struct ui_out
*uiout
= current_uiout
;
7942 struct breakpoint
*b
= bs
->breakpoint_at
;
7943 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7945 annotate_catchpoint (b
->number
);
7946 if (b
->disposition
== disp_del
)
7947 ui_out_text (uiout
, "\nTemporary catchpoint ");
7949 ui_out_text (uiout
, "\nCatchpoint ");
7950 if (ui_out_is_mi_like_p (uiout
))
7952 ui_out_field_string (uiout
, "reason",
7953 async_reason_lookup (EXEC_ASYNC_VFORK
));
7954 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7956 ui_out_field_int (uiout
, "bkptno", b
->number
);
7957 ui_out_text (uiout
, " (vforked process ");
7958 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7959 ui_out_text (uiout
, "), ");
7960 return PRINT_SRC_AND_LOC
;
7963 /* Implement the "print_one" breakpoint_ops method for vfork
7967 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7969 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7970 struct value_print_options opts
;
7971 struct ui_out
*uiout
= current_uiout
;
7973 get_user_print_options (&opts
);
7974 /* Field 4, the address, is omitted (which makes the columns not
7975 line up too nicely with the headers, but the effect is relatively
7977 if (opts
.addressprint
)
7978 ui_out_field_skip (uiout
, "addr");
7980 ui_out_text (uiout
, "vfork");
7981 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7983 ui_out_text (uiout
, ", process ");
7984 ui_out_field_int (uiout
, "what",
7985 ptid_get_pid (c
->forked_inferior_pid
));
7986 ui_out_spaces (uiout
, 1);
7989 if (ui_out_is_mi_like_p (uiout
))
7990 ui_out_field_string (uiout
, "catch-type", "vfork");
7993 /* Implement the "print_mention" breakpoint_ops method for vfork
7997 print_mention_catch_vfork (struct breakpoint
*b
)
7999 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8002 /* Implement the "print_recreate" breakpoint_ops method for vfork
8006 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8008 fprintf_unfiltered (fp
, "catch vfork");
8009 print_recreate_thread (b
, fp
);
8012 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8014 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8016 /* An instance of this type is used to represent an solib catchpoint.
8017 It includes a "struct breakpoint" as a kind of base class; users
8018 downcast to "struct breakpoint *" when needed. A breakpoint is
8019 really of this type iff its ops pointer points to
8020 CATCH_SOLIB_BREAKPOINT_OPS. */
8022 struct solib_catchpoint
8024 /* The base class. */
8025 struct breakpoint base
;
8027 /* True for "catch load", false for "catch unload". */
8028 unsigned char is_load
;
8030 /* Regular expression to match, if any. COMPILED is only valid when
8031 REGEX is non-NULL. */
8037 dtor_catch_solib (struct breakpoint
*b
)
8039 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8042 regfree (&self
->compiled
);
8043 xfree (self
->regex
);
8045 base_breakpoint_ops
.dtor (b
);
8049 insert_catch_solib (struct bp_location
*ignore
)
8055 remove_catch_solib (struct bp_location
*ignore
)
8061 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8062 struct address_space
*aspace
,
8064 const struct target_waitstatus
*ws
)
8066 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8067 struct breakpoint
*other
;
8069 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8072 ALL_BREAKPOINTS (other
)
8074 struct bp_location
*other_bl
;
8076 if (other
== bl
->owner
)
8079 if (other
->type
!= bp_shlib_event
)
8082 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8085 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8087 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8096 check_status_catch_solib (struct bpstats
*bs
)
8098 struct solib_catchpoint
*self
8099 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8104 struct so_list
*iter
;
8107 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8112 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8121 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8126 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8132 bs
->print_it
= print_it_noop
;
8135 static enum print_stop_action
8136 print_it_catch_solib (bpstat bs
)
8138 struct breakpoint
*b
= bs
->breakpoint_at
;
8139 struct ui_out
*uiout
= current_uiout
;
8141 annotate_catchpoint (b
->number
);
8142 if (b
->disposition
== disp_del
)
8143 ui_out_text (uiout
, "\nTemporary catchpoint ");
8145 ui_out_text (uiout
, "\nCatchpoint ");
8146 ui_out_field_int (uiout
, "bkptno", b
->number
);
8147 ui_out_text (uiout
, "\n");
8148 if (ui_out_is_mi_like_p (uiout
))
8149 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8150 print_solib_event (1);
8151 return PRINT_SRC_AND_LOC
;
8155 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8157 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8158 struct value_print_options opts
;
8159 struct ui_out
*uiout
= current_uiout
;
8162 get_user_print_options (&opts
);
8163 /* Field 4, the address, is omitted (which makes the columns not
8164 line up too nicely with the headers, but the effect is relatively
8166 if (opts
.addressprint
)
8169 ui_out_field_skip (uiout
, "addr");
8176 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8178 msg
= xstrdup (_("load of library"));
8183 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8185 msg
= xstrdup (_("unload of library"));
8187 ui_out_field_string (uiout
, "what", msg
);
8190 if (ui_out_is_mi_like_p (uiout
))
8191 ui_out_field_string (uiout
, "catch-type",
8192 self
->is_load
? "load" : "unload");
8196 print_mention_catch_solib (struct breakpoint
*b
)
8198 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8200 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8201 self
->is_load
? "load" : "unload");
8205 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8207 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8209 fprintf_unfiltered (fp
, "%s %s",
8210 b
->disposition
== disp_del
? "tcatch" : "catch",
8211 self
->is_load
? "load" : "unload");
8213 fprintf_unfiltered (fp
, " %s", self
->regex
);
8214 fprintf_unfiltered (fp
, "\n");
8217 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8219 /* Shared helper function (MI and CLI) for creating and installing
8220 a shared object event catchpoint. If IS_LOAD is non-zero then
8221 the events to be caught are load events, otherwise they are
8222 unload events. If IS_TEMP is non-zero the catchpoint is a
8223 temporary one. If ENABLED is non-zero the catchpoint is
8224 created in an enabled state. */
8227 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8229 struct solib_catchpoint
*c
;
8230 struct gdbarch
*gdbarch
= get_current_arch ();
8231 struct cleanup
*cleanup
;
8235 arg
= skip_spaces (arg
);
8237 c
= XCNEW (struct solib_catchpoint
);
8238 cleanup
= make_cleanup (xfree
, c
);
8244 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8247 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8249 make_cleanup (xfree
, err
);
8250 error (_("Invalid regexp (%s): %s"), err
, arg
);
8252 c
->regex
= xstrdup (arg
);
8255 c
->is_load
= is_load
;
8256 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8257 &catch_solib_breakpoint_ops
);
8259 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8261 discard_cleanups (cleanup
);
8262 install_breakpoint (0, &c
->base
, 1);
8265 /* A helper function that does all the work for "catch load" and
8269 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8270 struct cmd_list_element
*command
)
8273 const int enabled
= 1;
8275 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8277 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8281 catch_load_command_1 (char *arg
, int from_tty
,
8282 struct cmd_list_element
*command
)
8284 catch_load_or_unload (arg
, from_tty
, 1, command
);
8288 catch_unload_command_1 (char *arg
, int from_tty
,
8289 struct cmd_list_element
*command
)
8291 catch_load_or_unload (arg
, from_tty
, 0, command
);
8294 /* An instance of this type is used to represent a syscall catchpoint.
8295 It includes a "struct breakpoint" as a kind of base class; users
8296 downcast to "struct breakpoint *" when needed. A breakpoint is
8297 really of this type iff its ops pointer points to
8298 CATCH_SYSCALL_BREAKPOINT_OPS. */
8300 struct syscall_catchpoint
8302 /* The base class. */
8303 struct breakpoint base
;
8305 /* Syscall numbers used for the 'catch syscall' feature. If no
8306 syscall has been specified for filtering, its value is NULL.
8307 Otherwise, it holds a list of all syscalls to be caught. The
8308 list elements are allocated with xmalloc. */
8309 VEC(int) *syscalls_to_be_caught
;
8312 /* Implement the "dtor" breakpoint_ops method for syscall
8316 dtor_catch_syscall (struct breakpoint
*b
)
8318 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8320 VEC_free (int, c
->syscalls_to_be_caught
);
8322 base_breakpoint_ops
.dtor (b
);
8325 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8327 struct catch_syscall_inferior_data
8329 /* We keep a count of the number of times the user has requested a
8330 particular syscall to be tracked, and pass this information to the
8331 target. This lets capable targets implement filtering directly. */
8333 /* Number of times that "any" syscall is requested. */
8334 int any_syscall_count
;
8336 /* Count of each system call. */
8337 VEC(int) *syscalls_counts
;
8339 /* This counts all syscall catch requests, so we can readily determine
8340 if any catching is necessary. */
8341 int total_syscalls_count
;
8344 static struct catch_syscall_inferior_data
*
8345 get_catch_syscall_inferior_data (struct inferior
*inf
)
8347 struct catch_syscall_inferior_data
*inf_data
;
8349 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8350 if (inf_data
== NULL
)
8352 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8353 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8360 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8366 /* Implement the "insert" breakpoint_ops method for syscall
8370 insert_catch_syscall (struct bp_location
*bl
)
8372 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8373 struct inferior
*inf
= current_inferior ();
8374 struct catch_syscall_inferior_data
*inf_data
8375 = get_catch_syscall_inferior_data (inf
);
8377 ++inf_data
->total_syscalls_count
;
8378 if (!c
->syscalls_to_be_caught
)
8379 ++inf_data
->any_syscall_count
;
8385 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8390 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8392 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8393 uintptr_t vec_addr_offset
8394 = old_size
* ((uintptr_t) sizeof (int));
8396 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8397 vec_addr
= ((uintptr_t) VEC_address (int,
8398 inf_data
->syscalls_counts
)
8400 memset ((void *) vec_addr
, 0,
8401 (iter
+ 1 - old_size
) * sizeof (int));
8403 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8404 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8408 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8409 inf_data
->total_syscalls_count
!= 0,
8410 inf_data
->any_syscall_count
,
8412 inf_data
->syscalls_counts
),
8414 inf_data
->syscalls_counts
));
8417 /* Implement the "remove" breakpoint_ops method for syscall
8421 remove_catch_syscall (struct bp_location
*bl
)
8423 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8424 struct inferior
*inf
= current_inferior ();
8425 struct catch_syscall_inferior_data
*inf_data
8426 = get_catch_syscall_inferior_data (inf
);
8428 --inf_data
->total_syscalls_count
;
8429 if (!c
->syscalls_to_be_caught
)
8430 --inf_data
->any_syscall_count
;
8436 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8440 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8441 /* Shouldn't happen. */
8443 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8444 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8448 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8449 inf_data
->total_syscalls_count
!= 0,
8450 inf_data
->any_syscall_count
,
8452 inf_data
->syscalls_counts
),
8454 inf_data
->syscalls_counts
));
8457 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8461 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8462 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8463 const struct target_waitstatus
*ws
)
8465 /* We must check if we are catching specific syscalls in this
8466 breakpoint. If we are, then we must guarantee that the called
8467 syscall is the same syscall we are catching. */
8468 int syscall_number
= 0;
8469 const struct syscall_catchpoint
*c
8470 = (const struct syscall_catchpoint
*) bl
->owner
;
8472 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8473 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8476 syscall_number
= ws
->value
.syscall_number
;
8478 /* Now, checking if the syscall is the same. */
8479 if (c
->syscalls_to_be_caught
)
8484 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8486 if (syscall_number
== iter
)
8495 /* Implement the "print_it" breakpoint_ops method for syscall
8498 static enum print_stop_action
8499 print_it_catch_syscall (bpstat bs
)
8501 struct ui_out
*uiout
= current_uiout
;
8502 struct breakpoint
*b
= bs
->breakpoint_at
;
8503 /* These are needed because we want to know in which state a
8504 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8505 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8506 must print "called syscall" or "returned from syscall". */
8508 struct target_waitstatus last
;
8511 get_last_target_status (&ptid
, &last
);
8513 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8515 annotate_catchpoint (b
->number
);
8517 if (b
->disposition
== disp_del
)
8518 ui_out_text (uiout
, "\nTemporary catchpoint ");
8520 ui_out_text (uiout
, "\nCatchpoint ");
8521 if (ui_out_is_mi_like_p (uiout
))
8523 ui_out_field_string (uiout
, "reason",
8524 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8525 ? EXEC_ASYNC_SYSCALL_ENTRY
8526 : EXEC_ASYNC_SYSCALL_RETURN
));
8527 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8529 ui_out_field_int (uiout
, "bkptno", b
->number
);
8531 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8532 ui_out_text (uiout
, " (call to syscall ");
8534 ui_out_text (uiout
, " (returned from syscall ");
8536 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8537 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8539 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8541 ui_out_text (uiout
, "), ");
8543 return PRINT_SRC_AND_LOC
;
8546 /* Implement the "print_one" breakpoint_ops method for syscall
8550 print_one_catch_syscall (struct breakpoint
*b
,
8551 struct bp_location
**last_loc
)
8553 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8554 struct value_print_options opts
;
8555 struct ui_out
*uiout
= current_uiout
;
8557 get_user_print_options (&opts
);
8558 /* Field 4, the address, is omitted (which makes the columns not
8559 line up too nicely with the headers, but the effect is relatively
8561 if (opts
.addressprint
)
8562 ui_out_field_skip (uiout
, "addr");
8565 if (c
->syscalls_to_be_caught
8566 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8567 ui_out_text (uiout
, "syscalls \"");
8569 ui_out_text (uiout
, "syscall \"");
8571 if (c
->syscalls_to_be_caught
)
8574 char *text
= xstrprintf ("%s", "");
8577 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8582 get_syscall_by_number (iter
, &s
);
8585 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8587 text
= xstrprintf ("%s%d, ", text
, iter
);
8589 /* We have to xfree the last 'text' (now stored at 'x')
8590 because xstrprintf dynamically allocates new space for it
8594 /* Remove the last comma. */
8595 text
[strlen (text
) - 2] = '\0';
8596 ui_out_field_string (uiout
, "what", text
);
8599 ui_out_field_string (uiout
, "what", "<any syscall>");
8600 ui_out_text (uiout
, "\" ");
8602 if (ui_out_is_mi_like_p (uiout
))
8603 ui_out_field_string (uiout
, "catch-type", "syscall");
8606 /* Implement the "print_mention" breakpoint_ops method for syscall
8610 print_mention_catch_syscall (struct breakpoint
*b
)
8612 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8614 if (c
->syscalls_to_be_caught
)
8618 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8619 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8621 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8624 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8628 get_syscall_by_number (iter
, &s
);
8631 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8633 printf_filtered (" %d", s
.number
);
8635 printf_filtered (")");
8638 printf_filtered (_("Catchpoint %d (any syscall)"),
8642 /* Implement the "print_recreate" breakpoint_ops method for syscall
8646 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8648 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8650 fprintf_unfiltered (fp
, "catch syscall");
8652 if (c
->syscalls_to_be_caught
)
8657 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8662 get_syscall_by_number (iter
, &s
);
8664 fprintf_unfiltered (fp
, " %s", s
.name
);
8666 fprintf_unfiltered (fp
, " %d", s
.number
);
8669 print_recreate_thread (b
, fp
);
8672 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8674 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8676 /* Returns non-zero if 'b' is a syscall catchpoint. */
8679 syscall_catchpoint_p (struct breakpoint
*b
)
8681 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8684 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8685 is non-zero, then make the breakpoint temporary. If COND_STRING is
8686 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8687 the breakpoint_ops structure associated to the catchpoint. */
8690 init_catchpoint (struct breakpoint
*b
,
8691 struct gdbarch
*gdbarch
, int tempflag
,
8693 const struct breakpoint_ops
*ops
)
8695 struct symtab_and_line sal
;
8698 sal
.pspace
= current_program_space
;
8700 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8702 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8703 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8707 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8709 add_to_breakpoint_chain (b
);
8710 set_breakpoint_number (internal
, b
);
8711 if (is_tracepoint (b
))
8712 set_tracepoint_count (breakpoint_count
);
8715 observer_notify_breakpoint_created (b
);
8718 update_global_location_list (1);
8722 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8723 int tempflag
, char *cond_string
,
8724 const struct breakpoint_ops
*ops
)
8726 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8728 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8730 c
->forked_inferior_pid
= null_ptid
;
8732 install_breakpoint (0, &c
->base
, 1);
8735 /* Exec catchpoints. */
8737 /* An instance of this type is used to represent an exec catchpoint.
8738 It includes a "struct breakpoint" as a kind of base class; users
8739 downcast to "struct breakpoint *" when needed. A breakpoint is
8740 really of this type iff its ops pointer points to
8741 CATCH_EXEC_BREAKPOINT_OPS. */
8743 struct exec_catchpoint
8745 /* The base class. */
8746 struct breakpoint base
;
8748 /* Filename of a program whose exec triggered this catchpoint.
8749 This field is only valid immediately after this catchpoint has
8751 char *exec_pathname
;
8754 /* Implement the "dtor" breakpoint_ops method for exec
8758 dtor_catch_exec (struct breakpoint
*b
)
8760 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8762 xfree (c
->exec_pathname
);
8764 base_breakpoint_ops
.dtor (b
);
8768 insert_catch_exec (struct bp_location
*bl
)
8770 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8774 remove_catch_exec (struct bp_location
*bl
)
8776 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8780 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8781 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8782 const struct target_waitstatus
*ws
)
8784 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8786 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8789 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8793 static enum print_stop_action
8794 print_it_catch_exec (bpstat bs
)
8796 struct ui_out
*uiout
= current_uiout
;
8797 struct breakpoint
*b
= bs
->breakpoint_at
;
8798 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8800 annotate_catchpoint (b
->number
);
8801 if (b
->disposition
== disp_del
)
8802 ui_out_text (uiout
, "\nTemporary catchpoint ");
8804 ui_out_text (uiout
, "\nCatchpoint ");
8805 if (ui_out_is_mi_like_p (uiout
))
8807 ui_out_field_string (uiout
, "reason",
8808 async_reason_lookup (EXEC_ASYNC_EXEC
));
8809 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8811 ui_out_field_int (uiout
, "bkptno", b
->number
);
8812 ui_out_text (uiout
, " (exec'd ");
8813 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8814 ui_out_text (uiout
, "), ");
8816 return PRINT_SRC_AND_LOC
;
8820 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8822 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8823 struct value_print_options opts
;
8824 struct ui_out
*uiout
= current_uiout
;
8826 get_user_print_options (&opts
);
8828 /* Field 4, the address, is omitted (which makes the columns
8829 not line up too nicely with the headers, but the effect
8830 is relatively readable). */
8831 if (opts
.addressprint
)
8832 ui_out_field_skip (uiout
, "addr");
8834 ui_out_text (uiout
, "exec");
8835 if (c
->exec_pathname
!= NULL
)
8837 ui_out_text (uiout
, ", program \"");
8838 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8839 ui_out_text (uiout
, "\" ");
8842 if (ui_out_is_mi_like_p (uiout
))
8843 ui_out_field_string (uiout
, "catch-type", "exec");
8847 print_mention_catch_exec (struct breakpoint
*b
)
8849 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8852 /* Implement the "print_recreate" breakpoint_ops method for exec
8856 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8858 fprintf_unfiltered (fp
, "catch exec");
8859 print_recreate_thread (b
, fp
);
8862 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8865 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8866 const struct breakpoint_ops
*ops
)
8868 struct syscall_catchpoint
*c
;
8869 struct gdbarch
*gdbarch
= get_current_arch ();
8871 c
= XNEW (struct syscall_catchpoint
);
8872 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8873 c
->syscalls_to_be_caught
= filter
;
8875 install_breakpoint (0, &c
->base
, 1);
8879 hw_breakpoint_used_count (void)
8882 struct breakpoint
*b
;
8883 struct bp_location
*bl
;
8887 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8888 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8890 /* Special types of hardware breakpoints may use more than
8892 i
+= b
->ops
->resources_needed (bl
);
8899 /* Returns the resources B would use if it were a hardware
8903 hw_watchpoint_use_count (struct breakpoint
*b
)
8906 struct bp_location
*bl
;
8908 if (!breakpoint_enabled (b
))
8911 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8913 /* Special types of hardware watchpoints may use more than
8915 i
+= b
->ops
->resources_needed (bl
);
8921 /* Returns the sum the used resources of all hardware watchpoints of
8922 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8923 the sum of the used resources of all hardware watchpoints of other
8924 types _not_ TYPE. */
8927 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8928 enum bptype type
, int *other_type_used
)
8931 struct breakpoint
*b
;
8933 *other_type_used
= 0;
8938 if (!breakpoint_enabled (b
))
8941 if (b
->type
== type
)
8942 i
+= hw_watchpoint_use_count (b
);
8943 else if (is_hardware_watchpoint (b
))
8944 *other_type_used
= 1;
8951 disable_watchpoints_before_interactive_call_start (void)
8953 struct breakpoint
*b
;
8957 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8959 b
->enable_state
= bp_call_disabled
;
8960 update_global_location_list (0);
8966 enable_watchpoints_after_interactive_call_stop (void)
8968 struct breakpoint
*b
;
8972 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8974 b
->enable_state
= bp_enabled
;
8975 update_global_location_list (1);
8981 disable_breakpoints_before_startup (void)
8983 current_program_space
->executing_startup
= 1;
8984 update_global_location_list (0);
8988 enable_breakpoints_after_startup (void)
8990 current_program_space
->executing_startup
= 0;
8991 breakpoint_re_set ();
8995 /* Set a breakpoint that will evaporate an end of command
8996 at address specified by SAL.
8997 Restrict it to frame FRAME if FRAME is nonzero. */
9000 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9001 struct frame_id frame_id
, enum bptype type
)
9003 struct breakpoint
*b
;
9005 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9007 gdb_assert (!frame_id_artificial_p (frame_id
));
9009 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9010 b
->enable_state
= bp_enabled
;
9011 b
->disposition
= disp_donttouch
;
9012 b
->frame_id
= frame_id
;
9014 /* If we're debugging a multi-threaded program, then we want
9015 momentary breakpoints to be active in only a single thread of
9017 if (in_thread_list (inferior_ptid
))
9018 b
->thread
= pid_to_thread_id (inferior_ptid
);
9020 update_global_location_list_nothrow (1);
9025 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9026 The new breakpoint will have type TYPE, and use OPS as it
9029 static struct breakpoint
*
9030 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9032 const struct breakpoint_ops
*ops
)
9034 struct breakpoint
*copy
;
9036 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9037 copy
->loc
= allocate_bp_location (copy
);
9038 set_breakpoint_location_function (copy
->loc
, 1);
9040 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9041 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9042 copy
->loc
->address
= orig
->loc
->address
;
9043 copy
->loc
->section
= orig
->loc
->section
;
9044 copy
->loc
->pspace
= orig
->loc
->pspace
;
9045 copy
->loc
->probe
= orig
->loc
->probe
;
9046 copy
->loc
->line_number
= orig
->loc
->line_number
;
9047 copy
->loc
->symtab
= orig
->loc
->symtab
;
9048 copy
->frame_id
= orig
->frame_id
;
9049 copy
->thread
= orig
->thread
;
9050 copy
->pspace
= orig
->pspace
;
9052 copy
->enable_state
= bp_enabled
;
9053 copy
->disposition
= disp_donttouch
;
9054 copy
->number
= internal_breakpoint_number
--;
9056 update_global_location_list_nothrow (0);
9060 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9064 clone_momentary_breakpoint (struct breakpoint
*orig
)
9066 /* If there's nothing to clone, then return nothing. */
9070 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
9074 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9077 struct symtab_and_line sal
;
9079 sal
= find_pc_line (pc
, 0);
9081 sal
.section
= find_pc_overlay (pc
);
9082 sal
.explicit_pc
= 1;
9084 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9088 /* Tell the user we have just set a breakpoint B. */
9091 mention (struct breakpoint
*b
)
9093 b
->ops
->print_mention (b
);
9094 if (ui_out_is_mi_like_p (current_uiout
))
9096 printf_filtered ("\n");
9100 static struct bp_location
*
9101 add_location_to_breakpoint (struct breakpoint
*b
,
9102 const struct symtab_and_line
*sal
)
9104 struct bp_location
*loc
, **tmp
;
9105 CORE_ADDR adjusted_address
;
9106 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9108 if (loc_gdbarch
== NULL
)
9109 loc_gdbarch
= b
->gdbarch
;
9111 /* Adjust the breakpoint's address prior to allocating a location.
9112 Once we call allocate_bp_location(), that mostly uninitialized
9113 location will be placed on the location chain. Adjustment of the
9114 breakpoint may cause target_read_memory() to be called and we do
9115 not want its scan of the location chain to find a breakpoint and
9116 location that's only been partially initialized. */
9117 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9120 /* Sort the locations by their ADDRESS. */
9121 loc
= allocate_bp_location (b
);
9122 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9123 tmp
= &((*tmp
)->next
))
9128 loc
->requested_address
= sal
->pc
;
9129 loc
->address
= adjusted_address
;
9130 loc
->pspace
= sal
->pspace
;
9131 loc
->probe
.probe
= sal
->probe
;
9132 loc
->probe
.objfile
= sal
->objfile
;
9133 gdb_assert (loc
->pspace
!= NULL
);
9134 loc
->section
= sal
->section
;
9135 loc
->gdbarch
= loc_gdbarch
;
9136 loc
->line_number
= sal
->line
;
9137 loc
->symtab
= sal
->symtab
;
9139 set_breakpoint_location_function (loc
,
9140 sal
->explicit_pc
|| sal
->explicit_line
);
9145 /* Return 1 if LOC is pointing to a permanent breakpoint,
9146 return 0 otherwise. */
9149 bp_loc_is_permanent (struct bp_location
*loc
)
9153 const gdb_byte
*bpoint
;
9154 gdb_byte
*target_mem
;
9155 struct cleanup
*cleanup
;
9158 gdb_assert (loc
!= NULL
);
9160 addr
= loc
->address
;
9161 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9163 /* Software breakpoints unsupported? */
9167 target_mem
= alloca (len
);
9169 /* Enable the automatic memory restoration from breakpoints while
9170 we read the memory. Otherwise we could say about our temporary
9171 breakpoints they are permanent. */
9172 cleanup
= save_current_space_and_thread ();
9174 switch_to_program_space_and_thread (loc
->pspace
);
9175 make_show_memory_breakpoints_cleanup (0);
9177 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9178 && memcmp (target_mem
, bpoint
, len
) == 0)
9181 do_cleanups (cleanup
);
9186 /* Build a command list for the dprintf corresponding to the current
9187 settings of the dprintf style options. */
9190 update_dprintf_command_list (struct breakpoint
*b
)
9192 char *dprintf_args
= b
->extra_string
;
9193 char *printf_line
= NULL
;
9198 dprintf_args
= skip_spaces (dprintf_args
);
9200 /* Allow a comma, as it may have terminated a location, but don't
9202 if (*dprintf_args
== ',')
9204 dprintf_args
= skip_spaces (dprintf_args
);
9206 if (*dprintf_args
!= '"')
9207 error (_("Bad format string, missing '\"'."));
9209 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9210 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9211 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9213 if (!dprintf_function
)
9214 error (_("No function supplied for dprintf call"));
9216 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9217 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9222 printf_line
= xstrprintf ("call (void) %s (%s)",
9226 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9228 if (target_can_run_breakpoint_commands ())
9229 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9232 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9233 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9237 internal_error (__FILE__
, __LINE__
,
9238 _("Invalid dprintf style."));
9240 gdb_assert (printf_line
!= NULL
);
9241 /* Manufacture a printf sequence. */
9243 struct command_line
*printf_cmd_line
9244 = xmalloc (sizeof (struct command_line
));
9246 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9247 printf_cmd_line
->control_type
= simple_control
;
9248 printf_cmd_line
->body_count
= 0;
9249 printf_cmd_line
->body_list
= NULL
;
9250 printf_cmd_line
->next
= NULL
;
9251 printf_cmd_line
->line
= printf_line
;
9253 breakpoint_set_commands (b
, printf_cmd_line
);
9257 /* Update all dprintf commands, making their command lists reflect
9258 current style settings. */
9261 update_dprintf_commands (char *args
, int from_tty
,
9262 struct cmd_list_element
*c
)
9264 struct breakpoint
*b
;
9268 if (b
->type
== bp_dprintf
)
9269 update_dprintf_command_list (b
);
9273 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9274 as textual description of the location, and COND_STRING
9275 as condition expression. */
9278 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9279 struct symtabs_and_lines sals
, char *addr_string
,
9280 char *filter
, char *cond_string
,
9282 enum bptype type
, enum bpdisp disposition
,
9283 int thread
, int task
, int ignore_count
,
9284 const struct breakpoint_ops
*ops
, int from_tty
,
9285 int enabled
, int internal
, unsigned flags
,
9286 int display_canonical
)
9290 if (type
== bp_hardware_breakpoint
)
9292 int target_resources_ok
;
9294 i
= hw_breakpoint_used_count ();
9295 target_resources_ok
=
9296 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9298 if (target_resources_ok
== 0)
9299 error (_("No hardware breakpoint support in the target."));
9300 else if (target_resources_ok
< 0)
9301 error (_("Hardware breakpoints used exceeds limit."));
9304 gdb_assert (sals
.nelts
> 0);
9306 for (i
= 0; i
< sals
.nelts
; ++i
)
9308 struct symtab_and_line sal
= sals
.sals
[i
];
9309 struct bp_location
*loc
;
9313 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9315 loc_gdbarch
= gdbarch
;
9317 describe_other_breakpoints (loc_gdbarch
,
9318 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9323 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9327 b
->cond_string
= cond_string
;
9328 b
->extra_string
= extra_string
;
9329 b
->ignore_count
= ignore_count
;
9330 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9331 b
->disposition
= disposition
;
9333 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9334 b
->loc
->inserted
= 1;
9336 if (type
== bp_static_tracepoint
)
9338 struct tracepoint
*t
= (struct tracepoint
*) b
;
9339 struct static_tracepoint_marker marker
;
9341 if (strace_marker_p (b
))
9343 /* We already know the marker exists, otherwise, we
9344 wouldn't see a sal for it. */
9345 char *p
= &addr_string
[3];
9349 p
= skip_spaces (p
);
9351 endp
= skip_to_space (p
);
9353 marker_str
= savestring (p
, endp
- p
);
9354 t
->static_trace_marker_id
= marker_str
;
9356 printf_filtered (_("Probed static tracepoint "
9358 t
->static_trace_marker_id
);
9360 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9362 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9363 release_static_tracepoint_marker (&marker
);
9365 printf_filtered (_("Probed static tracepoint "
9367 t
->static_trace_marker_id
);
9370 warning (_("Couldn't determine the static "
9371 "tracepoint marker to probe"));
9378 loc
= add_location_to_breakpoint (b
, &sal
);
9379 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9383 if (bp_loc_is_permanent (loc
))
9384 make_breakpoint_permanent (b
);
9388 const char *arg
= b
->cond_string
;
9390 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9391 block_for_pc (loc
->address
), 0);
9393 error (_("Garbage '%s' follows condition"), arg
);
9396 /* Dynamic printf requires and uses additional arguments on the
9397 command line, otherwise it's an error. */
9398 if (type
== bp_dprintf
)
9400 if (b
->extra_string
)
9401 update_dprintf_command_list (b
);
9403 error (_("Format string required"));
9405 else if (b
->extra_string
)
9406 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9409 b
->display_canonical
= display_canonical
;
9411 b
->addr_string
= addr_string
;
9413 /* addr_string has to be used or breakpoint_re_set will delete
9416 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9421 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9422 struct symtabs_and_lines sals
, char *addr_string
,
9423 char *filter
, char *cond_string
,
9425 enum bptype type
, enum bpdisp disposition
,
9426 int thread
, int task
, int ignore_count
,
9427 const struct breakpoint_ops
*ops
, int from_tty
,
9428 int enabled
, int internal
, unsigned flags
,
9429 int display_canonical
)
9431 struct breakpoint
*b
;
9432 struct cleanup
*old_chain
;
9434 if (is_tracepoint_type (type
))
9436 struct tracepoint
*t
;
9438 t
= XCNEW (struct tracepoint
);
9442 b
= XNEW (struct breakpoint
);
9444 old_chain
= make_cleanup (xfree
, b
);
9446 init_breakpoint_sal (b
, gdbarch
,
9448 filter
, cond_string
, extra_string
,
9450 thread
, task
, ignore_count
,
9452 enabled
, internal
, flags
,
9454 discard_cleanups (old_chain
);
9456 install_breakpoint (internal
, b
, 0);
9459 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9460 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9461 value. COND_STRING, if not NULL, specified the condition to be
9462 used for all breakpoints. Essentially the only case where
9463 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9464 function. In that case, it's still not possible to specify
9465 separate conditions for different overloaded functions, so
9466 we take just a single condition string.
9468 NOTE: If the function succeeds, the caller is expected to cleanup
9469 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9470 array contents). If the function fails (error() is called), the
9471 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9472 COND and SALS arrays and each of those arrays contents. */
9475 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9476 struct linespec_result
*canonical
,
9477 char *cond_string
, char *extra_string
,
9478 enum bptype type
, enum bpdisp disposition
,
9479 int thread
, int task
, int ignore_count
,
9480 const struct breakpoint_ops
*ops
, int from_tty
,
9481 int enabled
, int internal
, unsigned flags
)
9484 struct linespec_sals
*lsal
;
9486 if (canonical
->pre_expanded
)
9487 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9489 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9491 /* Note that 'addr_string' can be NULL in the case of a plain
9492 'break', without arguments. */
9493 char *addr_string
= (canonical
->addr_string
9494 ? xstrdup (canonical
->addr_string
)
9496 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9497 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9499 make_cleanup (xfree
, filter_string
);
9500 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9503 cond_string
, extra_string
,
9505 thread
, task
, ignore_count
, ops
,
9506 from_tty
, enabled
, internal
, flags
,
9507 canonical
->special_display
);
9508 discard_cleanups (inner
);
9512 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9513 followed by conditionals. On return, SALS contains an array of SAL
9514 addresses found. ADDR_STRING contains a vector of (canonical)
9515 address strings. ADDRESS points to the end of the SAL.
9517 The array and the line spec strings are allocated on the heap, it is
9518 the caller's responsibility to free them. */
9521 parse_breakpoint_sals (char **address
,
9522 struct linespec_result
*canonical
)
9524 /* If no arg given, or if first arg is 'if ', use the default
9526 if ((*address
) == NULL
9527 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9529 /* The last displayed codepoint, if it's valid, is our default breakpoint
9531 if (last_displayed_sal_is_valid ())
9533 struct linespec_sals lsal
;
9534 struct symtab_and_line sal
;
9537 init_sal (&sal
); /* Initialize to zeroes. */
9538 lsal
.sals
.sals
= (struct symtab_and_line
*)
9539 xmalloc (sizeof (struct symtab_and_line
));
9541 /* Set sal's pspace, pc, symtab, and line to the values
9542 corresponding to the last call to print_frame_info.
9543 Be sure to reinitialize LINE with NOTCURRENT == 0
9544 as the breakpoint line number is inappropriate otherwise.
9545 find_pc_line would adjust PC, re-set it back. */
9546 get_last_displayed_sal (&sal
);
9548 sal
= find_pc_line (pc
, 0);
9550 /* "break" without arguments is equivalent to "break *PC"
9551 where PC is the last displayed codepoint's address. So
9552 make sure to set sal.explicit_pc to prevent GDB from
9553 trying to expand the list of sals to include all other
9554 instances with the same symtab and line. */
9556 sal
.explicit_pc
= 1;
9558 lsal
.sals
.sals
[0] = sal
;
9559 lsal
.sals
.nelts
= 1;
9560 lsal
.canonical
= NULL
;
9562 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9565 error (_("No default breakpoint address now."));
9569 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9571 /* Force almost all breakpoints to be in terms of the
9572 current_source_symtab (which is decode_line_1's default).
9573 This should produce the results we want almost all of the
9574 time while leaving default_breakpoint_* alone.
9576 ObjC: However, don't match an Objective-C method name which
9577 may have a '+' or '-' succeeded by a '['. */
9578 if (last_displayed_sal_is_valid ()
9580 || ((strchr ("+-", (*address
)[0]) != NULL
)
9581 && ((*address
)[1] != '['))))
9582 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9583 get_last_displayed_symtab (),
9584 get_last_displayed_line (),
9585 canonical
, NULL
, NULL
);
9587 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9588 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9593 /* Convert each SAL into a real PC. Verify that the PC can be
9594 inserted as a breakpoint. If it can't throw an error. */
9597 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9601 for (i
= 0; i
< sals
->nelts
; i
++)
9602 resolve_sal_pc (&sals
->sals
[i
]);
9605 /* Fast tracepoints may have restrictions on valid locations. For
9606 instance, a fast tracepoint using a jump instead of a trap will
9607 likely have to overwrite more bytes than a trap would, and so can
9608 only be placed where the instruction is longer than the jump, or a
9609 multi-instruction sequence does not have a jump into the middle of
9613 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9614 struct symtabs_and_lines
*sals
)
9617 struct symtab_and_line
*sal
;
9619 struct cleanup
*old_chain
;
9621 for (i
= 0; i
< sals
->nelts
; i
++)
9623 struct gdbarch
*sarch
;
9625 sal
= &sals
->sals
[i
];
9627 sarch
= get_sal_arch (*sal
);
9628 /* We fall back to GDBARCH if there is no architecture
9629 associated with SAL. */
9632 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9634 old_chain
= make_cleanup (xfree
, msg
);
9637 error (_("May not have a fast tracepoint at 0x%s%s"),
9638 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9640 do_cleanups (old_chain
);
9644 /* Issue an invalid thread ID error. */
9646 static void ATTRIBUTE_NORETURN
9647 invalid_thread_id_error (int id
)
9649 error (_("Unknown thread %d."), id
);
9652 /* Given TOK, a string specification of condition and thread, as
9653 accepted by the 'break' command, extract the condition
9654 string and thread number and set *COND_STRING and *THREAD.
9655 PC identifies the context at which the condition should be parsed.
9656 If no condition is found, *COND_STRING is set to NULL.
9657 If no thread is found, *THREAD is set to -1. */
9660 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9661 char **cond_string
, int *thread
, int *task
,
9664 *cond_string
= NULL
;
9671 const char *end_tok
;
9673 const char *cond_start
= NULL
;
9674 const char *cond_end
= NULL
;
9676 tok
= skip_spaces_const (tok
);
9678 if ((*tok
== '"' || *tok
== ',') && rest
)
9680 *rest
= savestring (tok
, strlen (tok
));
9684 end_tok
= skip_to_space_const (tok
);
9686 toklen
= end_tok
- tok
;
9688 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9690 struct expression
*expr
;
9692 tok
= cond_start
= end_tok
+ 1;
9693 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9696 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9698 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9703 *thread
= strtol (tok
, &tmptok
, 0);
9705 error (_("Junk after thread keyword."));
9706 if (!valid_thread_id (*thread
))
9707 invalid_thread_id_error (*thread
);
9710 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9715 *task
= strtol (tok
, &tmptok
, 0);
9717 error (_("Junk after task keyword."));
9718 if (!valid_task_id (*task
))
9719 error (_("Unknown task %d."), *task
);
9724 *rest
= savestring (tok
, strlen (tok
));
9728 error (_("Junk at end of arguments."));
9732 /* Decode a static tracepoint marker spec. */
9734 static struct symtabs_and_lines
9735 decode_static_tracepoint_spec (char **arg_p
)
9737 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9738 struct symtabs_and_lines sals
;
9739 struct cleanup
*old_chain
;
9740 char *p
= &(*arg_p
)[3];
9745 p
= skip_spaces (p
);
9747 endp
= skip_to_space (p
);
9749 marker_str
= savestring (p
, endp
- p
);
9750 old_chain
= make_cleanup (xfree
, marker_str
);
9752 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9753 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9754 error (_("No known static tracepoint marker named %s"), marker_str
);
9756 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9757 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9759 for (i
= 0; i
< sals
.nelts
; i
++)
9761 struct static_tracepoint_marker
*marker
;
9763 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9765 init_sal (&sals
.sals
[i
]);
9767 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9768 sals
.sals
[i
].pc
= marker
->address
;
9770 release_static_tracepoint_marker (marker
);
9773 do_cleanups (old_chain
);
9779 /* Set a breakpoint. This function is shared between CLI and MI
9780 functions for setting a breakpoint. This function has two major
9781 modes of operations, selected by the PARSE_ARG parameter. If
9782 non-zero, the function will parse ARG, extracting location,
9783 condition, thread and extra string. Otherwise, ARG is just the
9784 breakpoint's location, with condition, thread, and extra string
9785 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9786 If INTERNAL is non-zero, the breakpoint number will be allocated
9787 from the internal breakpoint count. Returns true if any breakpoint
9788 was created; false otherwise. */
9791 create_breakpoint (struct gdbarch
*gdbarch
,
9792 char *arg
, char *cond_string
,
9793 int thread
, char *extra_string
,
9795 int tempflag
, enum bptype type_wanted
,
9797 enum auto_boolean pending_break_support
,
9798 const struct breakpoint_ops
*ops
,
9799 int from_tty
, int enabled
, int internal
,
9802 volatile struct gdb_exception e
;
9803 char *copy_arg
= NULL
;
9804 char *addr_start
= arg
;
9805 struct linespec_result canonical
;
9806 struct cleanup
*old_chain
;
9807 struct cleanup
*bkpt_chain
= NULL
;
9810 int prev_bkpt_count
= breakpoint_count
;
9812 gdb_assert (ops
!= NULL
);
9814 init_linespec_result (&canonical
);
9816 TRY_CATCH (e
, RETURN_MASK_ALL
)
9818 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9819 addr_start
, ©_arg
);
9822 /* If caller is interested in rc value from parse, set value. */
9826 if (VEC_empty (linespec_sals
, canonical
.sals
))
9832 case NOT_FOUND_ERROR
:
9834 /* If pending breakpoint support is turned off, throw
9837 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9838 throw_exception (e
);
9840 exception_print (gdb_stderr
, e
);
9842 /* If pending breakpoint support is auto query and the user
9843 selects no, then simply return the error code. */
9844 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9845 && !nquery (_("Make %s pending on future shared library load? "),
9846 bptype_string (type_wanted
)))
9849 /* At this point, either the user was queried about setting
9850 a pending breakpoint and selected yes, or pending
9851 breakpoint behavior is on and thus a pending breakpoint
9852 is defaulted on behalf of the user. */
9854 struct linespec_sals lsal
;
9856 copy_arg
= xstrdup (addr_start
);
9857 lsal
.canonical
= xstrdup (copy_arg
);
9858 lsal
.sals
.nelts
= 1;
9859 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9860 init_sal (&lsal
.sals
.sals
[0]);
9862 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9866 throw_exception (e
);
9870 throw_exception (e
);
9873 /* Create a chain of things that always need to be cleaned up. */
9874 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9876 /* ----------------------------- SNIP -----------------------------
9877 Anything added to the cleanup chain beyond this point is assumed
9878 to be part of a breakpoint. If the breakpoint create succeeds
9879 then the memory is not reclaimed. */
9880 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9882 /* Resolve all line numbers to PC's and verify that the addresses
9883 are ok for the target. */
9887 struct linespec_sals
*iter
;
9889 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9890 breakpoint_sals_to_pc (&iter
->sals
);
9893 /* Fast tracepoints may have additional restrictions on location. */
9894 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9897 struct linespec_sals
*iter
;
9899 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9900 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9903 /* Verify that condition can be parsed, before setting any
9904 breakpoints. Allocate a separate condition expression for each
9911 struct linespec_sals
*lsal
;
9913 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9915 /* Here we only parse 'arg' to separate condition
9916 from thread number, so parsing in context of first
9917 sal is OK. When setting the breakpoint we'll
9918 re-parse it in context of each sal. */
9920 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9921 &thread
, &task
, &rest
);
9923 make_cleanup (xfree
, cond_string
);
9925 make_cleanup (xfree
, rest
);
9927 extra_string
= rest
;
9932 error (_("Garbage '%s' at end of location"), arg
);
9934 /* Create a private copy of condition string. */
9937 cond_string
= xstrdup (cond_string
);
9938 make_cleanup (xfree
, cond_string
);
9940 /* Create a private copy of any extra string. */
9943 extra_string
= xstrdup (extra_string
);
9944 make_cleanup (xfree
, extra_string
);
9948 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9949 cond_string
, extra_string
, type_wanted
,
9950 tempflag
? disp_del
: disp_donttouch
,
9951 thread
, task
, ignore_count
, ops
,
9952 from_tty
, enabled
, internal
, flags
);
9956 struct breakpoint
*b
;
9958 make_cleanup (xfree
, copy_arg
);
9960 if (is_tracepoint_type (type_wanted
))
9962 struct tracepoint
*t
;
9964 t
= XCNEW (struct tracepoint
);
9968 b
= XNEW (struct breakpoint
);
9970 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9972 b
->addr_string
= copy_arg
;
9974 b
->cond_string
= NULL
;
9977 /* Create a private copy of condition string. */
9980 cond_string
= xstrdup (cond_string
);
9981 make_cleanup (xfree
, cond_string
);
9983 b
->cond_string
= cond_string
;
9985 b
->extra_string
= NULL
;
9986 b
->ignore_count
= ignore_count
;
9987 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9988 b
->condition_not_parsed
= 1;
9989 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9990 if ((type_wanted
!= bp_breakpoint
9991 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9992 b
->pspace
= current_program_space
;
9994 install_breakpoint (internal
, b
, 0);
9997 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9999 warning (_("Multiple breakpoints were set.\nUse the "
10000 "\"delete\" command to delete unwanted breakpoints."));
10001 prev_breakpoint_count
= prev_bkpt_count
;
10004 /* That's it. Discard the cleanups for data inserted into the
10006 discard_cleanups (bkpt_chain
);
10007 /* But cleanup everything else. */
10008 do_cleanups (old_chain
);
10010 /* error call may happen here - have BKPT_CHAIN already discarded. */
10011 update_global_location_list (1);
10016 /* Set a breakpoint.
10017 ARG is a string describing breakpoint address,
10018 condition, and thread.
10019 FLAG specifies if a breakpoint is hardware on,
10020 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10021 and BP_TEMPFLAG. */
10024 break_command_1 (char *arg
, int flag
, int from_tty
)
10026 int tempflag
= flag
& BP_TEMPFLAG
;
10027 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10028 ? bp_hardware_breakpoint
10030 struct breakpoint_ops
*ops
;
10031 const char *arg_cp
= arg
;
10033 /* Matching breakpoints on probes. */
10034 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10035 ops
= &bkpt_probe_breakpoint_ops
;
10037 ops
= &bkpt_breakpoint_ops
;
10039 create_breakpoint (get_current_arch (),
10041 NULL
, 0, NULL
, 1 /* parse arg */,
10042 tempflag
, type_wanted
,
10043 0 /* Ignore count */,
10044 pending_break_support
,
10052 /* Helper function for break_command_1 and disassemble_command. */
10055 resolve_sal_pc (struct symtab_and_line
*sal
)
10059 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10061 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10062 error (_("No line %d in file \"%s\"."),
10063 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10066 /* If this SAL corresponds to a breakpoint inserted using a line
10067 number, then skip the function prologue if necessary. */
10068 if (sal
->explicit_line
)
10069 skip_prologue_sal (sal
);
10072 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10074 struct blockvector
*bv
;
10076 struct symbol
*sym
;
10078 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
10081 sym
= block_linkage_function (b
);
10084 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
10085 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
10089 /* It really is worthwhile to have the section, so we'll
10090 just have to look harder. This case can be executed
10091 if we have line numbers but no functions (as can
10092 happen in assembly source). */
10094 struct bound_minimal_symbol msym
;
10095 struct cleanup
*old_chain
= save_current_space_and_thread ();
10097 switch_to_program_space_and_thread (sal
->pspace
);
10099 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10101 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10103 do_cleanups (old_chain
);
10110 break_command (char *arg
, int from_tty
)
10112 break_command_1 (arg
, 0, from_tty
);
10116 tbreak_command (char *arg
, int from_tty
)
10118 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10122 hbreak_command (char *arg
, int from_tty
)
10124 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10128 thbreak_command (char *arg
, int from_tty
)
10130 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10134 stop_command (char *arg
, int from_tty
)
10136 printf_filtered (_("Specify the type of breakpoint to set.\n\
10137 Usage: stop in <function | address>\n\
10138 stop at <line>\n"));
10142 stopin_command (char *arg
, int from_tty
)
10146 if (arg
== (char *) NULL
)
10148 else if (*arg
!= '*')
10150 char *argptr
= arg
;
10153 /* Look for a ':'. If this is a line number specification, then
10154 say it is bad, otherwise, it should be an address or
10155 function/method name. */
10156 while (*argptr
&& !hasColon
)
10158 hasColon
= (*argptr
== ':');
10163 badInput
= (*argptr
!= ':'); /* Not a class::method */
10165 badInput
= isdigit (*arg
); /* a simple line number */
10169 printf_filtered (_("Usage: stop in <function | address>\n"));
10171 break_command_1 (arg
, 0, from_tty
);
10175 stopat_command (char *arg
, int from_tty
)
10179 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10183 char *argptr
= arg
;
10186 /* Look for a ':'. If there is a '::' then get out, otherwise
10187 it is probably a line number. */
10188 while (*argptr
&& !hasColon
)
10190 hasColon
= (*argptr
== ':');
10195 badInput
= (*argptr
== ':'); /* we have class::method */
10197 badInput
= !isdigit (*arg
); /* not a line number */
10201 printf_filtered (_("Usage: stop at <line>\n"));
10203 break_command_1 (arg
, 0, from_tty
);
10206 /* The dynamic printf command is mostly like a regular breakpoint, but
10207 with a prewired command list consisting of a single output command,
10208 built from extra arguments supplied on the dprintf command
10212 dprintf_command (char *arg
, int from_tty
)
10214 create_breakpoint (get_current_arch (),
10216 NULL
, 0, NULL
, 1 /* parse arg */,
10218 0 /* Ignore count */,
10219 pending_break_support
,
10220 &dprintf_breakpoint_ops
,
10228 agent_printf_command (char *arg
, int from_tty
)
10230 error (_("May only run agent-printf on the target"));
10233 /* Implement the "breakpoint_hit" breakpoint_ops method for
10234 ranged breakpoints. */
10237 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10238 struct address_space
*aspace
,
10240 const struct target_waitstatus
*ws
)
10242 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10243 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10246 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10247 bl
->length
, aspace
, bp_addr
);
10250 /* Implement the "resources_needed" breakpoint_ops method for
10251 ranged breakpoints. */
10254 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10256 return target_ranged_break_num_registers ();
10259 /* Implement the "print_it" breakpoint_ops method for
10260 ranged breakpoints. */
10262 static enum print_stop_action
10263 print_it_ranged_breakpoint (bpstat bs
)
10265 struct breakpoint
*b
= bs
->breakpoint_at
;
10266 struct bp_location
*bl
= b
->loc
;
10267 struct ui_out
*uiout
= current_uiout
;
10269 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10271 /* Ranged breakpoints have only one location. */
10272 gdb_assert (bl
&& bl
->next
== NULL
);
10274 annotate_breakpoint (b
->number
);
10275 if (b
->disposition
== disp_del
)
10276 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10278 ui_out_text (uiout
, "\nRanged breakpoint ");
10279 if (ui_out_is_mi_like_p (uiout
))
10281 ui_out_field_string (uiout
, "reason",
10282 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10283 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10285 ui_out_field_int (uiout
, "bkptno", b
->number
);
10286 ui_out_text (uiout
, ", ");
10288 return PRINT_SRC_AND_LOC
;
10291 /* Implement the "print_one" breakpoint_ops method for
10292 ranged breakpoints. */
10295 print_one_ranged_breakpoint (struct breakpoint
*b
,
10296 struct bp_location
**last_loc
)
10298 struct bp_location
*bl
= b
->loc
;
10299 struct value_print_options opts
;
10300 struct ui_out
*uiout
= current_uiout
;
10302 /* Ranged breakpoints have only one location. */
10303 gdb_assert (bl
&& bl
->next
== NULL
);
10305 get_user_print_options (&opts
);
10307 if (opts
.addressprint
)
10308 /* We don't print the address range here, it will be printed later
10309 by print_one_detail_ranged_breakpoint. */
10310 ui_out_field_skip (uiout
, "addr");
10311 annotate_field (5);
10312 print_breakpoint_location (b
, bl
);
10316 /* Implement the "print_one_detail" breakpoint_ops method for
10317 ranged breakpoints. */
10320 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10321 struct ui_out
*uiout
)
10323 CORE_ADDR address_start
, address_end
;
10324 struct bp_location
*bl
= b
->loc
;
10325 struct ui_file
*stb
= mem_fileopen ();
10326 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10330 address_start
= bl
->address
;
10331 address_end
= address_start
+ bl
->length
- 1;
10333 ui_out_text (uiout
, "\taddress range: ");
10334 fprintf_unfiltered (stb
, "[%s, %s]",
10335 print_core_address (bl
->gdbarch
, address_start
),
10336 print_core_address (bl
->gdbarch
, address_end
));
10337 ui_out_field_stream (uiout
, "addr", stb
);
10338 ui_out_text (uiout
, "\n");
10340 do_cleanups (cleanup
);
10343 /* Implement the "print_mention" breakpoint_ops method for
10344 ranged breakpoints. */
10347 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10349 struct bp_location
*bl
= b
->loc
;
10350 struct ui_out
*uiout
= current_uiout
;
10353 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10355 if (ui_out_is_mi_like_p (uiout
))
10358 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10359 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10360 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10363 /* Implement the "print_recreate" breakpoint_ops method for
10364 ranged breakpoints. */
10367 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10369 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10370 b
->addr_string_range_end
);
10371 print_recreate_thread (b
, fp
);
10374 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10376 static struct breakpoint_ops ranged_breakpoint_ops
;
10378 /* Find the address where the end of the breakpoint range should be
10379 placed, given the SAL of the end of the range. This is so that if
10380 the user provides a line number, the end of the range is set to the
10381 last instruction of the given line. */
10384 find_breakpoint_range_end (struct symtab_and_line sal
)
10388 /* If the user provided a PC value, use it. Otherwise,
10389 find the address of the end of the given location. */
10390 if (sal
.explicit_pc
)
10397 ret
= find_line_pc_range (sal
, &start
, &end
);
10399 error (_("Could not find location of the end of the range."));
10401 /* find_line_pc_range returns the start of the next line. */
10408 /* Implement the "break-range" CLI command. */
10411 break_range_command (char *arg
, int from_tty
)
10413 char *arg_start
, *addr_string_start
, *addr_string_end
;
10414 struct linespec_result canonical_start
, canonical_end
;
10415 int bp_count
, can_use_bp
, length
;
10417 struct breakpoint
*b
;
10418 struct symtab_and_line sal_start
, sal_end
;
10419 struct cleanup
*cleanup_bkpt
;
10420 struct linespec_sals
*lsal_start
, *lsal_end
;
10422 /* We don't support software ranged breakpoints. */
10423 if (target_ranged_break_num_registers () < 0)
10424 error (_("This target does not support hardware ranged breakpoints."));
10426 bp_count
= hw_breakpoint_used_count ();
10427 bp_count
+= target_ranged_break_num_registers ();
10428 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10430 if (can_use_bp
< 0)
10431 error (_("Hardware breakpoints used exceeds limit."));
10433 arg
= skip_spaces (arg
);
10434 if (arg
== NULL
|| arg
[0] == '\0')
10435 error(_("No address range specified."));
10437 init_linespec_result (&canonical_start
);
10440 parse_breakpoint_sals (&arg
, &canonical_start
);
10442 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10445 error (_("Too few arguments."));
10446 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10447 error (_("Could not find location of the beginning of the range."));
10449 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10451 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10452 || lsal_start
->sals
.nelts
!= 1)
10453 error (_("Cannot create a ranged breakpoint with multiple locations."));
10455 sal_start
= lsal_start
->sals
.sals
[0];
10456 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10457 make_cleanup (xfree
, addr_string_start
);
10459 arg
++; /* Skip the comma. */
10460 arg
= skip_spaces (arg
);
10462 /* Parse the end location. */
10464 init_linespec_result (&canonical_end
);
10467 /* We call decode_line_full directly here instead of using
10468 parse_breakpoint_sals because we need to specify the start location's
10469 symtab and line as the default symtab and line for the end of the
10470 range. This makes it possible to have ranges like "foo.c:27, +14",
10471 where +14 means 14 lines from the start location. */
10472 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10473 sal_start
.symtab
, sal_start
.line
,
10474 &canonical_end
, NULL
, NULL
);
10476 make_cleanup_destroy_linespec_result (&canonical_end
);
10478 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10479 error (_("Could not find location of the end of the range."));
10481 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10482 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10483 || lsal_end
->sals
.nelts
!= 1)
10484 error (_("Cannot create a ranged breakpoint with multiple locations."));
10486 sal_end
= lsal_end
->sals
.sals
[0];
10487 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10488 make_cleanup (xfree
, addr_string_end
);
10490 end
= find_breakpoint_range_end (sal_end
);
10491 if (sal_start
.pc
> end
)
10492 error (_("Invalid address range, end precedes start."));
10494 length
= end
- sal_start
.pc
+ 1;
10496 /* Length overflowed. */
10497 error (_("Address range too large."));
10498 else if (length
== 1)
10500 /* This range is simple enough to be handled by
10501 the `hbreak' command. */
10502 hbreak_command (addr_string_start
, 1);
10504 do_cleanups (cleanup_bkpt
);
10509 /* Now set up the breakpoint. */
10510 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10511 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10512 set_breakpoint_count (breakpoint_count
+ 1);
10513 b
->number
= breakpoint_count
;
10514 b
->disposition
= disp_donttouch
;
10515 b
->addr_string
= xstrdup (addr_string_start
);
10516 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10517 b
->loc
->length
= length
;
10519 do_cleanups (cleanup_bkpt
);
10522 observer_notify_breakpoint_created (b
);
10523 update_global_location_list (1);
10526 /* Return non-zero if EXP is verified as constant. Returned zero
10527 means EXP is variable. Also the constant detection may fail for
10528 some constant expressions and in such case still falsely return
10532 watchpoint_exp_is_const (const struct expression
*exp
)
10534 int i
= exp
->nelts
;
10540 /* We are only interested in the descriptor of each element. */
10541 operator_length (exp
, i
, &oplenp
, &argsp
);
10544 switch (exp
->elts
[i
].opcode
)
10554 case BINOP_LOGICAL_AND
:
10555 case BINOP_LOGICAL_OR
:
10556 case BINOP_BITWISE_AND
:
10557 case BINOP_BITWISE_IOR
:
10558 case BINOP_BITWISE_XOR
:
10560 case BINOP_NOTEQUAL
:
10589 case OP_OBJC_NSSTRING
:
10592 case UNOP_LOGICAL_NOT
:
10593 case UNOP_COMPLEMENT
:
10598 case UNOP_CAST_TYPE
:
10599 case UNOP_REINTERPRET_CAST
:
10600 case UNOP_DYNAMIC_CAST
:
10601 /* Unary, binary and ternary operators: We have to check
10602 their operands. If they are constant, then so is the
10603 result of that operation. For instance, if A and B are
10604 determined to be constants, then so is "A + B".
10606 UNOP_IND is one exception to the rule above, because the
10607 value of *ADDR is not necessarily a constant, even when
10612 /* Check whether the associated symbol is a constant.
10614 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10615 possible that a buggy compiler could mark a variable as
10616 constant even when it is not, and TYPE_CONST would return
10617 true in this case, while SYMBOL_CLASS wouldn't.
10619 We also have to check for function symbols because they
10620 are always constant. */
10622 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10624 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10625 && SYMBOL_CLASS (s
) != LOC_CONST
10626 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10631 /* The default action is to return 0 because we are using
10632 the optimistic approach here: If we don't know something,
10633 then it is not a constant. */
10642 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10645 dtor_watchpoint (struct breakpoint
*self
)
10647 struct watchpoint
*w
= (struct watchpoint
*) self
;
10649 xfree (w
->cond_exp
);
10651 xfree (w
->exp_string
);
10652 xfree (w
->exp_string_reparse
);
10653 value_free (w
->val
);
10655 base_breakpoint_ops
.dtor (self
);
10658 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10661 re_set_watchpoint (struct breakpoint
*b
)
10663 struct watchpoint
*w
= (struct watchpoint
*) b
;
10665 /* Watchpoint can be either on expression using entirely global
10666 variables, or it can be on local variables.
10668 Watchpoints of the first kind are never auto-deleted, and even
10669 persist across program restarts. Since they can use variables
10670 from shared libraries, we need to reparse expression as libraries
10671 are loaded and unloaded.
10673 Watchpoints on local variables can also change meaning as result
10674 of solib event. For example, if a watchpoint uses both a local
10675 and a global variables in expression, it's a local watchpoint,
10676 but unloading of a shared library will make the expression
10677 invalid. This is not a very common use case, but we still
10678 re-evaluate expression, to avoid surprises to the user.
10680 Note that for local watchpoints, we re-evaluate it only if
10681 watchpoints frame id is still valid. If it's not, it means the
10682 watchpoint is out of scope and will be deleted soon. In fact,
10683 I'm not sure we'll ever be called in this case.
10685 If a local watchpoint's frame id is still valid, then
10686 w->exp_valid_block is likewise valid, and we can safely use it.
10688 Don't do anything about disabled watchpoints, since they will be
10689 reevaluated again when enabled. */
10690 update_watchpoint (w
, 1 /* reparse */);
10693 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10696 insert_watchpoint (struct bp_location
*bl
)
10698 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10699 int length
= w
->exact
? 1 : bl
->length
;
10701 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10705 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10708 remove_watchpoint (struct bp_location
*bl
)
10710 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10711 int length
= w
->exact
? 1 : bl
->length
;
10713 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10718 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10719 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10720 const struct target_waitstatus
*ws
)
10722 struct breakpoint
*b
= bl
->owner
;
10723 struct watchpoint
*w
= (struct watchpoint
*) b
;
10725 /* Continuable hardware watchpoints are treated as non-existent if the
10726 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10727 some data address). Otherwise gdb won't stop on a break instruction
10728 in the code (not from a breakpoint) when a hardware watchpoint has
10729 been defined. Also skip watchpoints which we know did not trigger
10730 (did not match the data address). */
10731 if (is_hardware_watchpoint (b
)
10732 && w
->watchpoint_triggered
== watch_triggered_no
)
10739 check_status_watchpoint (bpstat bs
)
10741 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10743 bpstat_check_watchpoint (bs
);
10746 /* Implement the "resources_needed" breakpoint_ops method for
10747 hardware watchpoints. */
10750 resources_needed_watchpoint (const struct bp_location
*bl
)
10752 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10753 int length
= w
->exact
? 1 : bl
->length
;
10755 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10758 /* Implement the "works_in_software_mode" breakpoint_ops method for
10759 hardware watchpoints. */
10762 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10764 /* Read and access watchpoints only work with hardware support. */
10765 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10768 static enum print_stop_action
10769 print_it_watchpoint (bpstat bs
)
10771 struct cleanup
*old_chain
;
10772 struct breakpoint
*b
;
10773 struct ui_file
*stb
;
10774 enum print_stop_action result
;
10775 struct watchpoint
*w
;
10776 struct ui_out
*uiout
= current_uiout
;
10778 gdb_assert (bs
->bp_location_at
!= NULL
);
10780 b
= bs
->breakpoint_at
;
10781 w
= (struct watchpoint
*) b
;
10783 stb
= mem_fileopen ();
10784 old_chain
= make_cleanup_ui_file_delete (stb
);
10788 case bp_watchpoint
:
10789 case bp_hardware_watchpoint
:
10790 annotate_watchpoint (b
->number
);
10791 if (ui_out_is_mi_like_p (uiout
))
10792 ui_out_field_string
10794 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10796 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10797 ui_out_text (uiout
, "\nOld value = ");
10798 watchpoint_value_print (bs
->old_val
, stb
);
10799 ui_out_field_stream (uiout
, "old", stb
);
10800 ui_out_text (uiout
, "\nNew value = ");
10801 watchpoint_value_print (w
->val
, stb
);
10802 ui_out_field_stream (uiout
, "new", stb
);
10803 ui_out_text (uiout
, "\n");
10804 /* More than one watchpoint may have been triggered. */
10805 result
= PRINT_UNKNOWN
;
10808 case bp_read_watchpoint
:
10809 if (ui_out_is_mi_like_p (uiout
))
10810 ui_out_field_string
10812 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10814 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10815 ui_out_text (uiout
, "\nValue = ");
10816 watchpoint_value_print (w
->val
, stb
);
10817 ui_out_field_stream (uiout
, "value", stb
);
10818 ui_out_text (uiout
, "\n");
10819 result
= PRINT_UNKNOWN
;
10822 case bp_access_watchpoint
:
10823 if (bs
->old_val
!= NULL
)
10825 annotate_watchpoint (b
->number
);
10826 if (ui_out_is_mi_like_p (uiout
))
10827 ui_out_field_string
10829 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10831 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10832 ui_out_text (uiout
, "\nOld value = ");
10833 watchpoint_value_print (bs
->old_val
, stb
);
10834 ui_out_field_stream (uiout
, "old", stb
);
10835 ui_out_text (uiout
, "\nNew value = ");
10840 if (ui_out_is_mi_like_p (uiout
))
10841 ui_out_field_string
10843 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10844 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10845 ui_out_text (uiout
, "\nValue = ");
10847 watchpoint_value_print (w
->val
, stb
);
10848 ui_out_field_stream (uiout
, "new", stb
);
10849 ui_out_text (uiout
, "\n");
10850 result
= PRINT_UNKNOWN
;
10853 result
= PRINT_UNKNOWN
;
10856 do_cleanups (old_chain
);
10860 /* Implement the "print_mention" breakpoint_ops method for hardware
10864 print_mention_watchpoint (struct breakpoint
*b
)
10866 struct cleanup
*ui_out_chain
;
10867 struct watchpoint
*w
= (struct watchpoint
*) b
;
10868 struct ui_out
*uiout
= current_uiout
;
10872 case bp_watchpoint
:
10873 ui_out_text (uiout
, "Watchpoint ");
10874 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10876 case bp_hardware_watchpoint
:
10877 ui_out_text (uiout
, "Hardware watchpoint ");
10878 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10880 case bp_read_watchpoint
:
10881 ui_out_text (uiout
, "Hardware read watchpoint ");
10882 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10884 case bp_access_watchpoint
:
10885 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10886 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10889 internal_error (__FILE__
, __LINE__
,
10890 _("Invalid hardware watchpoint type."));
10893 ui_out_field_int (uiout
, "number", b
->number
);
10894 ui_out_text (uiout
, ": ");
10895 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10896 do_cleanups (ui_out_chain
);
10899 /* Implement the "print_recreate" breakpoint_ops method for
10903 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10905 struct watchpoint
*w
= (struct watchpoint
*) b
;
10909 case bp_watchpoint
:
10910 case bp_hardware_watchpoint
:
10911 fprintf_unfiltered (fp
, "watch");
10913 case bp_read_watchpoint
:
10914 fprintf_unfiltered (fp
, "rwatch");
10916 case bp_access_watchpoint
:
10917 fprintf_unfiltered (fp
, "awatch");
10920 internal_error (__FILE__
, __LINE__
,
10921 _("Invalid watchpoint type."));
10924 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10925 print_recreate_thread (b
, fp
);
10928 /* Implement the "explains_signal" breakpoint_ops method for
10932 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10934 /* A software watchpoint cannot cause a signal other than
10935 GDB_SIGNAL_TRAP. */
10936 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10942 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10944 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10946 /* Implement the "insert" breakpoint_ops method for
10947 masked hardware watchpoints. */
10950 insert_masked_watchpoint (struct bp_location
*bl
)
10952 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10954 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10955 bl
->watchpoint_type
);
10958 /* Implement the "remove" breakpoint_ops method for
10959 masked hardware watchpoints. */
10962 remove_masked_watchpoint (struct bp_location
*bl
)
10964 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10966 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10967 bl
->watchpoint_type
);
10970 /* Implement the "resources_needed" breakpoint_ops method for
10971 masked hardware watchpoints. */
10974 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10976 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10978 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10981 /* Implement the "works_in_software_mode" breakpoint_ops method for
10982 masked hardware watchpoints. */
10985 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10990 /* Implement the "print_it" breakpoint_ops method for
10991 masked hardware watchpoints. */
10993 static enum print_stop_action
10994 print_it_masked_watchpoint (bpstat bs
)
10996 struct breakpoint
*b
= bs
->breakpoint_at
;
10997 struct ui_out
*uiout
= current_uiout
;
10999 /* Masked watchpoints have only one location. */
11000 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11004 case bp_hardware_watchpoint
:
11005 annotate_watchpoint (b
->number
);
11006 if (ui_out_is_mi_like_p (uiout
))
11007 ui_out_field_string
11009 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11012 case bp_read_watchpoint
:
11013 if (ui_out_is_mi_like_p (uiout
))
11014 ui_out_field_string
11016 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11019 case bp_access_watchpoint
:
11020 if (ui_out_is_mi_like_p (uiout
))
11021 ui_out_field_string
11023 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11026 internal_error (__FILE__
, __LINE__
,
11027 _("Invalid hardware watchpoint type."));
11031 ui_out_text (uiout
, _("\n\
11032 Check the underlying instruction at PC for the memory\n\
11033 address and value which triggered this watchpoint.\n"));
11034 ui_out_text (uiout
, "\n");
11036 /* More than one watchpoint may have been triggered. */
11037 return PRINT_UNKNOWN
;
11040 /* Implement the "print_one_detail" breakpoint_ops method for
11041 masked hardware watchpoints. */
11044 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11045 struct ui_out
*uiout
)
11047 struct watchpoint
*w
= (struct watchpoint
*) b
;
11049 /* Masked watchpoints have only one location. */
11050 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11052 ui_out_text (uiout
, "\tmask ");
11053 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11054 ui_out_text (uiout
, "\n");
11057 /* Implement the "print_mention" breakpoint_ops method for
11058 masked hardware watchpoints. */
11061 print_mention_masked_watchpoint (struct breakpoint
*b
)
11063 struct watchpoint
*w
= (struct watchpoint
*) b
;
11064 struct ui_out
*uiout
= current_uiout
;
11065 struct cleanup
*ui_out_chain
;
11069 case bp_hardware_watchpoint
:
11070 ui_out_text (uiout
, "Masked hardware watchpoint ");
11071 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11073 case bp_read_watchpoint
:
11074 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11075 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11077 case bp_access_watchpoint
:
11078 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11079 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11082 internal_error (__FILE__
, __LINE__
,
11083 _("Invalid hardware watchpoint type."));
11086 ui_out_field_int (uiout
, "number", b
->number
);
11087 ui_out_text (uiout
, ": ");
11088 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11089 do_cleanups (ui_out_chain
);
11092 /* Implement the "print_recreate" breakpoint_ops method for
11093 masked hardware watchpoints. */
11096 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11098 struct watchpoint
*w
= (struct watchpoint
*) b
;
11103 case bp_hardware_watchpoint
:
11104 fprintf_unfiltered (fp
, "watch");
11106 case bp_read_watchpoint
:
11107 fprintf_unfiltered (fp
, "rwatch");
11109 case bp_access_watchpoint
:
11110 fprintf_unfiltered (fp
, "awatch");
11113 internal_error (__FILE__
, __LINE__
,
11114 _("Invalid hardware watchpoint type."));
11117 sprintf_vma (tmp
, w
->hw_wp_mask
);
11118 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11119 print_recreate_thread (b
, fp
);
11122 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11124 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11126 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11129 is_masked_watchpoint (const struct breakpoint
*b
)
11131 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11134 /* accessflag: hw_write: watch write,
11135 hw_read: watch read,
11136 hw_access: watch access (read or write) */
11138 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11139 int just_location
, int internal
)
11141 volatile struct gdb_exception e
;
11142 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11143 struct expression
*exp
;
11144 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11145 struct value
*val
, *mark
, *result
;
11146 struct frame_info
*frame
;
11147 const char *exp_start
= NULL
;
11148 const char *exp_end
= NULL
;
11149 const char *tok
, *end_tok
;
11151 const char *cond_start
= NULL
;
11152 const char *cond_end
= NULL
;
11153 enum bptype bp_type
;
11156 /* Flag to indicate whether we are going to use masks for
11157 the hardware watchpoint. */
11159 CORE_ADDR mask
= 0;
11160 struct watchpoint
*w
;
11162 struct cleanup
*back_to
;
11164 /* Make sure that we actually have parameters to parse. */
11165 if (arg
!= NULL
&& arg
[0] != '\0')
11167 const char *value_start
;
11169 exp_end
= arg
+ strlen (arg
);
11171 /* Look for "parameter value" pairs at the end
11172 of the arguments string. */
11173 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11175 /* Skip whitespace at the end of the argument list. */
11176 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11179 /* Find the beginning of the last token.
11180 This is the value of the parameter. */
11181 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11183 value_start
= tok
+ 1;
11185 /* Skip whitespace. */
11186 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11191 /* Find the beginning of the second to last token.
11192 This is the parameter itself. */
11193 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11196 toklen
= end_tok
- tok
+ 1;
11198 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11200 /* At this point we've found a "thread" token, which means
11201 the user is trying to set a watchpoint that triggers
11202 only in a specific thread. */
11206 error(_("You can specify only one thread."));
11208 /* Extract the thread ID from the next token. */
11209 thread
= strtol (value_start
, &endp
, 0);
11211 /* Check if the user provided a valid numeric value for the
11213 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11214 error (_("Invalid thread ID specification %s."), value_start
);
11216 /* Check if the thread actually exists. */
11217 if (!valid_thread_id (thread
))
11218 invalid_thread_id_error (thread
);
11220 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11222 /* We've found a "mask" token, which means the user wants to
11223 create a hardware watchpoint that is going to have the mask
11225 struct value
*mask_value
, *mark
;
11228 error(_("You can specify only one mask."));
11230 use_mask
= just_location
= 1;
11232 mark
= value_mark ();
11233 mask_value
= parse_to_comma_and_eval (&value_start
);
11234 mask
= value_as_address (mask_value
);
11235 value_free_to_mark (mark
);
11238 /* We didn't recognize what we found. We should stop here. */
11241 /* Truncate the string and get rid of the "parameter value" pair before
11242 the arguments string is parsed by the parse_exp_1 function. */
11249 /* Parse the rest of the arguments. From here on out, everything
11250 is in terms of a newly allocated string instead of the original
11252 innermost_block
= NULL
;
11253 expression
= savestring (arg
, exp_end
- arg
);
11254 back_to
= make_cleanup (xfree
, expression
);
11255 exp_start
= arg
= expression
;
11256 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11258 /* Remove trailing whitespace from the expression before saving it.
11259 This makes the eventual display of the expression string a bit
11261 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11264 /* Checking if the expression is not constant. */
11265 if (watchpoint_exp_is_const (exp
))
11269 len
= exp_end
- exp_start
;
11270 while (len
> 0 && isspace (exp_start
[len
- 1]))
11272 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11275 exp_valid_block
= innermost_block
;
11276 mark
= value_mark ();
11277 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11283 exp_valid_block
= NULL
;
11284 val
= value_addr (result
);
11285 release_value (val
);
11286 value_free_to_mark (mark
);
11290 ret
= target_masked_watch_num_registers (value_as_address (val
),
11293 error (_("This target does not support masked watchpoints."));
11294 else if (ret
== -2)
11295 error (_("Invalid mask or memory region."));
11298 else if (val
!= NULL
)
11299 release_value (val
);
11301 tok
= skip_spaces_const (arg
);
11302 end_tok
= skip_to_space_const (tok
);
11304 toklen
= end_tok
- tok
;
11305 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11307 struct expression
*cond
;
11309 innermost_block
= NULL
;
11310 tok
= cond_start
= end_tok
+ 1;
11311 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11313 /* The watchpoint expression may not be local, but the condition
11314 may still be. E.g.: `watch global if local > 0'. */
11315 cond_exp_valid_block
= innermost_block
;
11321 error (_("Junk at end of command."));
11323 frame
= block_innermost_frame (exp_valid_block
);
11325 /* If the expression is "local", then set up a "watchpoint scope"
11326 breakpoint at the point where we've left the scope of the watchpoint
11327 expression. Create the scope breakpoint before the watchpoint, so
11328 that we will encounter it first in bpstat_stop_status. */
11329 if (exp_valid_block
&& frame
)
11331 if (frame_id_p (frame_unwind_caller_id (frame
)))
11334 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11335 frame_unwind_caller_pc (frame
),
11336 bp_watchpoint_scope
,
11337 &momentary_breakpoint_ops
);
11339 scope_breakpoint
->enable_state
= bp_enabled
;
11341 /* Automatically delete the breakpoint when it hits. */
11342 scope_breakpoint
->disposition
= disp_del
;
11344 /* Only break in the proper frame (help with recursion). */
11345 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11347 /* Set the address at which we will stop. */
11348 scope_breakpoint
->loc
->gdbarch
11349 = frame_unwind_caller_arch (frame
);
11350 scope_breakpoint
->loc
->requested_address
11351 = frame_unwind_caller_pc (frame
);
11352 scope_breakpoint
->loc
->address
11353 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11354 scope_breakpoint
->loc
->requested_address
,
11355 scope_breakpoint
->type
);
11359 /* Now set up the breakpoint. We create all watchpoints as hardware
11360 watchpoints here even if hardware watchpoints are turned off, a call
11361 to update_watchpoint later in this function will cause the type to
11362 drop back to bp_watchpoint (software watchpoint) if required. */
11364 if (accessflag
== hw_read
)
11365 bp_type
= bp_read_watchpoint
;
11366 else if (accessflag
== hw_access
)
11367 bp_type
= bp_access_watchpoint
;
11369 bp_type
= bp_hardware_watchpoint
;
11371 w
= XCNEW (struct watchpoint
);
11374 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11375 &masked_watchpoint_breakpoint_ops
);
11377 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11378 &watchpoint_breakpoint_ops
);
11379 b
->thread
= thread
;
11380 b
->disposition
= disp_donttouch
;
11381 b
->pspace
= current_program_space
;
11383 w
->exp_valid_block
= exp_valid_block
;
11384 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11387 struct type
*t
= value_type (val
);
11388 CORE_ADDR addr
= value_as_address (val
);
11391 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11392 name
= type_to_string (t
);
11394 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11395 core_addr_to_string (addr
));
11398 w
->exp_string
= xstrprintf ("-location %.*s",
11399 (int) (exp_end
- exp_start
), exp_start
);
11401 /* The above expression is in C. */
11402 b
->language
= language_c
;
11405 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11409 w
->hw_wp_mask
= mask
;
11418 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11420 b
->cond_string
= 0;
11424 w
->watchpoint_frame
= get_frame_id (frame
);
11425 w
->watchpoint_thread
= inferior_ptid
;
11429 w
->watchpoint_frame
= null_frame_id
;
11430 w
->watchpoint_thread
= null_ptid
;
11433 if (scope_breakpoint
!= NULL
)
11435 /* The scope breakpoint is related to the watchpoint. We will
11436 need to act on them together. */
11437 b
->related_breakpoint
= scope_breakpoint
;
11438 scope_breakpoint
->related_breakpoint
= b
;
11441 if (!just_location
)
11442 value_free_to_mark (mark
);
11444 TRY_CATCH (e
, RETURN_MASK_ALL
)
11446 /* Finally update the new watchpoint. This creates the locations
11447 that should be inserted. */
11448 update_watchpoint (w
, 1);
11452 delete_breakpoint (b
);
11453 throw_exception (e
);
11456 install_breakpoint (internal
, b
, 1);
11457 do_cleanups (back_to
);
11460 /* Return count of debug registers needed to watch the given expression.
11461 If the watchpoint cannot be handled in hardware return zero. */
11464 can_use_hardware_watchpoint (struct value
*v
)
11466 int found_memory_cnt
= 0;
11467 struct value
*head
= v
;
11469 /* Did the user specifically forbid us to use hardware watchpoints? */
11470 if (!can_use_hw_watchpoints
)
11473 /* Make sure that the value of the expression depends only upon
11474 memory contents, and values computed from them within GDB. If we
11475 find any register references or function calls, we can't use a
11476 hardware watchpoint.
11478 The idea here is that evaluating an expression generates a series
11479 of values, one holding the value of every subexpression. (The
11480 expression a*b+c has five subexpressions: a, b, a*b, c, and
11481 a*b+c.) GDB's values hold almost enough information to establish
11482 the criteria given above --- they identify memory lvalues,
11483 register lvalues, computed values, etcetera. So we can evaluate
11484 the expression, and then scan the chain of values that leaves
11485 behind to decide whether we can detect any possible change to the
11486 expression's final value using only hardware watchpoints.
11488 However, I don't think that the values returned by inferior
11489 function calls are special in any way. So this function may not
11490 notice that an expression involving an inferior function call
11491 can't be watched with hardware watchpoints. FIXME. */
11492 for (; v
; v
= value_next (v
))
11494 if (VALUE_LVAL (v
) == lval_memory
)
11496 if (v
!= head
&& value_lazy (v
))
11497 /* A lazy memory lvalue in the chain is one that GDB never
11498 needed to fetch; we either just used its address (e.g.,
11499 `a' in `a.b') or we never needed it at all (e.g., `a'
11500 in `a,b'). This doesn't apply to HEAD; if that is
11501 lazy then it was not readable, but watch it anyway. */
11505 /* Ahh, memory we actually used! Check if we can cover
11506 it with hardware watchpoints. */
11507 struct type
*vtype
= check_typedef (value_type (v
));
11509 /* We only watch structs and arrays if user asked for it
11510 explicitly, never if they just happen to appear in a
11511 middle of some value chain. */
11513 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11514 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11516 CORE_ADDR vaddr
= value_address (v
);
11520 len
= (target_exact_watchpoints
11521 && is_scalar_type_recursive (vtype
))?
11522 1 : TYPE_LENGTH (value_type (v
));
11524 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11528 found_memory_cnt
+= num_regs
;
11532 else if (VALUE_LVAL (v
) != not_lval
11533 && deprecated_value_modifiable (v
) == 0)
11534 return 0; /* These are values from the history (e.g., $1). */
11535 else if (VALUE_LVAL (v
) == lval_register
)
11536 return 0; /* Cannot watch a register with a HW watchpoint. */
11539 /* The expression itself looks suitable for using a hardware
11540 watchpoint, but give the target machine a chance to reject it. */
11541 return found_memory_cnt
;
11545 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11547 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11550 /* A helper function that looks for the "-location" argument and then
11551 calls watch_command_1. */
11554 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11556 int just_location
= 0;
11559 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11560 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11562 arg
= skip_spaces (arg
);
11566 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11570 watch_command (char *arg
, int from_tty
)
11572 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11576 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11578 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11582 rwatch_command (char *arg
, int from_tty
)
11584 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11588 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11590 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11594 awatch_command (char *arg
, int from_tty
)
11596 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11600 /* Helper routines for the until_command routine in infcmd.c. Here
11601 because it uses the mechanisms of breakpoints. */
11603 struct until_break_command_continuation_args
11605 struct breakpoint
*breakpoint
;
11606 struct breakpoint
*breakpoint2
;
11610 /* This function is called by fetch_inferior_event via the
11611 cmd_continuation pointer, to complete the until command. It takes
11612 care of cleaning up the temporary breakpoints set up by the until
11615 until_break_command_continuation (void *arg
, int err
)
11617 struct until_break_command_continuation_args
*a
= arg
;
11619 delete_breakpoint (a
->breakpoint
);
11620 if (a
->breakpoint2
)
11621 delete_breakpoint (a
->breakpoint2
);
11622 delete_longjmp_breakpoint (a
->thread_num
);
11626 until_break_command (char *arg
, int from_tty
, int anywhere
)
11628 struct symtabs_and_lines sals
;
11629 struct symtab_and_line sal
;
11630 struct frame_info
*frame
;
11631 struct gdbarch
*frame_gdbarch
;
11632 struct frame_id stack_frame_id
;
11633 struct frame_id caller_frame_id
;
11634 struct breakpoint
*breakpoint
;
11635 struct breakpoint
*breakpoint2
= NULL
;
11636 struct cleanup
*old_chain
;
11638 struct thread_info
*tp
;
11640 clear_proceed_status ();
11642 /* Set a breakpoint where the user wants it and at return from
11645 if (last_displayed_sal_is_valid ())
11646 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11647 get_last_displayed_symtab (),
11648 get_last_displayed_line ());
11650 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11651 (struct symtab
*) NULL
, 0);
11653 if (sals
.nelts
!= 1)
11654 error (_("Couldn't get information on specified line."));
11656 sal
= sals
.sals
[0];
11657 xfree (sals
.sals
); /* malloc'd, so freed. */
11660 error (_("Junk at end of arguments."));
11662 resolve_sal_pc (&sal
);
11664 tp
= inferior_thread ();
11667 old_chain
= make_cleanup (null_cleanup
, NULL
);
11669 /* Note linespec handling above invalidates the frame chain.
11670 Installing a breakpoint also invalidates the frame chain (as it
11671 may need to switch threads), so do any frame handling before
11674 frame
= get_selected_frame (NULL
);
11675 frame_gdbarch
= get_frame_arch (frame
);
11676 stack_frame_id
= get_stack_frame_id (frame
);
11677 caller_frame_id
= frame_unwind_caller_id (frame
);
11679 /* Keep within the current frame, or in frames called by the current
11682 if (frame_id_p (caller_frame_id
))
11684 struct symtab_and_line sal2
;
11686 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11687 sal2
.pc
= frame_unwind_caller_pc (frame
);
11688 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11692 make_cleanup_delete_breakpoint (breakpoint2
);
11694 set_longjmp_breakpoint (tp
, caller_frame_id
);
11695 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11698 /* set_momentary_breakpoint could invalidate FRAME. */
11702 /* If the user told us to continue until a specified location,
11703 we don't specify a frame at which we need to stop. */
11704 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11705 null_frame_id
, bp_until
);
11707 /* Otherwise, specify the selected frame, because we want to stop
11708 only at the very same frame. */
11709 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11710 stack_frame_id
, bp_until
);
11711 make_cleanup_delete_breakpoint (breakpoint
);
11713 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11715 /* If we are running asynchronously, and proceed call above has
11716 actually managed to start the target, arrange for breakpoints to
11717 be deleted when the target stops. Otherwise, we're already
11718 stopped and delete breakpoints via cleanup chain. */
11720 if (target_can_async_p () && is_running (inferior_ptid
))
11722 struct until_break_command_continuation_args
*args
;
11723 args
= xmalloc (sizeof (*args
));
11725 args
->breakpoint
= breakpoint
;
11726 args
->breakpoint2
= breakpoint2
;
11727 args
->thread_num
= thread
;
11729 discard_cleanups (old_chain
);
11730 add_continuation (inferior_thread (),
11731 until_break_command_continuation
, args
,
11735 do_cleanups (old_chain
);
11738 /* This function attempts to parse an optional "if <cond>" clause
11739 from the arg string. If one is not found, it returns NULL.
11741 Else, it returns a pointer to the condition string. (It does not
11742 attempt to evaluate the string against a particular block.) And,
11743 it updates arg to point to the first character following the parsed
11744 if clause in the arg string. */
11747 ep_parse_optional_if_clause (char **arg
)
11751 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11754 /* Skip the "if" keyword. */
11757 /* Skip any extra leading whitespace, and record the start of the
11758 condition string. */
11759 *arg
= skip_spaces (*arg
);
11760 cond_string
= *arg
;
11762 /* Assume that the condition occupies the remainder of the arg
11764 (*arg
) += strlen (cond_string
);
11766 return cond_string
;
11769 /* Commands to deal with catching events, such as signals, exceptions,
11770 process start/exit, etc. */
11774 catch_fork_temporary
, catch_vfork_temporary
,
11775 catch_fork_permanent
, catch_vfork_permanent
11780 catch_fork_command_1 (char *arg
, int from_tty
,
11781 struct cmd_list_element
*command
)
11783 struct gdbarch
*gdbarch
= get_current_arch ();
11784 char *cond_string
= NULL
;
11785 catch_fork_kind fork_kind
;
11788 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11789 tempflag
= (fork_kind
== catch_fork_temporary
11790 || fork_kind
== catch_vfork_temporary
);
11794 arg
= skip_spaces (arg
);
11796 /* The allowed syntax is:
11798 catch [v]fork if <cond>
11800 First, check if there's an if clause. */
11801 cond_string
= ep_parse_optional_if_clause (&arg
);
11803 if ((*arg
!= '\0') && !isspace (*arg
))
11804 error (_("Junk at end of arguments."));
11806 /* If this target supports it, create a fork or vfork catchpoint
11807 and enable reporting of such events. */
11810 case catch_fork_temporary
:
11811 case catch_fork_permanent
:
11812 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11813 &catch_fork_breakpoint_ops
);
11815 case catch_vfork_temporary
:
11816 case catch_vfork_permanent
:
11817 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11818 &catch_vfork_breakpoint_ops
);
11821 error (_("unsupported or unknown fork kind; cannot catch it"));
11827 catch_exec_command_1 (char *arg
, int from_tty
,
11828 struct cmd_list_element
*command
)
11830 struct exec_catchpoint
*c
;
11831 struct gdbarch
*gdbarch
= get_current_arch ();
11833 char *cond_string
= NULL
;
11835 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11839 arg
= skip_spaces (arg
);
11841 /* The allowed syntax is:
11843 catch exec if <cond>
11845 First, check if there's an if clause. */
11846 cond_string
= ep_parse_optional_if_clause (&arg
);
11848 if ((*arg
!= '\0') && !isspace (*arg
))
11849 error (_("Junk at end of arguments."));
11851 c
= XNEW (struct exec_catchpoint
);
11852 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11853 &catch_exec_breakpoint_ops
);
11854 c
->exec_pathname
= NULL
;
11856 install_breakpoint (0, &c
->base
, 1);
11860 init_ada_exception_breakpoint (struct breakpoint
*b
,
11861 struct gdbarch
*gdbarch
,
11862 struct symtab_and_line sal
,
11864 const struct breakpoint_ops
*ops
,
11871 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11873 loc_gdbarch
= gdbarch
;
11875 describe_other_breakpoints (loc_gdbarch
,
11876 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11877 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11878 version for exception catchpoints, because two catchpoints
11879 used for different exception names will use the same address.
11880 In this case, a "breakpoint ... also set at..." warning is
11881 unproductive. Besides, the warning phrasing is also a bit
11882 inappropriate, we should use the word catchpoint, and tell
11883 the user what type of catchpoint it is. The above is good
11884 enough for now, though. */
11887 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11889 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11890 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11891 b
->addr_string
= addr_string
;
11892 b
->language
= language_ada
;
11895 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11896 filter list, or NULL if no filtering is required. */
11898 catch_syscall_split_args (char *arg
)
11900 VEC(int) *result
= NULL
;
11901 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11903 while (*arg
!= '\0')
11905 int i
, syscall_number
;
11907 char cur_name
[128];
11910 /* Skip whitespace. */
11911 arg
= skip_spaces (arg
);
11913 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11914 cur_name
[i
] = arg
[i
];
11915 cur_name
[i
] = '\0';
11918 /* Check if the user provided a syscall name or a number. */
11919 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11920 if (*endptr
== '\0')
11921 get_syscall_by_number (syscall_number
, &s
);
11924 /* We have a name. Let's check if it's valid and convert it
11926 get_syscall_by_name (cur_name
, &s
);
11928 if (s
.number
== UNKNOWN_SYSCALL
)
11929 /* Here we have to issue an error instead of a warning,
11930 because GDB cannot do anything useful if there's no
11931 syscall number to be caught. */
11932 error (_("Unknown syscall name '%s'."), cur_name
);
11935 /* Ok, it's valid. */
11936 VEC_safe_push (int, result
, s
.number
);
11939 discard_cleanups (cleanup
);
11943 /* Implement the "catch syscall" command. */
11946 catch_syscall_command_1 (char *arg
, int from_tty
,
11947 struct cmd_list_element
*command
)
11952 struct gdbarch
*gdbarch
= get_current_arch ();
11954 /* Checking if the feature if supported. */
11955 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11956 error (_("The feature 'catch syscall' is not supported on \
11957 this architecture yet."));
11959 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11961 arg
= skip_spaces (arg
);
11963 /* We need to do this first "dummy" translation in order
11964 to get the syscall XML file loaded or, most important,
11965 to display a warning to the user if there's no XML file
11966 for his/her architecture. */
11967 get_syscall_by_number (0, &s
);
11969 /* The allowed syntax is:
11971 catch syscall <name | number> [<name | number> ... <name | number>]
11973 Let's check if there's a syscall name. */
11976 filter
= catch_syscall_split_args (arg
);
11980 create_syscall_event_catchpoint (tempflag
, filter
,
11981 &catch_syscall_breakpoint_ops
);
11985 catch_command (char *arg
, int from_tty
)
11987 error (_("Catch requires an event name."));
11992 tcatch_command (char *arg
, int from_tty
)
11994 error (_("Catch requires an event name."));
11997 /* A qsort comparison function that sorts breakpoints in order. */
12000 compare_breakpoints (const void *a
, const void *b
)
12002 const breakpoint_p
*ba
= a
;
12003 uintptr_t ua
= (uintptr_t) *ba
;
12004 const breakpoint_p
*bb
= b
;
12005 uintptr_t ub
= (uintptr_t) *bb
;
12007 if ((*ba
)->number
< (*bb
)->number
)
12009 else if ((*ba
)->number
> (*bb
)->number
)
12012 /* Now sort by address, in case we see, e..g, two breakpoints with
12016 return ua
> ub
? 1 : 0;
12019 /* Delete breakpoints by address or line. */
12022 clear_command (char *arg
, int from_tty
)
12024 struct breakpoint
*b
, *prev
;
12025 VEC(breakpoint_p
) *found
= 0;
12028 struct symtabs_and_lines sals
;
12029 struct symtab_and_line sal
;
12031 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12035 sals
= decode_line_with_current_source (arg
,
12036 (DECODE_LINE_FUNFIRSTLINE
12037 | DECODE_LINE_LIST_MODE
));
12038 make_cleanup (xfree
, sals
.sals
);
12043 sals
.sals
= (struct symtab_and_line
*)
12044 xmalloc (sizeof (struct symtab_and_line
));
12045 make_cleanup (xfree
, sals
.sals
);
12046 init_sal (&sal
); /* Initialize to zeroes. */
12048 /* Set sal's line, symtab, pc, and pspace to the values
12049 corresponding to the last call to print_frame_info. If the
12050 codepoint is not valid, this will set all the fields to 0. */
12051 get_last_displayed_sal (&sal
);
12052 if (sal
.symtab
== 0)
12053 error (_("No source file specified."));
12055 sals
.sals
[0] = sal
;
12061 /* We don't call resolve_sal_pc here. That's not as bad as it
12062 seems, because all existing breakpoints typically have both
12063 file/line and pc set. So, if clear is given file/line, we can
12064 match this to existing breakpoint without obtaining pc at all.
12066 We only support clearing given the address explicitly
12067 present in breakpoint table. Say, we've set breakpoint
12068 at file:line. There were several PC values for that file:line,
12069 due to optimization, all in one block.
12071 We've picked one PC value. If "clear" is issued with another
12072 PC corresponding to the same file:line, the breakpoint won't
12073 be cleared. We probably can still clear the breakpoint, but
12074 since the other PC value is never presented to user, user
12075 can only find it by guessing, and it does not seem important
12076 to support that. */
12078 /* For each line spec given, delete bps which correspond to it. Do
12079 it in two passes, solely to preserve the current behavior that
12080 from_tty is forced true if we delete more than one
12084 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12085 for (i
= 0; i
< sals
.nelts
; i
++)
12087 const char *sal_fullname
;
12089 /* If exact pc given, clear bpts at that pc.
12090 If line given (pc == 0), clear all bpts on specified line.
12091 If defaulting, clear all bpts on default line
12094 defaulting sal.pc != 0 tests to do
12099 1 0 <can't happen> */
12101 sal
= sals
.sals
[i
];
12102 sal_fullname
= (sal
.symtab
== NULL
12103 ? NULL
: symtab_to_fullname (sal
.symtab
));
12105 /* Find all matching breakpoints and add them to 'found'. */
12106 ALL_BREAKPOINTS (b
)
12109 /* Are we going to delete b? */
12110 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12112 struct bp_location
*loc
= b
->loc
;
12113 for (; loc
; loc
= loc
->next
)
12115 /* If the user specified file:line, don't allow a PC
12116 match. This matches historical gdb behavior. */
12117 int pc_match
= (!sal
.explicit_line
12119 && (loc
->pspace
== sal
.pspace
)
12120 && (loc
->address
== sal
.pc
)
12121 && (!section_is_overlay (loc
->section
)
12122 || loc
->section
== sal
.section
));
12123 int line_match
= 0;
12125 if ((default_match
|| sal
.explicit_line
)
12126 && loc
->symtab
!= NULL
12127 && sal_fullname
!= NULL
12128 && sal
.pspace
== loc
->pspace
12129 && loc
->line_number
== sal
.line
12130 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12131 sal_fullname
) == 0)
12134 if (pc_match
|| line_match
)
12143 VEC_safe_push(breakpoint_p
, found
, b
);
12147 /* Now go thru the 'found' chain and delete them. */
12148 if (VEC_empty(breakpoint_p
, found
))
12151 error (_("No breakpoint at %s."), arg
);
12153 error (_("No breakpoint at this line."));
12156 /* Remove duplicates from the vec. */
12157 qsort (VEC_address (breakpoint_p
, found
),
12158 VEC_length (breakpoint_p
, found
),
12159 sizeof (breakpoint_p
),
12160 compare_breakpoints
);
12161 prev
= VEC_index (breakpoint_p
, found
, 0);
12162 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12166 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12171 if (VEC_length(breakpoint_p
, found
) > 1)
12172 from_tty
= 1; /* Always report if deleted more than one. */
12175 if (VEC_length(breakpoint_p
, found
) == 1)
12176 printf_unfiltered (_("Deleted breakpoint "));
12178 printf_unfiltered (_("Deleted breakpoints "));
12181 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12184 printf_unfiltered ("%d ", b
->number
);
12185 delete_breakpoint (b
);
12188 putchar_unfiltered ('\n');
12190 do_cleanups (cleanups
);
12193 /* Delete breakpoint in BS if they are `delete' breakpoints and
12194 all breakpoints that are marked for deletion, whether hit or not.
12195 This is called after any breakpoint is hit, or after errors. */
12198 breakpoint_auto_delete (bpstat bs
)
12200 struct breakpoint
*b
, *b_tmp
;
12202 for (; bs
; bs
= bs
->next
)
12203 if (bs
->breakpoint_at
12204 && bs
->breakpoint_at
->disposition
== disp_del
12206 delete_breakpoint (bs
->breakpoint_at
);
12208 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12210 if (b
->disposition
== disp_del_at_next_stop
)
12211 delete_breakpoint (b
);
12215 /* A comparison function for bp_location AP and BP being interfaced to
12216 qsort. Sort elements primarily by their ADDRESS (no matter what
12217 does breakpoint_address_is_meaningful say for its OWNER),
12218 secondarily by ordering first bp_permanent OWNERed elements and
12219 terciarily just ensuring the array is sorted stable way despite
12220 qsort being an unstable algorithm. */
12223 bp_location_compare (const void *ap
, const void *bp
)
12225 struct bp_location
*a
= *(void **) ap
;
12226 struct bp_location
*b
= *(void **) bp
;
12227 /* A and B come from existing breakpoints having non-NULL OWNER. */
12228 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12229 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12231 if (a
->address
!= b
->address
)
12232 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12234 /* Sort locations at the same address by their pspace number, keeping
12235 locations of the same inferior (in a multi-inferior environment)
12238 if (a
->pspace
->num
!= b
->pspace
->num
)
12239 return ((a
->pspace
->num
> b
->pspace
->num
)
12240 - (a
->pspace
->num
< b
->pspace
->num
));
12242 /* Sort permanent breakpoints first. */
12243 if (a_perm
!= b_perm
)
12244 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12246 /* Make the internal GDB representation stable across GDB runs
12247 where A and B memory inside GDB can differ. Breakpoint locations of
12248 the same type at the same address can be sorted in arbitrary order. */
12250 if (a
->owner
->number
!= b
->owner
->number
)
12251 return ((a
->owner
->number
> b
->owner
->number
)
12252 - (a
->owner
->number
< b
->owner
->number
));
12254 return (a
> b
) - (a
< b
);
12257 /* Set bp_location_placed_address_before_address_max and
12258 bp_location_shadow_len_after_address_max according to the current
12259 content of the bp_location array. */
12262 bp_location_target_extensions_update (void)
12264 struct bp_location
*bl
, **blp_tmp
;
12266 bp_location_placed_address_before_address_max
= 0;
12267 bp_location_shadow_len_after_address_max
= 0;
12269 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12271 CORE_ADDR start
, end
, addr
;
12273 if (!bp_location_has_shadow (bl
))
12276 start
= bl
->target_info
.placed_address
;
12277 end
= start
+ bl
->target_info
.shadow_len
;
12279 gdb_assert (bl
->address
>= start
);
12280 addr
= bl
->address
- start
;
12281 if (addr
> bp_location_placed_address_before_address_max
)
12282 bp_location_placed_address_before_address_max
= addr
;
12284 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12286 gdb_assert (bl
->address
< end
);
12287 addr
= end
- bl
->address
;
12288 if (addr
> bp_location_shadow_len_after_address_max
)
12289 bp_location_shadow_len_after_address_max
= addr
;
12293 /* Download tracepoint locations if they haven't been. */
12296 download_tracepoint_locations (void)
12298 struct breakpoint
*b
;
12299 struct cleanup
*old_chain
;
12301 if (!target_can_download_tracepoint ())
12304 old_chain
= save_current_space_and_thread ();
12306 ALL_TRACEPOINTS (b
)
12308 struct bp_location
*bl
;
12309 struct tracepoint
*t
;
12310 int bp_location_downloaded
= 0;
12312 if ((b
->type
== bp_fast_tracepoint
12313 ? !may_insert_fast_tracepoints
12314 : !may_insert_tracepoints
))
12317 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12319 /* In tracepoint, locations are _never_ duplicated, so
12320 should_be_inserted is equivalent to
12321 unduplicated_should_be_inserted. */
12322 if (!should_be_inserted (bl
) || bl
->inserted
)
12325 switch_to_program_space_and_thread (bl
->pspace
);
12327 target_download_tracepoint (bl
);
12330 bp_location_downloaded
= 1;
12332 t
= (struct tracepoint
*) b
;
12333 t
->number_on_target
= b
->number
;
12334 if (bp_location_downloaded
)
12335 observer_notify_breakpoint_modified (b
);
12338 do_cleanups (old_chain
);
12341 /* Swap the insertion/duplication state between two locations. */
12344 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12346 const int left_inserted
= left
->inserted
;
12347 const int left_duplicate
= left
->duplicate
;
12348 const int left_needs_update
= left
->needs_update
;
12349 const struct bp_target_info left_target_info
= left
->target_info
;
12351 /* Locations of tracepoints can never be duplicated. */
12352 if (is_tracepoint (left
->owner
))
12353 gdb_assert (!left
->duplicate
);
12354 if (is_tracepoint (right
->owner
))
12355 gdb_assert (!right
->duplicate
);
12357 left
->inserted
= right
->inserted
;
12358 left
->duplicate
= right
->duplicate
;
12359 left
->needs_update
= right
->needs_update
;
12360 left
->target_info
= right
->target_info
;
12361 right
->inserted
= left_inserted
;
12362 right
->duplicate
= left_duplicate
;
12363 right
->needs_update
= left_needs_update
;
12364 right
->target_info
= left_target_info
;
12367 /* Force the re-insertion of the locations at ADDRESS. This is called
12368 once a new/deleted/modified duplicate location is found and we are evaluating
12369 conditions on the target's side. Such conditions need to be updated on
12373 force_breakpoint_reinsertion (struct bp_location
*bl
)
12375 struct bp_location
**locp
= NULL
, **loc2p
;
12376 struct bp_location
*loc
;
12377 CORE_ADDR address
= 0;
12380 address
= bl
->address
;
12381 pspace_num
= bl
->pspace
->num
;
12383 /* This is only meaningful if the target is
12384 evaluating conditions and if the user has
12385 opted for condition evaluation on the target's
12387 if (gdb_evaluates_breakpoint_condition_p ()
12388 || !target_supports_evaluation_of_breakpoint_conditions ())
12391 /* Flag all breakpoint locations with this address and
12392 the same program space as the location
12393 as "its condition has changed". We need to
12394 update the conditions on the target's side. */
12395 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12399 if (!is_breakpoint (loc
->owner
)
12400 || pspace_num
!= loc
->pspace
->num
)
12403 /* Flag the location appropriately. We use a different state to
12404 let everyone know that we already updated the set of locations
12405 with addr bl->address and program space bl->pspace. This is so
12406 we don't have to keep calling these functions just to mark locations
12407 that have already been marked. */
12408 loc
->condition_changed
= condition_updated
;
12410 /* Free the agent expression bytecode as well. We will compute
12412 if (loc
->cond_bytecode
)
12414 free_agent_expr (loc
->cond_bytecode
);
12415 loc
->cond_bytecode
= NULL
;
12420 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12421 into the inferior, only remove already-inserted locations that no
12422 longer should be inserted. Functions that delete a breakpoint or
12423 breakpoints should pass false, so that deleting a breakpoint
12424 doesn't have the side effect of inserting the locations of other
12425 breakpoints that are marked not-inserted, but should_be_inserted
12426 returns true on them.
12428 This behaviour is useful is situations close to tear-down -- e.g.,
12429 after an exec, while the target still has execution, but breakpoint
12430 shadows of the previous executable image should *NOT* be restored
12431 to the new image; or before detaching, where the target still has
12432 execution and wants to delete breakpoints from GDB's lists, and all
12433 breakpoints had already been removed from the inferior. */
12436 update_global_location_list (int should_insert
)
12438 struct breakpoint
*b
;
12439 struct bp_location
**locp
, *loc
;
12440 struct cleanup
*cleanups
;
12441 /* Last breakpoint location address that was marked for update. */
12442 CORE_ADDR last_addr
= 0;
12443 /* Last breakpoint location program space that was marked for update. */
12444 int last_pspace_num
= -1;
12446 /* Used in the duplicates detection below. When iterating over all
12447 bp_locations, points to the first bp_location of a given address.
12448 Breakpoints and watchpoints of different types are never
12449 duplicates of each other. Keep one pointer for each type of
12450 breakpoint/watchpoint, so we only need to loop over all locations
12452 struct bp_location
*bp_loc_first
; /* breakpoint */
12453 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12454 struct bp_location
*awp_loc_first
; /* access watchpoint */
12455 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12457 /* Saved former bp_location array which we compare against the newly
12458 built bp_location from the current state of ALL_BREAKPOINTS. */
12459 struct bp_location
**old_location
, **old_locp
;
12460 unsigned old_location_count
;
12462 old_location
= bp_location
;
12463 old_location_count
= bp_location_count
;
12464 bp_location
= NULL
;
12465 bp_location_count
= 0;
12466 cleanups
= make_cleanup (xfree
, old_location
);
12468 ALL_BREAKPOINTS (b
)
12469 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12470 bp_location_count
++;
12472 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12473 locp
= bp_location
;
12474 ALL_BREAKPOINTS (b
)
12475 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12477 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12478 bp_location_compare
);
12480 bp_location_target_extensions_update ();
12482 /* Identify bp_location instances that are no longer present in the
12483 new list, and therefore should be freed. Note that it's not
12484 necessary that those locations should be removed from inferior --
12485 if there's another location at the same address (previously
12486 marked as duplicate), we don't need to remove/insert the
12489 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12490 and former bp_location array state respectively. */
12492 locp
= bp_location
;
12493 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12496 struct bp_location
*old_loc
= *old_locp
;
12497 struct bp_location
**loc2p
;
12499 /* Tells if 'old_loc' is found among the new locations. If
12500 not, we have to free it. */
12501 int found_object
= 0;
12502 /* Tells if the location should remain inserted in the target. */
12503 int keep_in_target
= 0;
12506 /* Skip LOCP entries which will definitely never be needed.
12507 Stop either at or being the one matching OLD_LOC. */
12508 while (locp
< bp_location
+ bp_location_count
12509 && (*locp
)->address
< old_loc
->address
)
12513 (loc2p
< bp_location
+ bp_location_count
12514 && (*loc2p
)->address
== old_loc
->address
);
12517 /* Check if this is a new/duplicated location or a duplicated
12518 location that had its condition modified. If so, we want to send
12519 its condition to the target if evaluation of conditions is taking
12521 if ((*loc2p
)->condition_changed
== condition_modified
12522 && (last_addr
!= old_loc
->address
12523 || last_pspace_num
!= old_loc
->pspace
->num
))
12525 force_breakpoint_reinsertion (*loc2p
);
12526 last_pspace_num
= old_loc
->pspace
->num
;
12529 if (*loc2p
== old_loc
)
12533 /* We have already handled this address, update it so that we don't
12534 have to go through updates again. */
12535 last_addr
= old_loc
->address
;
12537 /* Target-side condition evaluation: Handle deleted locations. */
12539 force_breakpoint_reinsertion (old_loc
);
12541 /* If this location is no longer present, and inserted, look if
12542 there's maybe a new location at the same address. If so,
12543 mark that one inserted, and don't remove this one. This is
12544 needed so that we don't have a time window where a breakpoint
12545 at certain location is not inserted. */
12547 if (old_loc
->inserted
)
12549 /* If the location is inserted now, we might have to remove
12552 if (found_object
&& should_be_inserted (old_loc
))
12554 /* The location is still present in the location list,
12555 and still should be inserted. Don't do anything. */
12556 keep_in_target
= 1;
12560 /* This location still exists, but it won't be kept in the
12561 target since it may have been disabled. We proceed to
12562 remove its target-side condition. */
12564 /* The location is either no longer present, or got
12565 disabled. See if there's another location at the
12566 same address, in which case we don't need to remove
12567 this one from the target. */
12569 /* OLD_LOC comes from existing struct breakpoint. */
12570 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12573 (loc2p
< bp_location
+ bp_location_count
12574 && (*loc2p
)->address
== old_loc
->address
);
12577 struct bp_location
*loc2
= *loc2p
;
12579 if (breakpoint_locations_match (loc2
, old_loc
))
12581 /* Read watchpoint locations are switched to
12582 access watchpoints, if the former are not
12583 supported, but the latter are. */
12584 if (is_hardware_watchpoint (old_loc
->owner
))
12586 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12587 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12590 /* loc2 is a duplicated location. We need to check
12591 if it should be inserted in case it will be
12593 if (loc2
!= old_loc
12594 && unduplicated_should_be_inserted (loc2
))
12596 swap_insertion (old_loc
, loc2
);
12597 keep_in_target
= 1;
12605 if (!keep_in_target
)
12607 if (remove_breakpoint (old_loc
, mark_uninserted
))
12609 /* This is just about all we can do. We could keep
12610 this location on the global list, and try to
12611 remove it next time, but there's no particular
12612 reason why we will succeed next time.
12614 Note that at this point, old_loc->owner is still
12615 valid, as delete_breakpoint frees the breakpoint
12616 only after calling us. */
12617 printf_filtered (_("warning: Error removing "
12618 "breakpoint %d\n"),
12619 old_loc
->owner
->number
);
12627 if (removed
&& non_stop
12628 && breakpoint_address_is_meaningful (old_loc
->owner
)
12629 && !is_hardware_watchpoint (old_loc
->owner
))
12631 /* This location was removed from the target. In
12632 non-stop mode, a race condition is possible where
12633 we've removed a breakpoint, but stop events for that
12634 breakpoint are already queued and will arrive later.
12635 We apply an heuristic to be able to distinguish such
12636 SIGTRAPs from other random SIGTRAPs: we keep this
12637 breakpoint location for a bit, and will retire it
12638 after we see some number of events. The theory here
12639 is that reporting of events should, "on the average",
12640 be fair, so after a while we'll see events from all
12641 threads that have anything of interest, and no longer
12642 need to keep this breakpoint location around. We
12643 don't hold locations forever so to reduce chances of
12644 mistaking a non-breakpoint SIGTRAP for a breakpoint
12647 The heuristic failing can be disastrous on
12648 decr_pc_after_break targets.
12650 On decr_pc_after_break targets, like e.g., x86-linux,
12651 if we fail to recognize a late breakpoint SIGTRAP,
12652 because events_till_retirement has reached 0 too
12653 soon, we'll fail to do the PC adjustment, and report
12654 a random SIGTRAP to the user. When the user resumes
12655 the inferior, it will most likely immediately crash
12656 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12657 corrupted, because of being resumed e.g., in the
12658 middle of a multi-byte instruction, or skipped a
12659 one-byte instruction. This was actually seen happen
12660 on native x86-linux, and should be less rare on
12661 targets that do not support new thread events, like
12662 remote, due to the heuristic depending on
12665 Mistaking a random SIGTRAP for a breakpoint trap
12666 causes similar symptoms (PC adjustment applied when
12667 it shouldn't), but then again, playing with SIGTRAPs
12668 behind the debugger's back is asking for trouble.
12670 Since hardware watchpoint traps are always
12671 distinguishable from other traps, so we don't need to
12672 apply keep hardware watchpoint moribund locations
12673 around. We simply always ignore hardware watchpoint
12674 traps we can no longer explain. */
12676 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12677 old_loc
->owner
= NULL
;
12679 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12683 old_loc
->owner
= NULL
;
12684 decref_bp_location (&old_loc
);
12689 /* Rescan breakpoints at the same address and section, marking the
12690 first one as "first" and any others as "duplicates". This is so
12691 that the bpt instruction is only inserted once. If we have a
12692 permanent breakpoint at the same place as BPT, make that one the
12693 official one, and the rest as duplicates. Permanent breakpoints
12694 are sorted first for the same address.
12696 Do the same for hardware watchpoints, but also considering the
12697 watchpoint's type (regular/access/read) and length. */
12699 bp_loc_first
= NULL
;
12700 wp_loc_first
= NULL
;
12701 awp_loc_first
= NULL
;
12702 rwp_loc_first
= NULL
;
12703 ALL_BP_LOCATIONS (loc
, locp
)
12705 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12707 struct bp_location
**loc_first_p
;
12710 if (!unduplicated_should_be_inserted (loc
)
12711 || !breakpoint_address_is_meaningful (b
)
12712 /* Don't detect duplicate for tracepoint locations because they are
12713 never duplicated. See the comments in field `duplicate' of
12714 `struct bp_location'. */
12715 || is_tracepoint (b
))
12717 /* Clear the condition modification flag. */
12718 loc
->condition_changed
= condition_unchanged
;
12722 /* Permanent breakpoint should always be inserted. */
12723 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12724 internal_error (__FILE__
, __LINE__
,
12725 _("allegedly permanent breakpoint is not "
12726 "actually inserted"));
12728 if (b
->type
== bp_hardware_watchpoint
)
12729 loc_first_p
= &wp_loc_first
;
12730 else if (b
->type
== bp_read_watchpoint
)
12731 loc_first_p
= &rwp_loc_first
;
12732 else if (b
->type
== bp_access_watchpoint
)
12733 loc_first_p
= &awp_loc_first
;
12735 loc_first_p
= &bp_loc_first
;
12737 if (*loc_first_p
== NULL
12738 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12739 || !breakpoint_locations_match (loc
, *loc_first_p
))
12741 *loc_first_p
= loc
;
12742 loc
->duplicate
= 0;
12744 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12746 loc
->needs_update
= 1;
12747 /* Clear the condition modification flag. */
12748 loc
->condition_changed
= condition_unchanged
;
12754 /* This and the above ensure the invariant that the first location
12755 is not duplicated, and is the inserted one.
12756 All following are marked as duplicated, and are not inserted. */
12758 swap_insertion (loc
, *loc_first_p
);
12759 loc
->duplicate
= 1;
12761 /* Clear the condition modification flag. */
12762 loc
->condition_changed
= condition_unchanged
;
12764 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12765 && b
->enable_state
!= bp_permanent
)
12766 internal_error (__FILE__
, __LINE__
,
12767 _("another breakpoint was inserted on top of "
12768 "a permanent breakpoint"));
12771 if (breakpoints_always_inserted_mode ()
12772 && (have_live_inferiors ()
12773 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12776 insert_breakpoint_locations ();
12779 /* Though should_insert is false, we may need to update conditions
12780 on the target's side if it is evaluating such conditions. We
12781 only update conditions for locations that are marked
12783 update_inserted_breakpoint_locations ();
12788 download_tracepoint_locations ();
12790 do_cleanups (cleanups
);
12794 breakpoint_retire_moribund (void)
12796 struct bp_location
*loc
;
12799 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12800 if (--(loc
->events_till_retirement
) == 0)
12802 decref_bp_location (&loc
);
12803 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12809 update_global_location_list_nothrow (int inserting
)
12811 volatile struct gdb_exception e
;
12813 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12814 update_global_location_list (inserting
);
12817 /* Clear BKP from a BPS. */
12820 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12824 for (bs
= bps
; bs
; bs
= bs
->next
)
12825 if (bs
->breakpoint_at
== bpt
)
12827 bs
->breakpoint_at
= NULL
;
12828 bs
->old_val
= NULL
;
12829 /* bs->commands will be freed later. */
12833 /* Callback for iterate_over_threads. */
12835 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12837 struct breakpoint
*bpt
= data
;
12839 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12843 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12847 say_where (struct breakpoint
*b
)
12849 struct value_print_options opts
;
12851 get_user_print_options (&opts
);
12853 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12855 if (b
->loc
== NULL
)
12857 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12861 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12863 printf_filtered (" at ");
12864 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12867 if (b
->loc
->symtab
!= NULL
)
12869 /* If there is a single location, we can print the location
12871 if (b
->loc
->next
== NULL
)
12872 printf_filtered (": file %s, line %d.",
12873 symtab_to_filename_for_display (b
->loc
->symtab
),
12874 b
->loc
->line_number
);
12876 /* This is not ideal, but each location may have a
12877 different file name, and this at least reflects the
12878 real situation somewhat. */
12879 printf_filtered (": %s.", b
->addr_string
);
12884 struct bp_location
*loc
= b
->loc
;
12886 for (; loc
; loc
= loc
->next
)
12888 printf_filtered (" (%d locations)", n
);
12893 /* Default bp_location_ops methods. */
12896 bp_location_dtor (struct bp_location
*self
)
12898 xfree (self
->cond
);
12899 if (self
->cond_bytecode
)
12900 free_agent_expr (self
->cond_bytecode
);
12901 xfree (self
->function_name
);
12903 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12904 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12907 static const struct bp_location_ops bp_location_ops
=
12912 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12916 base_breakpoint_dtor (struct breakpoint
*self
)
12918 decref_counted_command_line (&self
->commands
);
12919 xfree (self
->cond_string
);
12920 xfree (self
->extra_string
);
12921 xfree (self
->addr_string
);
12922 xfree (self
->filter
);
12923 xfree (self
->addr_string_range_end
);
12926 static struct bp_location
*
12927 base_breakpoint_allocate_location (struct breakpoint
*self
)
12929 struct bp_location
*loc
;
12931 loc
= XNEW (struct bp_location
);
12932 init_bp_location (loc
, &bp_location_ops
, self
);
12937 base_breakpoint_re_set (struct breakpoint
*b
)
12939 /* Nothing to re-set. */
12942 #define internal_error_pure_virtual_called() \
12943 gdb_assert_not_reached ("pure virtual function called")
12946 base_breakpoint_insert_location (struct bp_location
*bl
)
12948 internal_error_pure_virtual_called ();
12952 base_breakpoint_remove_location (struct bp_location
*bl
)
12954 internal_error_pure_virtual_called ();
12958 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12959 struct address_space
*aspace
,
12961 const struct target_waitstatus
*ws
)
12963 internal_error_pure_virtual_called ();
12967 base_breakpoint_check_status (bpstat bs
)
12972 /* A "works_in_software_mode" breakpoint_ops method that just internal
12976 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12978 internal_error_pure_virtual_called ();
12981 /* A "resources_needed" breakpoint_ops method that just internal
12985 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12987 internal_error_pure_virtual_called ();
12990 static enum print_stop_action
12991 base_breakpoint_print_it (bpstat bs
)
12993 internal_error_pure_virtual_called ();
12997 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12998 struct ui_out
*uiout
)
13004 base_breakpoint_print_mention (struct breakpoint
*b
)
13006 internal_error_pure_virtual_called ();
13010 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13012 internal_error_pure_virtual_called ();
13016 base_breakpoint_create_sals_from_address (char **arg
,
13017 struct linespec_result
*canonical
,
13018 enum bptype type_wanted
,
13022 internal_error_pure_virtual_called ();
13026 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13027 struct linespec_result
*c
,
13029 char *extra_string
,
13030 enum bptype type_wanted
,
13031 enum bpdisp disposition
,
13033 int task
, int ignore_count
,
13034 const struct breakpoint_ops
*o
,
13035 int from_tty
, int enabled
,
13036 int internal
, unsigned flags
)
13038 internal_error_pure_virtual_called ();
13042 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13043 struct symtabs_and_lines
*sals
)
13045 internal_error_pure_virtual_called ();
13048 /* The default 'explains_signal' method. */
13051 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13056 /* The default "after_condition_true" method. */
13059 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13061 /* Nothing to do. */
13064 struct breakpoint_ops base_breakpoint_ops
=
13066 base_breakpoint_dtor
,
13067 base_breakpoint_allocate_location
,
13068 base_breakpoint_re_set
,
13069 base_breakpoint_insert_location
,
13070 base_breakpoint_remove_location
,
13071 base_breakpoint_breakpoint_hit
,
13072 base_breakpoint_check_status
,
13073 base_breakpoint_resources_needed
,
13074 base_breakpoint_works_in_software_mode
,
13075 base_breakpoint_print_it
,
13077 base_breakpoint_print_one_detail
,
13078 base_breakpoint_print_mention
,
13079 base_breakpoint_print_recreate
,
13080 base_breakpoint_create_sals_from_address
,
13081 base_breakpoint_create_breakpoints_sal
,
13082 base_breakpoint_decode_linespec
,
13083 base_breakpoint_explains_signal
,
13084 base_breakpoint_after_condition_true
,
13087 /* Default breakpoint_ops methods. */
13090 bkpt_re_set (struct breakpoint
*b
)
13092 /* FIXME: is this still reachable? */
13093 if (b
->addr_string
== NULL
)
13095 /* Anything without a string can't be re-set. */
13096 delete_breakpoint (b
);
13100 breakpoint_re_set_default (b
);
13104 bkpt_insert_location (struct bp_location
*bl
)
13106 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13107 return target_insert_hw_breakpoint (bl
->gdbarch
,
13110 return target_insert_breakpoint (bl
->gdbarch
,
13115 bkpt_remove_location (struct bp_location
*bl
)
13117 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13118 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13120 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13124 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13125 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13126 const struct target_waitstatus
*ws
)
13128 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13129 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13132 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13136 if (overlay_debugging
/* unmapped overlay section */
13137 && section_is_overlay (bl
->section
)
13138 && !section_is_mapped (bl
->section
))
13145 bkpt_resources_needed (const struct bp_location
*bl
)
13147 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13152 static enum print_stop_action
13153 bkpt_print_it (bpstat bs
)
13155 struct breakpoint
*b
;
13156 const struct bp_location
*bl
;
13158 struct ui_out
*uiout
= current_uiout
;
13160 gdb_assert (bs
->bp_location_at
!= NULL
);
13162 bl
= bs
->bp_location_at
;
13163 b
= bs
->breakpoint_at
;
13165 bp_temp
= b
->disposition
== disp_del
;
13166 if (bl
->address
!= bl
->requested_address
)
13167 breakpoint_adjustment_warning (bl
->requested_address
,
13170 annotate_breakpoint (b
->number
);
13172 ui_out_text (uiout
, "\nTemporary breakpoint ");
13174 ui_out_text (uiout
, "\nBreakpoint ");
13175 if (ui_out_is_mi_like_p (uiout
))
13177 ui_out_field_string (uiout
, "reason",
13178 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13179 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13181 ui_out_field_int (uiout
, "bkptno", b
->number
);
13182 ui_out_text (uiout
, ", ");
13184 return PRINT_SRC_AND_LOC
;
13188 bkpt_print_mention (struct breakpoint
*b
)
13190 if (ui_out_is_mi_like_p (current_uiout
))
13195 case bp_breakpoint
:
13196 case bp_gnu_ifunc_resolver
:
13197 if (b
->disposition
== disp_del
)
13198 printf_filtered (_("Temporary breakpoint"));
13200 printf_filtered (_("Breakpoint"));
13201 printf_filtered (_(" %d"), b
->number
);
13202 if (b
->type
== bp_gnu_ifunc_resolver
)
13203 printf_filtered (_(" at gnu-indirect-function resolver"));
13205 case bp_hardware_breakpoint
:
13206 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13209 printf_filtered (_("Dprintf %d"), b
->number
);
13217 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13219 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13220 fprintf_unfiltered (fp
, "tbreak");
13221 else if (tp
->type
== bp_breakpoint
)
13222 fprintf_unfiltered (fp
, "break");
13223 else if (tp
->type
== bp_hardware_breakpoint
13224 && tp
->disposition
== disp_del
)
13225 fprintf_unfiltered (fp
, "thbreak");
13226 else if (tp
->type
== bp_hardware_breakpoint
)
13227 fprintf_unfiltered (fp
, "hbreak");
13229 internal_error (__FILE__
, __LINE__
,
13230 _("unhandled breakpoint type %d"), (int) tp
->type
);
13232 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13233 print_recreate_thread (tp
, fp
);
13237 bkpt_create_sals_from_address (char **arg
,
13238 struct linespec_result
*canonical
,
13239 enum bptype type_wanted
,
13240 char *addr_start
, char **copy_arg
)
13242 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13243 addr_start
, copy_arg
);
13247 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13248 struct linespec_result
*canonical
,
13250 char *extra_string
,
13251 enum bptype type_wanted
,
13252 enum bpdisp disposition
,
13254 int task
, int ignore_count
,
13255 const struct breakpoint_ops
*ops
,
13256 int from_tty
, int enabled
,
13257 int internal
, unsigned flags
)
13259 create_breakpoints_sal_default (gdbarch
, canonical
,
13260 cond_string
, extra_string
,
13262 disposition
, thread
, task
,
13263 ignore_count
, ops
, from_tty
,
13264 enabled
, internal
, flags
);
13268 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13269 struct symtabs_and_lines
*sals
)
13271 decode_linespec_default (b
, s
, sals
);
13274 /* Virtual table for internal breakpoints. */
13277 internal_bkpt_re_set (struct breakpoint
*b
)
13281 /* Delete overlay event and longjmp master breakpoints; they
13282 will be reset later by breakpoint_re_set. */
13283 case bp_overlay_event
:
13284 case bp_longjmp_master
:
13285 case bp_std_terminate_master
:
13286 case bp_exception_master
:
13287 delete_breakpoint (b
);
13290 /* This breakpoint is special, it's set up when the inferior
13291 starts and we really don't want to touch it. */
13292 case bp_shlib_event
:
13294 /* Like bp_shlib_event, this breakpoint type is special. Once
13295 it is set up, we do not want to touch it. */
13296 case bp_thread_event
:
13302 internal_bkpt_check_status (bpstat bs
)
13304 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13306 /* If requested, stop when the dynamic linker notifies GDB of
13307 events. This allows the user to get control and place
13308 breakpoints in initializer routines for dynamically loaded
13309 objects (among other things). */
13310 bs
->stop
= stop_on_solib_events
;
13311 bs
->print
= stop_on_solib_events
;
13317 static enum print_stop_action
13318 internal_bkpt_print_it (bpstat bs
)
13320 struct breakpoint
*b
;
13322 b
= bs
->breakpoint_at
;
13326 case bp_shlib_event
:
13327 /* Did we stop because the user set the stop_on_solib_events
13328 variable? (If so, we report this as a generic, "Stopped due
13329 to shlib event" message.) */
13330 print_solib_event (0);
13333 case bp_thread_event
:
13334 /* Not sure how we will get here.
13335 GDB should not stop for these breakpoints. */
13336 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13339 case bp_overlay_event
:
13340 /* By analogy with the thread event, GDB should not stop for these. */
13341 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13344 case bp_longjmp_master
:
13345 /* These should never be enabled. */
13346 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13349 case bp_std_terminate_master
:
13350 /* These should never be enabled. */
13351 printf_filtered (_("std::terminate Master Breakpoint: "
13352 "gdb should not stop!\n"));
13355 case bp_exception_master
:
13356 /* These should never be enabled. */
13357 printf_filtered (_("Exception Master Breakpoint: "
13358 "gdb should not stop!\n"));
13362 return PRINT_NOTHING
;
13366 internal_bkpt_print_mention (struct breakpoint
*b
)
13368 /* Nothing to mention. These breakpoints are internal. */
13371 /* Virtual table for momentary breakpoints */
13374 momentary_bkpt_re_set (struct breakpoint
*b
)
13376 /* Keep temporary breakpoints, which can be encountered when we step
13377 over a dlopen call and solib_add is resetting the breakpoints.
13378 Otherwise these should have been blown away via the cleanup chain
13379 or by breakpoint_init_inferior when we rerun the executable. */
13383 momentary_bkpt_check_status (bpstat bs
)
13385 /* Nothing. The point of these breakpoints is causing a stop. */
13388 static enum print_stop_action
13389 momentary_bkpt_print_it (bpstat bs
)
13391 struct ui_out
*uiout
= current_uiout
;
13393 if (ui_out_is_mi_like_p (uiout
))
13395 struct breakpoint
*b
= bs
->breakpoint_at
;
13400 ui_out_field_string
13402 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13406 ui_out_field_string
13408 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13413 return PRINT_UNKNOWN
;
13417 momentary_bkpt_print_mention (struct breakpoint
*b
)
13419 /* Nothing to mention. These breakpoints are internal. */
13422 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13424 It gets cleared already on the removal of the first one of such placed
13425 breakpoints. This is OK as they get all removed altogether. */
13428 longjmp_bkpt_dtor (struct breakpoint
*self
)
13430 struct thread_info
*tp
= find_thread_id (self
->thread
);
13433 tp
->initiating_frame
= null_frame_id
;
13435 momentary_breakpoint_ops
.dtor (self
);
13438 /* Specific methods for probe breakpoints. */
13441 bkpt_probe_insert_location (struct bp_location
*bl
)
13443 int v
= bkpt_insert_location (bl
);
13447 /* The insertion was successful, now let's set the probe's semaphore
13449 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13458 bkpt_probe_remove_location (struct bp_location
*bl
)
13460 /* Let's clear the semaphore before removing the location. */
13461 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13465 return bkpt_remove_location (bl
);
13469 bkpt_probe_create_sals_from_address (char **arg
,
13470 struct linespec_result
*canonical
,
13471 enum bptype type_wanted
,
13472 char *addr_start
, char **copy_arg
)
13474 struct linespec_sals lsal
;
13476 lsal
.sals
= parse_probes (arg
, canonical
);
13478 *copy_arg
= xstrdup (canonical
->addr_string
);
13479 lsal
.canonical
= xstrdup (*copy_arg
);
13481 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13485 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13486 struct symtabs_and_lines
*sals
)
13488 *sals
= parse_probes (s
, NULL
);
13490 error (_("probe not found"));
13493 /* The breakpoint_ops structure to be used in tracepoints. */
13496 tracepoint_re_set (struct breakpoint
*b
)
13498 breakpoint_re_set_default (b
);
13502 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13503 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13504 const struct target_waitstatus
*ws
)
13506 /* By definition, the inferior does not report stops at
13512 tracepoint_print_one_detail (const struct breakpoint
*self
,
13513 struct ui_out
*uiout
)
13515 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13516 if (tp
->static_trace_marker_id
)
13518 gdb_assert (self
->type
== bp_static_tracepoint
);
13520 ui_out_text (uiout
, "\tmarker id is ");
13521 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13522 tp
->static_trace_marker_id
);
13523 ui_out_text (uiout
, "\n");
13528 tracepoint_print_mention (struct breakpoint
*b
)
13530 if (ui_out_is_mi_like_p (current_uiout
))
13535 case bp_tracepoint
:
13536 printf_filtered (_("Tracepoint"));
13537 printf_filtered (_(" %d"), b
->number
);
13539 case bp_fast_tracepoint
:
13540 printf_filtered (_("Fast tracepoint"));
13541 printf_filtered (_(" %d"), b
->number
);
13543 case bp_static_tracepoint
:
13544 printf_filtered (_("Static tracepoint"));
13545 printf_filtered (_(" %d"), b
->number
);
13548 internal_error (__FILE__
, __LINE__
,
13549 _("unhandled tracepoint type %d"), (int) b
->type
);
13556 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13558 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13560 if (self
->type
== bp_fast_tracepoint
)
13561 fprintf_unfiltered (fp
, "ftrace");
13562 if (self
->type
== bp_static_tracepoint
)
13563 fprintf_unfiltered (fp
, "strace");
13564 else if (self
->type
== bp_tracepoint
)
13565 fprintf_unfiltered (fp
, "trace");
13567 internal_error (__FILE__
, __LINE__
,
13568 _("unhandled tracepoint type %d"), (int) self
->type
);
13570 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13571 print_recreate_thread (self
, fp
);
13573 if (tp
->pass_count
)
13574 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13578 tracepoint_create_sals_from_address (char **arg
,
13579 struct linespec_result
*canonical
,
13580 enum bptype type_wanted
,
13581 char *addr_start
, char **copy_arg
)
13583 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13584 addr_start
, copy_arg
);
13588 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13589 struct linespec_result
*canonical
,
13591 char *extra_string
,
13592 enum bptype type_wanted
,
13593 enum bpdisp disposition
,
13595 int task
, int ignore_count
,
13596 const struct breakpoint_ops
*ops
,
13597 int from_tty
, int enabled
,
13598 int internal
, unsigned flags
)
13600 create_breakpoints_sal_default (gdbarch
, canonical
,
13601 cond_string
, extra_string
,
13603 disposition
, thread
, task
,
13604 ignore_count
, ops
, from_tty
,
13605 enabled
, internal
, flags
);
13609 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13610 struct symtabs_and_lines
*sals
)
13612 decode_linespec_default (b
, s
, sals
);
13615 struct breakpoint_ops tracepoint_breakpoint_ops
;
13617 /* The breakpoint_ops structure to be use on tracepoints placed in a
13621 tracepoint_probe_create_sals_from_address (char **arg
,
13622 struct linespec_result
*canonical
,
13623 enum bptype type_wanted
,
13624 char *addr_start
, char **copy_arg
)
13626 /* We use the same method for breakpoint on probes. */
13627 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13628 addr_start
, copy_arg
);
13632 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13633 struct symtabs_and_lines
*sals
)
13635 /* We use the same method for breakpoint on probes. */
13636 bkpt_probe_decode_linespec (b
, s
, sals
);
13639 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13641 /* Dprintf breakpoint_ops methods. */
13644 dprintf_re_set (struct breakpoint
*b
)
13646 breakpoint_re_set_default (b
);
13648 /* This breakpoint could have been pending, and be resolved now, and
13649 if so, we should now have the extra string. If we don't, the
13650 dprintf was malformed when created, but we couldn't tell because
13651 we can't extract the extra string until the location is
13653 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13654 error (_("Format string required"));
13656 /* 1 - connect to target 1, that can run breakpoint commands.
13657 2 - create a dprintf, which resolves fine.
13658 3 - disconnect from target 1
13659 4 - connect to target 2, that can NOT run breakpoint commands.
13661 After steps #3/#4, you'll want the dprintf command list to
13662 be updated, because target 1 and 2 may well return different
13663 answers for target_can_run_breakpoint_commands().
13664 Given absence of finer grained resetting, we get to do
13665 it all the time. */
13666 if (b
->extra_string
!= NULL
)
13667 update_dprintf_command_list (b
);
13670 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13673 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13675 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13677 print_recreate_thread (tp
, fp
);
13680 /* Implement the "after_condition_true" breakpoint_ops method for
13683 dprintf's are implemented with regular commands in their command
13684 list, but we run the commands here instead of before presenting the
13685 stop to the user, as dprintf's don't actually cause a stop. This
13686 also makes it so that the commands of multiple dprintfs at the same
13687 address are all handled. */
13690 dprintf_after_condition_true (struct bpstats
*bs
)
13692 struct cleanup
*old_chain
;
13693 struct bpstats tmp_bs
= { NULL
};
13694 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13696 /* dprintf's never cause a stop. This wasn't set in the
13697 check_status hook instead because that would make the dprintf's
13698 condition not be evaluated. */
13701 /* Run the command list here. Take ownership of it instead of
13702 copying. We never want these commands to run later in
13703 bpstat_do_actions, if a breakpoint that causes a stop happens to
13704 be set at same address as this dprintf, or even if running the
13705 commands here throws. */
13706 tmp_bs
.commands
= bs
->commands
;
13707 bs
->commands
= NULL
;
13708 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13710 bpstat_do_actions_1 (&tmp_bs_p
);
13712 /* 'tmp_bs.commands' will usually be NULL by now, but
13713 bpstat_do_actions_1 may return early without processing the whole
13715 do_cleanups (old_chain
);
13718 /* The breakpoint_ops structure to be used on static tracepoints with
13722 strace_marker_create_sals_from_address (char **arg
,
13723 struct linespec_result
*canonical
,
13724 enum bptype type_wanted
,
13725 char *addr_start
, char **copy_arg
)
13727 struct linespec_sals lsal
;
13729 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13731 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13733 canonical
->addr_string
= xstrdup (*copy_arg
);
13734 lsal
.canonical
= xstrdup (*copy_arg
);
13735 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13739 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13740 struct linespec_result
*canonical
,
13742 char *extra_string
,
13743 enum bptype type_wanted
,
13744 enum bpdisp disposition
,
13746 int task
, int ignore_count
,
13747 const struct breakpoint_ops
*ops
,
13748 int from_tty
, int enabled
,
13749 int internal
, unsigned flags
)
13752 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13753 canonical
->sals
, 0);
13755 /* If the user is creating a static tracepoint by marker id
13756 (strace -m MARKER_ID), then store the sals index, so that
13757 breakpoint_re_set can try to match up which of the newly
13758 found markers corresponds to this one, and, don't try to
13759 expand multiple locations for each sal, given than SALS
13760 already should contain all sals for MARKER_ID. */
13762 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13764 struct symtabs_and_lines expanded
;
13765 struct tracepoint
*tp
;
13766 struct cleanup
*old_chain
;
13769 expanded
.nelts
= 1;
13770 expanded
.sals
= &lsal
->sals
.sals
[i
];
13772 addr_string
= xstrdup (canonical
->addr_string
);
13773 old_chain
= make_cleanup (xfree
, addr_string
);
13775 tp
= XCNEW (struct tracepoint
);
13776 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13778 cond_string
, extra_string
,
13779 type_wanted
, disposition
,
13780 thread
, task
, ignore_count
, ops
,
13781 from_tty
, enabled
, internal
, flags
,
13782 canonical
->special_display
);
13783 /* Given that its possible to have multiple markers with
13784 the same string id, if the user is creating a static
13785 tracepoint by marker id ("strace -m MARKER_ID"), then
13786 store the sals index, so that breakpoint_re_set can
13787 try to match up which of the newly found markers
13788 corresponds to this one */
13789 tp
->static_trace_marker_id_idx
= i
;
13791 install_breakpoint (internal
, &tp
->base
, 0);
13793 discard_cleanups (old_chain
);
13798 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13799 struct symtabs_and_lines
*sals
)
13801 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13803 *sals
= decode_static_tracepoint_spec (s
);
13804 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13806 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13810 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13813 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13816 strace_marker_p (struct breakpoint
*b
)
13818 return b
->ops
== &strace_marker_breakpoint_ops
;
13821 /* Delete a breakpoint and clean up all traces of it in the data
13825 delete_breakpoint (struct breakpoint
*bpt
)
13827 struct breakpoint
*b
;
13829 gdb_assert (bpt
!= NULL
);
13831 /* Has this bp already been deleted? This can happen because
13832 multiple lists can hold pointers to bp's. bpstat lists are
13835 One example of this happening is a watchpoint's scope bp. When
13836 the scope bp triggers, we notice that the watchpoint is out of
13837 scope, and delete it. We also delete its scope bp. But the
13838 scope bp is marked "auto-deleting", and is already on a bpstat.
13839 That bpstat is then checked for auto-deleting bp's, which are
13842 A real solution to this problem might involve reference counts in
13843 bp's, and/or giving them pointers back to their referencing
13844 bpstat's, and teaching delete_breakpoint to only free a bp's
13845 storage when no more references were extent. A cheaper bandaid
13847 if (bpt
->type
== bp_none
)
13850 /* At least avoid this stale reference until the reference counting
13851 of breakpoints gets resolved. */
13852 if (bpt
->related_breakpoint
!= bpt
)
13854 struct breakpoint
*related
;
13855 struct watchpoint
*w
;
13857 if (bpt
->type
== bp_watchpoint_scope
)
13858 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13859 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13860 w
= (struct watchpoint
*) bpt
;
13864 watchpoint_del_at_next_stop (w
);
13866 /* Unlink bpt from the bpt->related_breakpoint ring. */
13867 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13868 related
= related
->related_breakpoint
);
13869 related
->related_breakpoint
= bpt
->related_breakpoint
;
13870 bpt
->related_breakpoint
= bpt
;
13873 /* watch_command_1 creates a watchpoint but only sets its number if
13874 update_watchpoint succeeds in creating its bp_locations. If there's
13875 a problem in that process, we'll be asked to delete the half-created
13876 watchpoint. In that case, don't announce the deletion. */
13878 observer_notify_breakpoint_deleted (bpt
);
13880 if (breakpoint_chain
== bpt
)
13881 breakpoint_chain
= bpt
->next
;
13883 ALL_BREAKPOINTS (b
)
13884 if (b
->next
== bpt
)
13886 b
->next
= bpt
->next
;
13890 /* Be sure no bpstat's are pointing at the breakpoint after it's
13892 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13893 in all threads for now. Note that we cannot just remove bpstats
13894 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13895 commands are associated with the bpstat; if we remove it here,
13896 then the later call to bpstat_do_actions (&stop_bpstat); in
13897 event-top.c won't do anything, and temporary breakpoints with
13898 commands won't work. */
13900 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13902 /* Now that breakpoint is removed from breakpoint list, update the
13903 global location list. This will remove locations that used to
13904 belong to this breakpoint. Do this before freeing the breakpoint
13905 itself, since remove_breakpoint looks at location's owner. It
13906 might be better design to have location completely
13907 self-contained, but it's not the case now. */
13908 update_global_location_list (0);
13910 bpt
->ops
->dtor (bpt
);
13911 /* On the chance that someone will soon try again to delete this
13912 same bp, we mark it as deleted before freeing its storage. */
13913 bpt
->type
= bp_none
;
13918 do_delete_breakpoint_cleanup (void *b
)
13920 delete_breakpoint (b
);
13924 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13926 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13929 /* Iterator function to call a user-provided callback function once
13930 for each of B and its related breakpoints. */
13933 iterate_over_related_breakpoints (struct breakpoint
*b
,
13934 void (*function
) (struct breakpoint
*,
13938 struct breakpoint
*related
;
13943 struct breakpoint
*next
;
13945 /* FUNCTION may delete RELATED. */
13946 next
= related
->related_breakpoint
;
13948 if (next
== related
)
13950 /* RELATED is the last ring entry. */
13951 function (related
, data
);
13953 /* FUNCTION may have deleted it, so we'd never reach back to
13954 B. There's nothing left to do anyway, so just break
13959 function (related
, data
);
13963 while (related
!= b
);
13967 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13969 delete_breakpoint (b
);
13972 /* A callback for map_breakpoint_numbers that calls
13973 delete_breakpoint. */
13976 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13978 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13982 delete_command (char *arg
, int from_tty
)
13984 struct breakpoint
*b
, *b_tmp
;
13990 int breaks_to_delete
= 0;
13992 /* Delete all breakpoints if no argument. Do not delete
13993 internal breakpoints, these have to be deleted with an
13994 explicit breakpoint number argument. */
13995 ALL_BREAKPOINTS (b
)
13996 if (user_breakpoint_p (b
))
13998 breaks_to_delete
= 1;
14002 /* Ask user only if there are some breakpoints to delete. */
14004 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14006 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14007 if (user_breakpoint_p (b
))
14008 delete_breakpoint (b
);
14012 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14016 all_locations_are_pending (struct bp_location
*loc
)
14018 for (; loc
; loc
= loc
->next
)
14019 if (!loc
->shlib_disabled
14020 && !loc
->pspace
->executing_startup
)
14025 /* Subroutine of update_breakpoint_locations to simplify it.
14026 Return non-zero if multiple fns in list LOC have the same name.
14027 Null names are ignored. */
14030 ambiguous_names_p (struct bp_location
*loc
)
14032 struct bp_location
*l
;
14033 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14034 (int (*) (const void *,
14035 const void *)) streq
,
14036 NULL
, xcalloc
, xfree
);
14038 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14041 const char *name
= l
->function_name
;
14043 /* Allow for some names to be NULL, ignore them. */
14047 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14049 /* NOTE: We can assume slot != NULL here because xcalloc never
14053 htab_delete (htab
);
14059 htab_delete (htab
);
14063 /* When symbols change, it probably means the sources changed as well,
14064 and it might mean the static tracepoint markers are no longer at
14065 the same address or line numbers they used to be at last we
14066 checked. Losing your static tracepoints whenever you rebuild is
14067 undesirable. This function tries to resync/rematch gdb static
14068 tracepoints with the markers on the target, for static tracepoints
14069 that have not been set by marker id. Static tracepoint that have
14070 been set by marker id are reset by marker id in breakpoint_re_set.
14073 1) For a tracepoint set at a specific address, look for a marker at
14074 the old PC. If one is found there, assume to be the same marker.
14075 If the name / string id of the marker found is different from the
14076 previous known name, assume that means the user renamed the marker
14077 in the sources, and output a warning.
14079 2) For a tracepoint set at a given line number, look for a marker
14080 at the new address of the old line number. If one is found there,
14081 assume to be the same marker. If the name / string id of the
14082 marker found is different from the previous known name, assume that
14083 means the user renamed the marker in the sources, and output a
14086 3) If a marker is no longer found at the same address or line, it
14087 may mean the marker no longer exists. But it may also just mean
14088 the code changed a bit. Maybe the user added a few lines of code
14089 that made the marker move up or down (in line number terms). Ask
14090 the target for info about the marker with the string id as we knew
14091 it. If found, update line number and address in the matching
14092 static tracepoint. This will get confused if there's more than one
14093 marker with the same ID (possible in UST, although unadvised
14094 precisely because it confuses tools). */
14096 static struct symtab_and_line
14097 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14099 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14100 struct static_tracepoint_marker marker
;
14105 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14107 if (target_static_tracepoint_marker_at (pc
, &marker
))
14109 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14110 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14112 tp
->static_trace_marker_id
, marker
.str_id
);
14114 xfree (tp
->static_trace_marker_id
);
14115 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14116 release_static_tracepoint_marker (&marker
);
14121 /* Old marker wasn't found on target at lineno. Try looking it up
14123 if (!sal
.explicit_pc
14125 && sal
.symtab
!= NULL
14126 && tp
->static_trace_marker_id
!= NULL
)
14128 VEC(static_tracepoint_marker_p
) *markers
;
14131 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14133 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14135 struct symtab_and_line sal2
;
14136 struct symbol
*sym
;
14137 struct static_tracepoint_marker
*tpmarker
;
14138 struct ui_out
*uiout
= current_uiout
;
14140 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14142 xfree (tp
->static_trace_marker_id
);
14143 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14145 warning (_("marker for static tracepoint %d (%s) not "
14146 "found at previous line number"),
14147 b
->number
, tp
->static_trace_marker_id
);
14151 sal2
.pc
= tpmarker
->address
;
14153 sal2
= find_pc_line (tpmarker
->address
, 0);
14154 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14155 ui_out_text (uiout
, "Now in ");
14158 ui_out_field_string (uiout
, "func",
14159 SYMBOL_PRINT_NAME (sym
));
14160 ui_out_text (uiout
, " at ");
14162 ui_out_field_string (uiout
, "file",
14163 symtab_to_filename_for_display (sal2
.symtab
));
14164 ui_out_text (uiout
, ":");
14166 if (ui_out_is_mi_like_p (uiout
))
14168 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14170 ui_out_field_string (uiout
, "fullname", fullname
);
14173 ui_out_field_int (uiout
, "line", sal2
.line
);
14174 ui_out_text (uiout
, "\n");
14176 b
->loc
->line_number
= sal2
.line
;
14177 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14179 xfree (b
->addr_string
);
14180 b
->addr_string
= xstrprintf ("%s:%d",
14181 symtab_to_filename_for_display (sal2
.symtab
),
14182 b
->loc
->line_number
);
14184 /* Might be nice to check if function changed, and warn if
14187 release_static_tracepoint_marker (tpmarker
);
14193 /* Returns 1 iff locations A and B are sufficiently same that
14194 we don't need to report breakpoint as changed. */
14197 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14201 if (a
->address
!= b
->address
)
14204 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14207 if (a
->enabled
!= b
->enabled
)
14214 if ((a
== NULL
) != (b
== NULL
))
14220 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14221 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14222 a ranged breakpoint. */
14225 update_breakpoint_locations (struct breakpoint
*b
,
14226 struct symtabs_and_lines sals
,
14227 struct symtabs_and_lines sals_end
)
14230 struct bp_location
*existing_locations
= b
->loc
;
14232 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14234 /* Ranged breakpoints have only one start location and one end
14236 b
->enable_state
= bp_disabled
;
14237 update_global_location_list (1);
14238 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14239 "multiple locations found\n"),
14244 /* If there's no new locations, and all existing locations are
14245 pending, don't do anything. This optimizes the common case where
14246 all locations are in the same shared library, that was unloaded.
14247 We'd like to retain the location, so that when the library is
14248 loaded again, we don't loose the enabled/disabled status of the
14249 individual locations. */
14250 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14255 for (i
= 0; i
< sals
.nelts
; ++i
)
14257 struct bp_location
*new_loc
;
14259 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14261 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14263 /* Reparse conditions, they might contain references to the
14265 if (b
->cond_string
!= NULL
)
14268 volatile struct gdb_exception e
;
14270 s
= b
->cond_string
;
14271 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14273 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14274 block_for_pc (sals
.sals
[i
].pc
),
14279 warning (_("failed to reevaluate condition "
14280 "for breakpoint %d: %s"),
14281 b
->number
, e
.message
);
14282 new_loc
->enabled
= 0;
14286 if (sals_end
.nelts
)
14288 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14290 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14294 /* Update locations of permanent breakpoints. */
14295 if (b
->enable_state
== bp_permanent
)
14296 make_breakpoint_permanent (b
);
14298 /* If possible, carry over 'disable' status from existing
14301 struct bp_location
*e
= existing_locations
;
14302 /* If there are multiple breakpoints with the same function name,
14303 e.g. for inline functions, comparing function names won't work.
14304 Instead compare pc addresses; this is just a heuristic as things
14305 may have moved, but in practice it gives the correct answer
14306 often enough until a better solution is found. */
14307 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14309 for (; e
; e
= e
->next
)
14311 if (!e
->enabled
&& e
->function_name
)
14313 struct bp_location
*l
= b
->loc
;
14314 if (have_ambiguous_names
)
14316 for (; l
; l
= l
->next
)
14317 if (breakpoint_locations_match (e
, l
))
14325 for (; l
; l
= l
->next
)
14326 if (l
->function_name
14327 && strcmp (e
->function_name
, l
->function_name
) == 0)
14337 if (!locations_are_equal (existing_locations
, b
->loc
))
14338 observer_notify_breakpoint_modified (b
);
14340 update_global_location_list (1);
14343 /* Find the SaL locations corresponding to the given ADDR_STRING.
14344 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14346 static struct symtabs_and_lines
14347 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14350 struct symtabs_and_lines sals
= {0};
14351 volatile struct gdb_exception e
;
14353 gdb_assert (b
->ops
!= NULL
);
14356 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14358 b
->ops
->decode_linespec (b
, &s
, &sals
);
14362 int not_found_and_ok
= 0;
14363 /* For pending breakpoints, it's expected that parsing will
14364 fail until the right shared library is loaded. User has
14365 already told to create pending breakpoints and don't need
14366 extra messages. If breakpoint is in bp_shlib_disabled
14367 state, then user already saw the message about that
14368 breakpoint being disabled, and don't want to see more
14370 if (e
.error
== NOT_FOUND_ERROR
14371 && (b
->condition_not_parsed
14372 || (b
->loc
&& b
->loc
->shlib_disabled
)
14373 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14374 || b
->enable_state
== bp_disabled
))
14375 not_found_and_ok
= 1;
14377 if (!not_found_and_ok
)
14379 /* We surely don't want to warn about the same breakpoint
14380 10 times. One solution, implemented here, is disable
14381 the breakpoint on error. Another solution would be to
14382 have separate 'warning emitted' flag. Since this
14383 happens only when a binary has changed, I don't know
14384 which approach is better. */
14385 b
->enable_state
= bp_disabled
;
14386 throw_exception (e
);
14390 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14394 for (i
= 0; i
< sals
.nelts
; ++i
)
14395 resolve_sal_pc (&sals
.sals
[i
]);
14396 if (b
->condition_not_parsed
&& s
&& s
[0])
14398 char *cond_string
, *extra_string
;
14401 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14402 &cond_string
, &thread
, &task
,
14405 b
->cond_string
= cond_string
;
14406 b
->thread
= thread
;
14409 b
->extra_string
= extra_string
;
14410 b
->condition_not_parsed
= 0;
14413 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14414 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14424 /* The default re_set method, for typical hardware or software
14425 breakpoints. Reevaluate the breakpoint and recreate its
14429 breakpoint_re_set_default (struct breakpoint
*b
)
14432 struct symtabs_and_lines sals
, sals_end
;
14433 struct symtabs_and_lines expanded
= {0};
14434 struct symtabs_and_lines expanded_end
= {0};
14436 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14439 make_cleanup (xfree
, sals
.sals
);
14443 if (b
->addr_string_range_end
)
14445 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14448 make_cleanup (xfree
, sals_end
.sals
);
14449 expanded_end
= sals_end
;
14453 update_breakpoint_locations (b
, expanded
, expanded_end
);
14456 /* Default method for creating SALs from an address string. It basically
14457 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14460 create_sals_from_address_default (char **arg
,
14461 struct linespec_result
*canonical
,
14462 enum bptype type_wanted
,
14463 char *addr_start
, char **copy_arg
)
14465 parse_breakpoint_sals (arg
, canonical
);
14468 /* Call create_breakpoints_sal for the given arguments. This is the default
14469 function for the `create_breakpoints_sal' method of
14473 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14474 struct linespec_result
*canonical
,
14476 char *extra_string
,
14477 enum bptype type_wanted
,
14478 enum bpdisp disposition
,
14480 int task
, int ignore_count
,
14481 const struct breakpoint_ops
*ops
,
14482 int from_tty
, int enabled
,
14483 int internal
, unsigned flags
)
14485 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14487 type_wanted
, disposition
,
14488 thread
, task
, ignore_count
, ops
, from_tty
,
14489 enabled
, internal
, flags
);
14492 /* Decode the line represented by S by calling decode_line_full. This is the
14493 default function for the `decode_linespec' method of breakpoint_ops. */
14496 decode_linespec_default (struct breakpoint
*b
, char **s
,
14497 struct symtabs_and_lines
*sals
)
14499 struct linespec_result canonical
;
14501 init_linespec_result (&canonical
);
14502 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14503 (struct symtab
*) NULL
, 0,
14504 &canonical
, multiple_symbols_all
,
14507 /* We should get 0 or 1 resulting SALs. */
14508 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14510 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14512 struct linespec_sals
*lsal
;
14514 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14515 *sals
= lsal
->sals
;
14516 /* Arrange it so the destructor does not free the
14518 lsal
->sals
.sals
= NULL
;
14521 destroy_linespec_result (&canonical
);
14524 /* Prepare the global context for a re-set of breakpoint B. */
14526 static struct cleanup
*
14527 prepare_re_set_context (struct breakpoint
*b
)
14529 struct cleanup
*cleanups
;
14531 input_radix
= b
->input_radix
;
14532 cleanups
= save_current_space_and_thread ();
14533 if (b
->pspace
!= NULL
)
14534 switch_to_program_space_and_thread (b
->pspace
);
14535 set_language (b
->language
);
14540 /* Reset a breakpoint given it's struct breakpoint * BINT.
14541 The value we return ends up being the return value from catch_errors.
14542 Unused in this case. */
14545 breakpoint_re_set_one (void *bint
)
14547 /* Get past catch_errs. */
14548 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14549 struct cleanup
*cleanups
;
14551 cleanups
= prepare_re_set_context (b
);
14552 b
->ops
->re_set (b
);
14553 do_cleanups (cleanups
);
14557 /* Re-set all breakpoints after symbols have been re-loaded. */
14559 breakpoint_re_set (void)
14561 struct breakpoint
*b
, *b_tmp
;
14562 enum language save_language
;
14563 int save_input_radix
;
14564 struct cleanup
*old_chain
;
14566 save_language
= current_language
->la_language
;
14567 save_input_radix
= input_radix
;
14568 old_chain
= save_current_program_space ();
14570 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14572 /* Format possible error msg. */
14573 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14575 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14576 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14577 do_cleanups (cleanups
);
14579 set_language (save_language
);
14580 input_radix
= save_input_radix
;
14582 jit_breakpoint_re_set ();
14584 do_cleanups (old_chain
);
14586 create_overlay_event_breakpoint ();
14587 create_longjmp_master_breakpoint ();
14588 create_std_terminate_master_breakpoint ();
14589 create_exception_master_breakpoint ();
14592 /* Reset the thread number of this breakpoint:
14594 - If the breakpoint is for all threads, leave it as-is.
14595 - Else, reset it to the current thread for inferior_ptid. */
14597 breakpoint_re_set_thread (struct breakpoint
*b
)
14599 if (b
->thread
!= -1)
14601 if (in_thread_list (inferior_ptid
))
14602 b
->thread
= pid_to_thread_id (inferior_ptid
);
14604 /* We're being called after following a fork. The new fork is
14605 selected as current, and unless this was a vfork will have a
14606 different program space from the original thread. Reset that
14608 b
->loc
->pspace
= current_program_space
;
14612 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14613 If from_tty is nonzero, it prints a message to that effect,
14614 which ends with a period (no newline). */
14617 set_ignore_count (int bptnum
, int count
, int from_tty
)
14619 struct breakpoint
*b
;
14624 ALL_BREAKPOINTS (b
)
14625 if (b
->number
== bptnum
)
14627 if (is_tracepoint (b
))
14629 if (from_tty
&& count
!= 0)
14630 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14635 b
->ignore_count
= count
;
14639 printf_filtered (_("Will stop next time "
14640 "breakpoint %d is reached."),
14642 else if (count
== 1)
14643 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14646 printf_filtered (_("Will ignore next %d "
14647 "crossings of breakpoint %d."),
14650 observer_notify_breakpoint_modified (b
);
14654 error (_("No breakpoint number %d."), bptnum
);
14657 /* Command to set ignore-count of breakpoint N to COUNT. */
14660 ignore_command (char *args
, int from_tty
)
14666 error_no_arg (_("a breakpoint number"));
14668 num
= get_number (&p
);
14670 error (_("bad breakpoint number: '%s'"), args
);
14672 error (_("Second argument (specified ignore-count) is missing."));
14674 set_ignore_count (num
,
14675 longest_to_int (value_as_long (parse_and_eval (p
))),
14678 printf_filtered ("\n");
14681 /* Call FUNCTION on each of the breakpoints
14682 whose numbers are given in ARGS. */
14685 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14690 struct breakpoint
*b
, *tmp
;
14692 struct get_number_or_range_state state
;
14695 error_no_arg (_("one or more breakpoint numbers"));
14697 init_number_or_range (&state
, args
);
14699 while (!state
.finished
)
14701 char *p
= state
.string
;
14705 num
= get_number_or_range (&state
);
14708 warning (_("bad breakpoint number at or near '%s'"), p
);
14712 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14713 if (b
->number
== num
)
14716 function (b
, data
);
14720 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14725 static struct bp_location
*
14726 find_location_by_number (char *number
)
14728 char *dot
= strchr (number
, '.');
14732 struct breakpoint
*b
;
14733 struct bp_location
*loc
;
14738 bp_num
= get_number (&p1
);
14740 error (_("Bad breakpoint number '%s'"), number
);
14742 ALL_BREAKPOINTS (b
)
14743 if (b
->number
== bp_num
)
14748 if (!b
|| b
->number
!= bp_num
)
14749 error (_("Bad breakpoint number '%s'"), number
);
14752 loc_num
= get_number (&p1
);
14754 error (_("Bad breakpoint location number '%s'"), number
);
14758 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14761 error (_("Bad breakpoint location number '%s'"), dot
+1);
14767 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14768 If from_tty is nonzero, it prints a message to that effect,
14769 which ends with a period (no newline). */
14772 disable_breakpoint (struct breakpoint
*bpt
)
14774 /* Never disable a watchpoint scope breakpoint; we want to
14775 hit them when we leave scope so we can delete both the
14776 watchpoint and its scope breakpoint at that time. */
14777 if (bpt
->type
== bp_watchpoint_scope
)
14780 /* You can't disable permanent breakpoints. */
14781 if (bpt
->enable_state
== bp_permanent
)
14784 bpt
->enable_state
= bp_disabled
;
14786 /* Mark breakpoint locations modified. */
14787 mark_breakpoint_modified (bpt
);
14789 if (target_supports_enable_disable_tracepoint ()
14790 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14792 struct bp_location
*location
;
14794 for (location
= bpt
->loc
; location
; location
= location
->next
)
14795 target_disable_tracepoint (location
);
14798 update_global_location_list (0);
14800 observer_notify_breakpoint_modified (bpt
);
14803 /* A callback for iterate_over_related_breakpoints. */
14806 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14808 disable_breakpoint (b
);
14811 /* A callback for map_breakpoint_numbers that calls
14812 disable_breakpoint. */
14815 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14817 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14821 disable_command (char *args
, int from_tty
)
14825 struct breakpoint
*bpt
;
14827 ALL_BREAKPOINTS (bpt
)
14828 if (user_breakpoint_p (bpt
))
14829 disable_breakpoint (bpt
);
14833 char *num
= extract_arg (&args
);
14837 if (strchr (num
, '.'))
14839 struct bp_location
*loc
= find_location_by_number (num
);
14846 mark_breakpoint_location_modified (loc
);
14848 if (target_supports_enable_disable_tracepoint ()
14849 && current_trace_status ()->running
&& loc
->owner
14850 && is_tracepoint (loc
->owner
))
14851 target_disable_tracepoint (loc
);
14853 update_global_location_list (0);
14856 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14857 num
= extract_arg (&args
);
14863 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14866 int target_resources_ok
;
14868 if (bpt
->type
== bp_hardware_breakpoint
)
14871 i
= hw_breakpoint_used_count ();
14872 target_resources_ok
=
14873 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14875 if (target_resources_ok
== 0)
14876 error (_("No hardware breakpoint support in the target."));
14877 else if (target_resources_ok
< 0)
14878 error (_("Hardware breakpoints used exceeds limit."));
14881 if (is_watchpoint (bpt
))
14883 /* Initialize it just to avoid a GCC false warning. */
14884 enum enable_state orig_enable_state
= 0;
14885 volatile struct gdb_exception e
;
14887 TRY_CATCH (e
, RETURN_MASK_ALL
)
14889 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14891 orig_enable_state
= bpt
->enable_state
;
14892 bpt
->enable_state
= bp_enabled
;
14893 update_watchpoint (w
, 1 /* reparse */);
14897 bpt
->enable_state
= orig_enable_state
;
14898 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14904 if (bpt
->enable_state
!= bp_permanent
)
14905 bpt
->enable_state
= bp_enabled
;
14907 bpt
->enable_state
= bp_enabled
;
14909 /* Mark breakpoint locations modified. */
14910 mark_breakpoint_modified (bpt
);
14912 if (target_supports_enable_disable_tracepoint ()
14913 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14915 struct bp_location
*location
;
14917 for (location
= bpt
->loc
; location
; location
= location
->next
)
14918 target_enable_tracepoint (location
);
14921 bpt
->disposition
= disposition
;
14922 bpt
->enable_count
= count
;
14923 update_global_location_list (1);
14925 observer_notify_breakpoint_modified (bpt
);
14930 enable_breakpoint (struct breakpoint
*bpt
)
14932 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14936 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14938 enable_breakpoint (bpt
);
14941 /* A callback for map_breakpoint_numbers that calls
14942 enable_breakpoint. */
14945 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14947 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14950 /* The enable command enables the specified breakpoints (or all defined
14951 breakpoints) so they once again become (or continue to be) effective
14952 in stopping the inferior. */
14955 enable_command (char *args
, int from_tty
)
14959 struct breakpoint
*bpt
;
14961 ALL_BREAKPOINTS (bpt
)
14962 if (user_breakpoint_p (bpt
))
14963 enable_breakpoint (bpt
);
14967 char *num
= extract_arg (&args
);
14971 if (strchr (num
, '.'))
14973 struct bp_location
*loc
= find_location_by_number (num
);
14980 mark_breakpoint_location_modified (loc
);
14982 if (target_supports_enable_disable_tracepoint ()
14983 && current_trace_status ()->running
&& loc
->owner
14984 && is_tracepoint (loc
->owner
))
14985 target_enable_tracepoint (loc
);
14987 update_global_location_list (1);
14990 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14991 num
= extract_arg (&args
);
14996 /* This struct packages up disposition data for application to multiple
15006 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15008 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15010 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15014 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15016 struct disp_data disp
= { disp_disable
, 1 };
15018 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15022 enable_once_command (char *args
, int from_tty
)
15024 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15028 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15030 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15032 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15036 enable_count_command (char *args
, int from_tty
)
15038 int count
= get_number (&args
);
15040 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15044 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15046 struct disp_data disp
= { disp_del
, 1 };
15048 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15052 enable_delete_command (char *args
, int from_tty
)
15054 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15058 set_breakpoint_cmd (char *args
, int from_tty
)
15063 show_breakpoint_cmd (char *args
, int from_tty
)
15067 /* Invalidate last known value of any hardware watchpoint if
15068 the memory which that value represents has been written to by
15072 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15073 CORE_ADDR addr
, ssize_t len
,
15074 const bfd_byte
*data
)
15076 struct breakpoint
*bp
;
15078 ALL_BREAKPOINTS (bp
)
15079 if (bp
->enable_state
== bp_enabled
15080 && bp
->type
== bp_hardware_watchpoint
)
15082 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15084 if (wp
->val_valid
&& wp
->val
)
15086 struct bp_location
*loc
;
15088 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15089 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15090 && loc
->address
+ loc
->length
> addr
15091 && addr
+ len
> loc
->address
)
15093 value_free (wp
->val
);
15101 /* Create and insert a raw software breakpoint at PC. Return an
15102 identifier, which should be used to remove the breakpoint later.
15103 In general, places which call this should be using something on the
15104 breakpoint chain instead; this function should be eliminated
15108 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
15109 struct address_space
*aspace
, CORE_ADDR pc
)
15111 struct bp_target_info
*bp_tgt
;
15113 bp_tgt
= XCNEW (struct bp_target_info
);
15115 bp_tgt
->placed_address_space
= aspace
;
15116 bp_tgt
->placed_address
= pc
;
15118 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
15120 /* Could not insert the breakpoint. */
15128 /* Remove a breakpoint BP inserted by
15129 deprecated_insert_raw_breakpoint. */
15132 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
15134 struct bp_target_info
*bp_tgt
= bp
;
15137 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
15143 /* Create and insert a breakpoint for software single step. */
15146 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15147 struct address_space
*aspace
,
15152 if (single_step_breakpoints
[0] == NULL
)
15154 bpt_p
= &single_step_breakpoints
[0];
15155 single_step_gdbarch
[0] = gdbarch
;
15159 gdb_assert (single_step_breakpoints
[1] == NULL
);
15160 bpt_p
= &single_step_breakpoints
[1];
15161 single_step_gdbarch
[1] = gdbarch
;
15164 /* NOTE drow/2006-04-11: A future improvement to this function would
15165 be to only create the breakpoints once, and actually put them on
15166 the breakpoint chain. That would let us use set_raw_breakpoint.
15167 We could adjust the addresses each time they were needed. Doing
15168 this requires corresponding changes elsewhere where single step
15169 breakpoints are handled, however. So, for now, we use this. */
15171 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15172 if (*bpt_p
== NULL
)
15173 error (_("Could not insert single-step breakpoint at %s"),
15174 paddress (gdbarch
, next_pc
));
15177 /* Check if the breakpoints used for software single stepping
15178 were inserted or not. */
15181 single_step_breakpoints_inserted (void)
15183 return (single_step_breakpoints
[0] != NULL
15184 || single_step_breakpoints
[1] != NULL
);
15187 /* Remove and delete any breakpoints used for software single step. */
15190 remove_single_step_breakpoints (void)
15192 gdb_assert (single_step_breakpoints
[0] != NULL
);
15194 /* See insert_single_step_breakpoint for more about this deprecated
15196 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15197 single_step_breakpoints
[0]);
15198 single_step_gdbarch
[0] = NULL
;
15199 single_step_breakpoints
[0] = NULL
;
15201 if (single_step_breakpoints
[1] != NULL
)
15203 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15204 single_step_breakpoints
[1]);
15205 single_step_gdbarch
[1] = NULL
;
15206 single_step_breakpoints
[1] = NULL
;
15210 /* Delete software single step breakpoints without removing them from
15211 the inferior. This is intended to be used if the inferior's address
15212 space where they were inserted is already gone, e.g. after exit or
15216 cancel_single_step_breakpoints (void)
15220 for (i
= 0; i
< 2; i
++)
15221 if (single_step_breakpoints
[i
])
15223 xfree (single_step_breakpoints
[i
]);
15224 single_step_breakpoints
[i
] = NULL
;
15225 single_step_gdbarch
[i
] = NULL
;
15229 /* Detach software single-step breakpoints from INFERIOR_PTID without
15233 detach_single_step_breakpoints (void)
15237 for (i
= 0; i
< 2; i
++)
15238 if (single_step_breakpoints
[i
])
15239 target_remove_breakpoint (single_step_gdbarch
[i
],
15240 single_step_breakpoints
[i
]);
15243 /* Check whether a software single-step breakpoint is inserted at
15247 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15252 for (i
= 0; i
< 2; i
++)
15254 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15256 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15257 bp_tgt
->placed_address
,
15265 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15266 non-zero otherwise. */
15268 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15270 if (syscall_catchpoint_p (bp
)
15271 && bp
->enable_state
!= bp_disabled
15272 && bp
->enable_state
!= bp_call_disabled
)
15279 catch_syscall_enabled (void)
15281 struct catch_syscall_inferior_data
*inf_data
15282 = get_catch_syscall_inferior_data (current_inferior ());
15284 return inf_data
->total_syscalls_count
!= 0;
15288 catching_syscall_number (int syscall_number
)
15290 struct breakpoint
*bp
;
15292 ALL_BREAKPOINTS (bp
)
15293 if (is_syscall_catchpoint_enabled (bp
))
15295 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15297 if (c
->syscalls_to_be_caught
)
15301 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15303 if (syscall_number
== iter
)
15313 /* Complete syscall names. Used by "catch syscall". */
15314 static VEC (char_ptr
) *
15315 catch_syscall_completer (struct cmd_list_element
*cmd
,
15316 const char *text
, const char *word
)
15318 const char **list
= get_syscall_names ();
15319 VEC (char_ptr
) *retlist
15320 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15326 /* Tracepoint-specific operations. */
15328 /* Set tracepoint count to NUM. */
15330 set_tracepoint_count (int num
)
15332 tracepoint_count
= num
;
15333 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15337 trace_command (char *arg
, int from_tty
)
15339 struct breakpoint_ops
*ops
;
15340 const char *arg_cp
= arg
;
15342 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15343 ops
= &tracepoint_probe_breakpoint_ops
;
15345 ops
= &tracepoint_breakpoint_ops
;
15347 create_breakpoint (get_current_arch (),
15349 NULL
, 0, NULL
, 1 /* parse arg */,
15351 bp_tracepoint
/* type_wanted */,
15352 0 /* Ignore count */,
15353 pending_break_support
,
15357 0 /* internal */, 0);
15361 ftrace_command (char *arg
, int from_tty
)
15363 create_breakpoint (get_current_arch (),
15365 NULL
, 0, NULL
, 1 /* parse arg */,
15367 bp_fast_tracepoint
/* type_wanted */,
15368 0 /* Ignore count */,
15369 pending_break_support
,
15370 &tracepoint_breakpoint_ops
,
15373 0 /* internal */, 0);
15376 /* strace command implementation. Creates a static tracepoint. */
15379 strace_command (char *arg
, int from_tty
)
15381 struct breakpoint_ops
*ops
;
15383 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15384 or with a normal static tracepoint. */
15385 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15386 ops
= &strace_marker_breakpoint_ops
;
15388 ops
= &tracepoint_breakpoint_ops
;
15390 create_breakpoint (get_current_arch (),
15392 NULL
, 0, NULL
, 1 /* parse arg */,
15394 bp_static_tracepoint
/* type_wanted */,
15395 0 /* Ignore count */,
15396 pending_break_support
,
15400 0 /* internal */, 0);
15403 /* Set up a fake reader function that gets command lines from a linked
15404 list that was acquired during tracepoint uploading. */
15406 static struct uploaded_tp
*this_utp
;
15407 static int next_cmd
;
15410 read_uploaded_action (void)
15414 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15421 /* Given information about a tracepoint as recorded on a target (which
15422 can be either a live system or a trace file), attempt to create an
15423 equivalent GDB tracepoint. This is not a reliable process, since
15424 the target does not necessarily have all the information used when
15425 the tracepoint was originally defined. */
15427 struct tracepoint
*
15428 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15430 char *addr_str
, small_buf
[100];
15431 struct tracepoint
*tp
;
15433 if (utp
->at_string
)
15434 addr_str
= utp
->at_string
;
15437 /* In the absence of a source location, fall back to raw
15438 address. Since there is no way to confirm that the address
15439 means the same thing as when the trace was started, warn the
15441 warning (_("Uploaded tracepoint %d has no "
15442 "source location, using raw address"),
15444 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15445 addr_str
= small_buf
;
15448 /* There's not much we can do with a sequence of bytecodes. */
15449 if (utp
->cond
&& !utp
->cond_string
)
15450 warning (_("Uploaded tracepoint %d condition "
15451 "has no source form, ignoring it"),
15454 if (!create_breakpoint (get_current_arch (),
15456 utp
->cond_string
, -1, NULL
,
15457 0 /* parse cond/thread */,
15459 utp
->type
/* type_wanted */,
15460 0 /* Ignore count */,
15461 pending_break_support
,
15462 &tracepoint_breakpoint_ops
,
15464 utp
->enabled
/* enabled */,
15466 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15469 /* Get the tracepoint we just created. */
15470 tp
= get_tracepoint (tracepoint_count
);
15471 gdb_assert (tp
!= NULL
);
15475 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15478 trace_pass_command (small_buf
, 0);
15481 /* If we have uploaded versions of the original commands, set up a
15482 special-purpose "reader" function and call the usual command line
15483 reader, then pass the result to the breakpoint command-setting
15485 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15487 struct command_line
*cmd_list
;
15492 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15494 breakpoint_set_commands (&tp
->base
, cmd_list
);
15496 else if (!VEC_empty (char_ptr
, utp
->actions
)
15497 || !VEC_empty (char_ptr
, utp
->step_actions
))
15498 warning (_("Uploaded tracepoint %d actions "
15499 "have no source form, ignoring them"),
15502 /* Copy any status information that might be available. */
15503 tp
->base
.hit_count
= utp
->hit_count
;
15504 tp
->traceframe_usage
= utp
->traceframe_usage
;
15509 /* Print information on tracepoint number TPNUM_EXP, or all if
15513 tracepoints_info (char *args
, int from_tty
)
15515 struct ui_out
*uiout
= current_uiout
;
15518 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15520 if (num_printed
== 0)
15522 if (args
== NULL
|| *args
== '\0')
15523 ui_out_message (uiout
, 0, "No tracepoints.\n");
15525 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15528 default_collect_info ();
15531 /* The 'enable trace' command enables tracepoints.
15532 Not supported by all targets. */
15534 enable_trace_command (char *args
, int from_tty
)
15536 enable_command (args
, from_tty
);
15539 /* The 'disable trace' command disables tracepoints.
15540 Not supported by all targets. */
15542 disable_trace_command (char *args
, int from_tty
)
15544 disable_command (args
, from_tty
);
15547 /* Remove a tracepoint (or all if no argument). */
15549 delete_trace_command (char *arg
, int from_tty
)
15551 struct breakpoint
*b
, *b_tmp
;
15557 int breaks_to_delete
= 0;
15559 /* Delete all breakpoints if no argument.
15560 Do not delete internal or call-dummy breakpoints, these
15561 have to be deleted with an explicit breakpoint number
15563 ALL_TRACEPOINTS (b
)
15564 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15566 breaks_to_delete
= 1;
15570 /* Ask user only if there are some breakpoints to delete. */
15572 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15574 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15575 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15576 delete_breakpoint (b
);
15580 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15583 /* Helper function for trace_pass_command. */
15586 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15588 tp
->pass_count
= count
;
15589 observer_notify_breakpoint_modified (&tp
->base
);
15591 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15592 tp
->base
.number
, count
);
15595 /* Set passcount for tracepoint.
15597 First command argument is passcount, second is tracepoint number.
15598 If tracepoint number omitted, apply to most recently defined.
15599 Also accepts special argument "all". */
15602 trace_pass_command (char *args
, int from_tty
)
15604 struct tracepoint
*t1
;
15605 unsigned int count
;
15607 if (args
== 0 || *args
== 0)
15608 error (_("passcount command requires an "
15609 "argument (count + optional TP num)"));
15611 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15613 args
= skip_spaces (args
);
15614 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15616 struct breakpoint
*b
;
15618 args
+= 3; /* Skip special argument "all". */
15620 error (_("Junk at end of arguments."));
15622 ALL_TRACEPOINTS (b
)
15624 t1
= (struct tracepoint
*) b
;
15625 trace_pass_set_count (t1
, count
, from_tty
);
15628 else if (*args
== '\0')
15630 t1
= get_tracepoint_by_number (&args
, NULL
);
15632 trace_pass_set_count (t1
, count
, from_tty
);
15636 struct get_number_or_range_state state
;
15638 init_number_or_range (&state
, args
);
15639 while (!state
.finished
)
15641 t1
= get_tracepoint_by_number (&args
, &state
);
15643 trace_pass_set_count (t1
, count
, from_tty
);
15648 struct tracepoint
*
15649 get_tracepoint (int num
)
15651 struct breakpoint
*t
;
15653 ALL_TRACEPOINTS (t
)
15654 if (t
->number
== num
)
15655 return (struct tracepoint
*) t
;
15660 /* Find the tracepoint with the given target-side number (which may be
15661 different from the tracepoint number after disconnecting and
15664 struct tracepoint
*
15665 get_tracepoint_by_number_on_target (int num
)
15667 struct breakpoint
*b
;
15669 ALL_TRACEPOINTS (b
)
15671 struct tracepoint
*t
= (struct tracepoint
*) b
;
15673 if (t
->number_on_target
== num
)
15680 /* Utility: parse a tracepoint number and look it up in the list.
15681 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15682 If the argument is missing, the most recent tracepoint
15683 (tracepoint_count) is returned. */
15685 struct tracepoint
*
15686 get_tracepoint_by_number (char **arg
,
15687 struct get_number_or_range_state
*state
)
15689 struct breakpoint
*t
;
15691 char *instring
= arg
== NULL
? NULL
: *arg
;
15695 gdb_assert (!state
->finished
);
15696 tpnum
= get_number_or_range (state
);
15698 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15699 tpnum
= tracepoint_count
;
15701 tpnum
= get_number (arg
);
15705 if (instring
&& *instring
)
15706 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15709 printf_filtered (_("No previous tracepoint\n"));
15713 ALL_TRACEPOINTS (t
)
15714 if (t
->number
== tpnum
)
15716 return (struct tracepoint
*) t
;
15719 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15724 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15726 if (b
->thread
!= -1)
15727 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15730 fprintf_unfiltered (fp
, " task %d", b
->task
);
15732 fprintf_unfiltered (fp
, "\n");
15735 /* Save information on user settable breakpoints (watchpoints, etc) to
15736 a new script file named FILENAME. If FILTER is non-NULL, call it
15737 on each breakpoint and only include the ones for which it returns
15741 save_breakpoints (char *filename
, int from_tty
,
15742 int (*filter
) (const struct breakpoint
*))
15744 struct breakpoint
*tp
;
15746 struct cleanup
*cleanup
;
15747 struct ui_file
*fp
;
15748 int extra_trace_bits
= 0;
15750 if (filename
== 0 || *filename
== 0)
15751 error (_("Argument required (file name in which to save)"));
15753 /* See if we have anything to save. */
15754 ALL_BREAKPOINTS (tp
)
15756 /* Skip internal and momentary breakpoints. */
15757 if (!user_breakpoint_p (tp
))
15760 /* If we have a filter, only save the breakpoints it accepts. */
15761 if (filter
&& !filter (tp
))
15766 if (is_tracepoint (tp
))
15768 extra_trace_bits
= 1;
15770 /* We can stop searching. */
15777 warning (_("Nothing to save."));
15781 filename
= tilde_expand (filename
);
15782 cleanup
= make_cleanup (xfree
, filename
);
15783 fp
= gdb_fopen (filename
, "w");
15785 error (_("Unable to open file '%s' for saving (%s)"),
15786 filename
, safe_strerror (errno
));
15787 make_cleanup_ui_file_delete (fp
);
15789 if (extra_trace_bits
)
15790 save_trace_state_variables (fp
);
15792 ALL_BREAKPOINTS (tp
)
15794 /* Skip internal and momentary breakpoints. */
15795 if (!user_breakpoint_p (tp
))
15798 /* If we have a filter, only save the breakpoints it accepts. */
15799 if (filter
&& !filter (tp
))
15802 tp
->ops
->print_recreate (tp
, fp
);
15804 /* Note, we can't rely on tp->number for anything, as we can't
15805 assume the recreated breakpoint numbers will match. Use $bpnum
15808 if (tp
->cond_string
)
15809 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15811 if (tp
->ignore_count
)
15812 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15814 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15816 volatile struct gdb_exception ex
;
15818 fprintf_unfiltered (fp
, " commands\n");
15820 ui_out_redirect (current_uiout
, fp
);
15821 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15823 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15825 ui_out_redirect (current_uiout
, NULL
);
15828 throw_exception (ex
);
15830 fprintf_unfiltered (fp
, " end\n");
15833 if (tp
->enable_state
== bp_disabled
)
15834 fprintf_unfiltered (fp
, "disable\n");
15836 /* If this is a multi-location breakpoint, check if the locations
15837 should be individually disabled. Watchpoint locations are
15838 special, and not user visible. */
15839 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15841 struct bp_location
*loc
;
15844 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15846 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15850 if (extra_trace_bits
&& *default_collect
)
15851 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15854 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15855 do_cleanups (cleanup
);
15858 /* The `save breakpoints' command. */
15861 save_breakpoints_command (char *args
, int from_tty
)
15863 save_breakpoints (args
, from_tty
, NULL
);
15866 /* The `save tracepoints' command. */
15869 save_tracepoints_command (char *args
, int from_tty
)
15871 save_breakpoints (args
, from_tty
, is_tracepoint
);
15874 /* Create a vector of all tracepoints. */
15876 VEC(breakpoint_p
) *
15877 all_tracepoints (void)
15879 VEC(breakpoint_p
) *tp_vec
= 0;
15880 struct breakpoint
*tp
;
15882 ALL_TRACEPOINTS (tp
)
15884 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15891 /* This help string is used for the break, hbreak, tbreak and thbreak
15892 commands. It is defined as a macro to prevent duplication.
15893 COMMAND should be a string constant containing the name of the
15895 #define BREAK_ARGS_HELP(command) \
15896 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15897 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15898 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15899 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15900 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15901 If a line number is specified, break at start of code for that line.\n\
15902 If a function is specified, break at start of code for that function.\n\
15903 If an address is specified, break at that exact address.\n\
15904 With no LOCATION, uses current execution address of the selected\n\
15905 stack frame. This is useful for breaking on return to a stack frame.\n\
15907 THREADNUM is the number from \"info threads\".\n\
15908 CONDITION is a boolean expression.\n\
15910 Multiple breakpoints at one place are permitted, and useful if their\n\
15911 conditions are different.\n\
15913 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15915 /* List of subcommands for "catch". */
15916 static struct cmd_list_element
*catch_cmdlist
;
15918 /* List of subcommands for "tcatch". */
15919 static struct cmd_list_element
*tcatch_cmdlist
;
15922 add_catch_command (char *name
, char *docstring
,
15923 void (*sfunc
) (char *args
, int from_tty
,
15924 struct cmd_list_element
*command
),
15925 completer_ftype
*completer
,
15926 void *user_data_catch
,
15927 void *user_data_tcatch
)
15929 struct cmd_list_element
*command
;
15931 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15933 set_cmd_sfunc (command
, sfunc
);
15934 set_cmd_context (command
, user_data_catch
);
15935 set_cmd_completer (command
, completer
);
15937 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15939 set_cmd_sfunc (command
, sfunc
);
15940 set_cmd_context (command
, user_data_tcatch
);
15941 set_cmd_completer (command
, completer
);
15945 clear_syscall_counts (struct inferior
*inf
)
15947 struct catch_syscall_inferior_data
*inf_data
15948 = get_catch_syscall_inferior_data (inf
);
15950 inf_data
->total_syscalls_count
= 0;
15951 inf_data
->any_syscall_count
= 0;
15952 VEC_free (int, inf_data
->syscalls_counts
);
15956 save_command (char *arg
, int from_tty
)
15958 printf_unfiltered (_("\"save\" must be followed by "
15959 "the name of a save subcommand.\n"));
15960 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15963 struct breakpoint
*
15964 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15967 struct breakpoint
*b
, *b_tmp
;
15969 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15971 if ((*callback
) (b
, data
))
15978 /* Zero if any of the breakpoint's locations could be a location where
15979 functions have been inlined, nonzero otherwise. */
15982 is_non_inline_function (struct breakpoint
*b
)
15984 /* The shared library event breakpoint is set on the address of a
15985 non-inline function. */
15986 if (b
->type
== bp_shlib_event
)
15992 /* Nonzero if the specified PC cannot be a location where functions
15993 have been inlined. */
15996 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15997 const struct target_waitstatus
*ws
)
15999 struct breakpoint
*b
;
16000 struct bp_location
*bl
;
16002 ALL_BREAKPOINTS (b
)
16004 if (!is_non_inline_function (b
))
16007 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16009 if (!bl
->shlib_disabled
16010 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16018 /* Remove any references to OBJFILE which is going to be freed. */
16021 breakpoint_free_objfile (struct objfile
*objfile
)
16023 struct bp_location
**locp
, *loc
;
16025 ALL_BP_LOCATIONS (loc
, locp
)
16026 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
16027 loc
->symtab
= NULL
;
16031 initialize_breakpoint_ops (void)
16033 static int initialized
= 0;
16035 struct breakpoint_ops
*ops
;
16041 /* The breakpoint_ops structure to be inherit by all kinds of
16042 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16043 internal and momentary breakpoints, etc.). */
16044 ops
= &bkpt_base_breakpoint_ops
;
16045 *ops
= base_breakpoint_ops
;
16046 ops
->re_set
= bkpt_re_set
;
16047 ops
->insert_location
= bkpt_insert_location
;
16048 ops
->remove_location
= bkpt_remove_location
;
16049 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16050 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16051 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16052 ops
->decode_linespec
= bkpt_decode_linespec
;
16054 /* The breakpoint_ops structure to be used in regular breakpoints. */
16055 ops
= &bkpt_breakpoint_ops
;
16056 *ops
= bkpt_base_breakpoint_ops
;
16057 ops
->re_set
= bkpt_re_set
;
16058 ops
->resources_needed
= bkpt_resources_needed
;
16059 ops
->print_it
= bkpt_print_it
;
16060 ops
->print_mention
= bkpt_print_mention
;
16061 ops
->print_recreate
= bkpt_print_recreate
;
16063 /* Ranged breakpoints. */
16064 ops
= &ranged_breakpoint_ops
;
16065 *ops
= bkpt_breakpoint_ops
;
16066 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16067 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16068 ops
->print_it
= print_it_ranged_breakpoint
;
16069 ops
->print_one
= print_one_ranged_breakpoint
;
16070 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16071 ops
->print_mention
= print_mention_ranged_breakpoint
;
16072 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16074 /* Internal breakpoints. */
16075 ops
= &internal_breakpoint_ops
;
16076 *ops
= bkpt_base_breakpoint_ops
;
16077 ops
->re_set
= internal_bkpt_re_set
;
16078 ops
->check_status
= internal_bkpt_check_status
;
16079 ops
->print_it
= internal_bkpt_print_it
;
16080 ops
->print_mention
= internal_bkpt_print_mention
;
16082 /* Momentary breakpoints. */
16083 ops
= &momentary_breakpoint_ops
;
16084 *ops
= bkpt_base_breakpoint_ops
;
16085 ops
->re_set
= momentary_bkpt_re_set
;
16086 ops
->check_status
= momentary_bkpt_check_status
;
16087 ops
->print_it
= momentary_bkpt_print_it
;
16088 ops
->print_mention
= momentary_bkpt_print_mention
;
16090 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16091 ops
= &longjmp_breakpoint_ops
;
16092 *ops
= momentary_breakpoint_ops
;
16093 ops
->dtor
= longjmp_bkpt_dtor
;
16095 /* Probe breakpoints. */
16096 ops
= &bkpt_probe_breakpoint_ops
;
16097 *ops
= bkpt_breakpoint_ops
;
16098 ops
->insert_location
= bkpt_probe_insert_location
;
16099 ops
->remove_location
= bkpt_probe_remove_location
;
16100 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16101 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16104 ops
= &watchpoint_breakpoint_ops
;
16105 *ops
= base_breakpoint_ops
;
16106 ops
->dtor
= dtor_watchpoint
;
16107 ops
->re_set
= re_set_watchpoint
;
16108 ops
->insert_location
= insert_watchpoint
;
16109 ops
->remove_location
= remove_watchpoint
;
16110 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16111 ops
->check_status
= check_status_watchpoint
;
16112 ops
->resources_needed
= resources_needed_watchpoint
;
16113 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16114 ops
->print_it
= print_it_watchpoint
;
16115 ops
->print_mention
= print_mention_watchpoint
;
16116 ops
->print_recreate
= print_recreate_watchpoint
;
16117 ops
->explains_signal
= explains_signal_watchpoint
;
16119 /* Masked watchpoints. */
16120 ops
= &masked_watchpoint_breakpoint_ops
;
16121 *ops
= watchpoint_breakpoint_ops
;
16122 ops
->insert_location
= insert_masked_watchpoint
;
16123 ops
->remove_location
= remove_masked_watchpoint
;
16124 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16125 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16126 ops
->print_it
= print_it_masked_watchpoint
;
16127 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16128 ops
->print_mention
= print_mention_masked_watchpoint
;
16129 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16132 ops
= &tracepoint_breakpoint_ops
;
16133 *ops
= base_breakpoint_ops
;
16134 ops
->re_set
= tracepoint_re_set
;
16135 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16136 ops
->print_one_detail
= tracepoint_print_one_detail
;
16137 ops
->print_mention
= tracepoint_print_mention
;
16138 ops
->print_recreate
= tracepoint_print_recreate
;
16139 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16140 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16141 ops
->decode_linespec
= tracepoint_decode_linespec
;
16143 /* Probe tracepoints. */
16144 ops
= &tracepoint_probe_breakpoint_ops
;
16145 *ops
= tracepoint_breakpoint_ops
;
16146 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16147 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16149 /* Static tracepoints with marker (`-m'). */
16150 ops
= &strace_marker_breakpoint_ops
;
16151 *ops
= tracepoint_breakpoint_ops
;
16152 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16153 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16154 ops
->decode_linespec
= strace_marker_decode_linespec
;
16156 /* Fork catchpoints. */
16157 ops
= &catch_fork_breakpoint_ops
;
16158 *ops
= base_breakpoint_ops
;
16159 ops
->insert_location
= insert_catch_fork
;
16160 ops
->remove_location
= remove_catch_fork
;
16161 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16162 ops
->print_it
= print_it_catch_fork
;
16163 ops
->print_one
= print_one_catch_fork
;
16164 ops
->print_mention
= print_mention_catch_fork
;
16165 ops
->print_recreate
= print_recreate_catch_fork
;
16167 /* Vfork catchpoints. */
16168 ops
= &catch_vfork_breakpoint_ops
;
16169 *ops
= base_breakpoint_ops
;
16170 ops
->insert_location
= insert_catch_vfork
;
16171 ops
->remove_location
= remove_catch_vfork
;
16172 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16173 ops
->print_it
= print_it_catch_vfork
;
16174 ops
->print_one
= print_one_catch_vfork
;
16175 ops
->print_mention
= print_mention_catch_vfork
;
16176 ops
->print_recreate
= print_recreate_catch_vfork
;
16178 /* Exec catchpoints. */
16179 ops
= &catch_exec_breakpoint_ops
;
16180 *ops
= base_breakpoint_ops
;
16181 ops
->dtor
= dtor_catch_exec
;
16182 ops
->insert_location
= insert_catch_exec
;
16183 ops
->remove_location
= remove_catch_exec
;
16184 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16185 ops
->print_it
= print_it_catch_exec
;
16186 ops
->print_one
= print_one_catch_exec
;
16187 ops
->print_mention
= print_mention_catch_exec
;
16188 ops
->print_recreate
= print_recreate_catch_exec
;
16190 /* Syscall catchpoints. */
16191 ops
= &catch_syscall_breakpoint_ops
;
16192 *ops
= base_breakpoint_ops
;
16193 ops
->dtor
= dtor_catch_syscall
;
16194 ops
->insert_location
= insert_catch_syscall
;
16195 ops
->remove_location
= remove_catch_syscall
;
16196 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16197 ops
->print_it
= print_it_catch_syscall
;
16198 ops
->print_one
= print_one_catch_syscall
;
16199 ops
->print_mention
= print_mention_catch_syscall
;
16200 ops
->print_recreate
= print_recreate_catch_syscall
;
16202 /* Solib-related catchpoints. */
16203 ops
= &catch_solib_breakpoint_ops
;
16204 *ops
= base_breakpoint_ops
;
16205 ops
->dtor
= dtor_catch_solib
;
16206 ops
->insert_location
= insert_catch_solib
;
16207 ops
->remove_location
= remove_catch_solib
;
16208 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16209 ops
->check_status
= check_status_catch_solib
;
16210 ops
->print_it
= print_it_catch_solib
;
16211 ops
->print_one
= print_one_catch_solib
;
16212 ops
->print_mention
= print_mention_catch_solib
;
16213 ops
->print_recreate
= print_recreate_catch_solib
;
16215 ops
= &dprintf_breakpoint_ops
;
16216 *ops
= bkpt_base_breakpoint_ops
;
16217 ops
->re_set
= dprintf_re_set
;
16218 ops
->resources_needed
= bkpt_resources_needed
;
16219 ops
->print_it
= bkpt_print_it
;
16220 ops
->print_mention
= bkpt_print_mention
;
16221 ops
->print_recreate
= dprintf_print_recreate
;
16222 ops
->after_condition_true
= dprintf_after_condition_true
;
16225 /* Chain containing all defined "enable breakpoint" subcommands. */
16227 static struct cmd_list_element
*enablebreaklist
= NULL
;
16230 _initialize_breakpoint (void)
16232 struct cmd_list_element
*c
;
16234 initialize_breakpoint_ops ();
16236 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16237 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16238 observer_attach_inferior_exit (clear_syscall_counts
);
16239 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16241 breakpoint_objfile_key
16242 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16244 catch_syscall_inferior_data
16245 = register_inferior_data_with_cleanup (NULL
,
16246 catch_syscall_inferior_data_cleanup
);
16248 breakpoint_chain
= 0;
16249 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16250 before a breakpoint is set. */
16251 breakpoint_count
= 0;
16253 tracepoint_count
= 0;
16255 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16256 Set ignore-count of breakpoint number N to COUNT.\n\
16257 Usage is `ignore N COUNT'."));
16259 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16261 add_com ("commands", class_breakpoint
, commands_command
, _("\
16262 Set commands to be executed when a breakpoint is hit.\n\
16263 Give breakpoint number as argument after \"commands\".\n\
16264 With no argument, the targeted breakpoint is the last one set.\n\
16265 The commands themselves follow starting on the next line.\n\
16266 Type a line containing \"end\" to indicate the end of them.\n\
16267 Give \"silent\" as the first line to make the breakpoint silent;\n\
16268 then no output is printed when it is hit, except what the commands print."));
16270 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16271 Specify breakpoint number N to break only if COND is true.\n\
16272 Usage is `condition N COND', where N is an integer and COND is an\n\
16273 expression to be evaluated whenever breakpoint N is reached."));
16274 set_cmd_completer (c
, condition_completer
);
16276 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16277 Set a temporary breakpoint.\n\
16278 Like \"break\" except the breakpoint is only temporary,\n\
16279 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16280 by using \"enable delete\" on the breakpoint number.\n\
16282 BREAK_ARGS_HELP ("tbreak")));
16283 set_cmd_completer (c
, location_completer
);
16285 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16286 Set a hardware assisted breakpoint.\n\
16287 Like \"break\" except the breakpoint requires hardware support,\n\
16288 some target hardware may not have this support.\n\
16290 BREAK_ARGS_HELP ("hbreak")));
16291 set_cmd_completer (c
, location_completer
);
16293 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16294 Set a temporary hardware assisted breakpoint.\n\
16295 Like \"hbreak\" except the breakpoint is only temporary,\n\
16296 so it will be deleted when hit.\n\
16298 BREAK_ARGS_HELP ("thbreak")));
16299 set_cmd_completer (c
, location_completer
);
16301 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16302 Enable some breakpoints.\n\
16303 Give breakpoint numbers (separated by spaces) as arguments.\n\
16304 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16305 This is used to cancel the effect of the \"disable\" command.\n\
16306 With a subcommand you can enable temporarily."),
16307 &enablelist
, "enable ", 1, &cmdlist
);
16309 add_com ("ab", class_breakpoint
, enable_command
, _("\
16310 Enable some breakpoints.\n\
16311 Give breakpoint numbers (separated by spaces) as arguments.\n\
16312 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16313 This is used to cancel the effect of the \"disable\" command.\n\
16314 With a subcommand you can enable temporarily."));
16316 add_com_alias ("en", "enable", class_breakpoint
, 1);
16318 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16319 Enable some breakpoints.\n\
16320 Give breakpoint numbers (separated by spaces) as arguments.\n\
16321 This is used to cancel the effect of the \"disable\" command.\n\
16322 May be abbreviated to simply \"enable\".\n"),
16323 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16325 add_cmd ("once", no_class
, enable_once_command
, _("\
16326 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16327 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16330 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16331 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16332 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16335 add_cmd ("count", no_class
, enable_count_command
, _("\
16336 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16337 If a breakpoint is hit while enabled in this fashion,\n\
16338 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16341 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16342 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16343 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16346 add_cmd ("once", no_class
, enable_once_command
, _("\
16347 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16348 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16351 add_cmd ("count", no_class
, enable_count_command
, _("\
16352 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16353 If a breakpoint is hit while enabled in this fashion,\n\
16354 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16357 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16358 Disable some breakpoints.\n\
16359 Arguments are breakpoint numbers with spaces in between.\n\
16360 To disable all breakpoints, give no argument.\n\
16361 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16362 &disablelist
, "disable ", 1, &cmdlist
);
16363 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16364 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16366 add_com ("sb", class_breakpoint
, disable_command
, _("\
16367 Disable some breakpoints.\n\
16368 Arguments are breakpoint numbers with spaces in between.\n\
16369 To disable all breakpoints, give no argument.\n\
16370 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16372 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16373 Disable some breakpoints.\n\
16374 Arguments are breakpoint numbers with spaces in between.\n\
16375 To disable all breakpoints, give no argument.\n\
16376 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16377 This command may be abbreviated \"disable\"."),
16380 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16381 Delete some breakpoints or auto-display expressions.\n\
16382 Arguments are breakpoint numbers with spaces in between.\n\
16383 To delete all breakpoints, give no argument.\n\
16385 Also a prefix command for deletion of other GDB objects.\n\
16386 The \"unset\" command is also an alias for \"delete\"."),
16387 &deletelist
, "delete ", 1, &cmdlist
);
16388 add_com_alias ("d", "delete", class_breakpoint
, 1);
16389 add_com_alias ("del", "delete", class_breakpoint
, 1);
16391 add_com ("db", class_breakpoint
, delete_command
, _("\
16392 Delete some breakpoints.\n\
16393 Arguments are breakpoint numbers with spaces in between.\n\
16394 To delete all breakpoints, give no argument.\n"));
16396 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16397 Delete some breakpoints or auto-display expressions.\n\
16398 Arguments are breakpoint numbers with spaces in between.\n\
16399 To delete all breakpoints, give no argument.\n\
16400 This command may be abbreviated \"delete\"."),
16403 add_com ("clear", class_breakpoint
, clear_command
, _("\
16404 Clear breakpoint at specified line or function.\n\
16405 Argument may be line number, function name, or \"*\" and an address.\n\
16406 If line number is specified, all breakpoints in that line are cleared.\n\
16407 If function is specified, breakpoints at beginning of function are cleared.\n\
16408 If an address is specified, breakpoints at that address are cleared.\n\
16410 With no argument, clears all breakpoints in the line that the selected frame\n\
16411 is executing in.\n\
16413 See also the \"delete\" command which clears breakpoints by number."));
16414 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16416 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16417 Set breakpoint at specified line or function.\n"
16418 BREAK_ARGS_HELP ("break")));
16419 set_cmd_completer (c
, location_completer
);
16421 add_com_alias ("b", "break", class_run
, 1);
16422 add_com_alias ("br", "break", class_run
, 1);
16423 add_com_alias ("bre", "break", class_run
, 1);
16424 add_com_alias ("brea", "break", class_run
, 1);
16427 add_com_alias ("ba", "break", class_breakpoint
, 1);
16431 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16432 Break in function/address or break at a line in the current file."),
16433 &stoplist
, "stop ", 1, &cmdlist
);
16434 add_cmd ("in", class_breakpoint
, stopin_command
,
16435 _("Break in function or address."), &stoplist
);
16436 add_cmd ("at", class_breakpoint
, stopat_command
,
16437 _("Break at a line in the current file."), &stoplist
);
16438 add_com ("status", class_info
, breakpoints_info
, _("\
16439 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16440 The \"Type\" column indicates one of:\n\
16441 \tbreakpoint - normal breakpoint\n\
16442 \twatchpoint - watchpoint\n\
16443 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16444 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16445 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16446 address and file/line number respectively.\n\
16448 Convenience variable \"$_\" and default examine address for \"x\"\n\
16449 are set to the address of the last breakpoint listed unless the command\n\
16450 is prefixed with \"server \".\n\n\
16451 Convenience variable \"$bpnum\" contains the number of the last\n\
16452 breakpoint set."));
16455 add_info ("breakpoints", breakpoints_info
, _("\
16456 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16457 The \"Type\" column indicates one of:\n\
16458 \tbreakpoint - normal breakpoint\n\
16459 \twatchpoint - watchpoint\n\
16460 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16461 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16462 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16463 address and file/line number respectively.\n\
16465 Convenience variable \"$_\" and default examine address for \"x\"\n\
16466 are set to the address of the last breakpoint listed unless the command\n\
16467 is prefixed with \"server \".\n\n\
16468 Convenience variable \"$bpnum\" contains the number of the last\n\
16469 breakpoint set."));
16471 add_info_alias ("b", "breakpoints", 1);
16474 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16475 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16476 The \"Type\" column indicates one of:\n\
16477 \tbreakpoint - normal breakpoint\n\
16478 \twatchpoint - watchpoint\n\
16479 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16480 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16481 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16482 address and file/line number respectively.\n\
16484 Convenience variable \"$_\" and default examine address for \"x\"\n\
16485 are set to the address of the last breakpoint listed unless the command\n\
16486 is prefixed with \"server \".\n\n\
16487 Convenience variable \"$bpnum\" contains the number of the last\n\
16488 breakpoint set."));
16490 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16491 Status of all breakpoints, or breakpoint number NUMBER.\n\
16492 The \"Type\" column indicates one of:\n\
16493 \tbreakpoint - normal breakpoint\n\
16494 \twatchpoint - watchpoint\n\
16495 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16496 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16497 \tuntil - internal breakpoint used by the \"until\" command\n\
16498 \tfinish - internal breakpoint used by the \"finish\" command\n\
16499 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16500 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16501 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16502 address and file/line number respectively.\n\
16504 Convenience variable \"$_\" and default examine address for \"x\"\n\
16505 are set to the address of the last breakpoint listed unless the command\n\
16506 is prefixed with \"server \".\n\n\
16507 Convenience variable \"$bpnum\" contains the number of the last\n\
16509 &maintenanceinfolist
);
16511 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16512 Set catchpoints to catch events."),
16513 &catch_cmdlist
, "catch ",
16514 0/*allow-unknown*/, &cmdlist
);
16516 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16517 Set temporary catchpoints to catch events."),
16518 &tcatch_cmdlist
, "tcatch ",
16519 0/*allow-unknown*/, &cmdlist
);
16521 add_catch_command ("fork", _("Catch calls to fork."),
16522 catch_fork_command_1
,
16524 (void *) (uintptr_t) catch_fork_permanent
,
16525 (void *) (uintptr_t) catch_fork_temporary
);
16526 add_catch_command ("vfork", _("Catch calls to vfork."),
16527 catch_fork_command_1
,
16529 (void *) (uintptr_t) catch_vfork_permanent
,
16530 (void *) (uintptr_t) catch_vfork_temporary
);
16531 add_catch_command ("exec", _("Catch calls to exec."),
16532 catch_exec_command_1
,
16536 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16537 Usage: catch load [REGEX]\n\
16538 If REGEX is given, only stop for libraries matching the regular expression."),
16539 catch_load_command_1
,
16543 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16544 Usage: catch unload [REGEX]\n\
16545 If REGEX is given, only stop for libraries matching the regular expression."),
16546 catch_unload_command_1
,
16550 add_catch_command ("syscall", _("\
16551 Catch system calls by their names and/or numbers.\n\
16552 Arguments say which system calls to catch. If no arguments\n\
16553 are given, every system call will be caught.\n\
16554 Arguments, if given, should be one or more system call names\n\
16555 (if your system supports that), or system call numbers."),
16556 catch_syscall_command_1
,
16557 catch_syscall_completer
,
16561 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16562 Set a watchpoint for an expression.\n\
16563 Usage: watch [-l|-location] EXPRESSION\n\
16564 A watchpoint stops execution of your program whenever the value of\n\
16565 an expression changes.\n\
16566 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16567 the memory to which it refers."));
16568 set_cmd_completer (c
, expression_completer
);
16570 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16571 Set a read watchpoint for an expression.\n\
16572 Usage: rwatch [-l|-location] EXPRESSION\n\
16573 A watchpoint stops execution of your program whenever the value of\n\
16574 an expression is read.\n\
16575 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16576 the memory to which it refers."));
16577 set_cmd_completer (c
, expression_completer
);
16579 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16580 Set a watchpoint for an expression.\n\
16581 Usage: awatch [-l|-location] EXPRESSION\n\
16582 A watchpoint stops execution of your program whenever the value of\n\
16583 an expression is either read or written.\n\
16584 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16585 the memory to which it refers."));
16586 set_cmd_completer (c
, expression_completer
);
16588 add_info ("watchpoints", watchpoints_info
, _("\
16589 Status of specified watchpoints (all watchpoints if no argument)."));
16591 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16592 respond to changes - contrary to the description. */
16593 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16594 &can_use_hw_watchpoints
, _("\
16595 Set debugger's willingness to use watchpoint hardware."), _("\
16596 Show debugger's willingness to use watchpoint hardware."), _("\
16597 If zero, gdb will not use hardware for new watchpoints, even if\n\
16598 such is available. (However, any hardware watchpoints that were\n\
16599 created before setting this to nonzero, will continue to use watchpoint\n\
16602 show_can_use_hw_watchpoints
,
16603 &setlist
, &showlist
);
16605 can_use_hw_watchpoints
= 1;
16607 /* Tracepoint manipulation commands. */
16609 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16610 Set a tracepoint at specified line or function.\n\
16612 BREAK_ARGS_HELP ("trace") "\n\
16613 Do \"help tracepoints\" for info on other tracepoint commands."));
16614 set_cmd_completer (c
, location_completer
);
16616 add_com_alias ("tp", "trace", class_alias
, 0);
16617 add_com_alias ("tr", "trace", class_alias
, 1);
16618 add_com_alias ("tra", "trace", class_alias
, 1);
16619 add_com_alias ("trac", "trace", class_alias
, 1);
16621 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16622 Set a fast tracepoint at specified line or function.\n\
16624 BREAK_ARGS_HELP ("ftrace") "\n\
16625 Do \"help tracepoints\" for info on other tracepoint commands."));
16626 set_cmd_completer (c
, location_completer
);
16628 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16629 Set a static tracepoint at specified line, function or marker.\n\
16631 strace [LOCATION] [if CONDITION]\n\
16632 LOCATION may be a line number, function name, \"*\" and an address,\n\
16633 or -m MARKER_ID.\n\
16634 If a line number is specified, probe the marker at start of code\n\
16635 for that line. If a function is specified, probe the marker at start\n\
16636 of code for that function. If an address is specified, probe the marker\n\
16637 at that exact address. If a marker id is specified, probe the marker\n\
16638 with that name. With no LOCATION, uses current execution address of\n\
16639 the selected stack frame.\n\
16640 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16641 This collects arbitrary user data passed in the probe point call to the\n\
16642 tracing library. You can inspect it when analyzing the trace buffer,\n\
16643 by printing the $_sdata variable like any other convenience variable.\n\
16645 CONDITION is a boolean expression.\n\
16647 Multiple tracepoints at one place are permitted, and useful if their\n\
16648 conditions are different.\n\
16650 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16651 Do \"help tracepoints\" for info on other tracepoint commands."));
16652 set_cmd_completer (c
, location_completer
);
16654 add_info ("tracepoints", tracepoints_info
, _("\
16655 Status of specified tracepoints (all tracepoints if no argument).\n\
16656 Convenience variable \"$tpnum\" contains the number of the\n\
16657 last tracepoint set."));
16659 add_info_alias ("tp", "tracepoints", 1);
16661 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16662 Delete specified tracepoints.\n\
16663 Arguments are tracepoint numbers, separated by spaces.\n\
16664 No argument means delete all tracepoints."),
16666 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16668 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16669 Disable specified tracepoints.\n\
16670 Arguments are tracepoint numbers, separated by spaces.\n\
16671 No argument means disable all tracepoints."),
16673 deprecate_cmd (c
, "disable");
16675 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16676 Enable specified tracepoints.\n\
16677 Arguments are tracepoint numbers, separated by spaces.\n\
16678 No argument means enable all tracepoints."),
16680 deprecate_cmd (c
, "enable");
16682 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16683 Set the passcount for a tracepoint.\n\
16684 The trace will end when the tracepoint has been passed 'count' times.\n\
16685 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16686 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16688 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16689 _("Save breakpoint definitions as a script."),
16690 &save_cmdlist
, "save ",
16691 0/*allow-unknown*/, &cmdlist
);
16693 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16694 Save current breakpoint definitions as a script.\n\
16695 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16696 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16697 session to restore them."),
16699 set_cmd_completer (c
, filename_completer
);
16701 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16702 Save current tracepoint definitions as a script.\n\
16703 Use the 'source' command in another debug session to restore them."),
16705 set_cmd_completer (c
, filename_completer
);
16707 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16708 deprecate_cmd (c
, "save tracepoints");
16710 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16711 Breakpoint specific settings\n\
16712 Configure various breakpoint-specific variables such as\n\
16713 pending breakpoint behavior"),
16714 &breakpoint_set_cmdlist
, "set breakpoint ",
16715 0/*allow-unknown*/, &setlist
);
16716 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16717 Breakpoint specific settings\n\
16718 Configure various breakpoint-specific variables such as\n\
16719 pending breakpoint behavior"),
16720 &breakpoint_show_cmdlist
, "show breakpoint ",
16721 0/*allow-unknown*/, &showlist
);
16723 add_setshow_auto_boolean_cmd ("pending", no_class
,
16724 &pending_break_support
, _("\
16725 Set debugger's behavior regarding pending breakpoints."), _("\
16726 Show debugger's behavior regarding pending breakpoints."), _("\
16727 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16728 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16729 an error. If auto, an unrecognized breakpoint location results in a\n\
16730 user-query to see if a pending breakpoint should be created."),
16732 show_pending_break_support
,
16733 &breakpoint_set_cmdlist
,
16734 &breakpoint_show_cmdlist
);
16736 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16738 add_setshow_boolean_cmd ("auto-hw", no_class
,
16739 &automatic_hardware_breakpoints
, _("\
16740 Set automatic usage of hardware breakpoints."), _("\
16741 Show automatic usage of hardware breakpoints."), _("\
16742 If set, the debugger will automatically use hardware breakpoints for\n\
16743 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16744 a warning will be emitted for such breakpoints."),
16746 show_automatic_hardware_breakpoints
,
16747 &breakpoint_set_cmdlist
,
16748 &breakpoint_show_cmdlist
);
16750 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16751 &always_inserted_mode
, _("\
16752 Set mode for inserting breakpoints."), _("\
16753 Show mode for inserting breakpoints."), _("\
16754 When this mode is off, breakpoints are inserted in inferior when it is\n\
16755 resumed, and removed when execution stops. When this mode is on,\n\
16756 breakpoints are inserted immediately and removed only when the user\n\
16757 deletes the breakpoint. When this mode is auto (which is the default),\n\
16758 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16759 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16760 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16761 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16763 &show_always_inserted_mode
,
16764 &breakpoint_set_cmdlist
,
16765 &breakpoint_show_cmdlist
);
16767 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16768 condition_evaluation_enums
,
16769 &condition_evaluation_mode_1
, _("\
16770 Set mode of breakpoint condition evaluation."), _("\
16771 Show mode of breakpoint condition evaluation."), _("\
16772 When this is set to \"host\", breakpoint conditions will be\n\
16773 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16774 breakpoint conditions will be downloaded to the target (if the target\n\
16775 supports such feature) and conditions will be evaluated on the target's side.\n\
16776 If this is set to \"auto\" (default), this will be automatically set to\n\
16777 \"target\" if it supports condition evaluation, otherwise it will\n\
16778 be set to \"gdb\""),
16779 &set_condition_evaluation_mode
,
16780 &show_condition_evaluation_mode
,
16781 &breakpoint_set_cmdlist
,
16782 &breakpoint_show_cmdlist
);
16784 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16785 Set a breakpoint for an address range.\n\
16786 break-range START-LOCATION, END-LOCATION\n\
16787 where START-LOCATION and END-LOCATION can be one of the following:\n\
16788 LINENUM, for that line in the current file,\n\
16789 FILE:LINENUM, for that line in that file,\n\
16790 +OFFSET, for that number of lines after the current line\n\
16791 or the start of the range\n\
16792 FUNCTION, for the first line in that function,\n\
16793 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16794 *ADDRESS, for the instruction at that address.\n\
16796 The breakpoint will stop execution of the inferior whenever it executes\n\
16797 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16798 range (including START-LOCATION and END-LOCATION)."));
16800 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16801 Set a dynamic printf at specified line or function.\n\
16802 dprintf location,format string,arg1,arg2,...\n\
16803 location may be a line number, function name, or \"*\" and an address.\n\
16804 If a line number is specified, break at start of code for that line.\n\
16805 If a function is specified, break at start of code for that function."));
16806 set_cmd_completer (c
, location_completer
);
16808 add_setshow_enum_cmd ("dprintf-style", class_support
,
16809 dprintf_style_enums
, &dprintf_style
, _("\
16810 Set the style of usage for dynamic printf."), _("\
16811 Show the style of usage for dynamic printf."), _("\
16812 This setting chooses how GDB will do a dynamic printf.\n\
16813 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16814 console, as with the \"printf\" command.\n\
16815 If the value is \"call\", the print is done by calling a function in your\n\
16816 program; by default printf(), but you can choose a different function or\n\
16817 output stream by setting dprintf-function and dprintf-channel."),
16818 update_dprintf_commands
, NULL
,
16819 &setlist
, &showlist
);
16821 dprintf_function
= xstrdup ("printf");
16822 add_setshow_string_cmd ("dprintf-function", class_support
,
16823 &dprintf_function
, _("\
16824 Set the function to use for dynamic printf"), _("\
16825 Show the function to use for dynamic printf"), NULL
,
16826 update_dprintf_commands
, NULL
,
16827 &setlist
, &showlist
);
16829 dprintf_channel
= xstrdup ("");
16830 add_setshow_string_cmd ("dprintf-channel", class_support
,
16831 &dprintf_channel
, _("\
16832 Set the channel to use for dynamic printf"), _("\
16833 Show the channel to use for dynamic printf"), NULL
,
16834 update_dprintf_commands
, NULL
,
16835 &setlist
, &showlist
);
16837 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16838 &disconnected_dprintf
, _("\
16839 Set whether dprintf continues after GDB disconnects."), _("\
16840 Show whether dprintf continues after GDB disconnects."), _("\
16841 Use this to let dprintf commands continue to hit and produce output\n\
16842 even if GDB disconnects or detaches from the target."),
16845 &setlist
, &showlist
);
16847 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16848 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16849 (target agent only) This is useful for formatted output in user-defined commands."));
16851 automatic_hardware_breakpoints
= 1;
16853 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16854 observer_attach_thread_exit (remove_threaded_breakpoints
);