1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "xml-syscall.h"
60 #include "parser-defs.h"
61 #include "gdb_regex.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "dummy-frame.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 /* Enums for exception-handling support. */
83 enum exception_event_kind
90 /* Prototypes for local functions. */
92 static void enable_delete_command (char *, int);
94 static void enable_once_command (char *, int);
96 static void enable_count_command (char *, int);
98 static void disable_command (char *, int);
100 static void enable_command (char *, int);
102 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
106 static void ignore_command (char *, int);
108 static int breakpoint_re_set_one (void *);
110 static void breakpoint_re_set_default (struct breakpoint
*);
112 static void create_sals_from_address_default (char **,
113 struct linespec_result
*,
117 static void create_breakpoints_sal_default (struct gdbarch
*,
118 struct linespec_result
*,
119 char *, char *, enum bptype
,
120 enum bpdisp
, int, int,
122 const struct breakpoint_ops
*,
123 int, int, int, unsigned);
125 static void decode_linespec_default (struct breakpoint
*, char **,
126 struct symtabs_and_lines
*);
128 static void clear_command (char *, int);
130 static void catch_command (char *, int);
132 static int can_use_hardware_watchpoint (struct value
*);
134 static void break_command_1 (char *, int, int);
136 static void mention (struct breakpoint
*);
138 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
140 const struct breakpoint_ops
*);
141 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
142 const struct symtab_and_line
*);
144 /* This function is used in gdbtk sources and thus can not be made
146 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
147 struct symtab_and_line
,
149 const struct breakpoint_ops
*);
151 static struct breakpoint
*
152 momentary_breakpoint_from_master (struct breakpoint
*orig
,
154 const struct breakpoint_ops
*ops
,
157 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
159 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
163 static void describe_other_breakpoints (struct gdbarch
*,
164 struct program_space
*, CORE_ADDR
,
165 struct obj_section
*, int);
167 static int watchpoint_locations_match (struct bp_location
*loc1
,
168 struct bp_location
*loc2
);
170 static int breakpoint_location_address_match (struct bp_location
*bl
,
171 struct address_space
*aspace
,
174 static void breakpoints_info (char *, int);
176 static void watchpoints_info (char *, int);
178 static int breakpoint_1 (char *, int,
179 int (*) (const struct breakpoint
*));
181 static int breakpoint_cond_eval (void *);
183 static void cleanup_executing_breakpoints (void *);
185 static void commands_command (char *, int);
187 static void condition_command (char *, int);
196 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
197 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
199 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
201 static int watchpoint_check (void *);
203 static void maintenance_info_breakpoints (char *, int);
205 static int hw_breakpoint_used_count (void);
207 static int hw_watchpoint_use_count (struct breakpoint
*);
209 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
211 int *other_type_used
);
213 static void hbreak_command (char *, int);
215 static void thbreak_command (char *, int);
217 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
220 static void stop_command (char *arg
, int from_tty
);
222 static void stopin_command (char *arg
, int from_tty
);
224 static void stopat_command (char *arg
, int from_tty
);
226 static void tcatch_command (char *arg
, int from_tty
);
228 static void detach_single_step_breakpoints (void);
230 static int find_single_step_breakpoint (struct address_space
*aspace
,
233 static void free_bp_location (struct bp_location
*loc
);
234 static void incref_bp_location (struct bp_location
*loc
);
235 static void decref_bp_location (struct bp_location
**loc
);
237 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
239 /* update_global_location_list's modes of operation wrt to whether to
240 insert locations now. */
241 enum ugll_insert_mode
243 /* Don't insert any breakpoint locations into the inferior, only
244 remove already-inserted locations that no longer should be
245 inserted. Functions that delete a breakpoint or breakpoints
246 should specify this mode, so that deleting a breakpoint doesn't
247 have the side effect of inserting the locations of other
248 breakpoints that are marked not-inserted, but should_be_inserted
249 returns true on them.
251 This behavior is useful is situations close to tear-down -- e.g.,
252 after an exec, while the target still has execution, but
253 breakpoint shadows of the previous executable image should *NOT*
254 be restored to the new image; or before detaching, where the
255 target still has execution and wants to delete breakpoints from
256 GDB's lists, and all breakpoints had already been removed from
260 /* May insert breakpoints iff breakpoints_should_be_inserted_now
261 claims breakpoints should be inserted now. */
264 /* Insert locations now, irrespective of
265 breakpoints_should_be_inserted_now. E.g., say all threads are
266 stopped right now, and the user did "continue". We need to
267 insert breakpoints _before_ resuming the target, but
268 UGLL_MAY_INSERT wouldn't insert them, because
269 breakpoints_should_be_inserted_now returns false at that point,
270 as no thread is running yet. */
274 static void update_global_location_list (enum ugll_insert_mode
);
276 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
278 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
280 static void insert_breakpoint_locations (void);
282 static int syscall_catchpoint_p (struct breakpoint
*b
);
284 static void tracepoints_info (char *, int);
286 static void delete_trace_command (char *, int);
288 static void enable_trace_command (char *, int);
290 static void disable_trace_command (char *, int);
292 static void trace_pass_command (char *, int);
294 static void set_tracepoint_count (int num
);
296 static int is_masked_watchpoint (const struct breakpoint
*b
);
298 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
300 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
303 static int strace_marker_p (struct breakpoint
*b
);
305 /* The abstract base class all breakpoint_ops structures inherit
307 struct breakpoint_ops base_breakpoint_ops
;
309 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
310 that are implemented on top of software or hardware breakpoints
311 (user breakpoints, internal and momentary breakpoints, etc.). */
312 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
314 /* Internal breakpoints class type. */
315 static struct breakpoint_ops internal_breakpoint_ops
;
317 /* Momentary breakpoints class type. */
318 static struct breakpoint_ops momentary_breakpoint_ops
;
320 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
321 static struct breakpoint_ops longjmp_breakpoint_ops
;
323 /* The breakpoint_ops structure to be used in regular user created
325 struct breakpoint_ops bkpt_breakpoint_ops
;
327 /* Breakpoints set on probes. */
328 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
330 /* Dynamic printf class type. */
331 struct breakpoint_ops dprintf_breakpoint_ops
;
333 /* One (or perhaps two) breakpoints used for software single
336 static void *single_step_breakpoints
[2];
337 static struct gdbarch
*single_step_gdbarch
[2];
339 /* The style in which to perform a dynamic printf. This is a user
340 option because different output options have different tradeoffs;
341 if GDB does the printing, there is better error handling if there
342 is a problem with any of the arguments, but using an inferior
343 function lets you have special-purpose printers and sending of
344 output to the same place as compiled-in print functions. */
346 static const char dprintf_style_gdb
[] = "gdb";
347 static const char dprintf_style_call
[] = "call";
348 static const char dprintf_style_agent
[] = "agent";
349 static const char *const dprintf_style_enums
[] = {
355 static const char *dprintf_style
= dprintf_style_gdb
;
357 /* The function to use for dynamic printf if the preferred style is to
358 call into the inferior. The value is simply a string that is
359 copied into the command, so it can be anything that GDB can
360 evaluate to a callable address, not necessarily a function name. */
362 static char *dprintf_function
= "";
364 /* The channel to use for dynamic printf if the preferred style is to
365 call into the inferior; if a nonempty string, it will be passed to
366 the call as the first argument, with the format string as the
367 second. As with the dprintf function, this can be anything that
368 GDB knows how to evaluate, so in addition to common choices like
369 "stderr", this could be an app-specific expression like
370 "mystreams[curlogger]". */
372 static char *dprintf_channel
= "";
374 /* True if dprintf commands should continue to operate even if GDB
376 static int disconnected_dprintf
= 1;
378 /* A reference-counted struct command_line. This lets multiple
379 breakpoints share a single command list. */
380 struct counted_command_line
382 /* The reference count. */
385 /* The command list. */
386 struct command_line
*commands
;
389 struct command_line
*
390 breakpoint_commands (struct breakpoint
*b
)
392 return b
->commands
? b
->commands
->commands
: NULL
;
395 /* Flag indicating that a command has proceeded the inferior past the
396 current breakpoint. */
398 static int breakpoint_proceeded
;
401 bpdisp_text (enum bpdisp disp
)
403 /* NOTE: the following values are a part of MI protocol and
404 represent values of 'disp' field returned when inferior stops at
406 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
408 return bpdisps
[(int) disp
];
411 /* Prototypes for exported functions. */
412 /* If FALSE, gdb will not use hardware support for watchpoints, even
413 if such is available. */
414 static int can_use_hw_watchpoints
;
417 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
418 struct cmd_list_element
*c
,
421 fprintf_filtered (file
,
422 _("Debugger's willingness to use "
423 "watchpoint hardware is %s.\n"),
427 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
428 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
429 for unrecognized breakpoint locations.
430 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
431 static enum auto_boolean pending_break_support
;
433 show_pending_break_support (struct ui_file
*file
, int from_tty
,
434 struct cmd_list_element
*c
,
437 fprintf_filtered (file
,
438 _("Debugger's behavior regarding "
439 "pending breakpoints is %s.\n"),
443 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
444 set with "break" but falling in read-only memory.
445 If 0, gdb will warn about such breakpoints, but won't automatically
446 use hardware breakpoints. */
447 static int automatic_hardware_breakpoints
;
449 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
450 struct cmd_list_element
*c
,
453 fprintf_filtered (file
,
454 _("Automatic usage of hardware breakpoints is %s.\n"),
458 /* If on, GDB keeps breakpoints inserted even if the inferior is
459 stopped, and immediately inserts any new breakpoints as soon as
460 they're created. If off (default), GDB keeps breakpoints off of
461 the target as long as possible. That is, it delays inserting
462 breakpoints until the next resume, and removes them again when the
463 target fully stops. This is a bit safer in case GDB crashes while
464 processing user input. */
465 static int always_inserted_mode
= 0;
468 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
469 struct cmd_list_element
*c
, const char *value
)
471 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
475 /* See breakpoint.h. */
478 breakpoints_should_be_inserted_now (void)
480 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
482 /* If breakpoints are global, they should be inserted even if no
483 thread under gdb's control is running, or even if there are
484 no threads under GDB's control yet. */
487 else if (target_has_execution
)
489 if (always_inserted_mode
)
491 /* The user wants breakpoints inserted even if all threads
496 if (threads_are_executing ())
502 static const char condition_evaluation_both
[] = "host or target";
504 /* Modes for breakpoint condition evaluation. */
505 static const char condition_evaluation_auto
[] = "auto";
506 static const char condition_evaluation_host
[] = "host";
507 static const char condition_evaluation_target
[] = "target";
508 static const char *const condition_evaluation_enums
[] = {
509 condition_evaluation_auto
,
510 condition_evaluation_host
,
511 condition_evaluation_target
,
515 /* Global that holds the current mode for breakpoint condition evaluation. */
516 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
518 /* Global that we use to display information to the user (gets its value from
519 condition_evaluation_mode_1. */
520 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
522 /* Translate a condition evaluation mode MODE into either "host"
523 or "target". This is used mostly to translate from "auto" to the
524 real setting that is being used. It returns the translated
528 translate_condition_evaluation_mode (const char *mode
)
530 if (mode
== condition_evaluation_auto
)
532 if (target_supports_evaluation_of_breakpoint_conditions ())
533 return condition_evaluation_target
;
535 return condition_evaluation_host
;
541 /* Discovers what condition_evaluation_auto translates to. */
544 breakpoint_condition_evaluation_mode (void)
546 return translate_condition_evaluation_mode (condition_evaluation_mode
);
549 /* Return true if GDB should evaluate breakpoint conditions or false
553 gdb_evaluates_breakpoint_condition_p (void)
555 const char *mode
= breakpoint_condition_evaluation_mode ();
557 return (mode
== condition_evaluation_host
);
560 void _initialize_breakpoint (void);
562 /* Are we executing breakpoint commands? */
563 static int executing_breakpoint_commands
;
565 /* Are overlay event breakpoints enabled? */
566 static int overlay_events_enabled
;
568 /* See description in breakpoint.h. */
569 int target_exact_watchpoints
= 0;
571 /* Walk the following statement or block through all breakpoints.
572 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
573 current breakpoint. */
575 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
577 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
578 for (B = breakpoint_chain; \
579 B ? (TMP=B->next, 1): 0; \
582 /* Similar iterator for the low-level breakpoints. SAFE variant is
583 not provided so update_global_location_list must not be called
584 while executing the block of ALL_BP_LOCATIONS. */
586 #define ALL_BP_LOCATIONS(B,BP_TMP) \
587 for (BP_TMP = bp_location; \
588 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
591 /* Iterates through locations with address ADDRESS for the currently selected
592 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
593 to where the loop should start from.
594 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
595 appropriate location to start with. */
597 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
598 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
599 BP_LOCP_TMP = BP_LOCP_START; \
601 && (BP_LOCP_TMP < bp_location + bp_location_count \
602 && (*BP_LOCP_TMP)->address == ADDRESS); \
605 /* Iterator for tracepoints only. */
607 #define ALL_TRACEPOINTS(B) \
608 for (B = breakpoint_chain; B; B = B->next) \
609 if (is_tracepoint (B))
611 /* Chains of all breakpoints defined. */
613 struct breakpoint
*breakpoint_chain
;
615 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
617 static struct bp_location
**bp_location
;
619 /* Number of elements of BP_LOCATION. */
621 static unsigned bp_location_count
;
623 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
624 ADDRESS for the current elements of BP_LOCATION which get a valid
625 result from bp_location_has_shadow. You can use it for roughly
626 limiting the subrange of BP_LOCATION to scan for shadow bytes for
627 an address you need to read. */
629 static CORE_ADDR bp_location_placed_address_before_address_max
;
631 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
632 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
633 BP_LOCATION which get a valid result from bp_location_has_shadow.
634 You can use it for roughly limiting the subrange of BP_LOCATION to
635 scan for shadow bytes for an address you need to read. */
637 static CORE_ADDR bp_location_shadow_len_after_address_max
;
639 /* The locations that no longer correspond to any breakpoint, unlinked
640 from bp_location array, but for which a hit may still be reported
642 VEC(bp_location_p
) *moribund_locations
= NULL
;
644 /* Number of last breakpoint made. */
646 static int breakpoint_count
;
648 /* The value of `breakpoint_count' before the last command that
649 created breakpoints. If the last (break-like) command created more
650 than one breakpoint, then the difference between BREAKPOINT_COUNT
651 and PREV_BREAKPOINT_COUNT is more than one. */
652 static int prev_breakpoint_count
;
654 /* Number of last tracepoint made. */
656 static int tracepoint_count
;
658 static struct cmd_list_element
*breakpoint_set_cmdlist
;
659 static struct cmd_list_element
*breakpoint_show_cmdlist
;
660 struct cmd_list_element
*save_cmdlist
;
662 /* Return whether a breakpoint is an active enabled breakpoint. */
664 breakpoint_enabled (struct breakpoint
*b
)
666 return (b
->enable_state
== bp_enabled
);
669 /* Set breakpoint count to NUM. */
672 set_breakpoint_count (int num
)
674 prev_breakpoint_count
= breakpoint_count
;
675 breakpoint_count
= num
;
676 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
679 /* Used by `start_rbreak_breakpoints' below, to record the current
680 breakpoint count before "rbreak" creates any breakpoint. */
681 static int rbreak_start_breakpoint_count
;
683 /* Called at the start an "rbreak" command to record the first
687 start_rbreak_breakpoints (void)
689 rbreak_start_breakpoint_count
= breakpoint_count
;
692 /* Called at the end of an "rbreak" command to record the last
696 end_rbreak_breakpoints (void)
698 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
701 /* Used in run_command to zero the hit count when a new run starts. */
704 clear_breakpoint_hit_counts (void)
706 struct breakpoint
*b
;
712 /* Allocate a new counted_command_line with reference count of 1.
713 The new structure owns COMMANDS. */
715 static struct counted_command_line
*
716 alloc_counted_command_line (struct command_line
*commands
)
718 struct counted_command_line
*result
719 = xmalloc (sizeof (struct counted_command_line
));
722 result
->commands
= commands
;
726 /* Increment reference count. This does nothing if CMD is NULL. */
729 incref_counted_command_line (struct counted_command_line
*cmd
)
735 /* Decrement reference count. If the reference count reaches 0,
736 destroy the counted_command_line. Sets *CMDP to NULL. This does
737 nothing if *CMDP is NULL. */
740 decref_counted_command_line (struct counted_command_line
**cmdp
)
744 if (--(*cmdp
)->refc
== 0)
746 free_command_lines (&(*cmdp
)->commands
);
753 /* A cleanup function that calls decref_counted_command_line. */
756 do_cleanup_counted_command_line (void *arg
)
758 decref_counted_command_line (arg
);
761 /* Create a cleanup that calls decref_counted_command_line on the
764 static struct cleanup
*
765 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
767 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
771 /* Return the breakpoint with the specified number, or NULL
772 if the number does not refer to an existing breakpoint. */
775 get_breakpoint (int num
)
777 struct breakpoint
*b
;
780 if (b
->number
== num
)
788 /* Mark locations as "conditions have changed" in case the target supports
789 evaluating conditions on its side. */
792 mark_breakpoint_modified (struct breakpoint
*b
)
794 struct bp_location
*loc
;
796 /* This is only meaningful if the target is
797 evaluating conditions and if the user has
798 opted for condition evaluation on the target's
800 if (gdb_evaluates_breakpoint_condition_p ()
801 || !target_supports_evaluation_of_breakpoint_conditions ())
804 if (!is_breakpoint (b
))
807 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
808 loc
->condition_changed
= condition_modified
;
811 /* Mark location as "conditions have changed" in case the target supports
812 evaluating conditions on its side. */
815 mark_breakpoint_location_modified (struct bp_location
*loc
)
817 /* This is only meaningful if the target is
818 evaluating conditions and if the user has
819 opted for condition evaluation on the target's
821 if (gdb_evaluates_breakpoint_condition_p ()
822 || !target_supports_evaluation_of_breakpoint_conditions ())
826 if (!is_breakpoint (loc
->owner
))
829 loc
->condition_changed
= condition_modified
;
832 /* Sets the condition-evaluation mode using the static global
833 condition_evaluation_mode. */
836 set_condition_evaluation_mode (char *args
, int from_tty
,
837 struct cmd_list_element
*c
)
839 const char *old_mode
, *new_mode
;
841 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
842 && !target_supports_evaluation_of_breakpoint_conditions ())
844 condition_evaluation_mode_1
= condition_evaluation_mode
;
845 warning (_("Target does not support breakpoint condition evaluation.\n"
846 "Using host evaluation mode instead."));
850 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
851 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
853 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
854 settings was "auto". */
855 condition_evaluation_mode
= condition_evaluation_mode_1
;
857 /* Only update the mode if the user picked a different one. */
858 if (new_mode
!= old_mode
)
860 struct bp_location
*loc
, **loc_tmp
;
861 /* If the user switched to a different evaluation mode, we
862 need to synch the changes with the target as follows:
864 "host" -> "target": Send all (valid) conditions to the target.
865 "target" -> "host": Remove all the conditions from the target.
868 if (new_mode
== condition_evaluation_target
)
870 /* Mark everything modified and synch conditions with the
872 ALL_BP_LOCATIONS (loc
, loc_tmp
)
873 mark_breakpoint_location_modified (loc
);
877 /* Manually mark non-duplicate locations to synch conditions
878 with the target. We do this to remove all the conditions the
879 target knows about. */
880 ALL_BP_LOCATIONS (loc
, loc_tmp
)
881 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
882 loc
->needs_update
= 1;
886 update_global_location_list (UGLL_MAY_INSERT
);
892 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
893 what "auto" is translating to. */
896 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
897 struct cmd_list_element
*c
, const char *value
)
899 if (condition_evaluation_mode
== condition_evaluation_auto
)
900 fprintf_filtered (file
,
901 _("Breakpoint condition evaluation "
902 "mode is %s (currently %s).\n"),
904 breakpoint_condition_evaluation_mode ());
906 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
910 /* A comparison function for bp_location AP and BP that is used by
911 bsearch. This comparison function only cares about addresses, unlike
912 the more general bp_location_compare function. */
915 bp_location_compare_addrs (const void *ap
, const void *bp
)
917 struct bp_location
*a
= *(void **) ap
;
918 struct bp_location
*b
= *(void **) bp
;
920 if (a
->address
== b
->address
)
923 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
926 /* Helper function to skip all bp_locations with addresses
927 less than ADDRESS. It returns the first bp_location that
928 is greater than or equal to ADDRESS. If none is found, just
931 static struct bp_location
**
932 get_first_locp_gte_addr (CORE_ADDR address
)
934 struct bp_location dummy_loc
;
935 struct bp_location
*dummy_locp
= &dummy_loc
;
936 struct bp_location
**locp_found
= NULL
;
938 /* Initialize the dummy location's address field. */
939 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
940 dummy_loc
.address
= address
;
942 /* Find a close match to the first location at ADDRESS. */
943 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
944 sizeof (struct bp_location
**),
945 bp_location_compare_addrs
);
947 /* Nothing was found, nothing left to do. */
948 if (locp_found
== NULL
)
951 /* We may have found a location that is at ADDRESS but is not the first in the
952 location's list. Go backwards (if possible) and locate the first one. */
953 while ((locp_found
- 1) >= bp_location
954 && (*(locp_found
- 1))->address
== address
)
961 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
964 xfree (b
->cond_string
);
965 b
->cond_string
= NULL
;
967 if (is_watchpoint (b
))
969 struct watchpoint
*w
= (struct watchpoint
*) b
;
976 struct bp_location
*loc
;
978 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
983 /* No need to free the condition agent expression
984 bytecode (if we have one). We will handle this
985 when we go through update_global_location_list. */
992 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
996 const char *arg
= exp
;
998 /* I don't know if it matters whether this is the string the user
999 typed in or the decompiled expression. */
1000 b
->cond_string
= xstrdup (arg
);
1001 b
->condition_not_parsed
= 0;
1003 if (is_watchpoint (b
))
1005 struct watchpoint
*w
= (struct watchpoint
*) b
;
1007 innermost_block
= NULL
;
1009 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1011 error (_("Junk at end of expression"));
1012 w
->cond_exp_valid_block
= innermost_block
;
1016 struct bp_location
*loc
;
1018 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1022 parse_exp_1 (&arg
, loc
->address
,
1023 block_for_pc (loc
->address
), 0);
1025 error (_("Junk at end of expression"));
1029 mark_breakpoint_modified (b
);
1031 observer_notify_breakpoint_modified (b
);
1034 /* Completion for the "condition" command. */
1036 static VEC (char_ptr
) *
1037 condition_completer (struct cmd_list_element
*cmd
,
1038 const char *text
, const char *word
)
1042 text
= skip_spaces_const (text
);
1043 space
= skip_to_space_const (text
);
1047 struct breakpoint
*b
;
1048 VEC (char_ptr
) *result
= NULL
;
1052 /* We don't support completion of history indices. */
1053 if (isdigit (text
[1]))
1055 return complete_internalvar (&text
[1]);
1058 /* We're completing the breakpoint number. */
1059 len
= strlen (text
);
1065 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1067 if (strncmp (number
, text
, len
) == 0)
1068 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1074 /* We're completing the expression part. */
1075 text
= skip_spaces_const (space
);
1076 return expression_completer (cmd
, text
, word
);
1079 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1082 condition_command (char *arg
, int from_tty
)
1084 struct breakpoint
*b
;
1089 error_no_arg (_("breakpoint number"));
1092 bnum
= get_number (&p
);
1094 error (_("Bad breakpoint argument: '%s'"), arg
);
1097 if (b
->number
== bnum
)
1099 /* Check if this breakpoint has a "stop" method implemented in an
1100 extension language. This method and conditions entered into GDB
1101 from the CLI are mutually exclusive. */
1102 const struct extension_language_defn
*extlang
1103 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1105 if (extlang
!= NULL
)
1107 error (_("Only one stop condition allowed. There is currently"
1108 " a %s stop condition defined for this breakpoint."),
1109 ext_lang_capitalized_name (extlang
));
1111 set_breakpoint_condition (b
, p
, from_tty
);
1113 if (is_breakpoint (b
))
1114 update_global_location_list (UGLL_MAY_INSERT
);
1119 error (_("No breakpoint number %d."), bnum
);
1122 /* Check that COMMAND do not contain commands that are suitable
1123 only for tracepoints and not suitable for ordinary breakpoints.
1124 Throw if any such commands is found. */
1127 check_no_tracepoint_commands (struct command_line
*commands
)
1129 struct command_line
*c
;
1131 for (c
= commands
; c
; c
= c
->next
)
1135 if (c
->control_type
== while_stepping_control
)
1136 error (_("The 'while-stepping' command can "
1137 "only be used for tracepoints"));
1139 for (i
= 0; i
< c
->body_count
; ++i
)
1140 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1142 /* Not that command parsing removes leading whitespace and comment
1143 lines and also empty lines. So, we only need to check for
1144 command directly. */
1145 if (strstr (c
->line
, "collect ") == c
->line
)
1146 error (_("The 'collect' command can only be used for tracepoints"));
1148 if (strstr (c
->line
, "teval ") == c
->line
)
1149 error (_("The 'teval' command can only be used for tracepoints"));
1153 /* Encapsulate tests for different types of tracepoints. */
1156 is_tracepoint_type (enum bptype type
)
1158 return (type
== bp_tracepoint
1159 || type
== bp_fast_tracepoint
1160 || type
== bp_static_tracepoint
);
1164 is_tracepoint (const struct breakpoint
*b
)
1166 return is_tracepoint_type (b
->type
);
1169 /* A helper function that validates that COMMANDS are valid for a
1170 breakpoint. This function will throw an exception if a problem is
1174 validate_commands_for_breakpoint (struct breakpoint
*b
,
1175 struct command_line
*commands
)
1177 if (is_tracepoint (b
))
1179 struct tracepoint
*t
= (struct tracepoint
*) b
;
1180 struct command_line
*c
;
1181 struct command_line
*while_stepping
= 0;
1183 /* Reset the while-stepping step count. The previous commands
1184 might have included a while-stepping action, while the new
1188 /* We need to verify that each top-level element of commands is
1189 valid for tracepoints, that there's at most one
1190 while-stepping element, and that the while-stepping's body
1191 has valid tracing commands excluding nested while-stepping.
1192 We also need to validate the tracepoint action line in the
1193 context of the tracepoint --- validate_actionline actually
1194 has side effects, like setting the tracepoint's
1195 while-stepping STEP_COUNT, in addition to checking if the
1196 collect/teval actions parse and make sense in the
1197 tracepoint's context. */
1198 for (c
= commands
; c
; c
= c
->next
)
1200 if (c
->control_type
== while_stepping_control
)
1202 if (b
->type
== bp_fast_tracepoint
)
1203 error (_("The 'while-stepping' command "
1204 "cannot be used for fast tracepoint"));
1205 else if (b
->type
== bp_static_tracepoint
)
1206 error (_("The 'while-stepping' command "
1207 "cannot be used for static tracepoint"));
1210 error (_("The 'while-stepping' command "
1211 "can be used only once"));
1216 validate_actionline (c
->line
, b
);
1220 struct command_line
*c2
;
1222 gdb_assert (while_stepping
->body_count
== 1);
1223 c2
= while_stepping
->body_list
[0];
1224 for (; c2
; c2
= c2
->next
)
1226 if (c2
->control_type
== while_stepping_control
)
1227 error (_("The 'while-stepping' command cannot be nested"));
1233 check_no_tracepoint_commands (commands
);
1237 /* Return a vector of all the static tracepoints set at ADDR. The
1238 caller is responsible for releasing the vector. */
1241 static_tracepoints_here (CORE_ADDR addr
)
1243 struct breakpoint
*b
;
1244 VEC(breakpoint_p
) *found
= 0;
1245 struct bp_location
*loc
;
1248 if (b
->type
== bp_static_tracepoint
)
1250 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1251 if (loc
->address
== addr
)
1252 VEC_safe_push(breakpoint_p
, found
, b
);
1258 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1259 validate that only allowed commands are included. */
1262 breakpoint_set_commands (struct breakpoint
*b
,
1263 struct command_line
*commands
)
1265 validate_commands_for_breakpoint (b
, commands
);
1267 decref_counted_command_line (&b
->commands
);
1268 b
->commands
= alloc_counted_command_line (commands
);
1269 observer_notify_breakpoint_modified (b
);
1272 /* Set the internal `silent' flag on the breakpoint. Note that this
1273 is not the same as the "silent" that may appear in the breakpoint's
1277 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1279 int old_silent
= b
->silent
;
1282 if (old_silent
!= silent
)
1283 observer_notify_breakpoint_modified (b
);
1286 /* Set the thread for this breakpoint. If THREAD is -1, make the
1287 breakpoint work for any thread. */
1290 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1292 int old_thread
= b
->thread
;
1295 if (old_thread
!= thread
)
1296 observer_notify_breakpoint_modified (b
);
1299 /* Set the task for this breakpoint. If TASK is 0, make the
1300 breakpoint work for any task. */
1303 breakpoint_set_task (struct breakpoint
*b
, int task
)
1305 int old_task
= b
->task
;
1308 if (old_task
!= task
)
1309 observer_notify_breakpoint_modified (b
);
1313 check_tracepoint_command (char *line
, void *closure
)
1315 struct breakpoint
*b
= closure
;
1317 validate_actionline (line
, b
);
1320 /* A structure used to pass information through
1321 map_breakpoint_numbers. */
1323 struct commands_info
1325 /* True if the command was typed at a tty. */
1328 /* The breakpoint range spec. */
1331 /* Non-NULL if the body of the commands are being read from this
1332 already-parsed command. */
1333 struct command_line
*control
;
1335 /* The command lines read from the user, or NULL if they have not
1337 struct counted_command_line
*cmd
;
1340 /* A callback for map_breakpoint_numbers that sets the commands for
1341 commands_command. */
1344 do_map_commands_command (struct breakpoint
*b
, void *data
)
1346 struct commands_info
*info
= data
;
1348 if (info
->cmd
== NULL
)
1350 struct command_line
*l
;
1352 if (info
->control
!= NULL
)
1353 l
= copy_command_lines (info
->control
->body_list
[0]);
1356 struct cleanup
*old_chain
;
1359 str
= xstrprintf (_("Type commands for breakpoint(s) "
1360 "%s, one per line."),
1363 old_chain
= make_cleanup (xfree
, str
);
1365 l
= read_command_lines (str
,
1368 ? check_tracepoint_command
: 0),
1371 do_cleanups (old_chain
);
1374 info
->cmd
= alloc_counted_command_line (l
);
1377 /* If a breakpoint was on the list more than once, we don't need to
1379 if (b
->commands
!= info
->cmd
)
1381 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1382 incref_counted_command_line (info
->cmd
);
1383 decref_counted_command_line (&b
->commands
);
1384 b
->commands
= info
->cmd
;
1385 observer_notify_breakpoint_modified (b
);
1390 commands_command_1 (char *arg
, int from_tty
,
1391 struct command_line
*control
)
1393 struct cleanup
*cleanups
;
1394 struct commands_info info
;
1396 info
.from_tty
= from_tty
;
1397 info
.control
= control
;
1399 /* If we read command lines from the user, then `info' will hold an
1400 extra reference to the commands that we must clean up. */
1401 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1403 if (arg
== NULL
|| !*arg
)
1405 if (breakpoint_count
- prev_breakpoint_count
> 1)
1406 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1408 else if (breakpoint_count
> 0)
1409 arg
= xstrprintf ("%d", breakpoint_count
);
1412 /* So that we don't try to free the incoming non-NULL
1413 argument in the cleanup below. Mapping breakpoint
1414 numbers will fail in this case. */
1419 /* The command loop has some static state, so we need to preserve
1421 arg
= xstrdup (arg
);
1424 make_cleanup (xfree
, arg
);
1428 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1430 if (info
.cmd
== NULL
)
1431 error (_("No breakpoints specified."));
1433 do_cleanups (cleanups
);
1437 commands_command (char *arg
, int from_tty
)
1439 commands_command_1 (arg
, from_tty
, NULL
);
1442 /* Like commands_command, but instead of reading the commands from
1443 input stream, takes them from an already parsed command structure.
1445 This is used by cli-script.c to DTRT with breakpoint commands
1446 that are part of if and while bodies. */
1447 enum command_control_type
1448 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1450 commands_command_1 (arg
, 0, cmd
);
1451 return simple_control
;
1454 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1457 bp_location_has_shadow (struct bp_location
*bl
)
1459 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1463 if (bl
->target_info
.shadow_len
== 0)
1464 /* BL isn't valid, or doesn't shadow memory. */
1469 /* Update BUF, which is LEN bytes read from the target address
1470 MEMADDR, by replacing a memory breakpoint with its shadowed
1473 If READBUF is not NULL, this buffer must not overlap with the of
1474 the breakpoint location's shadow_contents buffer. Otherwise, a
1475 failed assertion internal error will be raised. */
1478 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1479 const gdb_byte
*writebuf_org
,
1480 ULONGEST memaddr
, LONGEST len
,
1481 struct bp_target_info
*target_info
,
1482 struct gdbarch
*gdbarch
)
1484 /* Now do full processing of the found relevant range of elements. */
1485 CORE_ADDR bp_addr
= 0;
1489 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1490 current_program_space
->aspace
, 0))
1492 /* The breakpoint is inserted in a different address space. */
1496 /* Addresses and length of the part of the breakpoint that
1498 bp_addr
= target_info
->placed_address
;
1499 bp_size
= target_info
->shadow_len
;
1501 if (bp_addr
+ bp_size
<= memaddr
)
1503 /* The breakpoint is entirely before the chunk of memory we are
1508 if (bp_addr
>= memaddr
+ len
)
1510 /* The breakpoint is entirely after the chunk of memory we are
1515 /* Offset within shadow_contents. */
1516 if (bp_addr
< memaddr
)
1518 /* Only copy the second part of the breakpoint. */
1519 bp_size
-= memaddr
- bp_addr
;
1520 bptoffset
= memaddr
- bp_addr
;
1524 if (bp_addr
+ bp_size
> memaddr
+ len
)
1526 /* Only copy the first part of the breakpoint. */
1527 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1530 if (readbuf
!= NULL
)
1532 /* Verify that the readbuf buffer does not overlap with the
1533 shadow_contents buffer. */
1534 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1535 || readbuf
>= (target_info
->shadow_contents
1536 + target_info
->shadow_len
));
1538 /* Update the read buffer with this inserted breakpoint's
1540 memcpy (readbuf
+ bp_addr
- memaddr
,
1541 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1545 const unsigned char *bp
;
1546 CORE_ADDR addr
= target_info
->reqstd_address
;
1549 /* Update the shadow with what we want to write to memory. */
1550 memcpy (target_info
->shadow_contents
+ bptoffset
,
1551 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1553 /* Determine appropriate breakpoint contents and size for this
1555 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1557 /* Update the final write buffer with this inserted
1558 breakpoint's INSN. */
1559 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1563 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1564 by replacing any memory breakpoints with their shadowed contents.
1566 If READBUF is not NULL, this buffer must not overlap with any of
1567 the breakpoint location's shadow_contents buffers. Otherwise,
1568 a failed assertion internal error will be raised.
1570 The range of shadowed area by each bp_location is:
1571 bl->address - bp_location_placed_address_before_address_max
1572 up to bl->address + bp_location_shadow_len_after_address_max
1573 The range we were requested to resolve shadows for is:
1574 memaddr ... memaddr + len
1575 Thus the safe cutoff boundaries for performance optimization are
1576 memaddr + len <= (bl->address
1577 - bp_location_placed_address_before_address_max)
1579 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1582 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1583 const gdb_byte
*writebuf_org
,
1584 ULONGEST memaddr
, LONGEST len
)
1586 /* Left boundary, right boundary and median element of our binary
1588 unsigned bc_l
, bc_r
, bc
;
1591 /* Find BC_L which is a leftmost element which may affect BUF
1592 content. It is safe to report lower value but a failure to
1593 report higher one. */
1596 bc_r
= bp_location_count
;
1597 while (bc_l
+ 1 < bc_r
)
1599 struct bp_location
*bl
;
1601 bc
= (bc_l
+ bc_r
) / 2;
1602 bl
= bp_location
[bc
];
1604 /* Check first BL->ADDRESS will not overflow due to the added
1605 constant. Then advance the left boundary only if we are sure
1606 the BC element can in no way affect the BUF content (MEMADDR
1607 to MEMADDR + LEN range).
1609 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1610 offset so that we cannot miss a breakpoint with its shadow
1611 range tail still reaching MEMADDR. */
1613 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1615 && (bl
->address
+ bp_location_shadow_len_after_address_max
1622 /* Due to the binary search above, we need to make sure we pick the
1623 first location that's at BC_L's address. E.g., if there are
1624 multiple locations at the same address, BC_L may end up pointing
1625 at a duplicate location, and miss the "master"/"inserted"
1626 location. Say, given locations L1, L2 and L3 at addresses A and
1629 L1@A, L2@A, L3@B, ...
1631 BC_L could end up pointing at location L2, while the "master"
1632 location could be L1. Since the `loc->inserted' flag is only set
1633 on "master" locations, we'd forget to restore the shadow of L1
1636 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1639 /* Now do full processing of the found relevant range of elements. */
1641 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1643 struct bp_location
*bl
= bp_location
[bc
];
1644 CORE_ADDR bp_addr
= 0;
1648 /* bp_location array has BL->OWNER always non-NULL. */
1649 if (bl
->owner
->type
== bp_none
)
1650 warning (_("reading through apparently deleted breakpoint #%d?"),
1653 /* Performance optimization: any further element can no longer affect BUF
1656 if (bl
->address
>= bp_location_placed_address_before_address_max
1657 && memaddr
+ len
<= (bl
->address
1658 - bp_location_placed_address_before_address_max
))
1661 if (!bp_location_has_shadow (bl
))
1664 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1665 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1668 /* Now process single-step breakpoints. These are not found in the
1669 bp_location array. */
1670 for (i
= 0; i
< 2; i
++)
1672 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
1676 struct gdbarch
*gdbarch
= single_step_gdbarch
[i
];
1678 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1679 memaddr
, len
, bp_tgt
, gdbarch
);
1686 /* Return true if BPT is either a software breakpoint or a hardware
1690 is_breakpoint (const struct breakpoint
*bpt
)
1692 return (bpt
->type
== bp_breakpoint
1693 || bpt
->type
== bp_hardware_breakpoint
1694 || bpt
->type
== bp_dprintf
);
1697 /* Return true if BPT is of any hardware watchpoint kind. */
1700 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1702 return (bpt
->type
== bp_hardware_watchpoint
1703 || bpt
->type
== bp_read_watchpoint
1704 || bpt
->type
== bp_access_watchpoint
);
1707 /* Return true if BPT is of any watchpoint kind, hardware or
1711 is_watchpoint (const struct breakpoint
*bpt
)
1713 return (is_hardware_watchpoint (bpt
)
1714 || bpt
->type
== bp_watchpoint
);
1717 /* Returns true if the current thread and its running state are safe
1718 to evaluate or update watchpoint B. Watchpoints on local
1719 expressions need to be evaluated in the context of the thread that
1720 was current when the watchpoint was created, and, that thread needs
1721 to be stopped to be able to select the correct frame context.
1722 Watchpoints on global expressions can be evaluated on any thread,
1723 and in any state. It is presently left to the target allowing
1724 memory accesses when threads are running. */
1727 watchpoint_in_thread_scope (struct watchpoint
*b
)
1729 return (b
->base
.pspace
== current_program_space
1730 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1731 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1732 && !is_executing (inferior_ptid
))));
1735 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1736 associated bp_watchpoint_scope breakpoint. */
1739 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1741 struct breakpoint
*b
= &w
->base
;
1743 if (b
->related_breakpoint
!= b
)
1745 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1746 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1747 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1748 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1749 b
->related_breakpoint
= b
;
1751 b
->disposition
= disp_del_at_next_stop
;
1754 /* Extract a bitfield value from value VAL using the bit parameters contained in
1757 static struct value
*
1758 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1760 struct value
*bit_val
;
1765 bit_val
= allocate_value (value_type (val
));
1767 unpack_value_bitfield (bit_val
,
1770 value_contents_for_printing (val
),
1777 /* Assuming that B is a watchpoint:
1778 - Reparse watchpoint expression, if REPARSE is non-zero
1779 - Evaluate expression and store the result in B->val
1780 - Evaluate the condition if there is one, and store the result
1782 - Update the list of values that must be watched in B->loc.
1784 If the watchpoint disposition is disp_del_at_next_stop, then do
1785 nothing. If this is local watchpoint that is out of scope, delete
1788 Even with `set breakpoint always-inserted on' the watchpoints are
1789 removed + inserted on each stop here. Normal breakpoints must
1790 never be removed because they might be missed by a running thread
1791 when debugging in non-stop mode. On the other hand, hardware
1792 watchpoints (is_hardware_watchpoint; processed here) are specific
1793 to each LWP since they are stored in each LWP's hardware debug
1794 registers. Therefore, such LWP must be stopped first in order to
1795 be able to modify its hardware watchpoints.
1797 Hardware watchpoints must be reset exactly once after being
1798 presented to the user. It cannot be done sooner, because it would
1799 reset the data used to present the watchpoint hit to the user. And
1800 it must not be done later because it could display the same single
1801 watchpoint hit during multiple GDB stops. Note that the latter is
1802 relevant only to the hardware watchpoint types bp_read_watchpoint
1803 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1804 not user-visible - its hit is suppressed if the memory content has
1807 The following constraints influence the location where we can reset
1808 hardware watchpoints:
1810 * target_stopped_by_watchpoint and target_stopped_data_address are
1811 called several times when GDB stops.
1814 * Multiple hardware watchpoints can be hit at the same time,
1815 causing GDB to stop. GDB only presents one hardware watchpoint
1816 hit at a time as the reason for stopping, and all the other hits
1817 are presented later, one after the other, each time the user
1818 requests the execution to be resumed. Execution is not resumed
1819 for the threads still having pending hit event stored in
1820 LWP_INFO->STATUS. While the watchpoint is already removed from
1821 the inferior on the first stop the thread hit event is kept being
1822 reported from its cached value by linux_nat_stopped_data_address
1823 until the real thread resume happens after the watchpoint gets
1824 presented and thus its LWP_INFO->STATUS gets reset.
1826 Therefore the hardware watchpoint hit can get safely reset on the
1827 watchpoint removal from inferior. */
1830 update_watchpoint (struct watchpoint
*b
, int reparse
)
1832 int within_current_scope
;
1833 struct frame_id saved_frame_id
;
1836 /* If this is a local watchpoint, we only want to check if the
1837 watchpoint frame is in scope if the current thread is the thread
1838 that was used to create the watchpoint. */
1839 if (!watchpoint_in_thread_scope (b
))
1842 if (b
->base
.disposition
== disp_del_at_next_stop
)
1847 /* Determine if the watchpoint is within scope. */
1848 if (b
->exp_valid_block
== NULL
)
1849 within_current_scope
= 1;
1852 struct frame_info
*fi
= get_current_frame ();
1853 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1854 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1856 /* If we're in a function epilogue, unwinding may not work
1857 properly, so do not attempt to recreate locations at this
1858 point. See similar comments in watchpoint_check. */
1859 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1862 /* Save the current frame's ID so we can restore it after
1863 evaluating the watchpoint expression on its own frame. */
1864 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1865 took a frame parameter, so that we didn't have to change the
1868 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1870 fi
= frame_find_by_id (b
->watchpoint_frame
);
1871 within_current_scope
= (fi
!= NULL
);
1872 if (within_current_scope
)
1876 /* We don't free locations. They are stored in the bp_location array
1877 and update_global_location_list will eventually delete them and
1878 remove breakpoints if needed. */
1881 if (within_current_scope
&& reparse
)
1890 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1891 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1892 /* If the meaning of expression itself changed, the old value is
1893 no longer relevant. We don't want to report a watchpoint hit
1894 to the user when the old value and the new value may actually
1895 be completely different objects. */
1896 value_free (b
->val
);
1900 /* Note that unlike with breakpoints, the watchpoint's condition
1901 expression is stored in the breakpoint object, not in the
1902 locations (re)created below. */
1903 if (b
->base
.cond_string
!= NULL
)
1905 if (b
->cond_exp
!= NULL
)
1907 xfree (b
->cond_exp
);
1911 s
= b
->base
.cond_string
;
1912 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1916 /* If we failed to parse the expression, for example because
1917 it refers to a global variable in a not-yet-loaded shared library,
1918 don't try to insert watchpoint. We don't automatically delete
1919 such watchpoint, though, since failure to parse expression
1920 is different from out-of-scope watchpoint. */
1921 if (!target_has_execution
)
1923 /* Without execution, memory can't change. No use to try and
1924 set watchpoint locations. The watchpoint will be reset when
1925 the target gains execution, through breakpoint_re_set. */
1926 if (!can_use_hw_watchpoints
)
1928 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1929 b
->base
.type
= bp_watchpoint
;
1931 error (_("Can't set read/access watchpoint when "
1932 "hardware watchpoints are disabled."));
1935 else if (within_current_scope
&& b
->exp
)
1938 struct value
*val_chain
, *v
, *result
, *next
;
1939 struct program_space
*frame_pspace
;
1941 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1943 /* Avoid setting b->val if it's already set. The meaning of
1944 b->val is 'the last value' user saw, and we should update
1945 it only if we reported that last value to user. As it
1946 happens, the code that reports it updates b->val directly.
1947 We don't keep track of the memory value for masked
1949 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1951 if (b
->val_bitsize
!= 0)
1953 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1961 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1963 /* Look at each value on the value chain. */
1964 for (v
= val_chain
; v
; v
= value_next (v
))
1966 /* If it's a memory location, and GDB actually needed
1967 its contents to evaluate the expression, then we
1968 must watch it. If the first value returned is
1969 still lazy, that means an error occurred reading it;
1970 watch it anyway in case it becomes readable. */
1971 if (VALUE_LVAL (v
) == lval_memory
1972 && (v
== val_chain
|| ! value_lazy (v
)))
1974 struct type
*vtype
= check_typedef (value_type (v
));
1976 /* We only watch structs and arrays if user asked
1977 for it explicitly, never if they just happen to
1978 appear in the middle of some value chain. */
1980 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1981 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1985 struct bp_location
*loc
, **tmp
;
1986 int bitpos
= 0, bitsize
= 0;
1988 if (value_bitsize (v
) != 0)
1990 /* Extract the bit parameters out from the bitfield
1992 bitpos
= value_bitpos (v
);
1993 bitsize
= value_bitsize (v
);
1995 else if (v
== result
&& b
->val_bitsize
!= 0)
1997 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1998 lvalue whose bit parameters are saved in the fields
1999 VAL_BITPOS and VAL_BITSIZE. */
2000 bitpos
= b
->val_bitpos
;
2001 bitsize
= b
->val_bitsize
;
2004 addr
= value_address (v
);
2007 /* Skip the bytes that don't contain the bitfield. */
2012 if (b
->base
.type
== bp_read_watchpoint
)
2014 else if (b
->base
.type
== bp_access_watchpoint
)
2017 loc
= allocate_bp_location (&b
->base
);
2018 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2021 loc
->gdbarch
= get_type_arch (value_type (v
));
2023 loc
->pspace
= frame_pspace
;
2024 loc
->address
= addr
;
2028 /* Just cover the bytes that make up the bitfield. */
2029 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2032 loc
->length
= TYPE_LENGTH (value_type (v
));
2034 loc
->watchpoint_type
= type
;
2039 /* Change the type of breakpoint between hardware assisted or
2040 an ordinary watchpoint depending on the hardware support
2041 and free hardware slots. REPARSE is set when the inferior
2046 enum bp_loc_type loc_type
;
2047 struct bp_location
*bl
;
2049 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2053 int i
, target_resources_ok
, other_type_used
;
2056 /* Use an exact watchpoint when there's only one memory region to be
2057 watched, and only one debug register is needed to watch it. */
2058 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2060 /* We need to determine how many resources are already
2061 used for all other hardware watchpoints plus this one
2062 to see if we still have enough resources to also fit
2063 this watchpoint in as well. */
2065 /* If this is a software watchpoint, we try to turn it
2066 to a hardware one -- count resources as if B was of
2067 hardware watchpoint type. */
2068 type
= b
->base
.type
;
2069 if (type
== bp_watchpoint
)
2070 type
= bp_hardware_watchpoint
;
2072 /* This watchpoint may or may not have been placed on
2073 the list yet at this point (it won't be in the list
2074 if we're trying to create it for the first time,
2075 through watch_command), so always account for it
2078 /* Count resources used by all watchpoints except B. */
2079 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2081 /* Add in the resources needed for B. */
2082 i
+= hw_watchpoint_use_count (&b
->base
);
2085 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2086 if (target_resources_ok
<= 0)
2088 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2090 if (target_resources_ok
== 0 && !sw_mode
)
2091 error (_("Target does not support this type of "
2092 "hardware watchpoint."));
2093 else if (target_resources_ok
< 0 && !sw_mode
)
2094 error (_("There are not enough available hardware "
2095 "resources for this watchpoint."));
2097 /* Downgrade to software watchpoint. */
2098 b
->base
.type
= bp_watchpoint
;
2102 /* If this was a software watchpoint, we've just
2103 found we have enough resources to turn it to a
2104 hardware watchpoint. Otherwise, this is a
2106 b
->base
.type
= type
;
2109 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2111 if (!can_use_hw_watchpoints
)
2112 error (_("Can't set read/access watchpoint when "
2113 "hardware watchpoints are disabled."));
2115 error (_("Expression cannot be implemented with "
2116 "read/access watchpoint."));
2119 b
->base
.type
= bp_watchpoint
;
2121 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2122 : bp_loc_hardware_watchpoint
);
2123 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2124 bl
->loc_type
= loc_type
;
2127 for (v
= val_chain
; v
; v
= next
)
2129 next
= value_next (v
);
2134 /* If a software watchpoint is not watching any memory, then the
2135 above left it without any location set up. But,
2136 bpstat_stop_status requires a location to be able to report
2137 stops, so make sure there's at least a dummy one. */
2138 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2140 struct breakpoint
*base
= &b
->base
;
2141 base
->loc
= allocate_bp_location (base
);
2142 base
->loc
->pspace
= frame_pspace
;
2143 base
->loc
->address
= -1;
2144 base
->loc
->length
= -1;
2145 base
->loc
->watchpoint_type
= -1;
2148 else if (!within_current_scope
)
2150 printf_filtered (_("\
2151 Watchpoint %d deleted because the program has left the block\n\
2152 in which its expression is valid.\n"),
2154 watchpoint_del_at_next_stop (b
);
2157 /* Restore the selected frame. */
2159 select_frame (frame_find_by_id (saved_frame_id
));
2163 /* Returns 1 iff breakpoint location should be
2164 inserted in the inferior. We don't differentiate the type of BL's owner
2165 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2166 breakpoint_ops is not defined, because in insert_bp_location,
2167 tracepoint's insert_location will not be called. */
2169 should_be_inserted (struct bp_location
*bl
)
2171 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2174 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2177 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2180 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2183 /* This is set for example, when we're attached to the parent of a
2184 vfork, and have detached from the child. The child is running
2185 free, and we expect it to do an exec or exit, at which point the
2186 OS makes the parent schedulable again (and the target reports
2187 that the vfork is done). Until the child is done with the shared
2188 memory region, do not insert breakpoints in the parent, otherwise
2189 the child could still trip on the parent's breakpoints. Since
2190 the parent is blocked anyway, it won't miss any breakpoint. */
2191 if (bl
->pspace
->breakpoints_not_allowed
)
2194 /* Don't insert a breakpoint if we're trying to step past its
2196 if ((bl
->loc_type
== bp_loc_software_breakpoint
2197 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2198 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2203 fprintf_unfiltered (gdb_stdlog
,
2204 "infrun: skipping breakpoint: "
2205 "stepping past insn at: %s\n",
2206 paddress (bl
->gdbarch
, bl
->address
));
2211 /* Don't insert watchpoints if we're trying to step past the
2212 instruction that triggered one. */
2213 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2214 && stepping_past_nonsteppable_watchpoint ())
2218 fprintf_unfiltered (gdb_stdlog
,
2219 "infrun: stepping past non-steppable watchpoint. "
2220 "skipping watchpoint at %s:%d\n",
2221 paddress (bl
->gdbarch
, bl
->address
),
2230 /* Same as should_be_inserted but does the check assuming
2231 that the location is not duplicated. */
2234 unduplicated_should_be_inserted (struct bp_location
*bl
)
2237 const int save_duplicate
= bl
->duplicate
;
2240 result
= should_be_inserted (bl
);
2241 bl
->duplicate
= save_duplicate
;
2245 /* Parses a conditional described by an expression COND into an
2246 agent expression bytecode suitable for evaluation
2247 by the bytecode interpreter. Return NULL if there was
2248 any error during parsing. */
2250 static struct agent_expr
*
2251 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2253 struct agent_expr
*aexpr
= NULL
;
2254 volatile struct gdb_exception ex
;
2259 /* We don't want to stop processing, so catch any errors
2260 that may show up. */
2261 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2263 aexpr
= gen_eval_for_expr (scope
, cond
);
2268 /* If we got here, it means the condition could not be parsed to a valid
2269 bytecode expression and thus can't be evaluated on the target's side.
2270 It's no use iterating through the conditions. */
2274 /* We have a valid agent expression. */
2278 /* Based on location BL, create a list of breakpoint conditions to be
2279 passed on to the target. If we have duplicated locations with different
2280 conditions, we will add such conditions to the list. The idea is that the
2281 target will evaluate the list of conditions and will only notify GDB when
2282 one of them is true. */
2285 build_target_condition_list (struct bp_location
*bl
)
2287 struct bp_location
**locp
= NULL
, **loc2p
;
2288 int null_condition_or_parse_error
= 0;
2289 int modified
= bl
->needs_update
;
2290 struct bp_location
*loc
;
2292 /* Release conditions left over from a previous insert. */
2293 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2295 /* This is only meaningful if the target is
2296 evaluating conditions and if the user has
2297 opted for condition evaluation on the target's
2299 if (gdb_evaluates_breakpoint_condition_p ()
2300 || !target_supports_evaluation_of_breakpoint_conditions ())
2303 /* Do a first pass to check for locations with no assigned
2304 conditions or conditions that fail to parse to a valid agent expression
2305 bytecode. If any of these happen, then it's no use to send conditions
2306 to the target since this location will always trigger and generate a
2307 response back to GDB. */
2308 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2311 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2315 struct agent_expr
*aexpr
;
2317 /* Re-parse the conditions since something changed. In that
2318 case we already freed the condition bytecodes (see
2319 force_breakpoint_reinsertion). We just
2320 need to parse the condition to bytecodes again. */
2321 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2322 loc
->cond_bytecode
= aexpr
;
2324 /* Check if we managed to parse the conditional expression
2325 correctly. If not, we will not send this condition
2331 /* If we have a NULL bytecode expression, it means something
2332 went wrong or we have a null condition expression. */
2333 if (!loc
->cond_bytecode
)
2335 null_condition_or_parse_error
= 1;
2341 /* If any of these happened, it means we will have to evaluate the conditions
2342 for the location's address on gdb's side. It is no use keeping bytecodes
2343 for all the other duplicate locations, thus we free all of them here.
2345 This is so we have a finer control over which locations' conditions are
2346 being evaluated by GDB or the remote stub. */
2347 if (null_condition_or_parse_error
)
2349 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2352 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2354 /* Only go as far as the first NULL bytecode is
2356 if (!loc
->cond_bytecode
)
2359 free_agent_expr (loc
->cond_bytecode
);
2360 loc
->cond_bytecode
= NULL
;
2365 /* No NULL conditions or failed bytecode generation. Build a condition list
2366 for this location's address. */
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2371 && is_breakpoint (loc
->owner
)
2372 && loc
->pspace
->num
== bl
->pspace
->num
2373 && loc
->owner
->enable_state
== bp_enabled
2375 /* Add the condition to the vector. This will be used later to send the
2376 conditions to the target. */
2377 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2378 loc
->cond_bytecode
);
2384 /* Parses a command described by string CMD into an agent expression
2385 bytecode suitable for evaluation by the bytecode interpreter.
2386 Return NULL if there was any error during parsing. */
2388 static struct agent_expr
*
2389 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2391 struct cleanup
*old_cleanups
= 0;
2392 struct expression
*expr
, **argvec
;
2393 struct agent_expr
*aexpr
= NULL
;
2394 volatile struct gdb_exception ex
;
2395 const char *cmdrest
;
2396 const char *format_start
, *format_end
;
2397 struct format_piece
*fpieces
;
2399 struct gdbarch
*gdbarch
= get_current_arch ();
2406 if (*cmdrest
== ',')
2408 cmdrest
= skip_spaces_const (cmdrest
);
2410 if (*cmdrest
++ != '"')
2411 error (_("No format string following the location"));
2413 format_start
= cmdrest
;
2415 fpieces
= parse_format_string (&cmdrest
);
2417 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2419 format_end
= cmdrest
;
2421 if (*cmdrest
++ != '"')
2422 error (_("Bad format string, non-terminated '\"'."));
2424 cmdrest
= skip_spaces_const (cmdrest
);
2426 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2427 error (_("Invalid argument syntax"));
2429 if (*cmdrest
== ',')
2431 cmdrest
= skip_spaces_const (cmdrest
);
2433 /* For each argument, make an expression. */
2435 argvec
= (struct expression
**) alloca (strlen (cmd
)
2436 * sizeof (struct expression
*));
2439 while (*cmdrest
!= '\0')
2444 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2445 argvec
[nargs
++] = expr
;
2447 if (*cmdrest
== ',')
2451 /* We don't want to stop processing, so catch any errors
2452 that may show up. */
2453 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2455 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2456 format_start
, format_end
- format_start
,
2457 fpieces
, nargs
, argvec
);
2460 do_cleanups (old_cleanups
);
2464 /* If we got here, it means the command could not be parsed to a valid
2465 bytecode expression and thus can't be evaluated on the target's side.
2466 It's no use iterating through the other commands. */
2470 /* We have a valid agent expression, return it. */
2474 /* Based on location BL, create a list of breakpoint commands to be
2475 passed on to the target. If we have duplicated locations with
2476 different commands, we will add any such to the list. */
2479 build_target_command_list (struct bp_location
*bl
)
2481 struct bp_location
**locp
= NULL
, **loc2p
;
2482 int null_command_or_parse_error
= 0;
2483 int modified
= bl
->needs_update
;
2484 struct bp_location
*loc
;
2486 /* Release commands left over from a previous insert. */
2487 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2489 if (!target_can_run_breakpoint_commands ())
2492 /* For now, limit to agent-style dprintf breakpoints. */
2493 if (dprintf_style
!= dprintf_style_agent
)
2496 /* For now, if we have any duplicate location that isn't a dprintf,
2497 don't install the target-side commands, as that would make the
2498 breakpoint not be reported to the core, and we'd lose
2500 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2503 if (is_breakpoint (loc
->owner
)
2504 && loc
->pspace
->num
== bl
->pspace
->num
2505 && loc
->owner
->type
!= bp_dprintf
)
2509 /* Do a first pass to check for locations with no assigned
2510 conditions or conditions that fail to parse to a valid agent expression
2511 bytecode. If any of these happen, then it's no use to send conditions
2512 to the target since this location will always trigger and generate a
2513 response back to GDB. */
2514 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2517 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2521 struct agent_expr
*aexpr
;
2523 /* Re-parse the commands since something changed. In that
2524 case we already freed the command bytecodes (see
2525 force_breakpoint_reinsertion). We just
2526 need to parse the command to bytecodes again. */
2527 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2528 loc
->owner
->extra_string
);
2529 loc
->cmd_bytecode
= aexpr
;
2535 /* If we have a NULL bytecode expression, it means something
2536 went wrong or we have a null command expression. */
2537 if (!loc
->cmd_bytecode
)
2539 null_command_or_parse_error
= 1;
2545 /* If anything failed, then we're not doing target-side commands,
2547 if (null_command_or_parse_error
)
2549 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2552 if (is_breakpoint (loc
->owner
)
2553 && loc
->pspace
->num
== bl
->pspace
->num
)
2555 /* Only go as far as the first NULL bytecode is
2557 if (loc
->cmd_bytecode
== NULL
)
2560 free_agent_expr (loc
->cmd_bytecode
);
2561 loc
->cmd_bytecode
= NULL
;
2566 /* No NULL commands or failed bytecode generation. Build a command list
2567 for this location's address. */
2568 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2571 if (loc
->owner
->extra_string
2572 && is_breakpoint (loc
->owner
)
2573 && loc
->pspace
->num
== bl
->pspace
->num
2574 && loc
->owner
->enable_state
== bp_enabled
2576 /* Add the command to the vector. This will be used later
2577 to send the commands to the target. */
2578 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2582 bl
->target_info
.persist
= 0;
2583 /* Maybe flag this location as persistent. */
2584 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2585 bl
->target_info
.persist
= 1;
2588 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2589 location. Any error messages are printed to TMP_ERROR_STREAM; and
2590 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2591 Returns 0 for success, 1 if the bp_location type is not supported or
2594 NOTE drow/2003-09-09: This routine could be broken down to an
2595 object-style method for each breakpoint or catchpoint type. */
2597 insert_bp_location (struct bp_location
*bl
,
2598 struct ui_file
*tmp_error_stream
,
2599 int *disabled_breaks
,
2600 int *hw_breakpoint_error
,
2601 int *hw_bp_error_explained_already
)
2603 enum errors bp_err
= GDB_NO_ERROR
;
2604 const char *bp_err_message
= NULL
;
2605 volatile struct gdb_exception e
;
2607 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2610 /* Note we don't initialize bl->target_info, as that wipes out
2611 the breakpoint location's shadow_contents if the breakpoint
2612 is still inserted at that location. This in turn breaks
2613 target_read_memory which depends on these buffers when
2614 a memory read is requested at the breakpoint location:
2615 Once the target_info has been wiped, we fail to see that
2616 we have a breakpoint inserted at that address and thus
2617 read the breakpoint instead of returning the data saved in
2618 the breakpoint location's shadow contents. */
2619 bl
->target_info
.reqstd_address
= bl
->address
;
2620 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2621 bl
->target_info
.length
= bl
->length
;
2623 /* When working with target-side conditions, we must pass all the conditions
2624 for the same breakpoint address down to the target since GDB will not
2625 insert those locations. With a list of breakpoint conditions, the target
2626 can decide when to stop and notify GDB. */
2628 if (is_breakpoint (bl
->owner
))
2630 build_target_condition_list (bl
);
2631 build_target_command_list (bl
);
2632 /* Reset the modification marker. */
2633 bl
->needs_update
= 0;
2636 if (bl
->loc_type
== bp_loc_software_breakpoint
2637 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2639 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2641 /* If the explicitly specified breakpoint type
2642 is not hardware breakpoint, check the memory map to see
2643 if the breakpoint address is in read only memory or not.
2645 Two important cases are:
2646 - location type is not hardware breakpoint, memory
2647 is readonly. We change the type of the location to
2648 hardware breakpoint.
2649 - location type is hardware breakpoint, memory is
2650 read-write. This means we've previously made the
2651 location hardware one, but then the memory map changed,
2654 When breakpoints are removed, remove_breakpoints will use
2655 location types we've just set here, the only possible
2656 problem is that memory map has changed during running
2657 program, but it's not going to work anyway with current
2659 struct mem_region
*mr
2660 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2664 if (automatic_hardware_breakpoints
)
2666 enum bp_loc_type new_type
;
2668 if (mr
->attrib
.mode
!= MEM_RW
)
2669 new_type
= bp_loc_hardware_breakpoint
;
2671 new_type
= bp_loc_software_breakpoint
;
2673 if (new_type
!= bl
->loc_type
)
2675 static int said
= 0;
2677 bl
->loc_type
= new_type
;
2680 fprintf_filtered (gdb_stdout
,
2681 _("Note: automatically using "
2682 "hardware breakpoints for "
2683 "read-only addresses.\n"));
2688 else if (bl
->loc_type
== bp_loc_software_breakpoint
2689 && mr
->attrib
.mode
!= MEM_RW
)
2691 fprintf_unfiltered (tmp_error_stream
,
2692 _("Cannot insert breakpoint %d.\n"
2693 "Cannot set software breakpoint "
2694 "at read-only address %s\n"),
2696 paddress (bl
->gdbarch
, bl
->address
));
2702 /* First check to see if we have to handle an overlay. */
2703 if (overlay_debugging
== ovly_off
2704 || bl
->section
== NULL
2705 || !(section_is_overlay (bl
->section
)))
2707 /* No overlay handling: just set the breakpoint. */
2708 TRY_CATCH (e
, RETURN_MASK_ALL
)
2712 val
= bl
->owner
->ops
->insert_location (bl
);
2714 bp_err
= GENERIC_ERROR
;
2719 bp_err_message
= e
.message
;
2724 /* This breakpoint is in an overlay section.
2725 Shall we set a breakpoint at the LMA? */
2726 if (!overlay_events_enabled
)
2728 /* Yes -- overlay event support is not active,
2729 so we must try to set a breakpoint at the LMA.
2730 This will not work for a hardware breakpoint. */
2731 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2732 warning (_("hardware breakpoint %d not supported in overlay!"),
2736 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2738 /* Set a software (trap) breakpoint at the LMA. */
2739 bl
->overlay_target_info
= bl
->target_info
;
2740 bl
->overlay_target_info
.reqstd_address
= addr
;
2742 /* No overlay handling: just set the breakpoint. */
2743 TRY_CATCH (e
, RETURN_MASK_ALL
)
2747 val
= target_insert_breakpoint (bl
->gdbarch
,
2748 &bl
->overlay_target_info
);
2750 bp_err
= GENERIC_ERROR
;
2755 bp_err_message
= e
.message
;
2758 if (bp_err
!= GDB_NO_ERROR
)
2759 fprintf_unfiltered (tmp_error_stream
,
2760 "Overlay breakpoint %d "
2761 "failed: in ROM?\n",
2765 /* Shall we set a breakpoint at the VMA? */
2766 if (section_is_mapped (bl
->section
))
2768 /* Yes. This overlay section is mapped into memory. */
2769 TRY_CATCH (e
, RETURN_MASK_ALL
)
2773 val
= bl
->owner
->ops
->insert_location (bl
);
2775 bp_err
= GENERIC_ERROR
;
2780 bp_err_message
= e
.message
;
2785 /* No. This breakpoint will not be inserted.
2786 No error, but do not mark the bp as 'inserted'. */
2791 if (bp_err
!= GDB_NO_ERROR
)
2793 /* Can't set the breakpoint. */
2795 /* In some cases, we might not be able to insert a
2796 breakpoint in a shared library that has already been
2797 removed, but we have not yet processed the shlib unload
2798 event. Unfortunately, some targets that implement
2799 breakpoint insertion themselves can't tell why the
2800 breakpoint insertion failed (e.g., the remote target
2801 doesn't define error codes), so we must treat generic
2802 errors as memory errors. */
2803 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2804 && bl
->loc_type
== bp_loc_software_breakpoint
2805 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2806 || shared_objfile_contains_address_p (bl
->pspace
,
2809 /* See also: disable_breakpoints_in_shlibs. */
2810 bl
->shlib_disabled
= 1;
2811 observer_notify_breakpoint_modified (bl
->owner
);
2812 if (!*disabled_breaks
)
2814 fprintf_unfiltered (tmp_error_stream
,
2815 "Cannot insert breakpoint %d.\n",
2817 fprintf_unfiltered (tmp_error_stream
,
2818 "Temporarily disabling shared "
2819 "library breakpoints:\n");
2821 *disabled_breaks
= 1;
2822 fprintf_unfiltered (tmp_error_stream
,
2823 "breakpoint #%d\n", bl
->owner
->number
);
2828 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2830 *hw_breakpoint_error
= 1;
2831 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2832 fprintf_unfiltered (tmp_error_stream
,
2833 "Cannot insert hardware breakpoint %d%s",
2834 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2835 if (bp_err_message
!= NULL
)
2836 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2840 if (bp_err_message
== NULL
)
2843 = memory_error_message (TARGET_XFER_E_IO
,
2844 bl
->gdbarch
, bl
->address
);
2845 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2847 fprintf_unfiltered (tmp_error_stream
,
2848 "Cannot insert breakpoint %d.\n"
2850 bl
->owner
->number
, message
);
2851 do_cleanups (old_chain
);
2855 fprintf_unfiltered (tmp_error_stream
,
2856 "Cannot insert breakpoint %d: %s\n",
2871 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2872 /* NOTE drow/2003-09-08: This state only exists for removing
2873 watchpoints. It's not clear that it's necessary... */
2874 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2878 gdb_assert (bl
->owner
->ops
!= NULL
2879 && bl
->owner
->ops
->insert_location
!= NULL
);
2881 val
= bl
->owner
->ops
->insert_location (bl
);
2883 /* If trying to set a read-watchpoint, and it turns out it's not
2884 supported, try emulating one with an access watchpoint. */
2885 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2887 struct bp_location
*loc
, **loc_temp
;
2889 /* But don't try to insert it, if there's already another
2890 hw_access location that would be considered a duplicate
2892 ALL_BP_LOCATIONS (loc
, loc_temp
)
2894 && loc
->watchpoint_type
== hw_access
2895 && watchpoint_locations_match (bl
, loc
))
2899 bl
->target_info
= loc
->target_info
;
2900 bl
->watchpoint_type
= hw_access
;
2907 bl
->watchpoint_type
= hw_access
;
2908 val
= bl
->owner
->ops
->insert_location (bl
);
2911 /* Back to the original value. */
2912 bl
->watchpoint_type
= hw_read
;
2916 bl
->inserted
= (val
== 0);
2919 else if (bl
->owner
->type
== bp_catchpoint
)
2923 gdb_assert (bl
->owner
->ops
!= NULL
2924 && bl
->owner
->ops
->insert_location
!= NULL
);
2926 val
= bl
->owner
->ops
->insert_location (bl
);
2929 bl
->owner
->enable_state
= bp_disabled
;
2933 Error inserting catchpoint %d: Your system does not support this type\n\
2934 of catchpoint."), bl
->owner
->number
);
2936 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2939 bl
->inserted
= (val
== 0);
2941 /* We've already printed an error message if there was a problem
2942 inserting this catchpoint, and we've disabled the catchpoint,
2943 so just return success. */
2950 /* This function is called when program space PSPACE is about to be
2951 deleted. It takes care of updating breakpoints to not reference
2955 breakpoint_program_space_exit (struct program_space
*pspace
)
2957 struct breakpoint
*b
, *b_temp
;
2958 struct bp_location
*loc
, **loc_temp
;
2960 /* Remove any breakpoint that was set through this program space. */
2961 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2963 if (b
->pspace
== pspace
)
2964 delete_breakpoint (b
);
2967 /* Breakpoints set through other program spaces could have locations
2968 bound to PSPACE as well. Remove those. */
2969 ALL_BP_LOCATIONS (loc
, loc_temp
)
2971 struct bp_location
*tmp
;
2973 if (loc
->pspace
== pspace
)
2975 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2976 if (loc
->owner
->loc
== loc
)
2977 loc
->owner
->loc
= loc
->next
;
2979 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2980 if (tmp
->next
== loc
)
2982 tmp
->next
= loc
->next
;
2988 /* Now update the global location list to permanently delete the
2989 removed locations above. */
2990 update_global_location_list (UGLL_DONT_INSERT
);
2993 /* Make sure all breakpoints are inserted in inferior.
2994 Throws exception on any error.
2995 A breakpoint that is already inserted won't be inserted
2996 again, so calling this function twice is safe. */
2998 insert_breakpoints (void)
3000 struct breakpoint
*bpt
;
3002 ALL_BREAKPOINTS (bpt
)
3003 if (is_hardware_watchpoint (bpt
))
3005 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3007 update_watchpoint (w
, 0 /* don't reparse. */);
3010 /* Updating watchpoints creates new locations, so update the global
3011 location list. Explicitly tell ugll to insert locations and
3012 ignore breakpoints_always_inserted_mode. */
3013 update_global_location_list (UGLL_INSERT
);
3016 /* Invoke CALLBACK for each of bp_location. */
3019 iterate_over_bp_locations (walk_bp_location_callback callback
)
3021 struct bp_location
*loc
, **loc_tmp
;
3023 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3025 callback (loc
, NULL
);
3029 /* This is used when we need to synch breakpoint conditions between GDB and the
3030 target. It is the case with deleting and disabling of breakpoints when using
3031 always-inserted mode. */
3034 update_inserted_breakpoint_locations (void)
3036 struct bp_location
*bl
, **blp_tmp
;
3039 int disabled_breaks
= 0;
3040 int hw_breakpoint_error
= 0;
3041 int hw_bp_details_reported
= 0;
3043 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3044 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3046 /* Explicitly mark the warning -- this will only be printed if
3047 there was an error. */
3048 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3050 save_current_space_and_thread ();
3052 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3054 /* We only want to update software breakpoints and hardware
3056 if (!is_breakpoint (bl
->owner
))
3059 /* We only want to update locations that are already inserted
3060 and need updating. This is to avoid unwanted insertion during
3061 deletion of breakpoints. */
3062 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3065 switch_to_program_space_and_thread (bl
->pspace
);
3067 /* For targets that support global breakpoints, there's no need
3068 to select an inferior to insert breakpoint to. In fact, even
3069 if we aren't attached to any process yet, we should still
3070 insert breakpoints. */
3071 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3072 && ptid_equal (inferior_ptid
, null_ptid
))
3075 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3076 &hw_breakpoint_error
, &hw_bp_details_reported
);
3083 target_terminal_ours_for_output ();
3084 error_stream (tmp_error_stream
);
3087 do_cleanups (cleanups
);
3090 /* Used when starting or continuing the program. */
3093 insert_breakpoint_locations (void)
3095 struct breakpoint
*bpt
;
3096 struct bp_location
*bl
, **blp_tmp
;
3099 int disabled_breaks
= 0;
3100 int hw_breakpoint_error
= 0;
3101 int hw_bp_error_explained_already
= 0;
3103 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3104 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3106 /* Explicitly mark the warning -- this will only be printed if
3107 there was an error. */
3108 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3110 save_current_space_and_thread ();
3112 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3114 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3117 /* There is no point inserting thread-specific breakpoints if
3118 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3119 has BL->OWNER always non-NULL. */
3120 if (bl
->owner
->thread
!= -1
3121 && !valid_thread_id (bl
->owner
->thread
))
3124 switch_to_program_space_and_thread (bl
->pspace
);
3126 /* For targets that support global breakpoints, there's no need
3127 to select an inferior to insert breakpoint to. In fact, even
3128 if we aren't attached to any process yet, we should still
3129 insert breakpoints. */
3130 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3131 && ptid_equal (inferior_ptid
, null_ptid
))
3134 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3135 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3140 /* If we failed to insert all locations of a watchpoint, remove
3141 them, as half-inserted watchpoint is of limited use. */
3142 ALL_BREAKPOINTS (bpt
)
3144 int some_failed
= 0;
3145 struct bp_location
*loc
;
3147 if (!is_hardware_watchpoint (bpt
))
3150 if (!breakpoint_enabled (bpt
))
3153 if (bpt
->disposition
== disp_del_at_next_stop
)
3156 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3157 if (!loc
->inserted
&& should_be_inserted (loc
))
3164 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3166 remove_breakpoint (loc
, mark_uninserted
);
3168 hw_breakpoint_error
= 1;
3169 fprintf_unfiltered (tmp_error_stream
,
3170 "Could not insert hardware watchpoint %d.\n",
3178 /* If a hardware breakpoint or watchpoint was inserted, add a
3179 message about possibly exhausted resources. */
3180 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3182 fprintf_unfiltered (tmp_error_stream
,
3183 "Could not insert hardware breakpoints:\n\
3184 You may have requested too many hardware breakpoints/watchpoints.\n");
3186 target_terminal_ours_for_output ();
3187 error_stream (tmp_error_stream
);
3190 do_cleanups (cleanups
);
3193 /* Used when the program stops.
3194 Returns zero if successful, or non-zero if there was a problem
3195 removing a breakpoint location. */
3198 remove_breakpoints (void)
3200 struct bp_location
*bl
, **blp_tmp
;
3203 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3205 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3206 val
|= remove_breakpoint (bl
, mark_uninserted
);
3211 /* When a thread exits, remove breakpoints that are related to
3215 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3217 struct breakpoint
*b
, *b_tmp
;
3219 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3221 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3223 b
->disposition
= disp_del_at_next_stop
;
3225 printf_filtered (_("\
3226 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3227 b
->number
, tp
->num
);
3229 /* Hide it from the user. */
3235 /* Remove breakpoints of process PID. */
3238 remove_breakpoints_pid (int pid
)
3240 struct bp_location
*bl
, **blp_tmp
;
3242 struct inferior
*inf
= find_inferior_pid (pid
);
3244 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3246 if (bl
->pspace
!= inf
->pspace
)
3249 if (bl
->owner
->type
== bp_dprintf
)
3254 val
= remove_breakpoint (bl
, mark_uninserted
);
3263 reattach_breakpoints (int pid
)
3265 struct cleanup
*old_chain
;
3266 struct bp_location
*bl
, **blp_tmp
;
3268 struct ui_file
*tmp_error_stream
;
3269 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3270 struct inferior
*inf
;
3271 struct thread_info
*tp
;
3273 tp
= any_live_thread_of_process (pid
);
3277 inf
= find_inferior_pid (pid
);
3278 old_chain
= save_inferior_ptid ();
3280 inferior_ptid
= tp
->ptid
;
3282 tmp_error_stream
= mem_fileopen ();
3283 make_cleanup_ui_file_delete (tmp_error_stream
);
3285 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3287 if (bl
->pspace
!= inf
->pspace
)
3293 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3296 do_cleanups (old_chain
);
3301 do_cleanups (old_chain
);
3305 static int internal_breakpoint_number
= -1;
3307 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3308 If INTERNAL is non-zero, the breakpoint number will be populated
3309 from internal_breakpoint_number and that variable decremented.
3310 Otherwise the breakpoint number will be populated from
3311 breakpoint_count and that value incremented. Internal breakpoints
3312 do not set the internal var bpnum. */
3314 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3317 b
->number
= internal_breakpoint_number
--;
3320 set_breakpoint_count (breakpoint_count
+ 1);
3321 b
->number
= breakpoint_count
;
3325 static struct breakpoint
*
3326 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3327 CORE_ADDR address
, enum bptype type
,
3328 const struct breakpoint_ops
*ops
)
3330 struct symtab_and_line sal
;
3331 struct breakpoint
*b
;
3333 init_sal (&sal
); /* Initialize to zeroes. */
3336 sal
.section
= find_pc_overlay (sal
.pc
);
3337 sal
.pspace
= current_program_space
;
3339 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3340 b
->number
= internal_breakpoint_number
--;
3341 b
->disposition
= disp_donttouch
;
3346 static const char *const longjmp_names
[] =
3348 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3350 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3352 /* Per-objfile data private to breakpoint.c. */
3353 struct breakpoint_objfile_data
3355 /* Minimal symbol for "_ovly_debug_event" (if any). */
3356 struct bound_minimal_symbol overlay_msym
;
3358 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3359 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3361 /* True if we have looked for longjmp probes. */
3362 int longjmp_searched
;
3364 /* SystemTap probe points for longjmp (if any). */
3365 VEC (probe_p
) *longjmp_probes
;
3367 /* Minimal symbol for "std::terminate()" (if any). */
3368 struct bound_minimal_symbol terminate_msym
;
3370 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3371 struct bound_minimal_symbol exception_msym
;
3373 /* True if we have looked for exception probes. */
3374 int exception_searched
;
3376 /* SystemTap probe points for unwinding (if any). */
3377 VEC (probe_p
) *exception_probes
;
3380 static const struct objfile_data
*breakpoint_objfile_key
;
3382 /* Minimal symbol not found sentinel. */
3383 static struct minimal_symbol msym_not_found
;
3385 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3388 msym_not_found_p (const struct minimal_symbol
*msym
)
3390 return msym
== &msym_not_found
;
3393 /* Return per-objfile data needed by breakpoint.c.
3394 Allocate the data if necessary. */
3396 static struct breakpoint_objfile_data
*
3397 get_breakpoint_objfile_data (struct objfile
*objfile
)
3399 struct breakpoint_objfile_data
*bp_objfile_data
;
3401 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3402 if (bp_objfile_data
== NULL
)
3404 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3405 sizeof (*bp_objfile_data
));
3407 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3408 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3410 return bp_objfile_data
;
3414 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3416 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3418 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3419 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3423 create_overlay_event_breakpoint (void)
3425 struct objfile
*objfile
;
3426 const char *const func_name
= "_ovly_debug_event";
3428 ALL_OBJFILES (objfile
)
3430 struct breakpoint
*b
;
3431 struct breakpoint_objfile_data
*bp_objfile_data
;
3434 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3436 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3439 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3441 struct bound_minimal_symbol m
;
3443 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3444 if (m
.minsym
== NULL
)
3446 /* Avoid future lookups in this objfile. */
3447 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3450 bp_objfile_data
->overlay_msym
= m
;
3453 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3454 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3456 &internal_breakpoint_ops
);
3457 b
->addr_string
= xstrdup (func_name
);
3459 if (overlay_debugging
== ovly_auto
)
3461 b
->enable_state
= bp_enabled
;
3462 overlay_events_enabled
= 1;
3466 b
->enable_state
= bp_disabled
;
3467 overlay_events_enabled
= 0;
3470 update_global_location_list (UGLL_MAY_INSERT
);
3474 create_longjmp_master_breakpoint (void)
3476 struct program_space
*pspace
;
3477 struct cleanup
*old_chain
;
3479 old_chain
= save_current_program_space ();
3481 ALL_PSPACES (pspace
)
3483 struct objfile
*objfile
;
3485 set_current_program_space (pspace
);
3487 ALL_OBJFILES (objfile
)
3490 struct gdbarch
*gdbarch
;
3491 struct breakpoint_objfile_data
*bp_objfile_data
;
3493 gdbarch
= get_objfile_arch (objfile
);
3495 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3497 if (!bp_objfile_data
->longjmp_searched
)
3501 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3504 /* We are only interested in checking one element. */
3505 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3507 if (!can_evaluate_probe_arguments (p
))
3509 /* We cannot use the probe interface here, because it does
3510 not know how to evaluate arguments. */
3511 VEC_free (probe_p
, ret
);
3515 bp_objfile_data
->longjmp_probes
= ret
;
3516 bp_objfile_data
->longjmp_searched
= 1;
3519 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3522 struct probe
*probe
;
3523 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3526 VEC_iterate (probe_p
,
3527 bp_objfile_data
->longjmp_probes
,
3531 struct breakpoint
*b
;
3533 b
= create_internal_breakpoint (gdbarch
,
3534 get_probe_address (probe
,
3537 &internal_breakpoint_ops
);
3538 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3539 b
->enable_state
= bp_disabled
;
3545 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3548 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3550 struct breakpoint
*b
;
3551 const char *func_name
;
3554 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3557 func_name
= longjmp_names
[i
];
3558 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3560 struct bound_minimal_symbol m
;
3562 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3563 if (m
.minsym
== NULL
)
3565 /* Prevent future lookups in this objfile. */
3566 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3569 bp_objfile_data
->longjmp_msym
[i
] = m
;
3572 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3573 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3574 &internal_breakpoint_ops
);
3575 b
->addr_string
= xstrdup (func_name
);
3576 b
->enable_state
= bp_disabled
;
3580 update_global_location_list (UGLL_MAY_INSERT
);
3582 do_cleanups (old_chain
);
3585 /* Create a master std::terminate breakpoint. */
3587 create_std_terminate_master_breakpoint (void)
3589 struct program_space
*pspace
;
3590 struct cleanup
*old_chain
;
3591 const char *const func_name
= "std::terminate()";
3593 old_chain
= save_current_program_space ();
3595 ALL_PSPACES (pspace
)
3597 struct objfile
*objfile
;
3600 set_current_program_space (pspace
);
3602 ALL_OBJFILES (objfile
)
3604 struct breakpoint
*b
;
3605 struct breakpoint_objfile_data
*bp_objfile_data
;
3607 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3609 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3612 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3614 struct bound_minimal_symbol m
;
3616 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3617 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3618 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3620 /* Prevent future lookups in this objfile. */
3621 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3624 bp_objfile_data
->terminate_msym
= m
;
3627 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3628 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3629 bp_std_terminate_master
,
3630 &internal_breakpoint_ops
);
3631 b
->addr_string
= xstrdup (func_name
);
3632 b
->enable_state
= bp_disabled
;
3636 update_global_location_list (UGLL_MAY_INSERT
);
3638 do_cleanups (old_chain
);
3641 /* Install a master breakpoint on the unwinder's debug hook. */
3644 create_exception_master_breakpoint (void)
3646 struct objfile
*objfile
;
3647 const char *const func_name
= "_Unwind_DebugHook";
3649 ALL_OBJFILES (objfile
)
3651 struct breakpoint
*b
;
3652 struct gdbarch
*gdbarch
;
3653 struct breakpoint_objfile_data
*bp_objfile_data
;
3656 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3658 /* We prefer the SystemTap probe point if it exists. */
3659 if (!bp_objfile_data
->exception_searched
)
3663 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3667 /* We are only interested in checking one element. */
3668 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3670 if (!can_evaluate_probe_arguments (p
))
3672 /* We cannot use the probe interface here, because it does
3673 not know how to evaluate arguments. */
3674 VEC_free (probe_p
, ret
);
3678 bp_objfile_data
->exception_probes
= ret
;
3679 bp_objfile_data
->exception_searched
= 1;
3682 if (bp_objfile_data
->exception_probes
!= NULL
)
3684 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3686 struct probe
*probe
;
3689 VEC_iterate (probe_p
,
3690 bp_objfile_data
->exception_probes
,
3694 struct breakpoint
*b
;
3696 b
= create_internal_breakpoint (gdbarch
,
3697 get_probe_address (probe
,
3699 bp_exception_master
,
3700 &internal_breakpoint_ops
);
3701 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3702 b
->enable_state
= bp_disabled
;
3708 /* Otherwise, try the hook function. */
3710 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3713 gdbarch
= get_objfile_arch (objfile
);
3715 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3717 struct bound_minimal_symbol debug_hook
;
3719 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3720 if (debug_hook
.minsym
== NULL
)
3722 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3726 bp_objfile_data
->exception_msym
= debug_hook
;
3729 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3730 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3732 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3733 &internal_breakpoint_ops
);
3734 b
->addr_string
= xstrdup (func_name
);
3735 b
->enable_state
= bp_disabled
;
3738 update_global_location_list (UGLL_MAY_INSERT
);
3742 update_breakpoints_after_exec (void)
3744 struct breakpoint
*b
, *b_tmp
;
3745 struct bp_location
*bploc
, **bplocp_tmp
;
3747 /* We're about to delete breakpoints from GDB's lists. If the
3748 INSERTED flag is true, GDB will try to lift the breakpoints by
3749 writing the breakpoints' "shadow contents" back into memory. The
3750 "shadow contents" are NOT valid after an exec, so GDB should not
3751 do that. Instead, the target is responsible from marking
3752 breakpoints out as soon as it detects an exec. We don't do that
3753 here instead, because there may be other attempts to delete
3754 breakpoints after detecting an exec and before reaching here. */
3755 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3756 if (bploc
->pspace
== current_program_space
)
3757 gdb_assert (!bploc
->inserted
);
3759 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3761 if (b
->pspace
!= current_program_space
)
3764 /* Solib breakpoints must be explicitly reset after an exec(). */
3765 if (b
->type
== bp_shlib_event
)
3767 delete_breakpoint (b
);
3771 /* JIT breakpoints must be explicitly reset after an exec(). */
3772 if (b
->type
== bp_jit_event
)
3774 delete_breakpoint (b
);
3778 /* Thread event breakpoints must be set anew after an exec(),
3779 as must overlay event and longjmp master breakpoints. */
3780 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3781 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3782 || b
->type
== bp_exception_master
)
3784 delete_breakpoint (b
);
3788 /* Step-resume breakpoints are meaningless after an exec(). */
3789 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3791 delete_breakpoint (b
);
3795 /* Longjmp and longjmp-resume breakpoints are also meaningless
3797 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3798 || b
->type
== bp_longjmp_call_dummy
3799 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3801 delete_breakpoint (b
);
3805 if (b
->type
== bp_catchpoint
)
3807 /* For now, none of the bp_catchpoint breakpoints need to
3808 do anything at this point. In the future, if some of
3809 the catchpoints need to something, we will need to add
3810 a new method, and call this method from here. */
3814 /* bp_finish is a special case. The only way we ought to be able
3815 to see one of these when an exec() has happened, is if the user
3816 caught a vfork, and then said "finish". Ordinarily a finish just
3817 carries them to the call-site of the current callee, by setting
3818 a temporary bp there and resuming. But in this case, the finish
3819 will carry them entirely through the vfork & exec.
3821 We don't want to allow a bp_finish to remain inserted now. But
3822 we can't safely delete it, 'cause finish_command has a handle to
3823 the bp on a bpstat, and will later want to delete it. There's a
3824 chance (and I've seen it happen) that if we delete the bp_finish
3825 here, that its storage will get reused by the time finish_command
3826 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3827 We really must allow finish_command to delete a bp_finish.
3829 In the absence of a general solution for the "how do we know
3830 it's safe to delete something others may have handles to?"
3831 problem, what we'll do here is just uninsert the bp_finish, and
3832 let finish_command delete it.
3834 (We know the bp_finish is "doomed" in the sense that it's
3835 momentary, and will be deleted as soon as finish_command sees
3836 the inferior stopped. So it doesn't matter that the bp's
3837 address is probably bogus in the new a.out, unlike e.g., the
3838 solib breakpoints.) */
3840 if (b
->type
== bp_finish
)
3845 /* Without a symbolic address, we have little hope of the
3846 pre-exec() address meaning the same thing in the post-exec()
3848 if (b
->addr_string
== NULL
)
3850 delete_breakpoint (b
);
3857 detach_breakpoints (ptid_t ptid
)
3859 struct bp_location
*bl
, **blp_tmp
;
3861 struct cleanup
*old_chain
= save_inferior_ptid ();
3862 struct inferior
*inf
= current_inferior ();
3864 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3865 error (_("Cannot detach breakpoints of inferior_ptid"));
3867 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3868 inferior_ptid
= ptid
;
3869 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3871 if (bl
->pspace
!= inf
->pspace
)
3874 /* This function must physically remove breakpoints locations
3875 from the specified ptid, without modifying the breakpoint
3876 package's state. Locations of type bp_loc_other are only
3877 maintained at GDB side. So, there is no need to remove
3878 these bp_loc_other locations. Moreover, removing these
3879 would modify the breakpoint package's state. */
3880 if (bl
->loc_type
== bp_loc_other
)
3884 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3887 /* Detach single-step breakpoints as well. */
3888 detach_single_step_breakpoints ();
3890 do_cleanups (old_chain
);
3894 /* Remove the breakpoint location BL from the current address space.
3895 Note that this is used to detach breakpoints from a child fork.
3896 When we get here, the child isn't in the inferior list, and neither
3897 do we have objects to represent its address space --- we should
3898 *not* look at bl->pspace->aspace here. */
3901 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3905 /* BL is never in moribund_locations by our callers. */
3906 gdb_assert (bl
->owner
!= NULL
);
3908 if (bl
->owner
->enable_state
== bp_permanent
)
3909 /* Permanent breakpoints cannot be inserted or removed. */
3912 /* The type of none suggests that owner is actually deleted.
3913 This should not ever happen. */
3914 gdb_assert (bl
->owner
->type
!= bp_none
);
3916 if (bl
->loc_type
== bp_loc_software_breakpoint
3917 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3919 /* "Normal" instruction breakpoint: either the standard
3920 trap-instruction bp (bp_breakpoint), or a
3921 bp_hardware_breakpoint. */
3923 /* First check to see if we have to handle an overlay. */
3924 if (overlay_debugging
== ovly_off
3925 || bl
->section
== NULL
3926 || !(section_is_overlay (bl
->section
)))
3928 /* No overlay handling: just remove the breakpoint. */
3930 /* If we're trying to uninsert a memory breakpoint that we
3931 know is set in a dynamic object that is marked
3932 shlib_disabled, then either the dynamic object was
3933 removed with "remove-symbol-file" or with
3934 "nosharedlibrary". In the former case, we don't know
3935 whether another dynamic object might have loaded over the
3936 breakpoint's address -- the user might well let us know
3937 about it next with add-symbol-file (the whole point of
3938 add-symbol-file is letting the user manually maintain a
3939 list of dynamically loaded objects). If we have the
3940 breakpoint's shadow memory, that is, this is a software
3941 breakpoint managed by GDB, check whether the breakpoint
3942 is still inserted in memory, to avoid overwriting wrong
3943 code with stale saved shadow contents. Note that HW
3944 breakpoints don't have shadow memory, as they're
3945 implemented using a mechanism that is not dependent on
3946 being able to modify the target's memory, and as such
3947 they should always be removed. */
3948 if (bl
->shlib_disabled
3949 && bl
->target_info
.shadow_len
!= 0
3950 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3953 val
= bl
->owner
->ops
->remove_location (bl
);
3957 /* This breakpoint is in an overlay section.
3958 Did we set a breakpoint at the LMA? */
3959 if (!overlay_events_enabled
)
3961 /* Yes -- overlay event support is not active, so we
3962 should have set a breakpoint at the LMA. Remove it.
3964 /* Ignore any failures: if the LMA is in ROM, we will
3965 have already warned when we failed to insert it. */
3966 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3967 target_remove_hw_breakpoint (bl
->gdbarch
,
3968 &bl
->overlay_target_info
);
3970 target_remove_breakpoint (bl
->gdbarch
,
3971 &bl
->overlay_target_info
);
3973 /* Did we set a breakpoint at the VMA?
3974 If so, we will have marked the breakpoint 'inserted'. */
3977 /* Yes -- remove it. Previously we did not bother to
3978 remove the breakpoint if the section had been
3979 unmapped, but let's not rely on that being safe. We
3980 don't know what the overlay manager might do. */
3982 /* However, we should remove *software* breakpoints only
3983 if the section is still mapped, or else we overwrite
3984 wrong code with the saved shadow contents. */
3985 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3986 || section_is_mapped (bl
->section
))
3987 val
= bl
->owner
->ops
->remove_location (bl
);
3993 /* No -- not inserted, so no need to remove. No error. */
3998 /* In some cases, we might not be able to remove a breakpoint in
3999 a shared library that has already been removed, but we have
4000 not yet processed the shlib unload event. Similarly for an
4001 unloaded add-symbol-file object - the user might not yet have
4002 had the chance to remove-symbol-file it. shlib_disabled will
4003 be set if the library/object has already been removed, but
4004 the breakpoint hasn't been uninserted yet, e.g., after
4005 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4006 always-inserted mode. */
4008 && (bl
->loc_type
== bp_loc_software_breakpoint
4009 && (bl
->shlib_disabled
4010 || solib_name_from_address (bl
->pspace
, bl
->address
)
4011 || shared_objfile_contains_address_p (bl
->pspace
,
4017 bl
->inserted
= (is
== mark_inserted
);
4019 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4021 gdb_assert (bl
->owner
->ops
!= NULL
4022 && bl
->owner
->ops
->remove_location
!= NULL
);
4024 bl
->inserted
= (is
== mark_inserted
);
4025 bl
->owner
->ops
->remove_location (bl
);
4027 /* Failure to remove any of the hardware watchpoints comes here. */
4028 if ((is
== mark_uninserted
) && (bl
->inserted
))
4029 warning (_("Could not remove hardware watchpoint %d."),
4032 else if (bl
->owner
->type
== bp_catchpoint
4033 && breakpoint_enabled (bl
->owner
)
4036 gdb_assert (bl
->owner
->ops
!= NULL
4037 && bl
->owner
->ops
->remove_location
!= NULL
);
4039 val
= bl
->owner
->ops
->remove_location (bl
);
4043 bl
->inserted
= (is
== mark_inserted
);
4050 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4053 struct cleanup
*old_chain
;
4055 /* BL is never in moribund_locations by our callers. */
4056 gdb_assert (bl
->owner
!= NULL
);
4058 if (bl
->owner
->enable_state
== bp_permanent
)
4059 /* Permanent breakpoints cannot be inserted or removed. */
4062 /* The type of none suggests that owner is actually deleted.
4063 This should not ever happen. */
4064 gdb_assert (bl
->owner
->type
!= bp_none
);
4066 old_chain
= save_current_space_and_thread ();
4068 switch_to_program_space_and_thread (bl
->pspace
);
4070 ret
= remove_breakpoint_1 (bl
, is
);
4072 do_cleanups (old_chain
);
4076 /* Clear the "inserted" flag in all breakpoints. */
4079 mark_breakpoints_out (void)
4081 struct bp_location
*bl
, **blp_tmp
;
4083 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4084 if (bl
->pspace
== current_program_space
)
4088 /* Clear the "inserted" flag in all breakpoints and delete any
4089 breakpoints which should go away between runs of the program.
4091 Plus other such housekeeping that has to be done for breakpoints
4094 Note: this function gets called at the end of a run (by
4095 generic_mourn_inferior) and when a run begins (by
4096 init_wait_for_inferior). */
4101 breakpoint_init_inferior (enum inf_context context
)
4103 struct breakpoint
*b
, *b_tmp
;
4104 struct bp_location
*bl
, **blp_tmp
;
4106 struct program_space
*pspace
= current_program_space
;
4108 /* If breakpoint locations are shared across processes, then there's
4110 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4113 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4115 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4116 if (bl
->pspace
== pspace
4117 && bl
->owner
->enable_state
!= bp_permanent
)
4121 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4123 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4129 case bp_longjmp_call_dummy
:
4131 /* If the call dummy breakpoint is at the entry point it will
4132 cause problems when the inferior is rerun, so we better get
4135 case bp_watchpoint_scope
:
4137 /* Also get rid of scope breakpoints. */
4139 case bp_shlib_event
:
4141 /* Also remove solib event breakpoints. Their addresses may
4142 have changed since the last time we ran the program.
4143 Actually we may now be debugging against different target;
4144 and so the solib backend that installed this breakpoint may
4145 not be used in by the target. E.g.,
4147 (gdb) file prog-linux
4148 (gdb) run # native linux target
4151 (gdb) file prog-win.exe
4152 (gdb) tar rem :9999 # remote Windows gdbserver.
4155 case bp_step_resume
:
4157 /* Also remove step-resume breakpoints. */
4159 delete_breakpoint (b
);
4163 case bp_hardware_watchpoint
:
4164 case bp_read_watchpoint
:
4165 case bp_access_watchpoint
:
4167 struct watchpoint
*w
= (struct watchpoint
*) b
;
4169 /* Likewise for watchpoints on local expressions. */
4170 if (w
->exp_valid_block
!= NULL
)
4171 delete_breakpoint (b
);
4172 else if (context
== inf_starting
)
4174 /* Reset val field to force reread of starting value in
4175 insert_breakpoints. */
4177 value_free (w
->val
);
4188 /* Get rid of the moribund locations. */
4189 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4190 decref_bp_location (&bl
);
4191 VEC_free (bp_location_p
, moribund_locations
);
4194 /* These functions concern about actual breakpoints inserted in the
4195 target --- to e.g. check if we need to do decr_pc adjustment or if
4196 we need to hop over the bkpt --- so we check for address space
4197 match, not program space. */
4199 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4200 exists at PC. It returns ordinary_breakpoint_here if it's an
4201 ordinary breakpoint, or permanent_breakpoint_here if it's a
4202 permanent breakpoint.
4203 - When continuing from a location with an ordinary breakpoint, we
4204 actually single step once before calling insert_breakpoints.
4205 - When continuing from a location with a permanent breakpoint, we
4206 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4207 the target, to advance the PC past the breakpoint. */
4209 enum breakpoint_here
4210 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4212 struct bp_location
*bl
, **blp_tmp
;
4213 int any_breakpoint_here
= 0;
4215 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4217 if (bl
->loc_type
!= bp_loc_software_breakpoint
4218 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4221 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4222 if ((breakpoint_enabled (bl
->owner
)
4223 || bl
->owner
->enable_state
== bp_permanent
)
4224 && breakpoint_location_address_match (bl
, aspace
, pc
))
4226 if (overlay_debugging
4227 && section_is_overlay (bl
->section
)
4228 && !section_is_mapped (bl
->section
))
4229 continue; /* unmapped overlay -- can't be a match */
4230 else if (bl
->owner
->enable_state
== bp_permanent
)
4231 return permanent_breakpoint_here
;
4233 any_breakpoint_here
= 1;
4237 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4240 /* Return true if there's a moribund breakpoint at PC. */
4243 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4245 struct bp_location
*loc
;
4248 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4249 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4255 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4256 inserted using regular breakpoint_chain / bp_location array
4257 mechanism. This does not check for single-step breakpoints, which
4258 are inserted and removed using direct target manipulation. */
4261 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
4264 struct bp_location
*bl
, **blp_tmp
;
4266 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4268 if (bl
->loc_type
!= bp_loc_software_breakpoint
4269 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4273 && breakpoint_location_address_match (bl
, aspace
, pc
))
4275 if (overlay_debugging
4276 && section_is_overlay (bl
->section
)
4277 && !section_is_mapped (bl
->section
))
4278 continue; /* unmapped overlay -- can't be a match */
4286 /* Returns non-zero iff there's either regular breakpoint
4287 or a single step breakpoint inserted at PC. */
4290 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4292 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
4295 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4301 /* Ignoring deprecated raw breakpoints, return non-zero iff there is a
4302 software breakpoint inserted at PC. */
4304 static struct bp_location
*
4305 find_non_raw_software_breakpoint_inserted_here (struct address_space
*aspace
,
4308 struct bp_location
*bl
, **blp_tmp
;
4310 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4312 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4316 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4319 if (overlay_debugging
4320 && section_is_overlay (bl
->section
)
4321 && !section_is_mapped (bl
->section
))
4322 continue; /* unmapped overlay -- can't be a match */
4331 /* This function returns non-zero iff there is a software breakpoint
4335 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4338 if (find_non_raw_software_breakpoint_inserted_here (aspace
, pc
) != NULL
)
4341 /* Also check for software single-step breakpoints. */
4342 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4349 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4350 CORE_ADDR addr
, ULONGEST len
)
4352 struct breakpoint
*bpt
;
4354 ALL_BREAKPOINTS (bpt
)
4356 struct bp_location
*loc
;
4358 if (bpt
->type
!= bp_hardware_watchpoint
4359 && bpt
->type
!= bp_access_watchpoint
)
4362 if (!breakpoint_enabled (bpt
))
4365 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4366 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4370 /* Check for intersection. */
4371 l
= max (loc
->address
, addr
);
4372 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4380 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4381 PC is valid for process/thread PTID. */
4384 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4387 struct bp_location
*bl
, **blp_tmp
;
4388 /* The thread and task IDs associated to PTID, computed lazily. */
4392 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4394 if (bl
->loc_type
!= bp_loc_software_breakpoint
4395 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4398 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4399 if (!breakpoint_enabled (bl
->owner
)
4400 && bl
->owner
->enable_state
!= bp_permanent
)
4403 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4406 if (bl
->owner
->thread
!= -1)
4408 /* This is a thread-specific breakpoint. Check that ptid
4409 matches that thread. If thread hasn't been computed yet,
4410 it is now time to do so. */
4412 thread
= pid_to_thread_id (ptid
);
4413 if (bl
->owner
->thread
!= thread
)
4417 if (bl
->owner
->task
!= 0)
4419 /* This is a task-specific breakpoint. Check that ptid
4420 matches that task. If task hasn't been computed yet,
4421 it is now time to do so. */
4423 task
= ada_get_task_number (ptid
);
4424 if (bl
->owner
->task
!= task
)
4428 if (overlay_debugging
4429 && section_is_overlay (bl
->section
)
4430 && !section_is_mapped (bl
->section
))
4431 continue; /* unmapped overlay -- can't be a match */
4440 /* bpstat stuff. External routines' interfaces are documented
4444 is_catchpoint (struct breakpoint
*ep
)
4446 return (ep
->type
== bp_catchpoint
);
4449 /* Frees any storage that is part of a bpstat. Does not walk the
4453 bpstat_free (bpstat bs
)
4455 if (bs
->old_val
!= NULL
)
4456 value_free (bs
->old_val
);
4457 decref_counted_command_line (&bs
->commands
);
4458 decref_bp_location (&bs
->bp_location_at
);
4462 /* Clear a bpstat so that it says we are not at any breakpoint.
4463 Also free any storage that is part of a bpstat. */
4466 bpstat_clear (bpstat
*bsp
)
4483 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4484 is part of the bpstat is copied as well. */
4487 bpstat_copy (bpstat bs
)
4491 bpstat retval
= NULL
;
4496 for (; bs
!= NULL
; bs
= bs
->next
)
4498 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4499 memcpy (tmp
, bs
, sizeof (*tmp
));
4500 incref_counted_command_line (tmp
->commands
);
4501 incref_bp_location (tmp
->bp_location_at
);
4502 if (bs
->old_val
!= NULL
)
4504 tmp
->old_val
= value_copy (bs
->old_val
);
4505 release_value (tmp
->old_val
);
4509 /* This is the first thing in the chain. */
4519 /* Find the bpstat associated with this breakpoint. */
4522 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4527 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4529 if (bsp
->breakpoint_at
== breakpoint
)
4535 /* See breakpoint.h. */
4538 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4540 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4542 if (bsp
->breakpoint_at
== NULL
)
4544 /* A moribund location can never explain a signal other than
4546 if (sig
== GDB_SIGNAL_TRAP
)
4551 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4560 /* Put in *NUM the breakpoint number of the first breakpoint we are
4561 stopped at. *BSP upon return is a bpstat which points to the
4562 remaining breakpoints stopped at (but which is not guaranteed to be
4563 good for anything but further calls to bpstat_num).
4565 Return 0 if passed a bpstat which does not indicate any breakpoints.
4566 Return -1 if stopped at a breakpoint that has been deleted since
4568 Return 1 otherwise. */
4571 bpstat_num (bpstat
*bsp
, int *num
)
4573 struct breakpoint
*b
;
4576 return 0; /* No more breakpoint values */
4578 /* We assume we'll never have several bpstats that correspond to a
4579 single breakpoint -- otherwise, this function might return the
4580 same number more than once and this will look ugly. */
4581 b
= (*bsp
)->breakpoint_at
;
4582 *bsp
= (*bsp
)->next
;
4584 return -1; /* breakpoint that's been deleted since */
4586 *num
= b
->number
; /* We have its number */
4590 /* See breakpoint.h. */
4593 bpstat_clear_actions (void)
4595 struct thread_info
*tp
;
4598 if (ptid_equal (inferior_ptid
, null_ptid
))
4601 tp
= find_thread_ptid (inferior_ptid
);
4605 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4607 decref_counted_command_line (&bs
->commands
);
4609 if (bs
->old_val
!= NULL
)
4611 value_free (bs
->old_val
);
4617 /* Called when a command is about to proceed the inferior. */
4620 breakpoint_about_to_proceed (void)
4622 if (!ptid_equal (inferior_ptid
, null_ptid
))
4624 struct thread_info
*tp
= inferior_thread ();
4626 /* Allow inferior function calls in breakpoint commands to not
4627 interrupt the command list. When the call finishes
4628 successfully, the inferior will be standing at the same
4629 breakpoint as if nothing happened. */
4630 if (tp
->control
.in_infcall
)
4634 breakpoint_proceeded
= 1;
4637 /* Stub for cleaning up our state if we error-out of a breakpoint
4640 cleanup_executing_breakpoints (void *ignore
)
4642 executing_breakpoint_commands
= 0;
4645 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4646 or its equivalent. */
4649 command_line_is_silent (struct command_line
*cmd
)
4651 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4652 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4655 /* Execute all the commands associated with all the breakpoints at
4656 this location. Any of these commands could cause the process to
4657 proceed beyond this point, etc. We look out for such changes by
4658 checking the global "breakpoint_proceeded" after each command.
4660 Returns true if a breakpoint command resumed the inferior. In that
4661 case, it is the caller's responsibility to recall it again with the
4662 bpstat of the current thread. */
4665 bpstat_do_actions_1 (bpstat
*bsp
)
4668 struct cleanup
*old_chain
;
4671 /* Avoid endless recursion if a `source' command is contained
4673 if (executing_breakpoint_commands
)
4676 executing_breakpoint_commands
= 1;
4677 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4679 prevent_dont_repeat ();
4681 /* This pointer will iterate over the list of bpstat's. */
4684 breakpoint_proceeded
= 0;
4685 for (; bs
!= NULL
; bs
= bs
->next
)
4687 struct counted_command_line
*ccmd
;
4688 struct command_line
*cmd
;
4689 struct cleanup
*this_cmd_tree_chain
;
4691 /* Take ownership of the BSP's command tree, if it has one.
4693 The command tree could legitimately contain commands like
4694 'step' and 'next', which call clear_proceed_status, which
4695 frees stop_bpstat's command tree. To make sure this doesn't
4696 free the tree we're executing out from under us, we need to
4697 take ownership of the tree ourselves. Since a given bpstat's
4698 commands are only executed once, we don't need to copy it; we
4699 can clear the pointer in the bpstat, and make sure we free
4700 the tree when we're done. */
4701 ccmd
= bs
->commands
;
4702 bs
->commands
= NULL
;
4703 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4704 cmd
= ccmd
? ccmd
->commands
: NULL
;
4705 if (command_line_is_silent (cmd
))
4707 /* The action has been already done by bpstat_stop_status. */
4713 execute_control_command (cmd
);
4715 if (breakpoint_proceeded
)
4721 /* We can free this command tree now. */
4722 do_cleanups (this_cmd_tree_chain
);
4724 if (breakpoint_proceeded
)
4726 if (target_can_async_p ())
4727 /* If we are in async mode, then the target might be still
4728 running, not stopped at any breakpoint, so nothing for
4729 us to do here -- just return to the event loop. */
4732 /* In sync mode, when execute_control_command returns
4733 we're already standing on the next breakpoint.
4734 Breakpoint commands for that stop were not run, since
4735 execute_command does not run breakpoint commands --
4736 only command_line_handler does, but that one is not
4737 involved in execution of breakpoint commands. So, we
4738 can now execute breakpoint commands. It should be
4739 noted that making execute_command do bpstat actions is
4740 not an option -- in this case we'll have recursive
4741 invocation of bpstat for each breakpoint with a
4742 command, and can easily blow up GDB stack. Instead, we
4743 return true, which will trigger the caller to recall us
4744 with the new stop_bpstat. */
4749 do_cleanups (old_chain
);
4754 bpstat_do_actions (void)
4756 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4758 /* Do any commands attached to breakpoint we are stopped at. */
4759 while (!ptid_equal (inferior_ptid
, null_ptid
)
4760 && target_has_execution
4761 && !is_exited (inferior_ptid
)
4762 && !is_executing (inferior_ptid
))
4763 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4764 and only return when it is stopped at the next breakpoint, we
4765 keep doing breakpoint actions until it returns false to
4766 indicate the inferior was not resumed. */
4767 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4770 discard_cleanups (cleanup_if_error
);
4773 /* Print out the (old or new) value associated with a watchpoint. */
4776 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4779 fprintf_unfiltered (stream
, _("<unreadable>"));
4782 struct value_print_options opts
;
4783 get_user_print_options (&opts
);
4784 value_print (val
, stream
, &opts
);
4788 /* Generic routine for printing messages indicating why we
4789 stopped. The behavior of this function depends on the value
4790 'print_it' in the bpstat structure. Under some circumstances we
4791 may decide not to print anything here and delegate the task to
4794 static enum print_stop_action
4795 print_bp_stop_message (bpstat bs
)
4797 switch (bs
->print_it
)
4800 /* Nothing should be printed for this bpstat entry. */
4801 return PRINT_UNKNOWN
;
4805 /* We still want to print the frame, but we already printed the
4806 relevant messages. */
4807 return PRINT_SRC_AND_LOC
;
4810 case print_it_normal
:
4812 struct breakpoint
*b
= bs
->breakpoint_at
;
4814 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4815 which has since been deleted. */
4817 return PRINT_UNKNOWN
;
4819 /* Normal case. Call the breakpoint's print_it method. */
4820 return b
->ops
->print_it (bs
);
4825 internal_error (__FILE__
, __LINE__
,
4826 _("print_bp_stop_message: unrecognized enum value"));
4831 /* A helper function that prints a shared library stopped event. */
4834 print_solib_event (int is_catchpoint
)
4837 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4839 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4843 if (any_added
|| any_deleted
)
4844 ui_out_text (current_uiout
,
4845 _("Stopped due to shared library event:\n"));
4847 ui_out_text (current_uiout
,
4848 _("Stopped due to shared library event (no "
4849 "libraries added or removed)\n"));
4852 if (ui_out_is_mi_like_p (current_uiout
))
4853 ui_out_field_string (current_uiout
, "reason",
4854 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4858 struct cleanup
*cleanup
;
4862 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4863 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4866 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4871 ui_out_text (current_uiout
, " ");
4872 ui_out_field_string (current_uiout
, "library", name
);
4873 ui_out_text (current_uiout
, "\n");
4876 do_cleanups (cleanup
);
4881 struct so_list
*iter
;
4883 struct cleanup
*cleanup
;
4885 ui_out_text (current_uiout
, _(" Inferior loaded "));
4886 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4889 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4894 ui_out_text (current_uiout
, " ");
4895 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4896 ui_out_text (current_uiout
, "\n");
4899 do_cleanups (cleanup
);
4903 /* Print a message indicating what happened. This is called from
4904 normal_stop(). The input to this routine is the head of the bpstat
4905 list - a list of the eventpoints that caused this stop. KIND is
4906 the target_waitkind for the stopping event. This
4907 routine calls the generic print routine for printing a message
4908 about reasons for stopping. This will print (for example) the
4909 "Breakpoint n," part of the output. The return value of this
4912 PRINT_UNKNOWN: Means we printed nothing.
4913 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4914 code to print the location. An example is
4915 "Breakpoint 1, " which should be followed by
4917 PRINT_SRC_ONLY: Means we printed something, but there is no need
4918 to also print the location part of the message.
4919 An example is the catch/throw messages, which
4920 don't require a location appended to the end.
4921 PRINT_NOTHING: We have done some printing and we don't need any
4922 further info to be printed. */
4924 enum print_stop_action
4925 bpstat_print (bpstat bs
, int kind
)
4929 /* Maybe another breakpoint in the chain caused us to stop.
4930 (Currently all watchpoints go on the bpstat whether hit or not.
4931 That probably could (should) be changed, provided care is taken
4932 with respect to bpstat_explains_signal). */
4933 for (; bs
; bs
= bs
->next
)
4935 val
= print_bp_stop_message (bs
);
4936 if (val
== PRINT_SRC_ONLY
4937 || val
== PRINT_SRC_AND_LOC
4938 || val
== PRINT_NOTHING
)
4942 /* If we had hit a shared library event breakpoint,
4943 print_bp_stop_message would print out this message. If we hit an
4944 OS-level shared library event, do the same thing. */
4945 if (kind
== TARGET_WAITKIND_LOADED
)
4947 print_solib_event (0);
4948 return PRINT_NOTHING
;
4951 /* We reached the end of the chain, or we got a null BS to start
4952 with and nothing was printed. */
4953 return PRINT_UNKNOWN
;
4956 /* Evaluate the expression EXP and return 1 if value is zero.
4957 This returns the inverse of the condition because it is called
4958 from catch_errors which returns 0 if an exception happened, and if an
4959 exception happens we want execution to stop.
4960 The argument is a "struct expression *" that has been cast to a
4961 "void *" to make it pass through catch_errors. */
4964 breakpoint_cond_eval (void *exp
)
4966 struct value
*mark
= value_mark ();
4967 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4969 value_free_to_mark (mark
);
4973 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4976 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4980 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4982 **bs_link_pointer
= bs
;
4983 *bs_link_pointer
= &bs
->next
;
4984 bs
->breakpoint_at
= bl
->owner
;
4985 bs
->bp_location_at
= bl
;
4986 incref_bp_location (bl
);
4987 /* If the condition is false, etc., don't do the commands. */
4988 bs
->commands
= NULL
;
4990 bs
->print_it
= print_it_normal
;
4994 /* The target has stopped with waitstatus WS. Check if any hardware
4995 watchpoints have triggered, according to the target. */
4998 watchpoints_triggered (struct target_waitstatus
*ws
)
5000 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5002 struct breakpoint
*b
;
5004 if (!stopped_by_watchpoint
)
5006 /* We were not stopped by a watchpoint. Mark all watchpoints
5007 as not triggered. */
5009 if (is_hardware_watchpoint (b
))
5011 struct watchpoint
*w
= (struct watchpoint
*) b
;
5013 w
->watchpoint_triggered
= watch_triggered_no
;
5019 if (!target_stopped_data_address (¤t_target
, &addr
))
5021 /* We were stopped by a watchpoint, but we don't know where.
5022 Mark all watchpoints as unknown. */
5024 if (is_hardware_watchpoint (b
))
5026 struct watchpoint
*w
= (struct watchpoint
*) b
;
5028 w
->watchpoint_triggered
= watch_triggered_unknown
;
5034 /* The target could report the data address. Mark watchpoints
5035 affected by this data address as triggered, and all others as not
5039 if (is_hardware_watchpoint (b
))
5041 struct watchpoint
*w
= (struct watchpoint
*) b
;
5042 struct bp_location
*loc
;
5044 w
->watchpoint_triggered
= watch_triggered_no
;
5045 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5047 if (is_masked_watchpoint (b
))
5049 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5050 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5052 if (newaddr
== start
)
5054 w
->watchpoint_triggered
= watch_triggered_yes
;
5058 /* Exact match not required. Within range is sufficient. */
5059 else if (target_watchpoint_addr_within_range (¤t_target
,
5063 w
->watchpoint_triggered
= watch_triggered_yes
;
5072 /* Possible return values for watchpoint_check (this can't be an enum
5073 because of check_errors). */
5074 /* The watchpoint has been deleted. */
5075 #define WP_DELETED 1
5076 /* The value has changed. */
5077 #define WP_VALUE_CHANGED 2
5078 /* The value has not changed. */
5079 #define WP_VALUE_NOT_CHANGED 3
5080 /* Ignore this watchpoint, no matter if the value changed or not. */
5083 #define BP_TEMPFLAG 1
5084 #define BP_HARDWAREFLAG 2
5086 /* Evaluate watchpoint condition expression and check if its value
5089 P should be a pointer to struct bpstat, but is defined as a void *
5090 in order for this function to be usable with catch_errors. */
5093 watchpoint_check (void *p
)
5095 bpstat bs
= (bpstat
) p
;
5096 struct watchpoint
*b
;
5097 struct frame_info
*fr
;
5098 int within_current_scope
;
5100 /* BS is built from an existing struct breakpoint. */
5101 gdb_assert (bs
->breakpoint_at
!= NULL
);
5102 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5104 /* If this is a local watchpoint, we only want to check if the
5105 watchpoint frame is in scope if the current thread is the thread
5106 that was used to create the watchpoint. */
5107 if (!watchpoint_in_thread_scope (b
))
5110 if (b
->exp_valid_block
== NULL
)
5111 within_current_scope
= 1;
5114 struct frame_info
*frame
= get_current_frame ();
5115 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5116 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5118 /* in_function_epilogue_p() returns a non-zero value if we're
5119 still in the function but the stack frame has already been
5120 invalidated. Since we can't rely on the values of local
5121 variables after the stack has been destroyed, we are treating
5122 the watchpoint in that state as `not changed' without further
5123 checking. Don't mark watchpoints as changed if the current
5124 frame is in an epilogue - even if they are in some other
5125 frame, our view of the stack is likely to be wrong and
5126 frame_find_by_id could error out. */
5127 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
5130 fr
= frame_find_by_id (b
->watchpoint_frame
);
5131 within_current_scope
= (fr
!= NULL
);
5133 /* If we've gotten confused in the unwinder, we might have
5134 returned a frame that can't describe this variable. */
5135 if (within_current_scope
)
5137 struct symbol
*function
;
5139 function
= get_frame_function (fr
);
5140 if (function
== NULL
5141 || !contained_in (b
->exp_valid_block
,
5142 SYMBOL_BLOCK_VALUE (function
)))
5143 within_current_scope
= 0;
5146 if (within_current_scope
)
5147 /* If we end up stopping, the current frame will get selected
5148 in normal_stop. So this call to select_frame won't affect
5153 if (within_current_scope
)
5155 /* We use value_{,free_to_}mark because it could be a *long*
5156 time before we return to the command level and call
5157 free_all_values. We can't call free_all_values because we
5158 might be in the middle of evaluating a function call. */
5162 struct value
*new_val
;
5164 if (is_masked_watchpoint (&b
->base
))
5165 /* Since we don't know the exact trigger address (from
5166 stopped_data_address), just tell the user we've triggered
5167 a mask watchpoint. */
5168 return WP_VALUE_CHANGED
;
5170 mark
= value_mark ();
5171 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5173 if (b
->val_bitsize
!= 0)
5174 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5176 /* We use value_equal_contents instead of value_equal because
5177 the latter coerces an array to a pointer, thus comparing just
5178 the address of the array instead of its contents. This is
5179 not what we want. */
5180 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5181 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5183 if (new_val
!= NULL
)
5185 release_value (new_val
);
5186 value_free_to_mark (mark
);
5188 bs
->old_val
= b
->val
;
5191 return WP_VALUE_CHANGED
;
5195 /* Nothing changed. */
5196 value_free_to_mark (mark
);
5197 return WP_VALUE_NOT_CHANGED
;
5202 struct ui_out
*uiout
= current_uiout
;
5204 /* This seems like the only logical thing to do because
5205 if we temporarily ignored the watchpoint, then when
5206 we reenter the block in which it is valid it contains
5207 garbage (in the case of a function, it may have two
5208 garbage values, one before and one after the prologue).
5209 So we can't even detect the first assignment to it and
5210 watch after that (since the garbage may or may not equal
5211 the first value assigned). */
5212 /* We print all the stop information in
5213 breakpoint_ops->print_it, but in this case, by the time we
5214 call breakpoint_ops->print_it this bp will be deleted
5215 already. So we have no choice but print the information
5217 if (ui_out_is_mi_like_p (uiout
))
5219 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5220 ui_out_text (uiout
, "\nWatchpoint ");
5221 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5223 " deleted because the program has left the block in\n\
5224 which its expression is valid.\n");
5226 /* Make sure the watchpoint's commands aren't executed. */
5227 decref_counted_command_line (&b
->base
.commands
);
5228 watchpoint_del_at_next_stop (b
);
5234 /* Return true if it looks like target has stopped due to hitting
5235 breakpoint location BL. This function does not check if we should
5236 stop, only if BL explains the stop. */
5239 bpstat_check_location (const struct bp_location
*bl
,
5240 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5241 const struct target_waitstatus
*ws
)
5243 struct breakpoint
*b
= bl
->owner
;
5245 /* BL is from an existing breakpoint. */
5246 gdb_assert (b
!= NULL
);
5248 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5251 /* Determine if the watched values have actually changed, and we
5252 should stop. If not, set BS->stop to 0. */
5255 bpstat_check_watchpoint (bpstat bs
)
5257 const struct bp_location
*bl
;
5258 struct watchpoint
*b
;
5260 /* BS is built for existing struct breakpoint. */
5261 bl
= bs
->bp_location_at
;
5262 gdb_assert (bl
!= NULL
);
5263 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5264 gdb_assert (b
!= NULL
);
5267 int must_check_value
= 0;
5269 if (b
->base
.type
== bp_watchpoint
)
5270 /* For a software watchpoint, we must always check the
5272 must_check_value
= 1;
5273 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5274 /* We have a hardware watchpoint (read, write, or access)
5275 and the target earlier reported an address watched by
5277 must_check_value
= 1;
5278 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5279 && b
->base
.type
== bp_hardware_watchpoint
)
5280 /* We were stopped by a hardware watchpoint, but the target could
5281 not report the data address. We must check the watchpoint's
5282 value. Access and read watchpoints are out of luck; without
5283 a data address, we can't figure it out. */
5284 must_check_value
= 1;
5286 if (must_check_value
)
5289 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5291 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5292 int e
= catch_errors (watchpoint_check
, bs
, message
,
5294 do_cleanups (cleanups
);
5298 /* We've already printed what needs to be printed. */
5299 bs
->print_it
= print_it_done
;
5303 bs
->print_it
= print_it_noop
;
5306 case WP_VALUE_CHANGED
:
5307 if (b
->base
.type
== bp_read_watchpoint
)
5309 /* There are two cases to consider here:
5311 1. We're watching the triggered memory for reads.
5312 In that case, trust the target, and always report
5313 the watchpoint hit to the user. Even though
5314 reads don't cause value changes, the value may
5315 have changed since the last time it was read, and
5316 since we're not trapping writes, we will not see
5317 those, and as such we should ignore our notion of
5320 2. We're watching the triggered memory for both
5321 reads and writes. There are two ways this may
5324 2.1. This is a target that can't break on data
5325 reads only, but can break on accesses (reads or
5326 writes), such as e.g., x86. We detect this case
5327 at the time we try to insert read watchpoints.
5329 2.2. Otherwise, the target supports read
5330 watchpoints, but, the user set an access or write
5331 watchpoint watching the same memory as this read
5334 If we're watching memory writes as well as reads,
5335 ignore watchpoint hits when we find that the
5336 value hasn't changed, as reads don't cause
5337 changes. This still gives false positives when
5338 the program writes the same value to memory as
5339 what there was already in memory (we will confuse
5340 it for a read), but it's much better than
5343 int other_write_watchpoint
= 0;
5345 if (bl
->watchpoint_type
== hw_read
)
5347 struct breakpoint
*other_b
;
5349 ALL_BREAKPOINTS (other_b
)
5350 if (other_b
->type
== bp_hardware_watchpoint
5351 || other_b
->type
== bp_access_watchpoint
)
5353 struct watchpoint
*other_w
=
5354 (struct watchpoint
*) other_b
;
5356 if (other_w
->watchpoint_triggered
5357 == watch_triggered_yes
)
5359 other_write_watchpoint
= 1;
5365 if (other_write_watchpoint
5366 || bl
->watchpoint_type
== hw_access
)
5368 /* We're watching the same memory for writes,
5369 and the value changed since the last time we
5370 updated it, so this trap must be for a write.
5372 bs
->print_it
= print_it_noop
;
5377 case WP_VALUE_NOT_CHANGED
:
5378 if (b
->base
.type
== bp_hardware_watchpoint
5379 || b
->base
.type
== bp_watchpoint
)
5381 /* Don't stop: write watchpoints shouldn't fire if
5382 the value hasn't changed. */
5383 bs
->print_it
= print_it_noop
;
5391 /* Error from catch_errors. */
5392 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5393 watchpoint_del_at_next_stop (b
);
5394 /* We've already printed what needs to be printed. */
5395 bs
->print_it
= print_it_done
;
5399 else /* must_check_value == 0 */
5401 /* This is a case where some watchpoint(s) triggered, but
5402 not at the address of this watchpoint, or else no
5403 watchpoint triggered after all. So don't print
5404 anything for this watchpoint. */
5405 bs
->print_it
= print_it_noop
;
5411 /* For breakpoints that are currently marked as telling gdb to stop,
5412 check conditions (condition proper, frame, thread and ignore count)
5413 of breakpoint referred to by BS. If we should not stop for this
5414 breakpoint, set BS->stop to 0. */
5417 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5419 const struct bp_location
*bl
;
5420 struct breakpoint
*b
;
5421 int value_is_zero
= 0;
5422 struct expression
*cond
;
5424 gdb_assert (bs
->stop
);
5426 /* BS is built for existing struct breakpoint. */
5427 bl
= bs
->bp_location_at
;
5428 gdb_assert (bl
!= NULL
);
5429 b
= bs
->breakpoint_at
;
5430 gdb_assert (b
!= NULL
);
5432 /* Even if the target evaluated the condition on its end and notified GDB, we
5433 need to do so again since GDB does not know if we stopped due to a
5434 breakpoint or a single step breakpoint. */
5436 if (frame_id_p (b
->frame_id
)
5437 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5443 /* If this is a thread/task-specific breakpoint, don't waste cpu
5444 evaluating the condition if this isn't the specified
5446 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5447 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5454 /* Evaluate extension language breakpoints that have a "stop" method
5456 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5458 if (is_watchpoint (b
))
5460 struct watchpoint
*w
= (struct watchpoint
*) b
;
5467 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5469 int within_current_scope
= 1;
5470 struct watchpoint
* w
;
5472 /* We use value_mark and value_free_to_mark because it could
5473 be a long time before we return to the command level and
5474 call free_all_values. We can't call free_all_values
5475 because we might be in the middle of evaluating a
5477 struct value
*mark
= value_mark ();
5479 if (is_watchpoint (b
))
5480 w
= (struct watchpoint
*) b
;
5484 /* Need to select the frame, with all that implies so that
5485 the conditions will have the right context. Because we
5486 use the frame, we will not see an inlined function's
5487 variables when we arrive at a breakpoint at the start
5488 of the inlined function; the current frame will be the
5490 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5491 select_frame (get_current_frame ());
5494 struct frame_info
*frame
;
5496 /* For local watchpoint expressions, which particular
5497 instance of a local is being watched matters, so we
5498 keep track of the frame to evaluate the expression
5499 in. To evaluate the condition however, it doesn't
5500 really matter which instantiation of the function
5501 where the condition makes sense triggers the
5502 watchpoint. This allows an expression like "watch
5503 global if q > 10" set in `func', catch writes to
5504 global on all threads that call `func', or catch
5505 writes on all recursive calls of `func' by a single
5506 thread. We simply always evaluate the condition in
5507 the innermost frame that's executing where it makes
5508 sense to evaluate the condition. It seems
5510 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5512 select_frame (frame
);
5514 within_current_scope
= 0;
5516 if (within_current_scope
)
5518 = catch_errors (breakpoint_cond_eval
, cond
,
5519 "Error in testing breakpoint condition:\n",
5523 warning (_("Watchpoint condition cannot be tested "
5524 "in the current scope"));
5525 /* If we failed to set the right context for this
5526 watchpoint, unconditionally report it. */
5529 /* FIXME-someday, should give breakpoint #. */
5530 value_free_to_mark (mark
);
5533 if (cond
&& value_is_zero
)
5537 else if (b
->ignore_count
> 0)
5541 /* Increase the hit count even though we don't stop. */
5543 observer_notify_breakpoint_modified (b
);
5548 /* Get a bpstat associated with having just stopped at address
5549 BP_ADDR in thread PTID.
5551 Determine whether we stopped at a breakpoint, etc, or whether we
5552 don't understand this stop. Result is a chain of bpstat's such
5555 if we don't understand the stop, the result is a null pointer.
5557 if we understand why we stopped, the result is not null.
5559 Each element of the chain refers to a particular breakpoint or
5560 watchpoint at which we have stopped. (We may have stopped for
5561 several reasons concurrently.)
5563 Each element of the chain has valid next, breakpoint_at,
5564 commands, FIXME??? fields. */
5567 bpstat_stop_status (struct address_space
*aspace
,
5568 CORE_ADDR bp_addr
, ptid_t ptid
,
5569 const struct target_waitstatus
*ws
)
5571 struct breakpoint
*b
= NULL
;
5572 struct bp_location
*bl
;
5573 struct bp_location
*loc
;
5574 /* First item of allocated bpstat's. */
5575 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5576 /* Pointer to the last thing in the chain currently. */
5579 int need_remove_insert
;
5582 /* First, build the bpstat chain with locations that explain a
5583 target stop, while being careful to not set the target running,
5584 as that may invalidate locations (in particular watchpoint
5585 locations are recreated). Resuming will happen here with
5586 breakpoint conditions or watchpoint expressions that include
5587 inferior function calls. */
5591 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5594 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5596 /* For hardware watchpoints, we look only at the first
5597 location. The watchpoint_check function will work on the
5598 entire expression, not the individual locations. For
5599 read watchpoints, the watchpoints_triggered function has
5600 checked all locations already. */
5601 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5604 if (!bl
->enabled
|| bl
->shlib_disabled
)
5607 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5610 /* Come here if it's a watchpoint, or if the break address
5613 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5616 /* Assume we stop. Should we find a watchpoint that is not
5617 actually triggered, or if the condition of the breakpoint
5618 evaluates as false, we'll reset 'stop' to 0. */
5622 /* If this is a scope breakpoint, mark the associated
5623 watchpoint as triggered so that we will handle the
5624 out-of-scope event. We'll get to the watchpoint next
5626 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5628 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5630 w
->watchpoint_triggered
= watch_triggered_yes
;
5635 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5637 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5639 bs
= bpstat_alloc (loc
, &bs_link
);
5640 /* For hits of moribund locations, we should just proceed. */
5643 bs
->print_it
= print_it_noop
;
5647 /* A bit of special processing for shlib breakpoints. We need to
5648 process solib loading here, so that the lists of loaded and
5649 unloaded libraries are correct before we handle "catch load" and
5651 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5653 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5655 handle_solib_event ();
5660 /* Now go through the locations that caused the target to stop, and
5661 check whether we're interested in reporting this stop to higher
5662 layers, or whether we should resume the target transparently. */
5666 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5671 b
= bs
->breakpoint_at
;
5672 b
->ops
->check_status (bs
);
5675 bpstat_check_breakpoint_conditions (bs
, ptid
);
5680 observer_notify_breakpoint_modified (b
);
5682 /* We will stop here. */
5683 if (b
->disposition
== disp_disable
)
5685 --(b
->enable_count
);
5686 if (b
->enable_count
<= 0
5687 && b
->enable_state
!= bp_permanent
)
5688 b
->enable_state
= bp_disabled
;
5693 bs
->commands
= b
->commands
;
5694 incref_counted_command_line (bs
->commands
);
5695 if (command_line_is_silent (bs
->commands
5696 ? bs
->commands
->commands
: NULL
))
5699 b
->ops
->after_condition_true (bs
);
5704 /* Print nothing for this entry if we don't stop or don't
5706 if (!bs
->stop
|| !bs
->print
)
5707 bs
->print_it
= print_it_noop
;
5710 /* If we aren't stopping, the value of some hardware watchpoint may
5711 not have changed, but the intermediate memory locations we are
5712 watching may have. Don't bother if we're stopping; this will get
5714 need_remove_insert
= 0;
5715 if (! bpstat_causes_stop (bs_head
))
5716 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5718 && bs
->breakpoint_at
5719 && is_hardware_watchpoint (bs
->breakpoint_at
))
5721 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5723 update_watchpoint (w
, 0 /* don't reparse. */);
5724 need_remove_insert
= 1;
5727 if (need_remove_insert
)
5728 update_global_location_list (UGLL_MAY_INSERT
);
5729 else if (removed_any
)
5730 update_global_location_list (UGLL_DONT_INSERT
);
5736 handle_jit_event (void)
5738 struct frame_info
*frame
;
5739 struct gdbarch
*gdbarch
;
5741 /* Switch terminal for any messages produced by
5742 breakpoint_re_set. */
5743 target_terminal_ours_for_output ();
5745 frame
= get_current_frame ();
5746 gdbarch
= get_frame_arch (frame
);
5748 jit_event_handler (gdbarch
);
5750 target_terminal_inferior ();
5753 /* Prepare WHAT final decision for infrun. */
5755 /* Decide what infrun needs to do with this bpstat. */
5758 bpstat_what (bpstat bs_head
)
5760 struct bpstat_what retval
;
5764 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5765 retval
.call_dummy
= STOP_NONE
;
5766 retval
.is_longjmp
= 0;
5768 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5770 /* Extract this BS's action. After processing each BS, we check
5771 if its action overrides all we've seem so far. */
5772 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5775 if (bs
->breakpoint_at
== NULL
)
5777 /* I suspect this can happen if it was a momentary
5778 breakpoint which has since been deleted. */
5782 bptype
= bs
->breakpoint_at
->type
;
5789 case bp_hardware_breakpoint
:
5792 case bp_shlib_event
:
5796 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5798 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5801 this_action
= BPSTAT_WHAT_SINGLE
;
5804 case bp_hardware_watchpoint
:
5805 case bp_read_watchpoint
:
5806 case bp_access_watchpoint
:
5810 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5812 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5816 /* There was a watchpoint, but we're not stopping.
5817 This requires no further action. */
5821 case bp_longjmp_call_dummy
:
5823 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5824 retval
.is_longjmp
= bptype
!= bp_exception
;
5826 case bp_longjmp_resume
:
5827 case bp_exception_resume
:
5828 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5829 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5831 case bp_step_resume
:
5833 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5836 /* It is for the wrong frame. */
5837 this_action
= BPSTAT_WHAT_SINGLE
;
5840 case bp_hp_step_resume
:
5842 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5845 /* It is for the wrong frame. */
5846 this_action
= BPSTAT_WHAT_SINGLE
;
5849 case bp_watchpoint_scope
:
5850 case bp_thread_event
:
5851 case bp_overlay_event
:
5852 case bp_longjmp_master
:
5853 case bp_std_terminate_master
:
5854 case bp_exception_master
:
5855 this_action
= BPSTAT_WHAT_SINGLE
;
5861 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5863 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5867 /* There was a catchpoint, but we're not stopping.
5868 This requires no further action. */
5873 this_action
= BPSTAT_WHAT_SINGLE
;
5876 /* Make sure the action is stop (silent or noisy),
5877 so infrun.c pops the dummy frame. */
5878 retval
.call_dummy
= STOP_STACK_DUMMY
;
5879 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5881 case bp_std_terminate
:
5882 /* Make sure the action is stop (silent or noisy),
5883 so infrun.c pops the dummy frame. */
5884 retval
.call_dummy
= STOP_STD_TERMINATE
;
5885 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5888 case bp_fast_tracepoint
:
5889 case bp_static_tracepoint
:
5890 /* Tracepoint hits should not be reported back to GDB, and
5891 if one got through somehow, it should have been filtered
5893 internal_error (__FILE__
, __LINE__
,
5894 _("bpstat_what: tracepoint encountered"));
5896 case bp_gnu_ifunc_resolver
:
5897 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5898 this_action
= BPSTAT_WHAT_SINGLE
;
5900 case bp_gnu_ifunc_resolver_return
:
5901 /* The breakpoint will be removed, execution will restart from the
5902 PC of the former breakpoint. */
5903 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5908 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5910 this_action
= BPSTAT_WHAT_SINGLE
;
5914 internal_error (__FILE__
, __LINE__
,
5915 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5918 retval
.main_action
= max (retval
.main_action
, this_action
);
5921 /* These operations may affect the bs->breakpoint_at state so they are
5922 delayed after MAIN_ACTION is decided above. */
5927 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5929 handle_jit_event ();
5932 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5934 struct breakpoint
*b
= bs
->breakpoint_at
;
5940 case bp_gnu_ifunc_resolver
:
5941 gnu_ifunc_resolver_stop (b
);
5943 case bp_gnu_ifunc_resolver_return
:
5944 gnu_ifunc_resolver_return_stop (b
);
5952 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5953 without hardware support). This isn't related to a specific bpstat,
5954 just to things like whether watchpoints are set. */
5957 bpstat_should_step (void)
5959 struct breakpoint
*b
;
5962 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5968 bpstat_causes_stop (bpstat bs
)
5970 for (; bs
!= NULL
; bs
= bs
->next
)
5979 /* Compute a string of spaces suitable to indent the next line
5980 so it starts at the position corresponding to the table column
5981 named COL_NAME in the currently active table of UIOUT. */
5984 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5986 static char wrap_indent
[80];
5987 int i
, total_width
, width
, align
;
5991 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5993 if (strcmp (text
, col_name
) == 0)
5995 gdb_assert (total_width
< sizeof wrap_indent
);
5996 memset (wrap_indent
, ' ', total_width
);
5997 wrap_indent
[total_width
] = 0;
6002 total_width
+= width
+ 1;
6008 /* Determine if the locations of this breakpoint will have their conditions
6009 evaluated by the target, host or a mix of both. Returns the following:
6011 "host": Host evals condition.
6012 "host or target": Host or Target evals condition.
6013 "target": Target evals condition.
6017 bp_condition_evaluator (struct breakpoint
*b
)
6019 struct bp_location
*bl
;
6020 char host_evals
= 0;
6021 char target_evals
= 0;
6026 if (!is_breakpoint (b
))
6029 if (gdb_evaluates_breakpoint_condition_p ()
6030 || !target_supports_evaluation_of_breakpoint_conditions ())
6031 return condition_evaluation_host
;
6033 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6035 if (bl
->cond_bytecode
)
6041 if (host_evals
&& target_evals
)
6042 return condition_evaluation_both
;
6043 else if (target_evals
)
6044 return condition_evaluation_target
;
6046 return condition_evaluation_host
;
6049 /* Determine the breakpoint location's condition evaluator. This is
6050 similar to bp_condition_evaluator, but for locations. */
6053 bp_location_condition_evaluator (struct bp_location
*bl
)
6055 if (bl
&& !is_breakpoint (bl
->owner
))
6058 if (gdb_evaluates_breakpoint_condition_p ()
6059 || !target_supports_evaluation_of_breakpoint_conditions ())
6060 return condition_evaluation_host
;
6062 if (bl
&& bl
->cond_bytecode
)
6063 return condition_evaluation_target
;
6065 return condition_evaluation_host
;
6068 /* Print the LOC location out of the list of B->LOC locations. */
6071 print_breakpoint_location (struct breakpoint
*b
,
6072 struct bp_location
*loc
)
6074 struct ui_out
*uiout
= current_uiout
;
6075 struct cleanup
*old_chain
= save_current_program_space ();
6077 if (loc
!= NULL
&& loc
->shlib_disabled
)
6081 set_current_program_space (loc
->pspace
);
6083 if (b
->display_canonical
)
6084 ui_out_field_string (uiout
, "what", b
->addr_string
);
6085 else if (loc
&& loc
->symtab
)
6088 = find_pc_sect_function (loc
->address
, loc
->section
);
6091 ui_out_text (uiout
, "in ");
6092 ui_out_field_string (uiout
, "func",
6093 SYMBOL_PRINT_NAME (sym
));
6094 ui_out_text (uiout
, " ");
6095 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6096 ui_out_text (uiout
, "at ");
6098 ui_out_field_string (uiout
, "file",
6099 symtab_to_filename_for_display (loc
->symtab
));
6100 ui_out_text (uiout
, ":");
6102 if (ui_out_is_mi_like_p (uiout
))
6103 ui_out_field_string (uiout
, "fullname",
6104 symtab_to_fullname (loc
->symtab
));
6106 ui_out_field_int (uiout
, "line", loc
->line_number
);
6110 struct ui_file
*stb
= mem_fileopen ();
6111 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6113 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6115 ui_out_field_stream (uiout
, "at", stb
);
6117 do_cleanups (stb_chain
);
6120 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6122 if (loc
&& is_breakpoint (b
)
6123 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6124 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6126 ui_out_text (uiout
, " (");
6127 ui_out_field_string (uiout
, "evaluated-by",
6128 bp_location_condition_evaluator (loc
));
6129 ui_out_text (uiout
, ")");
6132 do_cleanups (old_chain
);
6136 bptype_string (enum bptype type
)
6138 struct ep_type_description
6143 static struct ep_type_description bptypes
[] =
6145 {bp_none
, "?deleted?"},
6146 {bp_breakpoint
, "breakpoint"},
6147 {bp_hardware_breakpoint
, "hw breakpoint"},
6148 {bp_until
, "until"},
6149 {bp_finish
, "finish"},
6150 {bp_watchpoint
, "watchpoint"},
6151 {bp_hardware_watchpoint
, "hw watchpoint"},
6152 {bp_read_watchpoint
, "read watchpoint"},
6153 {bp_access_watchpoint
, "acc watchpoint"},
6154 {bp_longjmp
, "longjmp"},
6155 {bp_longjmp_resume
, "longjmp resume"},
6156 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6157 {bp_exception
, "exception"},
6158 {bp_exception_resume
, "exception resume"},
6159 {bp_step_resume
, "step resume"},
6160 {bp_hp_step_resume
, "high-priority step resume"},
6161 {bp_watchpoint_scope
, "watchpoint scope"},
6162 {bp_call_dummy
, "call dummy"},
6163 {bp_std_terminate
, "std::terminate"},
6164 {bp_shlib_event
, "shlib events"},
6165 {bp_thread_event
, "thread events"},
6166 {bp_overlay_event
, "overlay events"},
6167 {bp_longjmp_master
, "longjmp master"},
6168 {bp_std_terminate_master
, "std::terminate master"},
6169 {bp_exception_master
, "exception master"},
6170 {bp_catchpoint
, "catchpoint"},
6171 {bp_tracepoint
, "tracepoint"},
6172 {bp_fast_tracepoint
, "fast tracepoint"},
6173 {bp_static_tracepoint
, "static tracepoint"},
6174 {bp_dprintf
, "dprintf"},
6175 {bp_jit_event
, "jit events"},
6176 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6177 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6180 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6181 || ((int) type
!= bptypes
[(int) type
].type
))
6182 internal_error (__FILE__
, __LINE__
,
6183 _("bptypes table does not describe type #%d."),
6186 return bptypes
[(int) type
].description
;
6189 /* For MI, output a field named 'thread-groups' with a list as the value.
6190 For CLI, prefix the list with the string 'inf'. */
6193 output_thread_groups (struct ui_out
*uiout
,
6194 const char *field_name
,
6198 struct cleanup
*back_to
;
6199 int is_mi
= ui_out_is_mi_like_p (uiout
);
6203 /* For backward compatibility, don't display inferiors in CLI unless
6204 there are several. Always display them for MI. */
6205 if (!is_mi
&& mi_only
)
6208 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6210 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6216 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6217 ui_out_field_string (uiout
, NULL
, mi_group
);
6222 ui_out_text (uiout
, " inf ");
6224 ui_out_text (uiout
, ", ");
6226 ui_out_text (uiout
, plongest (inf
));
6230 do_cleanups (back_to
);
6233 /* Print B to gdb_stdout. */
6236 print_one_breakpoint_location (struct breakpoint
*b
,
6237 struct bp_location
*loc
,
6239 struct bp_location
**last_loc
,
6242 struct command_line
*l
;
6243 static char bpenables
[] = "nynny";
6245 struct ui_out
*uiout
= current_uiout
;
6246 int header_of_multiple
= 0;
6247 int part_of_multiple
= (loc
!= NULL
);
6248 struct value_print_options opts
;
6250 get_user_print_options (&opts
);
6252 gdb_assert (!loc
|| loc_number
!= 0);
6253 /* See comment in print_one_breakpoint concerning treatment of
6254 breakpoints with single disabled location. */
6257 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6258 header_of_multiple
= 1;
6266 if (part_of_multiple
)
6269 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6270 ui_out_field_string (uiout
, "number", formatted
);
6275 ui_out_field_int (uiout
, "number", b
->number
);
6280 if (part_of_multiple
)
6281 ui_out_field_skip (uiout
, "type");
6283 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6287 if (part_of_multiple
)
6288 ui_out_field_skip (uiout
, "disp");
6290 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6295 if (part_of_multiple
)
6296 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6298 ui_out_field_fmt (uiout
, "enabled", "%c",
6299 bpenables
[(int) b
->enable_state
]);
6300 ui_out_spaces (uiout
, 2);
6304 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6306 /* Although the print_one can possibly print all locations,
6307 calling it here is not likely to get any nice result. So,
6308 make sure there's just one location. */
6309 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6310 b
->ops
->print_one (b
, last_loc
);
6316 internal_error (__FILE__
, __LINE__
,
6317 _("print_one_breakpoint: bp_none encountered\n"));
6321 case bp_hardware_watchpoint
:
6322 case bp_read_watchpoint
:
6323 case bp_access_watchpoint
:
6325 struct watchpoint
*w
= (struct watchpoint
*) b
;
6327 /* Field 4, the address, is omitted (which makes the columns
6328 not line up too nicely with the headers, but the effect
6329 is relatively readable). */
6330 if (opts
.addressprint
)
6331 ui_out_field_skip (uiout
, "addr");
6333 ui_out_field_string (uiout
, "what", w
->exp_string
);
6338 case bp_hardware_breakpoint
:
6342 case bp_longjmp_resume
:
6343 case bp_longjmp_call_dummy
:
6345 case bp_exception_resume
:
6346 case bp_step_resume
:
6347 case bp_hp_step_resume
:
6348 case bp_watchpoint_scope
:
6350 case bp_std_terminate
:
6351 case bp_shlib_event
:
6352 case bp_thread_event
:
6353 case bp_overlay_event
:
6354 case bp_longjmp_master
:
6355 case bp_std_terminate_master
:
6356 case bp_exception_master
:
6358 case bp_fast_tracepoint
:
6359 case bp_static_tracepoint
:
6362 case bp_gnu_ifunc_resolver
:
6363 case bp_gnu_ifunc_resolver_return
:
6364 if (opts
.addressprint
)
6367 if (header_of_multiple
)
6368 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6369 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6370 ui_out_field_string (uiout
, "addr", "<PENDING>");
6372 ui_out_field_core_addr (uiout
, "addr",
6373 loc
->gdbarch
, loc
->address
);
6376 if (!header_of_multiple
)
6377 print_breakpoint_location (b
, loc
);
6384 if (loc
!= NULL
&& !header_of_multiple
)
6386 struct inferior
*inf
;
6387 VEC(int) *inf_num
= NULL
;
6392 if (inf
->pspace
== loc
->pspace
)
6393 VEC_safe_push (int, inf_num
, inf
->num
);
6396 /* For backward compatibility, don't display inferiors in CLI unless
6397 there are several. Always display for MI. */
6399 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6400 && (number_of_program_spaces () > 1
6401 || number_of_inferiors () > 1)
6402 /* LOC is for existing B, it cannot be in
6403 moribund_locations and thus having NULL OWNER. */
6404 && loc
->owner
->type
!= bp_catchpoint
))
6406 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6407 VEC_free (int, inf_num
);
6410 if (!part_of_multiple
)
6412 if (b
->thread
!= -1)
6414 /* FIXME: This seems to be redundant and lost here; see the
6415 "stop only in" line a little further down. */
6416 ui_out_text (uiout
, " thread ");
6417 ui_out_field_int (uiout
, "thread", b
->thread
);
6419 else if (b
->task
!= 0)
6421 ui_out_text (uiout
, " task ");
6422 ui_out_field_int (uiout
, "task", b
->task
);
6426 ui_out_text (uiout
, "\n");
6428 if (!part_of_multiple
)
6429 b
->ops
->print_one_detail (b
, uiout
);
6431 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6434 ui_out_text (uiout
, "\tstop only in stack frame at ");
6435 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6437 ui_out_field_core_addr (uiout
, "frame",
6438 b
->gdbarch
, b
->frame_id
.stack_addr
);
6439 ui_out_text (uiout
, "\n");
6442 if (!part_of_multiple
&& b
->cond_string
)
6445 if (is_tracepoint (b
))
6446 ui_out_text (uiout
, "\ttrace only if ");
6448 ui_out_text (uiout
, "\tstop only if ");
6449 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6451 /* Print whether the target is doing the breakpoint's condition
6452 evaluation. If GDB is doing the evaluation, don't print anything. */
6453 if (is_breakpoint (b
)
6454 && breakpoint_condition_evaluation_mode ()
6455 == condition_evaluation_target
)
6457 ui_out_text (uiout
, " (");
6458 ui_out_field_string (uiout
, "evaluated-by",
6459 bp_condition_evaluator (b
));
6460 ui_out_text (uiout
, " evals)");
6462 ui_out_text (uiout
, "\n");
6465 if (!part_of_multiple
&& b
->thread
!= -1)
6467 /* FIXME should make an annotation for this. */
6468 ui_out_text (uiout
, "\tstop only in thread ");
6469 ui_out_field_int (uiout
, "thread", b
->thread
);
6470 ui_out_text (uiout
, "\n");
6473 if (!part_of_multiple
)
6477 /* FIXME should make an annotation for this. */
6478 if (is_catchpoint (b
))
6479 ui_out_text (uiout
, "\tcatchpoint");
6480 else if (is_tracepoint (b
))
6481 ui_out_text (uiout
, "\ttracepoint");
6483 ui_out_text (uiout
, "\tbreakpoint");
6484 ui_out_text (uiout
, " already hit ");
6485 ui_out_field_int (uiout
, "times", b
->hit_count
);
6486 if (b
->hit_count
== 1)
6487 ui_out_text (uiout
, " time\n");
6489 ui_out_text (uiout
, " times\n");
6493 /* Output the count also if it is zero, but only if this is mi. */
6494 if (ui_out_is_mi_like_p (uiout
))
6495 ui_out_field_int (uiout
, "times", b
->hit_count
);
6499 if (!part_of_multiple
&& b
->ignore_count
)
6502 ui_out_text (uiout
, "\tignore next ");
6503 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6504 ui_out_text (uiout
, " hits\n");
6507 /* Note that an enable count of 1 corresponds to "enable once"
6508 behavior, which is reported by the combination of enablement and
6509 disposition, so we don't need to mention it here. */
6510 if (!part_of_multiple
&& b
->enable_count
> 1)
6513 ui_out_text (uiout
, "\tdisable after ");
6514 /* Tweak the wording to clarify that ignore and enable counts
6515 are distinct, and have additive effect. */
6516 if (b
->ignore_count
)
6517 ui_out_text (uiout
, "additional ");
6519 ui_out_text (uiout
, "next ");
6520 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6521 ui_out_text (uiout
, " hits\n");
6524 if (!part_of_multiple
&& is_tracepoint (b
))
6526 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6528 if (tp
->traceframe_usage
)
6530 ui_out_text (uiout
, "\ttrace buffer usage ");
6531 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6532 ui_out_text (uiout
, " bytes\n");
6536 l
= b
->commands
? b
->commands
->commands
: NULL
;
6537 if (!part_of_multiple
&& l
)
6539 struct cleanup
*script_chain
;
6542 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6543 print_command_lines (uiout
, l
, 4);
6544 do_cleanups (script_chain
);
6547 if (is_tracepoint (b
))
6549 struct tracepoint
*t
= (struct tracepoint
*) b
;
6551 if (!part_of_multiple
&& t
->pass_count
)
6553 annotate_field (10);
6554 ui_out_text (uiout
, "\tpass count ");
6555 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6556 ui_out_text (uiout
, " \n");
6559 /* Don't display it when tracepoint or tracepoint location is
6561 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6563 annotate_field (11);
6565 if (ui_out_is_mi_like_p (uiout
))
6566 ui_out_field_string (uiout
, "installed",
6567 loc
->inserted
? "y" : "n");
6571 ui_out_text (uiout
, "\t");
6573 ui_out_text (uiout
, "\tnot ");
6574 ui_out_text (uiout
, "installed on target\n");
6579 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6581 if (is_watchpoint (b
))
6583 struct watchpoint
*w
= (struct watchpoint
*) b
;
6585 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6587 else if (b
->addr_string
)
6588 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6593 print_one_breakpoint (struct breakpoint
*b
,
6594 struct bp_location
**last_loc
,
6597 struct cleanup
*bkpt_chain
;
6598 struct ui_out
*uiout
= current_uiout
;
6600 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6602 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6603 do_cleanups (bkpt_chain
);
6605 /* If this breakpoint has custom print function,
6606 it's already printed. Otherwise, print individual
6607 locations, if any. */
6608 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6610 /* If breakpoint has a single location that is disabled, we
6611 print it as if it had several locations, since otherwise it's
6612 hard to represent "breakpoint enabled, location disabled"
6615 Note that while hardware watchpoints have several locations
6616 internally, that's not a property exposed to user. */
6618 && !is_hardware_watchpoint (b
)
6619 && (b
->loc
->next
|| !b
->loc
->enabled
))
6621 struct bp_location
*loc
;
6624 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6626 struct cleanup
*inner2
=
6627 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6628 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6629 do_cleanups (inner2
);
6636 breakpoint_address_bits (struct breakpoint
*b
)
6638 int print_address_bits
= 0;
6639 struct bp_location
*loc
;
6641 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6645 /* Software watchpoints that aren't watching memory don't have
6646 an address to print. */
6647 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6650 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6651 if (addr_bit
> print_address_bits
)
6652 print_address_bits
= addr_bit
;
6655 return print_address_bits
;
6658 struct captured_breakpoint_query_args
6664 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6666 struct captured_breakpoint_query_args
*args
= data
;
6667 struct breakpoint
*b
;
6668 struct bp_location
*dummy_loc
= NULL
;
6672 if (args
->bnum
== b
->number
)
6674 print_one_breakpoint (b
, &dummy_loc
, 0);
6682 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6683 char **error_message
)
6685 struct captured_breakpoint_query_args args
;
6688 /* For the moment we don't trust print_one_breakpoint() to not throw
6690 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6691 error_message
, RETURN_MASK_ALL
) < 0)
6697 /* Return true if this breakpoint was set by the user, false if it is
6698 internal or momentary. */
6701 user_breakpoint_p (struct breakpoint
*b
)
6703 return b
->number
> 0;
6706 /* Print information on user settable breakpoint (watchpoint, etc)
6707 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6708 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6709 FILTER is non-NULL, call it on each breakpoint and only include the
6710 ones for which it returns non-zero. Return the total number of
6711 breakpoints listed. */
6714 breakpoint_1 (char *args
, int allflag
,
6715 int (*filter
) (const struct breakpoint
*))
6717 struct breakpoint
*b
;
6718 struct bp_location
*last_loc
= NULL
;
6719 int nr_printable_breakpoints
;
6720 struct cleanup
*bkpttbl_chain
;
6721 struct value_print_options opts
;
6722 int print_address_bits
= 0;
6723 int print_type_col_width
= 14;
6724 struct ui_out
*uiout
= current_uiout
;
6726 get_user_print_options (&opts
);
6728 /* Compute the number of rows in the table, as well as the size
6729 required for address fields. */
6730 nr_printable_breakpoints
= 0;
6733 /* If we have a filter, only list the breakpoints it accepts. */
6734 if (filter
&& !filter (b
))
6737 /* If we have an "args" string, it is a list of breakpoints to
6738 accept. Skip the others. */
6739 if (args
!= NULL
&& *args
!= '\0')
6741 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6743 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6747 if (allflag
|| user_breakpoint_p (b
))
6749 int addr_bit
, type_len
;
6751 addr_bit
= breakpoint_address_bits (b
);
6752 if (addr_bit
> print_address_bits
)
6753 print_address_bits
= addr_bit
;
6755 type_len
= strlen (bptype_string (b
->type
));
6756 if (type_len
> print_type_col_width
)
6757 print_type_col_width
= type_len
;
6759 nr_printable_breakpoints
++;
6763 if (opts
.addressprint
)
6765 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6766 nr_printable_breakpoints
,
6770 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6771 nr_printable_breakpoints
,
6774 if (nr_printable_breakpoints
> 0)
6775 annotate_breakpoints_headers ();
6776 if (nr_printable_breakpoints
> 0)
6778 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6779 if (nr_printable_breakpoints
> 0)
6781 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6782 "type", "Type"); /* 2 */
6783 if (nr_printable_breakpoints
> 0)
6785 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6786 if (nr_printable_breakpoints
> 0)
6788 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6789 if (opts
.addressprint
)
6791 if (nr_printable_breakpoints
> 0)
6793 if (print_address_bits
<= 32)
6794 ui_out_table_header (uiout
, 10, ui_left
,
6795 "addr", "Address"); /* 5 */
6797 ui_out_table_header (uiout
, 18, ui_left
,
6798 "addr", "Address"); /* 5 */
6800 if (nr_printable_breakpoints
> 0)
6802 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6803 ui_out_table_body (uiout
);
6804 if (nr_printable_breakpoints
> 0)
6805 annotate_breakpoints_table ();
6810 /* If we have a filter, only list the breakpoints it accepts. */
6811 if (filter
&& !filter (b
))
6814 /* If we have an "args" string, it is a list of breakpoints to
6815 accept. Skip the others. */
6817 if (args
!= NULL
&& *args
!= '\0')
6819 if (allflag
) /* maintenance info breakpoint */
6821 if (parse_and_eval_long (args
) != b
->number
)
6824 else /* all others */
6826 if (!number_is_in_list (args
, b
->number
))
6830 /* We only print out user settable breakpoints unless the
6832 if (allflag
|| user_breakpoint_p (b
))
6833 print_one_breakpoint (b
, &last_loc
, allflag
);
6836 do_cleanups (bkpttbl_chain
);
6838 if (nr_printable_breakpoints
== 0)
6840 /* If there's a filter, let the caller decide how to report
6844 if (args
== NULL
|| *args
== '\0')
6845 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6847 ui_out_message (uiout
, 0,
6848 "No breakpoint or watchpoint matching '%s'.\n",
6854 if (last_loc
&& !server_command
)
6855 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6858 /* FIXME? Should this be moved up so that it is only called when
6859 there have been breakpoints? */
6860 annotate_breakpoints_table_end ();
6862 return nr_printable_breakpoints
;
6865 /* Display the value of default-collect in a way that is generally
6866 compatible with the breakpoint list. */
6869 default_collect_info (void)
6871 struct ui_out
*uiout
= current_uiout
;
6873 /* If it has no value (which is frequently the case), say nothing; a
6874 message like "No default-collect." gets in user's face when it's
6876 if (!*default_collect
)
6879 /* The following phrase lines up nicely with per-tracepoint collect
6881 ui_out_text (uiout
, "default collect ");
6882 ui_out_field_string (uiout
, "default-collect", default_collect
);
6883 ui_out_text (uiout
, " \n");
6887 breakpoints_info (char *args
, int from_tty
)
6889 breakpoint_1 (args
, 0, NULL
);
6891 default_collect_info ();
6895 watchpoints_info (char *args
, int from_tty
)
6897 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6898 struct ui_out
*uiout
= current_uiout
;
6900 if (num_printed
== 0)
6902 if (args
== NULL
|| *args
== '\0')
6903 ui_out_message (uiout
, 0, "No watchpoints.\n");
6905 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6910 maintenance_info_breakpoints (char *args
, int from_tty
)
6912 breakpoint_1 (args
, 1, NULL
);
6914 default_collect_info ();
6918 breakpoint_has_pc (struct breakpoint
*b
,
6919 struct program_space
*pspace
,
6920 CORE_ADDR pc
, struct obj_section
*section
)
6922 struct bp_location
*bl
= b
->loc
;
6924 for (; bl
; bl
= bl
->next
)
6926 if (bl
->pspace
== pspace
6927 && bl
->address
== pc
6928 && (!overlay_debugging
|| bl
->section
== section
))
6934 /* Print a message describing any user-breakpoints set at PC. This
6935 concerns with logical breakpoints, so we match program spaces, not
6939 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6940 struct program_space
*pspace
, CORE_ADDR pc
,
6941 struct obj_section
*section
, int thread
)
6944 struct breakpoint
*b
;
6947 others
+= (user_breakpoint_p (b
)
6948 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6952 printf_filtered (_("Note: breakpoint "));
6953 else /* if (others == ???) */
6954 printf_filtered (_("Note: breakpoints "));
6956 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6959 printf_filtered ("%d", b
->number
);
6960 if (b
->thread
== -1 && thread
!= -1)
6961 printf_filtered (" (all threads)");
6962 else if (b
->thread
!= -1)
6963 printf_filtered (" (thread %d)", b
->thread
);
6964 printf_filtered ("%s%s ",
6965 ((b
->enable_state
== bp_disabled
6966 || b
->enable_state
== bp_call_disabled
)
6968 : b
->enable_state
== bp_permanent
6972 : ((others
== 1) ? " and" : ""));
6974 printf_filtered (_("also set at pc "));
6975 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6976 printf_filtered (".\n");
6981 /* Return true iff it is meaningful to use the address member of
6982 BPT. For some breakpoint types, the address member is irrelevant
6983 and it makes no sense to attempt to compare it to other addresses
6984 (or use it for any other purpose either).
6986 More specifically, each of the following breakpoint types will
6987 always have a zero valued address and we don't want to mark
6988 breakpoints of any of these types to be a duplicate of an actual
6989 breakpoint at address zero:
6997 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6999 enum bptype type
= bpt
->type
;
7001 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7004 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7005 true if LOC1 and LOC2 represent the same watchpoint location. */
7008 watchpoint_locations_match (struct bp_location
*loc1
,
7009 struct bp_location
*loc2
)
7011 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7012 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7014 /* Both of them must exist. */
7015 gdb_assert (w1
!= NULL
);
7016 gdb_assert (w2
!= NULL
);
7018 /* If the target can evaluate the condition expression in hardware,
7019 then we we need to insert both watchpoints even if they are at
7020 the same place. Otherwise the watchpoint will only trigger when
7021 the condition of whichever watchpoint was inserted evaluates to
7022 true, not giving a chance for GDB to check the condition of the
7023 other watchpoint. */
7025 && target_can_accel_watchpoint_condition (loc1
->address
,
7027 loc1
->watchpoint_type
,
7030 && target_can_accel_watchpoint_condition (loc2
->address
,
7032 loc2
->watchpoint_type
,
7036 /* Note that this checks the owner's type, not the location's. In
7037 case the target does not support read watchpoints, but does
7038 support access watchpoints, we'll have bp_read_watchpoint
7039 watchpoints with hw_access locations. Those should be considered
7040 duplicates of hw_read locations. The hw_read locations will
7041 become hw_access locations later. */
7042 return (loc1
->owner
->type
== loc2
->owner
->type
7043 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7044 && loc1
->address
== loc2
->address
7045 && loc1
->length
== loc2
->length
);
7048 /* See breakpoint.h. */
7051 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7052 struct address_space
*aspace2
, CORE_ADDR addr2
)
7054 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7055 || aspace1
== aspace2
)
7059 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7060 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7061 matches ASPACE2. On targets that have global breakpoints, the address
7062 space doesn't really matter. */
7065 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7066 int len1
, struct address_space
*aspace2
,
7069 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7070 || aspace1
== aspace2
)
7071 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7074 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7075 a ranged breakpoint. In most targets, a match happens only if ASPACE
7076 matches the breakpoint's address space. On targets that have global
7077 breakpoints, the address space doesn't really matter. */
7080 breakpoint_location_address_match (struct bp_location
*bl
,
7081 struct address_space
*aspace
,
7084 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7087 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7088 bl
->address
, bl
->length
,
7092 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7093 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7094 true, otherwise returns false. */
7097 tracepoint_locations_match (struct bp_location
*loc1
,
7098 struct bp_location
*loc2
)
7100 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7101 /* Since tracepoint locations are never duplicated with others', tracepoint
7102 locations at the same address of different tracepoints are regarded as
7103 different locations. */
7104 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7109 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7110 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7111 represent the same location. */
7114 breakpoint_locations_match (struct bp_location
*loc1
,
7115 struct bp_location
*loc2
)
7117 int hw_point1
, hw_point2
;
7119 /* Both of them must not be in moribund_locations. */
7120 gdb_assert (loc1
->owner
!= NULL
);
7121 gdb_assert (loc2
->owner
!= NULL
);
7123 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7124 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7126 if (hw_point1
!= hw_point2
)
7129 return watchpoint_locations_match (loc1
, loc2
);
7130 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7131 return tracepoint_locations_match (loc1
, loc2
);
7133 /* We compare bp_location.length in order to cover ranged breakpoints. */
7134 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7135 loc2
->pspace
->aspace
, loc2
->address
)
7136 && loc1
->length
== loc2
->length
);
7140 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7141 int bnum
, int have_bnum
)
7143 /* The longest string possibly returned by hex_string_custom
7144 is 50 chars. These must be at least that big for safety. */
7148 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7149 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7151 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7152 bnum
, astr1
, astr2
);
7154 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7157 /* Adjust a breakpoint's address to account for architectural
7158 constraints on breakpoint placement. Return the adjusted address.
7159 Note: Very few targets require this kind of adjustment. For most
7160 targets, this function is simply the identity function. */
7163 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7164 CORE_ADDR bpaddr
, enum bptype bptype
)
7166 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7168 /* Very few targets need any kind of breakpoint adjustment. */
7171 else if (bptype
== bp_watchpoint
7172 || bptype
== bp_hardware_watchpoint
7173 || bptype
== bp_read_watchpoint
7174 || bptype
== bp_access_watchpoint
7175 || bptype
== bp_catchpoint
)
7177 /* Watchpoints and the various bp_catch_* eventpoints should not
7178 have their addresses modified. */
7183 CORE_ADDR adjusted_bpaddr
;
7185 /* Some targets have architectural constraints on the placement
7186 of breakpoint instructions. Obtain the adjusted address. */
7187 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7189 /* An adjusted breakpoint address can significantly alter
7190 a user's expectations. Print a warning if an adjustment
7192 if (adjusted_bpaddr
!= bpaddr
)
7193 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7195 return adjusted_bpaddr
;
7200 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7201 struct breakpoint
*owner
)
7203 memset (loc
, 0, sizeof (*loc
));
7205 gdb_assert (ops
!= NULL
);
7210 loc
->cond_bytecode
= NULL
;
7211 loc
->shlib_disabled
= 0;
7214 switch (owner
->type
)
7220 case bp_longjmp_resume
:
7221 case bp_longjmp_call_dummy
:
7223 case bp_exception_resume
:
7224 case bp_step_resume
:
7225 case bp_hp_step_resume
:
7226 case bp_watchpoint_scope
:
7228 case bp_std_terminate
:
7229 case bp_shlib_event
:
7230 case bp_thread_event
:
7231 case bp_overlay_event
:
7233 case bp_longjmp_master
:
7234 case bp_std_terminate_master
:
7235 case bp_exception_master
:
7236 case bp_gnu_ifunc_resolver
:
7237 case bp_gnu_ifunc_resolver_return
:
7239 loc
->loc_type
= bp_loc_software_breakpoint
;
7240 mark_breakpoint_location_modified (loc
);
7242 case bp_hardware_breakpoint
:
7243 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7244 mark_breakpoint_location_modified (loc
);
7246 case bp_hardware_watchpoint
:
7247 case bp_read_watchpoint
:
7248 case bp_access_watchpoint
:
7249 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7254 case bp_fast_tracepoint
:
7255 case bp_static_tracepoint
:
7256 loc
->loc_type
= bp_loc_other
;
7259 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7265 /* Allocate a struct bp_location. */
7267 static struct bp_location
*
7268 allocate_bp_location (struct breakpoint
*bpt
)
7270 return bpt
->ops
->allocate_location (bpt
);
7274 free_bp_location (struct bp_location
*loc
)
7276 loc
->ops
->dtor (loc
);
7280 /* Increment reference count. */
7283 incref_bp_location (struct bp_location
*bl
)
7288 /* Decrement reference count. If the reference count reaches 0,
7289 destroy the bp_location. Sets *BLP to NULL. */
7292 decref_bp_location (struct bp_location
**blp
)
7294 gdb_assert ((*blp
)->refc
> 0);
7296 if (--(*blp
)->refc
== 0)
7297 free_bp_location (*blp
);
7301 /* Add breakpoint B at the end of the global breakpoint chain. */
7304 add_to_breakpoint_chain (struct breakpoint
*b
)
7306 struct breakpoint
*b1
;
7308 /* Add this breakpoint to the end of the chain so that a list of
7309 breakpoints will come out in order of increasing numbers. */
7311 b1
= breakpoint_chain
;
7313 breakpoint_chain
= b
;
7322 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7325 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7326 struct gdbarch
*gdbarch
,
7328 const struct breakpoint_ops
*ops
)
7330 memset (b
, 0, sizeof (*b
));
7332 gdb_assert (ops
!= NULL
);
7336 b
->gdbarch
= gdbarch
;
7337 b
->language
= current_language
->la_language
;
7338 b
->input_radix
= input_radix
;
7340 b
->enable_state
= bp_enabled
;
7343 b
->ignore_count
= 0;
7345 b
->frame_id
= null_frame_id
;
7346 b
->condition_not_parsed
= 0;
7347 b
->py_bp_object
= NULL
;
7348 b
->related_breakpoint
= b
;
7351 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7352 that has type BPTYPE and has no locations as yet. */
7354 static struct breakpoint
*
7355 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7357 const struct breakpoint_ops
*ops
)
7359 struct breakpoint
*b
= XNEW (struct breakpoint
);
7361 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7362 add_to_breakpoint_chain (b
);
7366 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7367 resolutions should be made as the user specified the location explicitly
7371 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7373 gdb_assert (loc
->owner
!= NULL
);
7375 if (loc
->owner
->type
== bp_breakpoint
7376 || loc
->owner
->type
== bp_hardware_breakpoint
7377 || is_tracepoint (loc
->owner
))
7380 const char *function_name
;
7381 CORE_ADDR func_addr
;
7383 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7384 &func_addr
, NULL
, &is_gnu_ifunc
);
7386 if (is_gnu_ifunc
&& !explicit_loc
)
7388 struct breakpoint
*b
= loc
->owner
;
7390 gdb_assert (loc
->pspace
== current_program_space
);
7391 if (gnu_ifunc_resolve_name (function_name
,
7392 &loc
->requested_address
))
7394 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7395 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7396 loc
->requested_address
,
7399 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7400 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7402 /* Create only the whole new breakpoint of this type but do not
7403 mess more complicated breakpoints with multiple locations. */
7404 b
->type
= bp_gnu_ifunc_resolver
;
7405 /* Remember the resolver's address for use by the return
7407 loc
->related_address
= func_addr
;
7412 loc
->function_name
= xstrdup (function_name
);
7416 /* Attempt to determine architecture of location identified by SAL. */
7418 get_sal_arch (struct symtab_and_line sal
)
7421 return get_objfile_arch (sal
.section
->objfile
);
7423 return get_objfile_arch (sal
.symtab
->objfile
);
7428 /* Low level routine for partially initializing a breakpoint of type
7429 BPTYPE. The newly created breakpoint's address, section, source
7430 file name, and line number are provided by SAL.
7432 It is expected that the caller will complete the initialization of
7433 the newly created breakpoint struct as well as output any status
7434 information regarding the creation of a new breakpoint. */
7437 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7438 struct symtab_and_line sal
, enum bptype bptype
,
7439 const struct breakpoint_ops
*ops
)
7441 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7443 add_location_to_breakpoint (b
, &sal
);
7445 if (bptype
!= bp_catchpoint
)
7446 gdb_assert (sal
.pspace
!= NULL
);
7448 /* Store the program space that was used to set the breakpoint,
7449 except for ordinary breakpoints, which are independent of the
7451 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7452 b
->pspace
= sal
.pspace
;
7455 /* set_raw_breakpoint is a low level routine for allocating and
7456 partially initializing a breakpoint of type BPTYPE. The newly
7457 created breakpoint's address, section, source file name, and line
7458 number are provided by SAL. The newly created and partially
7459 initialized breakpoint is added to the breakpoint chain and
7460 is also returned as the value of this function.
7462 It is expected that the caller will complete the initialization of
7463 the newly created breakpoint struct as well as output any status
7464 information regarding the creation of a new breakpoint. In
7465 particular, set_raw_breakpoint does NOT set the breakpoint
7466 number! Care should be taken to not allow an error to occur
7467 prior to completing the initialization of the breakpoint. If this
7468 should happen, a bogus breakpoint will be left on the chain. */
7471 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7472 struct symtab_and_line sal
, enum bptype bptype
,
7473 const struct breakpoint_ops
*ops
)
7475 struct breakpoint
*b
= XNEW (struct breakpoint
);
7477 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7478 add_to_breakpoint_chain (b
);
7483 /* Note that the breakpoint object B describes a permanent breakpoint
7484 instruction, hard-wired into the inferior's code. */
7486 make_breakpoint_permanent (struct breakpoint
*b
)
7488 struct bp_location
*bl
;
7490 b
->enable_state
= bp_permanent
;
7492 /* By definition, permanent breakpoints are already present in the
7493 code. Mark all locations as inserted. For now,
7494 make_breakpoint_permanent is called in just one place, so it's
7495 hard to say if it's reasonable to have permanent breakpoint with
7496 multiple locations or not, but it's easy to implement. */
7497 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7501 /* Call this routine when stepping and nexting to enable a breakpoint
7502 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7503 initiated the operation. */
7506 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7508 struct breakpoint
*b
, *b_tmp
;
7509 int thread
= tp
->num
;
7511 /* To avoid having to rescan all objfile symbols at every step,
7512 we maintain a list of continually-inserted but always disabled
7513 longjmp "master" breakpoints. Here, we simply create momentary
7514 clones of those and enable them for the requested thread. */
7515 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7516 if (b
->pspace
== current_program_space
7517 && (b
->type
== bp_longjmp_master
7518 || b
->type
== bp_exception_master
))
7520 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7521 struct breakpoint
*clone
;
7523 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7524 after their removal. */
7525 clone
= momentary_breakpoint_from_master (b
, type
,
7526 &longjmp_breakpoint_ops
, 1);
7527 clone
->thread
= thread
;
7530 tp
->initiating_frame
= frame
;
7533 /* Delete all longjmp breakpoints from THREAD. */
7535 delete_longjmp_breakpoint (int thread
)
7537 struct breakpoint
*b
, *b_tmp
;
7539 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7540 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7542 if (b
->thread
== thread
)
7543 delete_breakpoint (b
);
7548 delete_longjmp_breakpoint_at_next_stop (int thread
)
7550 struct breakpoint
*b
, *b_tmp
;
7552 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7553 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7555 if (b
->thread
== thread
)
7556 b
->disposition
= disp_del_at_next_stop
;
7560 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7561 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7562 pointer to any of them. Return NULL if this system cannot place longjmp
7566 set_longjmp_breakpoint_for_call_dummy (void)
7568 struct breakpoint
*b
, *retval
= NULL
;
7571 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7573 struct breakpoint
*new_b
;
7575 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7576 &momentary_breakpoint_ops
,
7578 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7580 /* Link NEW_B into the chain of RETVAL breakpoints. */
7582 gdb_assert (new_b
->related_breakpoint
== new_b
);
7585 new_b
->related_breakpoint
= retval
;
7586 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7587 retval
= retval
->related_breakpoint
;
7588 retval
->related_breakpoint
= new_b
;
7594 /* Verify all existing dummy frames and their associated breakpoints for
7595 TP. Remove those which can no longer be found in the current frame
7598 You should call this function only at places where it is safe to currently
7599 unwind the whole stack. Failed stack unwind would discard live dummy
7603 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7605 struct breakpoint
*b
, *b_tmp
;
7607 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7608 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7610 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7612 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7613 dummy_b
= dummy_b
->related_breakpoint
;
7614 if (dummy_b
->type
!= bp_call_dummy
7615 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7618 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7620 while (b
->related_breakpoint
!= b
)
7622 if (b_tmp
== b
->related_breakpoint
)
7623 b_tmp
= b
->related_breakpoint
->next
;
7624 delete_breakpoint (b
->related_breakpoint
);
7626 delete_breakpoint (b
);
7631 enable_overlay_breakpoints (void)
7633 struct breakpoint
*b
;
7636 if (b
->type
== bp_overlay_event
)
7638 b
->enable_state
= bp_enabled
;
7639 update_global_location_list (UGLL_MAY_INSERT
);
7640 overlay_events_enabled
= 1;
7645 disable_overlay_breakpoints (void)
7647 struct breakpoint
*b
;
7650 if (b
->type
== bp_overlay_event
)
7652 b
->enable_state
= bp_disabled
;
7653 update_global_location_list (UGLL_DONT_INSERT
);
7654 overlay_events_enabled
= 0;
7658 /* Set an active std::terminate breakpoint for each std::terminate
7659 master breakpoint. */
7661 set_std_terminate_breakpoint (void)
7663 struct breakpoint
*b
, *b_tmp
;
7665 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7666 if (b
->pspace
== current_program_space
7667 && b
->type
== bp_std_terminate_master
)
7669 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7670 &momentary_breakpoint_ops
, 1);
7674 /* Delete all the std::terminate breakpoints. */
7676 delete_std_terminate_breakpoint (void)
7678 struct breakpoint
*b
, *b_tmp
;
7680 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7681 if (b
->type
== bp_std_terminate
)
7682 delete_breakpoint (b
);
7686 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7688 struct breakpoint
*b
;
7690 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7691 &internal_breakpoint_ops
);
7693 b
->enable_state
= bp_enabled
;
7694 /* addr_string has to be used or breakpoint_re_set will delete me. */
7696 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7698 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7704 remove_thread_event_breakpoints (void)
7706 struct breakpoint
*b
, *b_tmp
;
7708 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7709 if (b
->type
== bp_thread_event
7710 && b
->loc
->pspace
== current_program_space
)
7711 delete_breakpoint (b
);
7714 struct lang_and_radix
7720 /* Create a breakpoint for JIT code registration and unregistration. */
7723 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7725 struct breakpoint
*b
;
7727 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7728 &internal_breakpoint_ops
);
7729 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7733 /* Remove JIT code registration and unregistration breakpoint(s). */
7736 remove_jit_event_breakpoints (void)
7738 struct breakpoint
*b
, *b_tmp
;
7740 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7741 if (b
->type
== bp_jit_event
7742 && b
->loc
->pspace
== current_program_space
)
7743 delete_breakpoint (b
);
7747 remove_solib_event_breakpoints (void)
7749 struct breakpoint
*b
, *b_tmp
;
7751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7752 if (b
->type
== bp_shlib_event
7753 && b
->loc
->pspace
== current_program_space
)
7754 delete_breakpoint (b
);
7757 /* See breakpoint.h. */
7760 remove_solib_event_breakpoints_at_next_stop (void)
7762 struct breakpoint
*b
, *b_tmp
;
7764 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7765 if (b
->type
== bp_shlib_event
7766 && b
->loc
->pspace
== current_program_space
)
7767 b
->disposition
= disp_del_at_next_stop
;
7770 /* Helper for create_solib_event_breakpoint /
7771 create_and_insert_solib_event_breakpoint. Allows specifying which
7772 INSERT_MODE to pass through to update_global_location_list. */
7774 static struct breakpoint
*
7775 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7776 enum ugll_insert_mode insert_mode
)
7778 struct breakpoint
*b
;
7780 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7781 &internal_breakpoint_ops
);
7782 update_global_location_list_nothrow (insert_mode
);
7787 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7789 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7792 /* See breakpoint.h. */
7795 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7797 struct breakpoint
*b
;
7799 /* Explicitly tell update_global_location_list to insert
7801 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7802 if (!b
->loc
->inserted
)
7804 delete_breakpoint (b
);
7810 /* Disable any breakpoints that are on code in shared libraries. Only
7811 apply to enabled breakpoints, disabled ones can just stay disabled. */
7814 disable_breakpoints_in_shlibs (void)
7816 struct bp_location
*loc
, **locp_tmp
;
7818 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7820 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7821 struct breakpoint
*b
= loc
->owner
;
7823 /* We apply the check to all breakpoints, including disabled for
7824 those with loc->duplicate set. This is so that when breakpoint
7825 becomes enabled, or the duplicate is removed, gdb will try to
7826 insert all breakpoints. If we don't set shlib_disabled here,
7827 we'll try to insert those breakpoints and fail. */
7828 if (((b
->type
== bp_breakpoint
)
7829 || (b
->type
== bp_jit_event
)
7830 || (b
->type
== bp_hardware_breakpoint
)
7831 || (is_tracepoint (b
)))
7832 && loc
->pspace
== current_program_space
7833 && !loc
->shlib_disabled
7834 && solib_name_from_address (loc
->pspace
, loc
->address
)
7837 loc
->shlib_disabled
= 1;
7842 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7843 notification of unloaded_shlib. Only apply to enabled breakpoints,
7844 disabled ones can just stay disabled. */
7847 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7849 struct bp_location
*loc
, **locp_tmp
;
7850 int disabled_shlib_breaks
= 0;
7852 /* SunOS a.out shared libraries are always mapped, so do not
7853 disable breakpoints; they will only be reported as unloaded
7854 through clear_solib when GDB discards its shared library
7855 list. See clear_solib for more information. */
7856 if (exec_bfd
!= NULL
7857 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7860 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7862 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7863 struct breakpoint
*b
= loc
->owner
;
7865 if (solib
->pspace
== loc
->pspace
7866 && !loc
->shlib_disabled
7867 && (((b
->type
== bp_breakpoint
7868 || b
->type
== bp_jit_event
7869 || b
->type
== bp_hardware_breakpoint
)
7870 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7871 || loc
->loc_type
== bp_loc_software_breakpoint
))
7872 || is_tracepoint (b
))
7873 && solib_contains_address_p (solib
, loc
->address
))
7875 loc
->shlib_disabled
= 1;
7876 /* At this point, we cannot rely on remove_breakpoint
7877 succeeding so we must mark the breakpoint as not inserted
7878 to prevent future errors occurring in remove_breakpoints. */
7881 /* This may cause duplicate notifications for the same breakpoint. */
7882 observer_notify_breakpoint_modified (b
);
7884 if (!disabled_shlib_breaks
)
7886 target_terminal_ours_for_output ();
7887 warning (_("Temporarily disabling breakpoints "
7888 "for unloaded shared library \"%s\""),
7891 disabled_shlib_breaks
= 1;
7896 /* Disable any breakpoints and tracepoints in OBJFILE upon
7897 notification of free_objfile. Only apply to enabled breakpoints,
7898 disabled ones can just stay disabled. */
7901 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7903 struct breakpoint
*b
;
7905 if (objfile
== NULL
)
7908 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7909 managed by the user with add-symbol-file/remove-symbol-file.
7910 Similarly to how breakpoints in shared libraries are handled in
7911 response to "nosharedlibrary", mark breakpoints in such modules
7912 shlib_disabled so they end up uninserted on the next global
7913 location list update. Shared libraries not loaded by the user
7914 aren't handled here -- they're already handled in
7915 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7916 solib_unloaded observer. We skip objfiles that are not
7917 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7919 if ((objfile
->flags
& OBJF_SHARED
) == 0
7920 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7925 struct bp_location
*loc
;
7926 int bp_modified
= 0;
7928 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7931 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7933 CORE_ADDR loc_addr
= loc
->address
;
7935 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7936 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7939 if (loc
->shlib_disabled
!= 0)
7942 if (objfile
->pspace
!= loc
->pspace
)
7945 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7946 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7949 if (is_addr_in_objfile (loc_addr
, objfile
))
7951 loc
->shlib_disabled
= 1;
7952 /* At this point, we don't know whether the object was
7953 unmapped from the inferior or not, so leave the
7954 inserted flag alone. We'll handle failure to
7955 uninsert quietly, in case the object was indeed
7958 mark_breakpoint_location_modified (loc
);
7965 observer_notify_breakpoint_modified (b
);
7969 /* FORK & VFORK catchpoints. */
7971 /* An instance of this type is used to represent a fork or vfork
7972 catchpoint. It includes a "struct breakpoint" as a kind of base
7973 class; users downcast to "struct breakpoint *" when needed. A
7974 breakpoint is really of this type iff its ops pointer points to
7975 CATCH_FORK_BREAKPOINT_OPS. */
7977 struct fork_catchpoint
7979 /* The base class. */
7980 struct breakpoint base
;
7982 /* Process id of a child process whose forking triggered this
7983 catchpoint. This field is only valid immediately after this
7984 catchpoint has triggered. */
7985 ptid_t forked_inferior_pid
;
7988 /* Implement the "insert" breakpoint_ops method for fork
7992 insert_catch_fork (struct bp_location
*bl
)
7994 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7997 /* Implement the "remove" breakpoint_ops method for fork
8001 remove_catch_fork (struct bp_location
*bl
)
8003 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8006 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8010 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8011 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8012 const struct target_waitstatus
*ws
)
8014 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8016 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8019 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8023 /* Implement the "print_it" breakpoint_ops method for fork
8026 static enum print_stop_action
8027 print_it_catch_fork (bpstat bs
)
8029 struct ui_out
*uiout
= current_uiout
;
8030 struct breakpoint
*b
= bs
->breakpoint_at
;
8031 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8033 annotate_catchpoint (b
->number
);
8034 if (b
->disposition
== disp_del
)
8035 ui_out_text (uiout
, "\nTemporary catchpoint ");
8037 ui_out_text (uiout
, "\nCatchpoint ");
8038 if (ui_out_is_mi_like_p (uiout
))
8040 ui_out_field_string (uiout
, "reason",
8041 async_reason_lookup (EXEC_ASYNC_FORK
));
8042 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8044 ui_out_field_int (uiout
, "bkptno", b
->number
);
8045 ui_out_text (uiout
, " (forked process ");
8046 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8047 ui_out_text (uiout
, "), ");
8048 return PRINT_SRC_AND_LOC
;
8051 /* Implement the "print_one" breakpoint_ops method for fork
8055 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8057 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8058 struct value_print_options opts
;
8059 struct ui_out
*uiout
= current_uiout
;
8061 get_user_print_options (&opts
);
8063 /* Field 4, the address, is omitted (which makes the columns not
8064 line up too nicely with the headers, but the effect is relatively
8066 if (opts
.addressprint
)
8067 ui_out_field_skip (uiout
, "addr");
8069 ui_out_text (uiout
, "fork");
8070 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8072 ui_out_text (uiout
, ", process ");
8073 ui_out_field_int (uiout
, "what",
8074 ptid_get_pid (c
->forked_inferior_pid
));
8075 ui_out_spaces (uiout
, 1);
8078 if (ui_out_is_mi_like_p (uiout
))
8079 ui_out_field_string (uiout
, "catch-type", "fork");
8082 /* Implement the "print_mention" breakpoint_ops method for fork
8086 print_mention_catch_fork (struct breakpoint
*b
)
8088 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8091 /* Implement the "print_recreate" breakpoint_ops method for fork
8095 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8097 fprintf_unfiltered (fp
, "catch fork");
8098 print_recreate_thread (b
, fp
);
8101 /* The breakpoint_ops structure to be used in fork catchpoints. */
8103 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8105 /* Implement the "insert" breakpoint_ops method for vfork
8109 insert_catch_vfork (struct bp_location
*bl
)
8111 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8114 /* Implement the "remove" breakpoint_ops method for vfork
8118 remove_catch_vfork (struct bp_location
*bl
)
8120 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8123 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8127 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8128 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8129 const struct target_waitstatus
*ws
)
8131 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8133 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8136 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8140 /* Implement the "print_it" breakpoint_ops method for vfork
8143 static enum print_stop_action
8144 print_it_catch_vfork (bpstat bs
)
8146 struct ui_out
*uiout
= current_uiout
;
8147 struct breakpoint
*b
= bs
->breakpoint_at
;
8148 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8150 annotate_catchpoint (b
->number
);
8151 if (b
->disposition
== disp_del
)
8152 ui_out_text (uiout
, "\nTemporary catchpoint ");
8154 ui_out_text (uiout
, "\nCatchpoint ");
8155 if (ui_out_is_mi_like_p (uiout
))
8157 ui_out_field_string (uiout
, "reason",
8158 async_reason_lookup (EXEC_ASYNC_VFORK
));
8159 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8161 ui_out_field_int (uiout
, "bkptno", b
->number
);
8162 ui_out_text (uiout
, " (vforked process ");
8163 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8164 ui_out_text (uiout
, "), ");
8165 return PRINT_SRC_AND_LOC
;
8168 /* Implement the "print_one" breakpoint_ops method for vfork
8172 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8174 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8175 struct value_print_options opts
;
8176 struct ui_out
*uiout
= current_uiout
;
8178 get_user_print_options (&opts
);
8179 /* Field 4, the address, is omitted (which makes the columns not
8180 line up too nicely with the headers, but the effect is relatively
8182 if (opts
.addressprint
)
8183 ui_out_field_skip (uiout
, "addr");
8185 ui_out_text (uiout
, "vfork");
8186 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8188 ui_out_text (uiout
, ", process ");
8189 ui_out_field_int (uiout
, "what",
8190 ptid_get_pid (c
->forked_inferior_pid
));
8191 ui_out_spaces (uiout
, 1);
8194 if (ui_out_is_mi_like_p (uiout
))
8195 ui_out_field_string (uiout
, "catch-type", "vfork");
8198 /* Implement the "print_mention" breakpoint_ops method for vfork
8202 print_mention_catch_vfork (struct breakpoint
*b
)
8204 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8207 /* Implement the "print_recreate" breakpoint_ops method for vfork
8211 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8213 fprintf_unfiltered (fp
, "catch vfork");
8214 print_recreate_thread (b
, fp
);
8217 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8219 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8221 /* An instance of this type is used to represent an solib catchpoint.
8222 It includes a "struct breakpoint" as a kind of base class; users
8223 downcast to "struct breakpoint *" when needed. A breakpoint is
8224 really of this type iff its ops pointer points to
8225 CATCH_SOLIB_BREAKPOINT_OPS. */
8227 struct solib_catchpoint
8229 /* The base class. */
8230 struct breakpoint base
;
8232 /* True for "catch load", false for "catch unload". */
8233 unsigned char is_load
;
8235 /* Regular expression to match, if any. COMPILED is only valid when
8236 REGEX is non-NULL. */
8242 dtor_catch_solib (struct breakpoint
*b
)
8244 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8247 regfree (&self
->compiled
);
8248 xfree (self
->regex
);
8250 base_breakpoint_ops
.dtor (b
);
8254 insert_catch_solib (struct bp_location
*ignore
)
8260 remove_catch_solib (struct bp_location
*ignore
)
8266 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8267 struct address_space
*aspace
,
8269 const struct target_waitstatus
*ws
)
8271 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8272 struct breakpoint
*other
;
8274 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8277 ALL_BREAKPOINTS (other
)
8279 struct bp_location
*other_bl
;
8281 if (other
== bl
->owner
)
8284 if (other
->type
!= bp_shlib_event
)
8287 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8290 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8292 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8301 check_status_catch_solib (struct bpstats
*bs
)
8303 struct solib_catchpoint
*self
8304 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8309 struct so_list
*iter
;
8312 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8317 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8326 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8331 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8337 bs
->print_it
= print_it_noop
;
8340 static enum print_stop_action
8341 print_it_catch_solib (bpstat bs
)
8343 struct breakpoint
*b
= bs
->breakpoint_at
;
8344 struct ui_out
*uiout
= current_uiout
;
8346 annotate_catchpoint (b
->number
);
8347 if (b
->disposition
== disp_del
)
8348 ui_out_text (uiout
, "\nTemporary catchpoint ");
8350 ui_out_text (uiout
, "\nCatchpoint ");
8351 ui_out_field_int (uiout
, "bkptno", b
->number
);
8352 ui_out_text (uiout
, "\n");
8353 if (ui_out_is_mi_like_p (uiout
))
8354 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8355 print_solib_event (1);
8356 return PRINT_SRC_AND_LOC
;
8360 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8362 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8363 struct value_print_options opts
;
8364 struct ui_out
*uiout
= current_uiout
;
8367 get_user_print_options (&opts
);
8368 /* Field 4, the address, is omitted (which makes the columns not
8369 line up too nicely with the headers, but the effect is relatively
8371 if (opts
.addressprint
)
8374 ui_out_field_skip (uiout
, "addr");
8381 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8383 msg
= xstrdup (_("load of library"));
8388 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8390 msg
= xstrdup (_("unload of library"));
8392 ui_out_field_string (uiout
, "what", msg
);
8395 if (ui_out_is_mi_like_p (uiout
))
8396 ui_out_field_string (uiout
, "catch-type",
8397 self
->is_load
? "load" : "unload");
8401 print_mention_catch_solib (struct breakpoint
*b
)
8403 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8405 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8406 self
->is_load
? "load" : "unload");
8410 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8412 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8414 fprintf_unfiltered (fp
, "%s %s",
8415 b
->disposition
== disp_del
? "tcatch" : "catch",
8416 self
->is_load
? "load" : "unload");
8418 fprintf_unfiltered (fp
, " %s", self
->regex
);
8419 fprintf_unfiltered (fp
, "\n");
8422 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8424 /* Shared helper function (MI and CLI) for creating and installing
8425 a shared object event catchpoint. If IS_LOAD is non-zero then
8426 the events to be caught are load events, otherwise they are
8427 unload events. If IS_TEMP is non-zero the catchpoint is a
8428 temporary one. If ENABLED is non-zero the catchpoint is
8429 created in an enabled state. */
8432 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8434 struct solib_catchpoint
*c
;
8435 struct gdbarch
*gdbarch
= get_current_arch ();
8436 struct cleanup
*cleanup
;
8440 arg
= skip_spaces (arg
);
8442 c
= XCNEW (struct solib_catchpoint
);
8443 cleanup
= make_cleanup (xfree
, c
);
8449 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8452 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8454 make_cleanup (xfree
, err
);
8455 error (_("Invalid regexp (%s): %s"), err
, arg
);
8457 c
->regex
= xstrdup (arg
);
8460 c
->is_load
= is_load
;
8461 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8462 &catch_solib_breakpoint_ops
);
8464 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8466 discard_cleanups (cleanup
);
8467 install_breakpoint (0, &c
->base
, 1);
8470 /* A helper function that does all the work for "catch load" and
8474 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8475 struct cmd_list_element
*command
)
8478 const int enabled
= 1;
8480 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8482 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8486 catch_load_command_1 (char *arg
, int from_tty
,
8487 struct cmd_list_element
*command
)
8489 catch_load_or_unload (arg
, from_tty
, 1, command
);
8493 catch_unload_command_1 (char *arg
, int from_tty
,
8494 struct cmd_list_element
*command
)
8496 catch_load_or_unload (arg
, from_tty
, 0, command
);
8499 /* An instance of this type is used to represent a syscall catchpoint.
8500 It includes a "struct breakpoint" as a kind of base class; users
8501 downcast to "struct breakpoint *" when needed. A breakpoint is
8502 really of this type iff its ops pointer points to
8503 CATCH_SYSCALL_BREAKPOINT_OPS. */
8505 struct syscall_catchpoint
8507 /* The base class. */
8508 struct breakpoint base
;
8510 /* Syscall numbers used for the 'catch syscall' feature. If no
8511 syscall has been specified for filtering, its value is NULL.
8512 Otherwise, it holds a list of all syscalls to be caught. The
8513 list elements are allocated with xmalloc. */
8514 VEC(int) *syscalls_to_be_caught
;
8517 /* Implement the "dtor" breakpoint_ops method for syscall
8521 dtor_catch_syscall (struct breakpoint
*b
)
8523 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8525 VEC_free (int, c
->syscalls_to_be_caught
);
8527 base_breakpoint_ops
.dtor (b
);
8530 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8532 struct catch_syscall_inferior_data
8534 /* We keep a count of the number of times the user has requested a
8535 particular syscall to be tracked, and pass this information to the
8536 target. This lets capable targets implement filtering directly. */
8538 /* Number of times that "any" syscall is requested. */
8539 int any_syscall_count
;
8541 /* Count of each system call. */
8542 VEC(int) *syscalls_counts
;
8544 /* This counts all syscall catch requests, so we can readily determine
8545 if any catching is necessary. */
8546 int total_syscalls_count
;
8549 static struct catch_syscall_inferior_data
*
8550 get_catch_syscall_inferior_data (struct inferior
*inf
)
8552 struct catch_syscall_inferior_data
*inf_data
;
8554 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8555 if (inf_data
== NULL
)
8557 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8558 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8565 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8571 /* Implement the "insert" breakpoint_ops method for syscall
8575 insert_catch_syscall (struct bp_location
*bl
)
8577 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8578 struct inferior
*inf
= current_inferior ();
8579 struct catch_syscall_inferior_data
*inf_data
8580 = get_catch_syscall_inferior_data (inf
);
8582 ++inf_data
->total_syscalls_count
;
8583 if (!c
->syscalls_to_be_caught
)
8584 ++inf_data
->any_syscall_count
;
8590 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8595 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8597 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8598 uintptr_t vec_addr_offset
8599 = old_size
* ((uintptr_t) sizeof (int));
8601 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8602 vec_addr
= ((uintptr_t) VEC_address (int,
8603 inf_data
->syscalls_counts
)
8605 memset ((void *) vec_addr
, 0,
8606 (iter
+ 1 - old_size
) * sizeof (int));
8608 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8609 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8613 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8614 inf_data
->total_syscalls_count
!= 0,
8615 inf_data
->any_syscall_count
,
8617 inf_data
->syscalls_counts
),
8619 inf_data
->syscalls_counts
));
8622 /* Implement the "remove" breakpoint_ops method for syscall
8626 remove_catch_syscall (struct bp_location
*bl
)
8628 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8629 struct inferior
*inf
= current_inferior ();
8630 struct catch_syscall_inferior_data
*inf_data
8631 = get_catch_syscall_inferior_data (inf
);
8633 --inf_data
->total_syscalls_count
;
8634 if (!c
->syscalls_to_be_caught
)
8635 --inf_data
->any_syscall_count
;
8641 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8645 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8646 /* Shouldn't happen. */
8648 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8649 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8653 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8654 inf_data
->total_syscalls_count
!= 0,
8655 inf_data
->any_syscall_count
,
8657 inf_data
->syscalls_counts
),
8659 inf_data
->syscalls_counts
));
8662 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8666 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8667 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8668 const struct target_waitstatus
*ws
)
8670 /* We must check if we are catching specific syscalls in this
8671 breakpoint. If we are, then we must guarantee that the called
8672 syscall is the same syscall we are catching. */
8673 int syscall_number
= 0;
8674 const struct syscall_catchpoint
*c
8675 = (const struct syscall_catchpoint
*) bl
->owner
;
8677 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8678 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8681 syscall_number
= ws
->value
.syscall_number
;
8683 /* Now, checking if the syscall is the same. */
8684 if (c
->syscalls_to_be_caught
)
8689 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8691 if (syscall_number
== iter
)
8700 /* Implement the "print_it" breakpoint_ops method for syscall
8703 static enum print_stop_action
8704 print_it_catch_syscall (bpstat bs
)
8706 struct ui_out
*uiout
= current_uiout
;
8707 struct breakpoint
*b
= bs
->breakpoint_at
;
8708 /* These are needed because we want to know in which state a
8709 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8710 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8711 must print "called syscall" or "returned from syscall". */
8713 struct target_waitstatus last
;
8716 get_last_target_status (&ptid
, &last
);
8718 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8720 annotate_catchpoint (b
->number
);
8722 if (b
->disposition
== disp_del
)
8723 ui_out_text (uiout
, "\nTemporary catchpoint ");
8725 ui_out_text (uiout
, "\nCatchpoint ");
8726 if (ui_out_is_mi_like_p (uiout
))
8728 ui_out_field_string (uiout
, "reason",
8729 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8730 ? EXEC_ASYNC_SYSCALL_ENTRY
8731 : EXEC_ASYNC_SYSCALL_RETURN
));
8732 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8734 ui_out_field_int (uiout
, "bkptno", b
->number
);
8736 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8737 ui_out_text (uiout
, " (call to syscall ");
8739 ui_out_text (uiout
, " (returned from syscall ");
8741 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8742 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8744 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8746 ui_out_text (uiout
, "), ");
8748 return PRINT_SRC_AND_LOC
;
8751 /* Implement the "print_one" breakpoint_ops method for syscall
8755 print_one_catch_syscall (struct breakpoint
*b
,
8756 struct bp_location
**last_loc
)
8758 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8759 struct value_print_options opts
;
8760 struct ui_out
*uiout
= current_uiout
;
8762 get_user_print_options (&opts
);
8763 /* Field 4, the address, is omitted (which makes the columns not
8764 line up too nicely with the headers, but the effect is relatively
8766 if (opts
.addressprint
)
8767 ui_out_field_skip (uiout
, "addr");
8770 if (c
->syscalls_to_be_caught
8771 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8772 ui_out_text (uiout
, "syscalls \"");
8774 ui_out_text (uiout
, "syscall \"");
8776 if (c
->syscalls_to_be_caught
)
8779 char *text
= xstrprintf ("%s", "");
8782 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8787 get_syscall_by_number (iter
, &s
);
8790 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8792 text
= xstrprintf ("%s%d, ", text
, iter
);
8794 /* We have to xfree the last 'text' (now stored at 'x')
8795 because xstrprintf dynamically allocates new space for it
8799 /* Remove the last comma. */
8800 text
[strlen (text
) - 2] = '\0';
8801 ui_out_field_string (uiout
, "what", text
);
8804 ui_out_field_string (uiout
, "what", "<any syscall>");
8805 ui_out_text (uiout
, "\" ");
8807 if (ui_out_is_mi_like_p (uiout
))
8808 ui_out_field_string (uiout
, "catch-type", "syscall");
8811 /* Implement the "print_mention" breakpoint_ops method for syscall
8815 print_mention_catch_syscall (struct breakpoint
*b
)
8817 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8819 if (c
->syscalls_to_be_caught
)
8823 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8824 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8826 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8829 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8833 get_syscall_by_number (iter
, &s
);
8836 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8838 printf_filtered (" %d", s
.number
);
8840 printf_filtered (")");
8843 printf_filtered (_("Catchpoint %d (any syscall)"),
8847 /* Implement the "print_recreate" breakpoint_ops method for syscall
8851 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8853 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8855 fprintf_unfiltered (fp
, "catch syscall");
8857 if (c
->syscalls_to_be_caught
)
8862 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8867 get_syscall_by_number (iter
, &s
);
8869 fprintf_unfiltered (fp
, " %s", s
.name
);
8871 fprintf_unfiltered (fp
, " %d", s
.number
);
8874 print_recreate_thread (b
, fp
);
8877 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8879 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8881 /* Returns non-zero if 'b' is a syscall catchpoint. */
8884 syscall_catchpoint_p (struct breakpoint
*b
)
8886 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8889 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8890 is non-zero, then make the breakpoint temporary. If COND_STRING is
8891 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8892 the breakpoint_ops structure associated to the catchpoint. */
8895 init_catchpoint (struct breakpoint
*b
,
8896 struct gdbarch
*gdbarch
, int tempflag
,
8898 const struct breakpoint_ops
*ops
)
8900 struct symtab_and_line sal
;
8903 sal
.pspace
= current_program_space
;
8905 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8907 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8908 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8912 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8914 add_to_breakpoint_chain (b
);
8915 set_breakpoint_number (internal
, b
);
8916 if (is_tracepoint (b
))
8917 set_tracepoint_count (breakpoint_count
);
8920 observer_notify_breakpoint_created (b
);
8923 update_global_location_list (UGLL_MAY_INSERT
);
8927 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8928 int tempflag
, char *cond_string
,
8929 const struct breakpoint_ops
*ops
)
8931 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8933 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8935 c
->forked_inferior_pid
= null_ptid
;
8937 install_breakpoint (0, &c
->base
, 1);
8940 /* Exec catchpoints. */
8942 /* An instance of this type is used to represent an exec catchpoint.
8943 It includes a "struct breakpoint" as a kind of base class; users
8944 downcast to "struct breakpoint *" when needed. A breakpoint is
8945 really of this type iff its ops pointer points to
8946 CATCH_EXEC_BREAKPOINT_OPS. */
8948 struct exec_catchpoint
8950 /* The base class. */
8951 struct breakpoint base
;
8953 /* Filename of a program whose exec triggered this catchpoint.
8954 This field is only valid immediately after this catchpoint has
8956 char *exec_pathname
;
8959 /* Implement the "dtor" breakpoint_ops method for exec
8963 dtor_catch_exec (struct breakpoint
*b
)
8965 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8967 xfree (c
->exec_pathname
);
8969 base_breakpoint_ops
.dtor (b
);
8973 insert_catch_exec (struct bp_location
*bl
)
8975 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8979 remove_catch_exec (struct bp_location
*bl
)
8981 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8985 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8986 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8987 const struct target_waitstatus
*ws
)
8989 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8991 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8994 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8998 static enum print_stop_action
8999 print_it_catch_exec (bpstat bs
)
9001 struct ui_out
*uiout
= current_uiout
;
9002 struct breakpoint
*b
= bs
->breakpoint_at
;
9003 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
9005 annotate_catchpoint (b
->number
);
9006 if (b
->disposition
== disp_del
)
9007 ui_out_text (uiout
, "\nTemporary catchpoint ");
9009 ui_out_text (uiout
, "\nCatchpoint ");
9010 if (ui_out_is_mi_like_p (uiout
))
9012 ui_out_field_string (uiout
, "reason",
9013 async_reason_lookup (EXEC_ASYNC_EXEC
));
9014 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9016 ui_out_field_int (uiout
, "bkptno", b
->number
);
9017 ui_out_text (uiout
, " (exec'd ");
9018 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
9019 ui_out_text (uiout
, "), ");
9021 return PRINT_SRC_AND_LOC
;
9025 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
9027 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
9028 struct value_print_options opts
;
9029 struct ui_out
*uiout
= current_uiout
;
9031 get_user_print_options (&opts
);
9033 /* Field 4, the address, is omitted (which makes the columns
9034 not line up too nicely with the headers, but the effect
9035 is relatively readable). */
9036 if (opts
.addressprint
)
9037 ui_out_field_skip (uiout
, "addr");
9039 ui_out_text (uiout
, "exec");
9040 if (c
->exec_pathname
!= NULL
)
9042 ui_out_text (uiout
, ", program \"");
9043 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
9044 ui_out_text (uiout
, "\" ");
9047 if (ui_out_is_mi_like_p (uiout
))
9048 ui_out_field_string (uiout
, "catch-type", "exec");
9052 print_mention_catch_exec (struct breakpoint
*b
)
9054 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
9057 /* Implement the "print_recreate" breakpoint_ops method for exec
9061 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
9063 fprintf_unfiltered (fp
, "catch exec");
9064 print_recreate_thread (b
, fp
);
9067 static struct breakpoint_ops catch_exec_breakpoint_ops
;
9070 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
9071 const struct breakpoint_ops
*ops
)
9073 struct syscall_catchpoint
*c
;
9074 struct gdbarch
*gdbarch
= get_current_arch ();
9076 c
= XNEW (struct syscall_catchpoint
);
9077 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
9078 c
->syscalls_to_be_caught
= filter
;
9080 install_breakpoint (0, &c
->base
, 1);
9084 hw_breakpoint_used_count (void)
9087 struct breakpoint
*b
;
9088 struct bp_location
*bl
;
9092 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
9093 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9095 /* Special types of hardware breakpoints may use more than
9097 i
+= b
->ops
->resources_needed (bl
);
9104 /* Returns the resources B would use if it were a hardware
9108 hw_watchpoint_use_count (struct breakpoint
*b
)
9111 struct bp_location
*bl
;
9113 if (!breakpoint_enabled (b
))
9116 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9118 /* Special types of hardware watchpoints may use more than
9120 i
+= b
->ops
->resources_needed (bl
);
9126 /* Returns the sum the used resources of all hardware watchpoints of
9127 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9128 the sum of the used resources of all hardware watchpoints of other
9129 types _not_ TYPE. */
9132 hw_watchpoint_used_count_others (struct breakpoint
*except
,
9133 enum bptype type
, int *other_type_used
)
9136 struct breakpoint
*b
;
9138 *other_type_used
= 0;
9143 if (!breakpoint_enabled (b
))
9146 if (b
->type
== type
)
9147 i
+= hw_watchpoint_use_count (b
);
9148 else if (is_hardware_watchpoint (b
))
9149 *other_type_used
= 1;
9156 disable_watchpoints_before_interactive_call_start (void)
9158 struct breakpoint
*b
;
9162 if (is_watchpoint (b
) && breakpoint_enabled (b
))
9164 b
->enable_state
= bp_call_disabled
;
9165 update_global_location_list (UGLL_DONT_INSERT
);
9171 enable_watchpoints_after_interactive_call_stop (void)
9173 struct breakpoint
*b
;
9177 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
9179 b
->enable_state
= bp_enabled
;
9180 update_global_location_list (UGLL_MAY_INSERT
);
9186 disable_breakpoints_before_startup (void)
9188 current_program_space
->executing_startup
= 1;
9189 update_global_location_list (UGLL_DONT_INSERT
);
9193 enable_breakpoints_after_startup (void)
9195 current_program_space
->executing_startup
= 0;
9196 breakpoint_re_set ();
9200 /* Set a breakpoint that will evaporate an end of command
9201 at address specified by SAL.
9202 Restrict it to frame FRAME if FRAME is nonzero. */
9205 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9206 struct frame_id frame_id
, enum bptype type
)
9208 struct breakpoint
*b
;
9210 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9212 gdb_assert (!frame_id_artificial_p (frame_id
));
9214 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9215 b
->enable_state
= bp_enabled
;
9216 b
->disposition
= disp_donttouch
;
9217 b
->frame_id
= frame_id
;
9219 /* If we're debugging a multi-threaded program, then we want
9220 momentary breakpoints to be active in only a single thread of
9222 if (in_thread_list (inferior_ptid
))
9223 b
->thread
= pid_to_thread_id (inferior_ptid
);
9225 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
9230 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9231 The new breakpoint will have type TYPE, use OPS as its
9232 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9234 static struct breakpoint
*
9235 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9237 const struct breakpoint_ops
*ops
,
9240 struct breakpoint
*copy
;
9242 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9243 copy
->loc
= allocate_bp_location (copy
);
9244 set_breakpoint_location_function (copy
->loc
, 1);
9246 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9247 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9248 copy
->loc
->address
= orig
->loc
->address
;
9249 copy
->loc
->section
= orig
->loc
->section
;
9250 copy
->loc
->pspace
= orig
->loc
->pspace
;
9251 copy
->loc
->probe
= orig
->loc
->probe
;
9252 copy
->loc
->line_number
= orig
->loc
->line_number
;
9253 copy
->loc
->symtab
= orig
->loc
->symtab
;
9254 copy
->loc
->enabled
= loc_enabled
;
9255 copy
->frame_id
= orig
->frame_id
;
9256 copy
->thread
= orig
->thread
;
9257 copy
->pspace
= orig
->pspace
;
9259 copy
->enable_state
= bp_enabled
;
9260 copy
->disposition
= disp_donttouch
;
9261 copy
->number
= internal_breakpoint_number
--;
9263 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9267 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9271 clone_momentary_breakpoint (struct breakpoint
*orig
)
9273 /* If there's nothing to clone, then return nothing. */
9277 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9281 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9284 struct symtab_and_line sal
;
9286 sal
= find_pc_line (pc
, 0);
9288 sal
.section
= find_pc_overlay (pc
);
9289 sal
.explicit_pc
= 1;
9291 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9295 /* Tell the user we have just set a breakpoint B. */
9298 mention (struct breakpoint
*b
)
9300 b
->ops
->print_mention (b
);
9301 if (ui_out_is_mi_like_p (current_uiout
))
9303 printf_filtered ("\n");
9307 static struct bp_location
*
9308 add_location_to_breakpoint (struct breakpoint
*b
,
9309 const struct symtab_and_line
*sal
)
9311 struct bp_location
*loc
, **tmp
;
9312 CORE_ADDR adjusted_address
;
9313 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9315 if (loc_gdbarch
== NULL
)
9316 loc_gdbarch
= b
->gdbarch
;
9318 /* Adjust the breakpoint's address prior to allocating a location.
9319 Once we call allocate_bp_location(), that mostly uninitialized
9320 location will be placed on the location chain. Adjustment of the
9321 breakpoint may cause target_read_memory() to be called and we do
9322 not want its scan of the location chain to find a breakpoint and
9323 location that's only been partially initialized. */
9324 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9327 /* Sort the locations by their ADDRESS. */
9328 loc
= allocate_bp_location (b
);
9329 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9330 tmp
= &((*tmp
)->next
))
9335 loc
->requested_address
= sal
->pc
;
9336 loc
->address
= adjusted_address
;
9337 loc
->pspace
= sal
->pspace
;
9338 loc
->probe
.probe
= sal
->probe
;
9339 loc
->probe
.objfile
= sal
->objfile
;
9340 gdb_assert (loc
->pspace
!= NULL
);
9341 loc
->section
= sal
->section
;
9342 loc
->gdbarch
= loc_gdbarch
;
9343 loc
->line_number
= sal
->line
;
9344 loc
->symtab
= sal
->symtab
;
9346 set_breakpoint_location_function (loc
,
9347 sal
->explicit_pc
|| sal
->explicit_line
);
9352 /* Return 1 if LOC is pointing to a permanent breakpoint,
9353 return 0 otherwise. */
9356 bp_loc_is_permanent (struct bp_location
*loc
)
9360 const gdb_byte
*bpoint
;
9361 gdb_byte
*target_mem
;
9362 struct cleanup
*cleanup
;
9365 gdb_assert (loc
!= NULL
);
9367 addr
= loc
->address
;
9368 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9370 /* Software breakpoints unsupported? */
9374 target_mem
= alloca (len
);
9376 /* Enable the automatic memory restoration from breakpoints while
9377 we read the memory. Otherwise we could say about our temporary
9378 breakpoints they are permanent. */
9379 cleanup
= save_current_space_and_thread ();
9381 switch_to_program_space_and_thread (loc
->pspace
);
9382 make_show_memory_breakpoints_cleanup (0);
9384 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9385 && memcmp (target_mem
, bpoint
, len
) == 0)
9388 do_cleanups (cleanup
);
9393 /* Build a command list for the dprintf corresponding to the current
9394 settings of the dprintf style options. */
9397 update_dprintf_command_list (struct breakpoint
*b
)
9399 char *dprintf_args
= b
->extra_string
;
9400 char *printf_line
= NULL
;
9405 dprintf_args
= skip_spaces (dprintf_args
);
9407 /* Allow a comma, as it may have terminated a location, but don't
9409 if (*dprintf_args
== ',')
9411 dprintf_args
= skip_spaces (dprintf_args
);
9413 if (*dprintf_args
!= '"')
9414 error (_("Bad format string, missing '\"'."));
9416 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9417 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9418 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9420 if (!dprintf_function
)
9421 error (_("No function supplied for dprintf call"));
9423 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9424 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9429 printf_line
= xstrprintf ("call (void) %s (%s)",
9433 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9435 if (target_can_run_breakpoint_commands ())
9436 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9439 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9440 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9444 internal_error (__FILE__
, __LINE__
,
9445 _("Invalid dprintf style."));
9447 gdb_assert (printf_line
!= NULL
);
9448 /* Manufacture a printf sequence. */
9450 struct command_line
*printf_cmd_line
9451 = xmalloc (sizeof (struct command_line
));
9453 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9454 printf_cmd_line
->control_type
= simple_control
;
9455 printf_cmd_line
->body_count
= 0;
9456 printf_cmd_line
->body_list
= NULL
;
9457 printf_cmd_line
->next
= NULL
;
9458 printf_cmd_line
->line
= printf_line
;
9460 breakpoint_set_commands (b
, printf_cmd_line
);
9464 /* Update all dprintf commands, making their command lists reflect
9465 current style settings. */
9468 update_dprintf_commands (char *args
, int from_tty
,
9469 struct cmd_list_element
*c
)
9471 struct breakpoint
*b
;
9475 if (b
->type
== bp_dprintf
)
9476 update_dprintf_command_list (b
);
9480 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9481 as textual description of the location, and COND_STRING
9482 as condition expression. */
9485 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9486 struct symtabs_and_lines sals
, char *addr_string
,
9487 char *filter
, char *cond_string
,
9489 enum bptype type
, enum bpdisp disposition
,
9490 int thread
, int task
, int ignore_count
,
9491 const struct breakpoint_ops
*ops
, int from_tty
,
9492 int enabled
, int internal
, unsigned flags
,
9493 int display_canonical
)
9497 if (type
== bp_hardware_breakpoint
)
9499 int target_resources_ok
;
9501 i
= hw_breakpoint_used_count ();
9502 target_resources_ok
=
9503 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9505 if (target_resources_ok
== 0)
9506 error (_("No hardware breakpoint support in the target."));
9507 else if (target_resources_ok
< 0)
9508 error (_("Hardware breakpoints used exceeds limit."));
9511 gdb_assert (sals
.nelts
> 0);
9513 for (i
= 0; i
< sals
.nelts
; ++i
)
9515 struct symtab_and_line sal
= sals
.sals
[i
];
9516 struct bp_location
*loc
;
9520 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9522 loc_gdbarch
= gdbarch
;
9524 describe_other_breakpoints (loc_gdbarch
,
9525 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9530 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9534 b
->cond_string
= cond_string
;
9535 b
->extra_string
= extra_string
;
9536 b
->ignore_count
= ignore_count
;
9537 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9538 b
->disposition
= disposition
;
9540 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9541 b
->loc
->inserted
= 1;
9543 if (type
== bp_static_tracepoint
)
9545 struct tracepoint
*t
= (struct tracepoint
*) b
;
9546 struct static_tracepoint_marker marker
;
9548 if (strace_marker_p (b
))
9550 /* We already know the marker exists, otherwise, we
9551 wouldn't see a sal for it. */
9552 char *p
= &addr_string
[3];
9556 p
= skip_spaces (p
);
9558 endp
= skip_to_space (p
);
9560 marker_str
= savestring (p
, endp
- p
);
9561 t
->static_trace_marker_id
= marker_str
;
9563 printf_filtered (_("Probed static tracepoint "
9565 t
->static_trace_marker_id
);
9567 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9569 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9570 release_static_tracepoint_marker (&marker
);
9572 printf_filtered (_("Probed static tracepoint "
9574 t
->static_trace_marker_id
);
9577 warning (_("Couldn't determine the static "
9578 "tracepoint marker to probe"));
9585 loc
= add_location_to_breakpoint (b
, &sal
);
9586 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9590 if (bp_loc_is_permanent (loc
))
9591 make_breakpoint_permanent (b
);
9595 const char *arg
= b
->cond_string
;
9597 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9598 block_for_pc (loc
->address
), 0);
9600 error (_("Garbage '%s' follows condition"), arg
);
9603 /* Dynamic printf requires and uses additional arguments on the
9604 command line, otherwise it's an error. */
9605 if (type
== bp_dprintf
)
9607 if (b
->extra_string
)
9608 update_dprintf_command_list (b
);
9610 error (_("Format string required"));
9612 else if (b
->extra_string
)
9613 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9616 b
->display_canonical
= display_canonical
;
9618 b
->addr_string
= addr_string
;
9620 /* addr_string has to be used or breakpoint_re_set will delete
9623 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9628 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9629 struct symtabs_and_lines sals
, char *addr_string
,
9630 char *filter
, char *cond_string
,
9632 enum bptype type
, enum bpdisp disposition
,
9633 int thread
, int task
, int ignore_count
,
9634 const struct breakpoint_ops
*ops
, int from_tty
,
9635 int enabled
, int internal
, unsigned flags
,
9636 int display_canonical
)
9638 struct breakpoint
*b
;
9639 struct cleanup
*old_chain
;
9641 if (is_tracepoint_type (type
))
9643 struct tracepoint
*t
;
9645 t
= XCNEW (struct tracepoint
);
9649 b
= XNEW (struct breakpoint
);
9651 old_chain
= make_cleanup (xfree
, b
);
9653 init_breakpoint_sal (b
, gdbarch
,
9655 filter
, cond_string
, extra_string
,
9657 thread
, task
, ignore_count
,
9659 enabled
, internal
, flags
,
9661 discard_cleanups (old_chain
);
9663 install_breakpoint (internal
, b
, 0);
9666 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9667 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9668 value. COND_STRING, if not NULL, specified the condition to be
9669 used for all breakpoints. Essentially the only case where
9670 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9671 function. In that case, it's still not possible to specify
9672 separate conditions for different overloaded functions, so
9673 we take just a single condition string.
9675 NOTE: If the function succeeds, the caller is expected to cleanup
9676 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9677 array contents). If the function fails (error() is called), the
9678 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9679 COND and SALS arrays and each of those arrays contents. */
9682 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9683 struct linespec_result
*canonical
,
9684 char *cond_string
, char *extra_string
,
9685 enum bptype type
, enum bpdisp disposition
,
9686 int thread
, int task
, int ignore_count
,
9687 const struct breakpoint_ops
*ops
, int from_tty
,
9688 int enabled
, int internal
, unsigned flags
)
9691 struct linespec_sals
*lsal
;
9693 if (canonical
->pre_expanded
)
9694 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9696 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9698 /* Note that 'addr_string' can be NULL in the case of a plain
9699 'break', without arguments. */
9700 char *addr_string
= (canonical
->addr_string
9701 ? xstrdup (canonical
->addr_string
)
9703 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9704 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9706 make_cleanup (xfree
, filter_string
);
9707 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9710 cond_string
, extra_string
,
9712 thread
, task
, ignore_count
, ops
,
9713 from_tty
, enabled
, internal
, flags
,
9714 canonical
->special_display
);
9715 discard_cleanups (inner
);
9719 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9720 followed by conditionals. On return, SALS contains an array of SAL
9721 addresses found. ADDR_STRING contains a vector of (canonical)
9722 address strings. ADDRESS points to the end of the SAL.
9724 The array and the line spec strings are allocated on the heap, it is
9725 the caller's responsibility to free them. */
9728 parse_breakpoint_sals (char **address
,
9729 struct linespec_result
*canonical
)
9731 /* If no arg given, or if first arg is 'if ', use the default
9733 if ((*address
) == NULL
9734 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9736 /* The last displayed codepoint, if it's valid, is our default breakpoint
9738 if (last_displayed_sal_is_valid ())
9740 struct linespec_sals lsal
;
9741 struct symtab_and_line sal
;
9744 init_sal (&sal
); /* Initialize to zeroes. */
9745 lsal
.sals
.sals
= (struct symtab_and_line
*)
9746 xmalloc (sizeof (struct symtab_and_line
));
9748 /* Set sal's pspace, pc, symtab, and line to the values
9749 corresponding to the last call to print_frame_info.
9750 Be sure to reinitialize LINE with NOTCURRENT == 0
9751 as the breakpoint line number is inappropriate otherwise.
9752 find_pc_line would adjust PC, re-set it back. */
9753 get_last_displayed_sal (&sal
);
9755 sal
= find_pc_line (pc
, 0);
9757 /* "break" without arguments is equivalent to "break *PC"
9758 where PC is the last displayed codepoint's address. So
9759 make sure to set sal.explicit_pc to prevent GDB from
9760 trying to expand the list of sals to include all other
9761 instances with the same symtab and line. */
9763 sal
.explicit_pc
= 1;
9765 lsal
.sals
.sals
[0] = sal
;
9766 lsal
.sals
.nelts
= 1;
9767 lsal
.canonical
= NULL
;
9769 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9772 error (_("No default breakpoint address now."));
9776 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9778 /* Force almost all breakpoints to be in terms of the
9779 current_source_symtab (which is decode_line_1's default).
9780 This should produce the results we want almost all of the
9781 time while leaving default_breakpoint_* alone.
9783 ObjC: However, don't match an Objective-C method name which
9784 may have a '+' or '-' succeeded by a '['. */
9785 if (last_displayed_sal_is_valid ()
9787 || ((strchr ("+-", (*address
)[0]) != NULL
)
9788 && ((*address
)[1] != '['))))
9789 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9790 get_last_displayed_symtab (),
9791 get_last_displayed_line (),
9792 canonical
, NULL
, NULL
);
9794 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9795 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9800 /* Convert each SAL into a real PC. Verify that the PC can be
9801 inserted as a breakpoint. If it can't throw an error. */
9804 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9808 for (i
= 0; i
< sals
->nelts
; i
++)
9809 resolve_sal_pc (&sals
->sals
[i
]);
9812 /* Fast tracepoints may have restrictions on valid locations. For
9813 instance, a fast tracepoint using a jump instead of a trap will
9814 likely have to overwrite more bytes than a trap would, and so can
9815 only be placed where the instruction is longer than the jump, or a
9816 multi-instruction sequence does not have a jump into the middle of
9820 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9821 struct symtabs_and_lines
*sals
)
9824 struct symtab_and_line
*sal
;
9826 struct cleanup
*old_chain
;
9828 for (i
= 0; i
< sals
->nelts
; i
++)
9830 struct gdbarch
*sarch
;
9832 sal
= &sals
->sals
[i
];
9834 sarch
= get_sal_arch (*sal
);
9835 /* We fall back to GDBARCH if there is no architecture
9836 associated with SAL. */
9839 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9841 old_chain
= make_cleanup (xfree
, msg
);
9844 error (_("May not have a fast tracepoint at 0x%s%s"),
9845 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9847 do_cleanups (old_chain
);
9851 /* Issue an invalid thread ID error. */
9853 static void ATTRIBUTE_NORETURN
9854 invalid_thread_id_error (int id
)
9856 error (_("Unknown thread %d."), id
);
9859 /* Given TOK, a string specification of condition and thread, as
9860 accepted by the 'break' command, extract the condition
9861 string and thread number and set *COND_STRING and *THREAD.
9862 PC identifies the context at which the condition should be parsed.
9863 If no condition is found, *COND_STRING is set to NULL.
9864 If no thread is found, *THREAD is set to -1. */
9867 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9868 char **cond_string
, int *thread
, int *task
,
9871 *cond_string
= NULL
;
9878 const char *end_tok
;
9880 const char *cond_start
= NULL
;
9881 const char *cond_end
= NULL
;
9883 tok
= skip_spaces_const (tok
);
9885 if ((*tok
== '"' || *tok
== ',') && rest
)
9887 *rest
= savestring (tok
, strlen (tok
));
9891 end_tok
= skip_to_space_const (tok
);
9893 toklen
= end_tok
- tok
;
9895 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9897 struct expression
*expr
;
9899 tok
= cond_start
= end_tok
+ 1;
9900 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9903 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9905 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9910 *thread
= strtol (tok
, &tmptok
, 0);
9912 error (_("Junk after thread keyword."));
9913 if (!valid_thread_id (*thread
))
9914 invalid_thread_id_error (*thread
);
9917 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9922 *task
= strtol (tok
, &tmptok
, 0);
9924 error (_("Junk after task keyword."));
9925 if (!valid_task_id (*task
))
9926 error (_("Unknown task %d."), *task
);
9931 *rest
= savestring (tok
, strlen (tok
));
9935 error (_("Junk at end of arguments."));
9939 /* Decode a static tracepoint marker spec. */
9941 static struct symtabs_and_lines
9942 decode_static_tracepoint_spec (char **arg_p
)
9944 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9945 struct symtabs_and_lines sals
;
9946 struct cleanup
*old_chain
;
9947 char *p
= &(*arg_p
)[3];
9952 p
= skip_spaces (p
);
9954 endp
= skip_to_space (p
);
9956 marker_str
= savestring (p
, endp
- p
);
9957 old_chain
= make_cleanup (xfree
, marker_str
);
9959 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9960 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9961 error (_("No known static tracepoint marker named %s"), marker_str
);
9963 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9964 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9966 for (i
= 0; i
< sals
.nelts
; i
++)
9968 struct static_tracepoint_marker
*marker
;
9970 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9972 init_sal (&sals
.sals
[i
]);
9974 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9975 sals
.sals
[i
].pc
= marker
->address
;
9977 release_static_tracepoint_marker (marker
);
9980 do_cleanups (old_chain
);
9986 /* Set a breakpoint. This function is shared between CLI and MI
9987 functions for setting a breakpoint. This function has two major
9988 modes of operations, selected by the PARSE_ARG parameter. If
9989 non-zero, the function will parse ARG, extracting location,
9990 condition, thread and extra string. Otherwise, ARG is just the
9991 breakpoint's location, with condition, thread, and extra string
9992 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9993 If INTERNAL is non-zero, the breakpoint number will be allocated
9994 from the internal breakpoint count. Returns true if any breakpoint
9995 was created; false otherwise. */
9998 create_breakpoint (struct gdbarch
*gdbarch
,
9999 char *arg
, char *cond_string
,
10000 int thread
, char *extra_string
,
10002 int tempflag
, enum bptype type_wanted
,
10004 enum auto_boolean pending_break_support
,
10005 const struct breakpoint_ops
*ops
,
10006 int from_tty
, int enabled
, int internal
,
10009 volatile struct gdb_exception e
;
10010 char *copy_arg
= NULL
;
10011 char *addr_start
= arg
;
10012 struct linespec_result canonical
;
10013 struct cleanup
*old_chain
;
10014 struct cleanup
*bkpt_chain
= NULL
;
10017 int prev_bkpt_count
= breakpoint_count
;
10019 gdb_assert (ops
!= NULL
);
10021 init_linespec_result (&canonical
);
10023 TRY_CATCH (e
, RETURN_MASK_ALL
)
10025 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
10026 addr_start
, ©_arg
);
10029 /* If caller is interested in rc value from parse, set value. */
10033 if (VEC_empty (linespec_sals
, canonical
.sals
))
10039 case NOT_FOUND_ERROR
:
10041 /* If pending breakpoint support is turned off, throw
10044 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
10045 throw_exception (e
);
10047 exception_print (gdb_stderr
, e
);
10049 /* If pending breakpoint support is auto query and the user
10050 selects no, then simply return the error code. */
10051 if (pending_break_support
== AUTO_BOOLEAN_AUTO
10052 && !nquery (_("Make %s pending on future shared library load? "),
10053 bptype_string (type_wanted
)))
10056 /* At this point, either the user was queried about setting
10057 a pending breakpoint and selected yes, or pending
10058 breakpoint behavior is on and thus a pending breakpoint
10059 is defaulted on behalf of the user. */
10061 struct linespec_sals lsal
;
10063 copy_arg
= xstrdup (addr_start
);
10064 lsal
.canonical
= xstrdup (copy_arg
);
10065 lsal
.sals
.nelts
= 1;
10066 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
10067 init_sal (&lsal
.sals
.sals
[0]);
10069 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
10073 throw_exception (e
);
10077 throw_exception (e
);
10080 /* Create a chain of things that always need to be cleaned up. */
10081 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
10083 /* ----------------------------- SNIP -----------------------------
10084 Anything added to the cleanup chain beyond this point is assumed
10085 to be part of a breakpoint. If the breakpoint create succeeds
10086 then the memory is not reclaimed. */
10087 bkpt_chain
= make_cleanup (null_cleanup
, 0);
10089 /* Resolve all line numbers to PC's and verify that the addresses
10090 are ok for the target. */
10094 struct linespec_sals
*iter
;
10096 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10097 breakpoint_sals_to_pc (&iter
->sals
);
10100 /* Fast tracepoints may have additional restrictions on location. */
10101 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
10104 struct linespec_sals
*iter
;
10106 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10107 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
10110 /* Verify that condition can be parsed, before setting any
10111 breakpoints. Allocate a separate condition expression for each
10118 struct linespec_sals
*lsal
;
10120 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
10122 /* Here we only parse 'arg' to separate condition
10123 from thread number, so parsing in context of first
10124 sal is OK. When setting the breakpoint we'll
10125 re-parse it in context of each sal. */
10127 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
10128 &thread
, &task
, &rest
);
10130 make_cleanup (xfree
, cond_string
);
10132 make_cleanup (xfree
, rest
);
10134 extra_string
= rest
;
10139 error (_("Garbage '%s' at end of location"), arg
);
10141 /* Create a private copy of condition string. */
10144 cond_string
= xstrdup (cond_string
);
10145 make_cleanup (xfree
, cond_string
);
10147 /* Create a private copy of any extra string. */
10150 extra_string
= xstrdup (extra_string
);
10151 make_cleanup (xfree
, extra_string
);
10155 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
10156 cond_string
, extra_string
, type_wanted
,
10157 tempflag
? disp_del
: disp_donttouch
,
10158 thread
, task
, ignore_count
, ops
,
10159 from_tty
, enabled
, internal
, flags
);
10163 struct breakpoint
*b
;
10165 make_cleanup (xfree
, copy_arg
);
10167 if (is_tracepoint_type (type_wanted
))
10169 struct tracepoint
*t
;
10171 t
= XCNEW (struct tracepoint
);
10175 b
= XNEW (struct breakpoint
);
10177 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
10179 b
->addr_string
= copy_arg
;
10181 b
->cond_string
= NULL
;
10184 /* Create a private copy of condition string. */
10187 cond_string
= xstrdup (cond_string
);
10188 make_cleanup (xfree
, cond_string
);
10190 b
->cond_string
= cond_string
;
10192 b
->extra_string
= NULL
;
10193 b
->ignore_count
= ignore_count
;
10194 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10195 b
->condition_not_parsed
= 1;
10196 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10197 if ((type_wanted
!= bp_breakpoint
10198 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
10199 b
->pspace
= current_program_space
;
10201 install_breakpoint (internal
, b
, 0);
10204 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
10206 warning (_("Multiple breakpoints were set.\nUse the "
10207 "\"delete\" command to delete unwanted breakpoints."));
10208 prev_breakpoint_count
= prev_bkpt_count
;
10211 /* That's it. Discard the cleanups for data inserted into the
10213 discard_cleanups (bkpt_chain
);
10214 /* But cleanup everything else. */
10215 do_cleanups (old_chain
);
10217 /* error call may happen here - have BKPT_CHAIN already discarded. */
10218 update_global_location_list (UGLL_MAY_INSERT
);
10223 /* Set a breakpoint.
10224 ARG is a string describing breakpoint address,
10225 condition, and thread.
10226 FLAG specifies if a breakpoint is hardware on,
10227 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10228 and BP_TEMPFLAG. */
10231 break_command_1 (char *arg
, int flag
, int from_tty
)
10233 int tempflag
= flag
& BP_TEMPFLAG
;
10234 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10235 ? bp_hardware_breakpoint
10237 struct breakpoint_ops
*ops
;
10238 const char *arg_cp
= arg
;
10240 /* Matching breakpoints on probes. */
10241 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10242 ops
= &bkpt_probe_breakpoint_ops
;
10244 ops
= &bkpt_breakpoint_ops
;
10246 create_breakpoint (get_current_arch (),
10248 NULL
, 0, NULL
, 1 /* parse arg */,
10249 tempflag
, type_wanted
,
10250 0 /* Ignore count */,
10251 pending_break_support
,
10259 /* Helper function for break_command_1 and disassemble_command. */
10262 resolve_sal_pc (struct symtab_and_line
*sal
)
10266 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10268 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10269 error (_("No line %d in file \"%s\"."),
10270 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10273 /* If this SAL corresponds to a breakpoint inserted using a line
10274 number, then skip the function prologue if necessary. */
10275 if (sal
->explicit_line
)
10276 skip_prologue_sal (sal
);
10279 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10281 const struct blockvector
*bv
;
10282 const struct block
*b
;
10283 struct symbol
*sym
;
10285 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
10288 sym
= block_linkage_function (b
);
10291 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
10292 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
10296 /* It really is worthwhile to have the section, so we'll
10297 just have to look harder. This case can be executed
10298 if we have line numbers but no functions (as can
10299 happen in assembly source). */
10301 struct bound_minimal_symbol msym
;
10302 struct cleanup
*old_chain
= save_current_space_and_thread ();
10304 switch_to_program_space_and_thread (sal
->pspace
);
10306 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10308 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10310 do_cleanups (old_chain
);
10317 break_command (char *arg
, int from_tty
)
10319 break_command_1 (arg
, 0, from_tty
);
10323 tbreak_command (char *arg
, int from_tty
)
10325 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10329 hbreak_command (char *arg
, int from_tty
)
10331 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10335 thbreak_command (char *arg
, int from_tty
)
10337 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10341 stop_command (char *arg
, int from_tty
)
10343 printf_filtered (_("Specify the type of breakpoint to set.\n\
10344 Usage: stop in <function | address>\n\
10345 stop at <line>\n"));
10349 stopin_command (char *arg
, int from_tty
)
10353 if (arg
== (char *) NULL
)
10355 else if (*arg
!= '*')
10357 char *argptr
= arg
;
10360 /* Look for a ':'. If this is a line number specification, then
10361 say it is bad, otherwise, it should be an address or
10362 function/method name. */
10363 while (*argptr
&& !hasColon
)
10365 hasColon
= (*argptr
== ':');
10370 badInput
= (*argptr
!= ':'); /* Not a class::method */
10372 badInput
= isdigit (*arg
); /* a simple line number */
10376 printf_filtered (_("Usage: stop in <function | address>\n"));
10378 break_command_1 (arg
, 0, from_tty
);
10382 stopat_command (char *arg
, int from_tty
)
10386 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10390 char *argptr
= arg
;
10393 /* Look for a ':'. If there is a '::' then get out, otherwise
10394 it is probably a line number. */
10395 while (*argptr
&& !hasColon
)
10397 hasColon
= (*argptr
== ':');
10402 badInput
= (*argptr
== ':'); /* we have class::method */
10404 badInput
= !isdigit (*arg
); /* not a line number */
10408 printf_filtered (_("Usage: stop at <line>\n"));
10410 break_command_1 (arg
, 0, from_tty
);
10413 /* The dynamic printf command is mostly like a regular breakpoint, but
10414 with a prewired command list consisting of a single output command,
10415 built from extra arguments supplied on the dprintf command
10419 dprintf_command (char *arg
, int from_tty
)
10421 create_breakpoint (get_current_arch (),
10423 NULL
, 0, NULL
, 1 /* parse arg */,
10425 0 /* Ignore count */,
10426 pending_break_support
,
10427 &dprintf_breakpoint_ops
,
10435 agent_printf_command (char *arg
, int from_tty
)
10437 error (_("May only run agent-printf on the target"));
10440 /* Implement the "breakpoint_hit" breakpoint_ops method for
10441 ranged breakpoints. */
10444 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10445 struct address_space
*aspace
,
10447 const struct target_waitstatus
*ws
)
10449 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10450 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10453 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10454 bl
->length
, aspace
, bp_addr
);
10457 /* Implement the "resources_needed" breakpoint_ops method for
10458 ranged breakpoints. */
10461 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10463 return target_ranged_break_num_registers ();
10466 /* Implement the "print_it" breakpoint_ops method for
10467 ranged breakpoints. */
10469 static enum print_stop_action
10470 print_it_ranged_breakpoint (bpstat bs
)
10472 struct breakpoint
*b
= bs
->breakpoint_at
;
10473 struct bp_location
*bl
= b
->loc
;
10474 struct ui_out
*uiout
= current_uiout
;
10476 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10478 /* Ranged breakpoints have only one location. */
10479 gdb_assert (bl
&& bl
->next
== NULL
);
10481 annotate_breakpoint (b
->number
);
10482 if (b
->disposition
== disp_del
)
10483 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10485 ui_out_text (uiout
, "\nRanged breakpoint ");
10486 if (ui_out_is_mi_like_p (uiout
))
10488 ui_out_field_string (uiout
, "reason",
10489 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10490 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10492 ui_out_field_int (uiout
, "bkptno", b
->number
);
10493 ui_out_text (uiout
, ", ");
10495 return PRINT_SRC_AND_LOC
;
10498 /* Implement the "print_one" breakpoint_ops method for
10499 ranged breakpoints. */
10502 print_one_ranged_breakpoint (struct breakpoint
*b
,
10503 struct bp_location
**last_loc
)
10505 struct bp_location
*bl
= b
->loc
;
10506 struct value_print_options opts
;
10507 struct ui_out
*uiout
= current_uiout
;
10509 /* Ranged breakpoints have only one location. */
10510 gdb_assert (bl
&& bl
->next
== NULL
);
10512 get_user_print_options (&opts
);
10514 if (opts
.addressprint
)
10515 /* We don't print the address range here, it will be printed later
10516 by print_one_detail_ranged_breakpoint. */
10517 ui_out_field_skip (uiout
, "addr");
10518 annotate_field (5);
10519 print_breakpoint_location (b
, bl
);
10523 /* Implement the "print_one_detail" breakpoint_ops method for
10524 ranged breakpoints. */
10527 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10528 struct ui_out
*uiout
)
10530 CORE_ADDR address_start
, address_end
;
10531 struct bp_location
*bl
= b
->loc
;
10532 struct ui_file
*stb
= mem_fileopen ();
10533 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10537 address_start
= bl
->address
;
10538 address_end
= address_start
+ bl
->length
- 1;
10540 ui_out_text (uiout
, "\taddress range: ");
10541 fprintf_unfiltered (stb
, "[%s, %s]",
10542 print_core_address (bl
->gdbarch
, address_start
),
10543 print_core_address (bl
->gdbarch
, address_end
));
10544 ui_out_field_stream (uiout
, "addr", stb
);
10545 ui_out_text (uiout
, "\n");
10547 do_cleanups (cleanup
);
10550 /* Implement the "print_mention" breakpoint_ops method for
10551 ranged breakpoints. */
10554 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10556 struct bp_location
*bl
= b
->loc
;
10557 struct ui_out
*uiout
= current_uiout
;
10560 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10562 if (ui_out_is_mi_like_p (uiout
))
10565 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10566 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10567 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10570 /* Implement the "print_recreate" breakpoint_ops method for
10571 ranged breakpoints. */
10574 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10576 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10577 b
->addr_string_range_end
);
10578 print_recreate_thread (b
, fp
);
10581 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10583 static struct breakpoint_ops ranged_breakpoint_ops
;
10585 /* Find the address where the end of the breakpoint range should be
10586 placed, given the SAL of the end of the range. This is so that if
10587 the user provides a line number, the end of the range is set to the
10588 last instruction of the given line. */
10591 find_breakpoint_range_end (struct symtab_and_line sal
)
10595 /* If the user provided a PC value, use it. Otherwise,
10596 find the address of the end of the given location. */
10597 if (sal
.explicit_pc
)
10604 ret
= find_line_pc_range (sal
, &start
, &end
);
10606 error (_("Could not find location of the end of the range."));
10608 /* find_line_pc_range returns the start of the next line. */
10615 /* Implement the "break-range" CLI command. */
10618 break_range_command (char *arg
, int from_tty
)
10620 char *arg_start
, *addr_string_start
, *addr_string_end
;
10621 struct linespec_result canonical_start
, canonical_end
;
10622 int bp_count
, can_use_bp
, length
;
10624 struct breakpoint
*b
;
10625 struct symtab_and_line sal_start
, sal_end
;
10626 struct cleanup
*cleanup_bkpt
;
10627 struct linespec_sals
*lsal_start
, *lsal_end
;
10629 /* We don't support software ranged breakpoints. */
10630 if (target_ranged_break_num_registers () < 0)
10631 error (_("This target does not support hardware ranged breakpoints."));
10633 bp_count
= hw_breakpoint_used_count ();
10634 bp_count
+= target_ranged_break_num_registers ();
10635 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10637 if (can_use_bp
< 0)
10638 error (_("Hardware breakpoints used exceeds limit."));
10640 arg
= skip_spaces (arg
);
10641 if (arg
== NULL
|| arg
[0] == '\0')
10642 error(_("No address range specified."));
10644 init_linespec_result (&canonical_start
);
10647 parse_breakpoint_sals (&arg
, &canonical_start
);
10649 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10652 error (_("Too few arguments."));
10653 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10654 error (_("Could not find location of the beginning of the range."));
10656 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10658 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10659 || lsal_start
->sals
.nelts
!= 1)
10660 error (_("Cannot create a ranged breakpoint with multiple locations."));
10662 sal_start
= lsal_start
->sals
.sals
[0];
10663 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10664 make_cleanup (xfree
, addr_string_start
);
10666 arg
++; /* Skip the comma. */
10667 arg
= skip_spaces (arg
);
10669 /* Parse the end location. */
10671 init_linespec_result (&canonical_end
);
10674 /* We call decode_line_full directly here instead of using
10675 parse_breakpoint_sals because we need to specify the start location's
10676 symtab and line as the default symtab and line for the end of the
10677 range. This makes it possible to have ranges like "foo.c:27, +14",
10678 where +14 means 14 lines from the start location. */
10679 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10680 sal_start
.symtab
, sal_start
.line
,
10681 &canonical_end
, NULL
, NULL
);
10683 make_cleanup_destroy_linespec_result (&canonical_end
);
10685 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10686 error (_("Could not find location of the end of the range."));
10688 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10689 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10690 || lsal_end
->sals
.nelts
!= 1)
10691 error (_("Cannot create a ranged breakpoint with multiple locations."));
10693 sal_end
= lsal_end
->sals
.sals
[0];
10694 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10695 make_cleanup (xfree
, addr_string_end
);
10697 end
= find_breakpoint_range_end (sal_end
);
10698 if (sal_start
.pc
> end
)
10699 error (_("Invalid address range, end precedes start."));
10701 length
= end
- sal_start
.pc
+ 1;
10703 /* Length overflowed. */
10704 error (_("Address range too large."));
10705 else if (length
== 1)
10707 /* This range is simple enough to be handled by
10708 the `hbreak' command. */
10709 hbreak_command (addr_string_start
, 1);
10711 do_cleanups (cleanup_bkpt
);
10716 /* Now set up the breakpoint. */
10717 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10718 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10719 set_breakpoint_count (breakpoint_count
+ 1);
10720 b
->number
= breakpoint_count
;
10721 b
->disposition
= disp_donttouch
;
10722 b
->addr_string
= xstrdup (addr_string_start
);
10723 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10724 b
->loc
->length
= length
;
10726 do_cleanups (cleanup_bkpt
);
10729 observer_notify_breakpoint_created (b
);
10730 update_global_location_list (UGLL_MAY_INSERT
);
10733 /* Return non-zero if EXP is verified as constant. Returned zero
10734 means EXP is variable. Also the constant detection may fail for
10735 some constant expressions and in such case still falsely return
10739 watchpoint_exp_is_const (const struct expression
*exp
)
10741 int i
= exp
->nelts
;
10747 /* We are only interested in the descriptor of each element. */
10748 operator_length (exp
, i
, &oplenp
, &argsp
);
10751 switch (exp
->elts
[i
].opcode
)
10761 case BINOP_LOGICAL_AND
:
10762 case BINOP_LOGICAL_OR
:
10763 case BINOP_BITWISE_AND
:
10764 case BINOP_BITWISE_IOR
:
10765 case BINOP_BITWISE_XOR
:
10767 case BINOP_NOTEQUAL
:
10794 case OP_OBJC_NSSTRING
:
10797 case UNOP_LOGICAL_NOT
:
10798 case UNOP_COMPLEMENT
:
10803 case UNOP_CAST_TYPE
:
10804 case UNOP_REINTERPRET_CAST
:
10805 case UNOP_DYNAMIC_CAST
:
10806 /* Unary, binary and ternary operators: We have to check
10807 their operands. If they are constant, then so is the
10808 result of that operation. For instance, if A and B are
10809 determined to be constants, then so is "A + B".
10811 UNOP_IND is one exception to the rule above, because the
10812 value of *ADDR is not necessarily a constant, even when
10817 /* Check whether the associated symbol is a constant.
10819 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10820 possible that a buggy compiler could mark a variable as
10821 constant even when it is not, and TYPE_CONST would return
10822 true in this case, while SYMBOL_CLASS wouldn't.
10824 We also have to check for function symbols because they
10825 are always constant. */
10827 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10829 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10830 && SYMBOL_CLASS (s
) != LOC_CONST
10831 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10836 /* The default action is to return 0 because we are using
10837 the optimistic approach here: If we don't know something,
10838 then it is not a constant. */
10847 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10850 dtor_watchpoint (struct breakpoint
*self
)
10852 struct watchpoint
*w
= (struct watchpoint
*) self
;
10854 xfree (w
->cond_exp
);
10856 xfree (w
->exp_string
);
10857 xfree (w
->exp_string_reparse
);
10858 value_free (w
->val
);
10860 base_breakpoint_ops
.dtor (self
);
10863 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10866 re_set_watchpoint (struct breakpoint
*b
)
10868 struct watchpoint
*w
= (struct watchpoint
*) b
;
10870 /* Watchpoint can be either on expression using entirely global
10871 variables, or it can be on local variables.
10873 Watchpoints of the first kind are never auto-deleted, and even
10874 persist across program restarts. Since they can use variables
10875 from shared libraries, we need to reparse expression as libraries
10876 are loaded and unloaded.
10878 Watchpoints on local variables can also change meaning as result
10879 of solib event. For example, if a watchpoint uses both a local
10880 and a global variables in expression, it's a local watchpoint,
10881 but unloading of a shared library will make the expression
10882 invalid. This is not a very common use case, but we still
10883 re-evaluate expression, to avoid surprises to the user.
10885 Note that for local watchpoints, we re-evaluate it only if
10886 watchpoints frame id is still valid. If it's not, it means the
10887 watchpoint is out of scope and will be deleted soon. In fact,
10888 I'm not sure we'll ever be called in this case.
10890 If a local watchpoint's frame id is still valid, then
10891 w->exp_valid_block is likewise valid, and we can safely use it.
10893 Don't do anything about disabled watchpoints, since they will be
10894 reevaluated again when enabled. */
10895 update_watchpoint (w
, 1 /* reparse */);
10898 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10901 insert_watchpoint (struct bp_location
*bl
)
10903 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10904 int length
= w
->exact
? 1 : bl
->length
;
10906 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10910 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10913 remove_watchpoint (struct bp_location
*bl
)
10915 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10916 int length
= w
->exact
? 1 : bl
->length
;
10918 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10923 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10924 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10925 const struct target_waitstatus
*ws
)
10927 struct breakpoint
*b
= bl
->owner
;
10928 struct watchpoint
*w
= (struct watchpoint
*) b
;
10930 /* Continuable hardware watchpoints are treated as non-existent if the
10931 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10932 some data address). Otherwise gdb won't stop on a break instruction
10933 in the code (not from a breakpoint) when a hardware watchpoint has
10934 been defined. Also skip watchpoints which we know did not trigger
10935 (did not match the data address). */
10936 if (is_hardware_watchpoint (b
)
10937 && w
->watchpoint_triggered
== watch_triggered_no
)
10944 check_status_watchpoint (bpstat bs
)
10946 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10948 bpstat_check_watchpoint (bs
);
10951 /* Implement the "resources_needed" breakpoint_ops method for
10952 hardware watchpoints. */
10955 resources_needed_watchpoint (const struct bp_location
*bl
)
10957 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10958 int length
= w
->exact
? 1 : bl
->length
;
10960 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10963 /* Implement the "works_in_software_mode" breakpoint_ops method for
10964 hardware watchpoints. */
10967 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10969 /* Read and access watchpoints only work with hardware support. */
10970 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10973 static enum print_stop_action
10974 print_it_watchpoint (bpstat bs
)
10976 struct cleanup
*old_chain
;
10977 struct breakpoint
*b
;
10978 struct ui_file
*stb
;
10979 enum print_stop_action result
;
10980 struct watchpoint
*w
;
10981 struct ui_out
*uiout
= current_uiout
;
10983 gdb_assert (bs
->bp_location_at
!= NULL
);
10985 b
= bs
->breakpoint_at
;
10986 w
= (struct watchpoint
*) b
;
10988 stb
= mem_fileopen ();
10989 old_chain
= make_cleanup_ui_file_delete (stb
);
10993 case bp_watchpoint
:
10994 case bp_hardware_watchpoint
:
10995 annotate_watchpoint (b
->number
);
10996 if (ui_out_is_mi_like_p (uiout
))
10997 ui_out_field_string
10999 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11001 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11002 ui_out_text (uiout
, "\nOld value = ");
11003 watchpoint_value_print (bs
->old_val
, stb
);
11004 ui_out_field_stream (uiout
, "old", stb
);
11005 ui_out_text (uiout
, "\nNew value = ");
11006 watchpoint_value_print (w
->val
, stb
);
11007 ui_out_field_stream (uiout
, "new", stb
);
11008 ui_out_text (uiout
, "\n");
11009 /* More than one watchpoint may have been triggered. */
11010 result
= PRINT_UNKNOWN
;
11013 case bp_read_watchpoint
:
11014 if (ui_out_is_mi_like_p (uiout
))
11015 ui_out_field_string
11017 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11019 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11020 ui_out_text (uiout
, "\nValue = ");
11021 watchpoint_value_print (w
->val
, stb
);
11022 ui_out_field_stream (uiout
, "value", stb
);
11023 ui_out_text (uiout
, "\n");
11024 result
= PRINT_UNKNOWN
;
11027 case bp_access_watchpoint
:
11028 if (bs
->old_val
!= NULL
)
11030 annotate_watchpoint (b
->number
);
11031 if (ui_out_is_mi_like_p (uiout
))
11032 ui_out_field_string
11034 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11036 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11037 ui_out_text (uiout
, "\nOld value = ");
11038 watchpoint_value_print (bs
->old_val
, stb
);
11039 ui_out_field_stream (uiout
, "old", stb
);
11040 ui_out_text (uiout
, "\nNew value = ");
11045 if (ui_out_is_mi_like_p (uiout
))
11046 ui_out_field_string
11048 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11049 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
11050 ui_out_text (uiout
, "\nValue = ");
11052 watchpoint_value_print (w
->val
, stb
);
11053 ui_out_field_stream (uiout
, "new", stb
);
11054 ui_out_text (uiout
, "\n");
11055 result
= PRINT_UNKNOWN
;
11058 result
= PRINT_UNKNOWN
;
11061 do_cleanups (old_chain
);
11065 /* Implement the "print_mention" breakpoint_ops method for hardware
11069 print_mention_watchpoint (struct breakpoint
*b
)
11071 struct cleanup
*ui_out_chain
;
11072 struct watchpoint
*w
= (struct watchpoint
*) b
;
11073 struct ui_out
*uiout
= current_uiout
;
11077 case bp_watchpoint
:
11078 ui_out_text (uiout
, "Watchpoint ");
11079 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11081 case bp_hardware_watchpoint
:
11082 ui_out_text (uiout
, "Hardware watchpoint ");
11083 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11085 case bp_read_watchpoint
:
11086 ui_out_text (uiout
, "Hardware read watchpoint ");
11087 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11089 case bp_access_watchpoint
:
11090 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
11091 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11094 internal_error (__FILE__
, __LINE__
,
11095 _("Invalid hardware watchpoint type."));
11098 ui_out_field_int (uiout
, "number", b
->number
);
11099 ui_out_text (uiout
, ": ");
11100 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11101 do_cleanups (ui_out_chain
);
11104 /* Implement the "print_recreate" breakpoint_ops method for
11108 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11110 struct watchpoint
*w
= (struct watchpoint
*) b
;
11114 case bp_watchpoint
:
11115 case bp_hardware_watchpoint
:
11116 fprintf_unfiltered (fp
, "watch");
11118 case bp_read_watchpoint
:
11119 fprintf_unfiltered (fp
, "rwatch");
11121 case bp_access_watchpoint
:
11122 fprintf_unfiltered (fp
, "awatch");
11125 internal_error (__FILE__
, __LINE__
,
11126 _("Invalid watchpoint type."));
11129 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
11130 print_recreate_thread (b
, fp
);
11133 /* Implement the "explains_signal" breakpoint_ops method for
11137 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
11139 /* A software watchpoint cannot cause a signal other than
11140 GDB_SIGNAL_TRAP. */
11141 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
11147 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11149 static struct breakpoint_ops watchpoint_breakpoint_ops
;
11151 /* Implement the "insert" breakpoint_ops method for
11152 masked hardware watchpoints. */
11155 insert_masked_watchpoint (struct bp_location
*bl
)
11157 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11159 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11160 bl
->watchpoint_type
);
11163 /* Implement the "remove" breakpoint_ops method for
11164 masked hardware watchpoints. */
11167 remove_masked_watchpoint (struct bp_location
*bl
)
11169 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11171 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11172 bl
->watchpoint_type
);
11175 /* Implement the "resources_needed" breakpoint_ops method for
11176 masked hardware watchpoints. */
11179 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11181 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11183 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11186 /* Implement the "works_in_software_mode" breakpoint_ops method for
11187 masked hardware watchpoints. */
11190 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11195 /* Implement the "print_it" breakpoint_ops method for
11196 masked hardware watchpoints. */
11198 static enum print_stop_action
11199 print_it_masked_watchpoint (bpstat bs
)
11201 struct breakpoint
*b
= bs
->breakpoint_at
;
11202 struct ui_out
*uiout
= current_uiout
;
11204 /* Masked watchpoints have only one location. */
11205 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11209 case bp_hardware_watchpoint
:
11210 annotate_watchpoint (b
->number
);
11211 if (ui_out_is_mi_like_p (uiout
))
11212 ui_out_field_string
11214 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11217 case bp_read_watchpoint
:
11218 if (ui_out_is_mi_like_p (uiout
))
11219 ui_out_field_string
11221 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11224 case bp_access_watchpoint
:
11225 if (ui_out_is_mi_like_p (uiout
))
11226 ui_out_field_string
11228 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11231 internal_error (__FILE__
, __LINE__
,
11232 _("Invalid hardware watchpoint type."));
11236 ui_out_text (uiout
, _("\n\
11237 Check the underlying instruction at PC for the memory\n\
11238 address and value which triggered this watchpoint.\n"));
11239 ui_out_text (uiout
, "\n");
11241 /* More than one watchpoint may have been triggered. */
11242 return PRINT_UNKNOWN
;
11245 /* Implement the "print_one_detail" breakpoint_ops method for
11246 masked hardware watchpoints. */
11249 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11250 struct ui_out
*uiout
)
11252 struct watchpoint
*w
= (struct watchpoint
*) b
;
11254 /* Masked watchpoints have only one location. */
11255 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11257 ui_out_text (uiout
, "\tmask ");
11258 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11259 ui_out_text (uiout
, "\n");
11262 /* Implement the "print_mention" breakpoint_ops method for
11263 masked hardware watchpoints. */
11266 print_mention_masked_watchpoint (struct breakpoint
*b
)
11268 struct watchpoint
*w
= (struct watchpoint
*) b
;
11269 struct ui_out
*uiout
= current_uiout
;
11270 struct cleanup
*ui_out_chain
;
11274 case bp_hardware_watchpoint
:
11275 ui_out_text (uiout
, "Masked hardware watchpoint ");
11276 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11278 case bp_read_watchpoint
:
11279 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11280 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11282 case bp_access_watchpoint
:
11283 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11284 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11287 internal_error (__FILE__
, __LINE__
,
11288 _("Invalid hardware watchpoint type."));
11291 ui_out_field_int (uiout
, "number", b
->number
);
11292 ui_out_text (uiout
, ": ");
11293 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11294 do_cleanups (ui_out_chain
);
11297 /* Implement the "print_recreate" breakpoint_ops method for
11298 masked hardware watchpoints. */
11301 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11303 struct watchpoint
*w
= (struct watchpoint
*) b
;
11308 case bp_hardware_watchpoint
:
11309 fprintf_unfiltered (fp
, "watch");
11311 case bp_read_watchpoint
:
11312 fprintf_unfiltered (fp
, "rwatch");
11314 case bp_access_watchpoint
:
11315 fprintf_unfiltered (fp
, "awatch");
11318 internal_error (__FILE__
, __LINE__
,
11319 _("Invalid hardware watchpoint type."));
11322 sprintf_vma (tmp
, w
->hw_wp_mask
);
11323 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11324 print_recreate_thread (b
, fp
);
11327 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11329 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11331 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11334 is_masked_watchpoint (const struct breakpoint
*b
)
11336 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11339 /* accessflag: hw_write: watch write,
11340 hw_read: watch read,
11341 hw_access: watch access (read or write) */
11343 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11344 int just_location
, int internal
)
11346 volatile struct gdb_exception e
;
11347 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11348 struct expression
*exp
;
11349 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11350 struct value
*val
, *mark
, *result
;
11351 int saved_bitpos
= 0, saved_bitsize
= 0;
11352 struct frame_info
*frame
;
11353 const char *exp_start
= NULL
;
11354 const char *exp_end
= NULL
;
11355 const char *tok
, *end_tok
;
11357 const char *cond_start
= NULL
;
11358 const char *cond_end
= NULL
;
11359 enum bptype bp_type
;
11362 /* Flag to indicate whether we are going to use masks for
11363 the hardware watchpoint. */
11365 CORE_ADDR mask
= 0;
11366 struct watchpoint
*w
;
11368 struct cleanup
*back_to
;
11370 /* Make sure that we actually have parameters to parse. */
11371 if (arg
!= NULL
&& arg
[0] != '\0')
11373 const char *value_start
;
11375 exp_end
= arg
+ strlen (arg
);
11377 /* Look for "parameter value" pairs at the end
11378 of the arguments string. */
11379 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11381 /* Skip whitespace at the end of the argument list. */
11382 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11385 /* Find the beginning of the last token.
11386 This is the value of the parameter. */
11387 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11389 value_start
= tok
+ 1;
11391 /* Skip whitespace. */
11392 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11397 /* Find the beginning of the second to last token.
11398 This is the parameter itself. */
11399 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11402 toklen
= end_tok
- tok
+ 1;
11404 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11406 /* At this point we've found a "thread" token, which means
11407 the user is trying to set a watchpoint that triggers
11408 only in a specific thread. */
11412 error(_("You can specify only one thread."));
11414 /* Extract the thread ID from the next token. */
11415 thread
= strtol (value_start
, &endp
, 0);
11417 /* Check if the user provided a valid numeric value for the
11419 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11420 error (_("Invalid thread ID specification %s."), value_start
);
11422 /* Check if the thread actually exists. */
11423 if (!valid_thread_id (thread
))
11424 invalid_thread_id_error (thread
);
11426 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11428 /* We've found a "mask" token, which means the user wants to
11429 create a hardware watchpoint that is going to have the mask
11431 struct value
*mask_value
, *mark
;
11434 error(_("You can specify only one mask."));
11436 use_mask
= just_location
= 1;
11438 mark
= value_mark ();
11439 mask_value
= parse_to_comma_and_eval (&value_start
);
11440 mask
= value_as_address (mask_value
);
11441 value_free_to_mark (mark
);
11444 /* We didn't recognize what we found. We should stop here. */
11447 /* Truncate the string and get rid of the "parameter value" pair before
11448 the arguments string is parsed by the parse_exp_1 function. */
11455 /* Parse the rest of the arguments. From here on out, everything
11456 is in terms of a newly allocated string instead of the original
11458 innermost_block
= NULL
;
11459 expression
= savestring (arg
, exp_end
- arg
);
11460 back_to
= make_cleanup (xfree
, expression
);
11461 exp_start
= arg
= expression
;
11462 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11464 /* Remove trailing whitespace from the expression before saving it.
11465 This makes the eventual display of the expression string a bit
11467 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11470 /* Checking if the expression is not constant. */
11471 if (watchpoint_exp_is_const (exp
))
11475 len
= exp_end
- exp_start
;
11476 while (len
> 0 && isspace (exp_start
[len
- 1]))
11478 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11481 exp_valid_block
= innermost_block
;
11482 mark
= value_mark ();
11483 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11485 if (val
!= NULL
&& just_location
)
11487 saved_bitpos
= value_bitpos (val
);
11488 saved_bitsize
= value_bitsize (val
);
11495 exp_valid_block
= NULL
;
11496 val
= value_addr (result
);
11497 release_value (val
);
11498 value_free_to_mark (mark
);
11502 ret
= target_masked_watch_num_registers (value_as_address (val
),
11505 error (_("This target does not support masked watchpoints."));
11506 else if (ret
== -2)
11507 error (_("Invalid mask or memory region."));
11510 else if (val
!= NULL
)
11511 release_value (val
);
11513 tok
= skip_spaces_const (arg
);
11514 end_tok
= skip_to_space_const (tok
);
11516 toklen
= end_tok
- tok
;
11517 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11519 struct expression
*cond
;
11521 innermost_block
= NULL
;
11522 tok
= cond_start
= end_tok
+ 1;
11523 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11525 /* The watchpoint expression may not be local, but the condition
11526 may still be. E.g.: `watch global if local > 0'. */
11527 cond_exp_valid_block
= innermost_block
;
11533 error (_("Junk at end of command."));
11535 frame
= block_innermost_frame (exp_valid_block
);
11537 /* If the expression is "local", then set up a "watchpoint scope"
11538 breakpoint at the point where we've left the scope of the watchpoint
11539 expression. Create the scope breakpoint before the watchpoint, so
11540 that we will encounter it first in bpstat_stop_status. */
11541 if (exp_valid_block
&& frame
)
11543 if (frame_id_p (frame_unwind_caller_id (frame
)))
11546 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11547 frame_unwind_caller_pc (frame
),
11548 bp_watchpoint_scope
,
11549 &momentary_breakpoint_ops
);
11551 scope_breakpoint
->enable_state
= bp_enabled
;
11553 /* Automatically delete the breakpoint when it hits. */
11554 scope_breakpoint
->disposition
= disp_del
;
11556 /* Only break in the proper frame (help with recursion). */
11557 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11559 /* Set the address at which we will stop. */
11560 scope_breakpoint
->loc
->gdbarch
11561 = frame_unwind_caller_arch (frame
);
11562 scope_breakpoint
->loc
->requested_address
11563 = frame_unwind_caller_pc (frame
);
11564 scope_breakpoint
->loc
->address
11565 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11566 scope_breakpoint
->loc
->requested_address
,
11567 scope_breakpoint
->type
);
11571 /* Now set up the breakpoint. We create all watchpoints as hardware
11572 watchpoints here even if hardware watchpoints are turned off, a call
11573 to update_watchpoint later in this function will cause the type to
11574 drop back to bp_watchpoint (software watchpoint) if required. */
11576 if (accessflag
== hw_read
)
11577 bp_type
= bp_read_watchpoint
;
11578 else if (accessflag
== hw_access
)
11579 bp_type
= bp_access_watchpoint
;
11581 bp_type
= bp_hardware_watchpoint
;
11583 w
= XCNEW (struct watchpoint
);
11586 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11587 &masked_watchpoint_breakpoint_ops
);
11589 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11590 &watchpoint_breakpoint_ops
);
11591 b
->thread
= thread
;
11592 b
->disposition
= disp_donttouch
;
11593 b
->pspace
= current_program_space
;
11595 w
->exp_valid_block
= exp_valid_block
;
11596 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11599 struct type
*t
= value_type (val
);
11600 CORE_ADDR addr
= value_as_address (val
);
11603 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11604 name
= type_to_string (t
);
11606 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11607 core_addr_to_string (addr
));
11610 w
->exp_string
= xstrprintf ("-location %.*s",
11611 (int) (exp_end
- exp_start
), exp_start
);
11613 /* The above expression is in C. */
11614 b
->language
= language_c
;
11617 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11621 w
->hw_wp_mask
= mask
;
11626 w
->val_bitpos
= saved_bitpos
;
11627 w
->val_bitsize
= saved_bitsize
;
11632 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11634 b
->cond_string
= 0;
11638 w
->watchpoint_frame
= get_frame_id (frame
);
11639 w
->watchpoint_thread
= inferior_ptid
;
11643 w
->watchpoint_frame
= null_frame_id
;
11644 w
->watchpoint_thread
= null_ptid
;
11647 if (scope_breakpoint
!= NULL
)
11649 /* The scope breakpoint is related to the watchpoint. We will
11650 need to act on them together. */
11651 b
->related_breakpoint
= scope_breakpoint
;
11652 scope_breakpoint
->related_breakpoint
= b
;
11655 if (!just_location
)
11656 value_free_to_mark (mark
);
11658 TRY_CATCH (e
, RETURN_MASK_ALL
)
11660 /* Finally update the new watchpoint. This creates the locations
11661 that should be inserted. */
11662 update_watchpoint (w
, 1);
11666 delete_breakpoint (b
);
11667 throw_exception (e
);
11670 install_breakpoint (internal
, b
, 1);
11671 do_cleanups (back_to
);
11674 /* Return count of debug registers needed to watch the given expression.
11675 If the watchpoint cannot be handled in hardware return zero. */
11678 can_use_hardware_watchpoint (struct value
*v
)
11680 int found_memory_cnt
= 0;
11681 struct value
*head
= v
;
11683 /* Did the user specifically forbid us to use hardware watchpoints? */
11684 if (!can_use_hw_watchpoints
)
11687 /* Make sure that the value of the expression depends only upon
11688 memory contents, and values computed from them within GDB. If we
11689 find any register references or function calls, we can't use a
11690 hardware watchpoint.
11692 The idea here is that evaluating an expression generates a series
11693 of values, one holding the value of every subexpression. (The
11694 expression a*b+c has five subexpressions: a, b, a*b, c, and
11695 a*b+c.) GDB's values hold almost enough information to establish
11696 the criteria given above --- they identify memory lvalues,
11697 register lvalues, computed values, etcetera. So we can evaluate
11698 the expression, and then scan the chain of values that leaves
11699 behind to decide whether we can detect any possible change to the
11700 expression's final value using only hardware watchpoints.
11702 However, I don't think that the values returned by inferior
11703 function calls are special in any way. So this function may not
11704 notice that an expression involving an inferior function call
11705 can't be watched with hardware watchpoints. FIXME. */
11706 for (; v
; v
= value_next (v
))
11708 if (VALUE_LVAL (v
) == lval_memory
)
11710 if (v
!= head
&& value_lazy (v
))
11711 /* A lazy memory lvalue in the chain is one that GDB never
11712 needed to fetch; we either just used its address (e.g.,
11713 `a' in `a.b') or we never needed it at all (e.g., `a'
11714 in `a,b'). This doesn't apply to HEAD; if that is
11715 lazy then it was not readable, but watch it anyway. */
11719 /* Ahh, memory we actually used! Check if we can cover
11720 it with hardware watchpoints. */
11721 struct type
*vtype
= check_typedef (value_type (v
));
11723 /* We only watch structs and arrays if user asked for it
11724 explicitly, never if they just happen to appear in a
11725 middle of some value chain. */
11727 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11728 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11730 CORE_ADDR vaddr
= value_address (v
);
11734 len
= (target_exact_watchpoints
11735 && is_scalar_type_recursive (vtype
))?
11736 1 : TYPE_LENGTH (value_type (v
));
11738 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11742 found_memory_cnt
+= num_regs
;
11746 else if (VALUE_LVAL (v
) != not_lval
11747 && deprecated_value_modifiable (v
) == 0)
11748 return 0; /* These are values from the history (e.g., $1). */
11749 else if (VALUE_LVAL (v
) == lval_register
)
11750 return 0; /* Cannot watch a register with a HW watchpoint. */
11753 /* The expression itself looks suitable for using a hardware
11754 watchpoint, but give the target machine a chance to reject it. */
11755 return found_memory_cnt
;
11759 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11761 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11764 /* A helper function that looks for the "-location" argument and then
11765 calls watch_command_1. */
11768 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11770 int just_location
= 0;
11773 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11774 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11776 arg
= skip_spaces (arg
);
11780 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11784 watch_command (char *arg
, int from_tty
)
11786 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11790 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11792 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11796 rwatch_command (char *arg
, int from_tty
)
11798 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11802 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11804 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11808 awatch_command (char *arg
, int from_tty
)
11810 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11814 /* Helper routines for the until_command routine in infcmd.c. Here
11815 because it uses the mechanisms of breakpoints. */
11817 struct until_break_command_continuation_args
11819 struct breakpoint
*breakpoint
;
11820 struct breakpoint
*breakpoint2
;
11824 /* This function is called by fetch_inferior_event via the
11825 cmd_continuation pointer, to complete the until command. It takes
11826 care of cleaning up the temporary breakpoints set up by the until
11829 until_break_command_continuation (void *arg
, int err
)
11831 struct until_break_command_continuation_args
*a
= arg
;
11833 delete_breakpoint (a
->breakpoint
);
11834 if (a
->breakpoint2
)
11835 delete_breakpoint (a
->breakpoint2
);
11836 delete_longjmp_breakpoint (a
->thread_num
);
11840 until_break_command (char *arg
, int from_tty
, int anywhere
)
11842 struct symtabs_and_lines sals
;
11843 struct symtab_and_line sal
;
11844 struct frame_info
*frame
;
11845 struct gdbarch
*frame_gdbarch
;
11846 struct frame_id stack_frame_id
;
11847 struct frame_id caller_frame_id
;
11848 struct breakpoint
*breakpoint
;
11849 struct breakpoint
*breakpoint2
= NULL
;
11850 struct cleanup
*old_chain
;
11852 struct thread_info
*tp
;
11854 clear_proceed_status (0);
11856 /* Set a breakpoint where the user wants it and at return from
11859 if (last_displayed_sal_is_valid ())
11860 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11861 get_last_displayed_symtab (),
11862 get_last_displayed_line ());
11864 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11865 (struct symtab
*) NULL
, 0);
11867 if (sals
.nelts
!= 1)
11868 error (_("Couldn't get information on specified line."));
11870 sal
= sals
.sals
[0];
11871 xfree (sals
.sals
); /* malloc'd, so freed. */
11874 error (_("Junk at end of arguments."));
11876 resolve_sal_pc (&sal
);
11878 tp
= inferior_thread ();
11881 old_chain
= make_cleanup (null_cleanup
, NULL
);
11883 /* Note linespec handling above invalidates the frame chain.
11884 Installing a breakpoint also invalidates the frame chain (as it
11885 may need to switch threads), so do any frame handling before
11888 frame
= get_selected_frame (NULL
);
11889 frame_gdbarch
= get_frame_arch (frame
);
11890 stack_frame_id
= get_stack_frame_id (frame
);
11891 caller_frame_id
= frame_unwind_caller_id (frame
);
11893 /* Keep within the current frame, or in frames called by the current
11896 if (frame_id_p (caller_frame_id
))
11898 struct symtab_and_line sal2
;
11900 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11901 sal2
.pc
= frame_unwind_caller_pc (frame
);
11902 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11906 make_cleanup_delete_breakpoint (breakpoint2
);
11908 set_longjmp_breakpoint (tp
, caller_frame_id
);
11909 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11912 /* set_momentary_breakpoint could invalidate FRAME. */
11916 /* If the user told us to continue until a specified location,
11917 we don't specify a frame at which we need to stop. */
11918 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11919 null_frame_id
, bp_until
);
11921 /* Otherwise, specify the selected frame, because we want to stop
11922 only at the very same frame. */
11923 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11924 stack_frame_id
, bp_until
);
11925 make_cleanup_delete_breakpoint (breakpoint
);
11927 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11929 /* If we are running asynchronously, and proceed call above has
11930 actually managed to start the target, arrange for breakpoints to
11931 be deleted when the target stops. Otherwise, we're already
11932 stopped and delete breakpoints via cleanup chain. */
11934 if (target_can_async_p () && is_running (inferior_ptid
))
11936 struct until_break_command_continuation_args
*args
;
11937 args
= xmalloc (sizeof (*args
));
11939 args
->breakpoint
= breakpoint
;
11940 args
->breakpoint2
= breakpoint2
;
11941 args
->thread_num
= thread
;
11943 discard_cleanups (old_chain
);
11944 add_continuation (inferior_thread (),
11945 until_break_command_continuation
, args
,
11949 do_cleanups (old_chain
);
11952 /* This function attempts to parse an optional "if <cond>" clause
11953 from the arg string. If one is not found, it returns NULL.
11955 Else, it returns a pointer to the condition string. (It does not
11956 attempt to evaluate the string against a particular block.) And,
11957 it updates arg to point to the first character following the parsed
11958 if clause in the arg string. */
11961 ep_parse_optional_if_clause (char **arg
)
11965 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11968 /* Skip the "if" keyword. */
11971 /* Skip any extra leading whitespace, and record the start of the
11972 condition string. */
11973 *arg
= skip_spaces (*arg
);
11974 cond_string
= *arg
;
11976 /* Assume that the condition occupies the remainder of the arg
11978 (*arg
) += strlen (cond_string
);
11980 return cond_string
;
11983 /* Commands to deal with catching events, such as signals, exceptions,
11984 process start/exit, etc. */
11988 catch_fork_temporary
, catch_vfork_temporary
,
11989 catch_fork_permanent
, catch_vfork_permanent
11994 catch_fork_command_1 (char *arg
, int from_tty
,
11995 struct cmd_list_element
*command
)
11997 struct gdbarch
*gdbarch
= get_current_arch ();
11998 char *cond_string
= NULL
;
11999 catch_fork_kind fork_kind
;
12002 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
12003 tempflag
= (fork_kind
== catch_fork_temporary
12004 || fork_kind
== catch_vfork_temporary
);
12008 arg
= skip_spaces (arg
);
12010 /* The allowed syntax is:
12012 catch [v]fork if <cond>
12014 First, check if there's an if clause. */
12015 cond_string
= ep_parse_optional_if_clause (&arg
);
12017 if ((*arg
!= '\0') && !isspace (*arg
))
12018 error (_("Junk at end of arguments."));
12020 /* If this target supports it, create a fork or vfork catchpoint
12021 and enable reporting of such events. */
12024 case catch_fork_temporary
:
12025 case catch_fork_permanent
:
12026 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
12027 &catch_fork_breakpoint_ops
);
12029 case catch_vfork_temporary
:
12030 case catch_vfork_permanent
:
12031 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
12032 &catch_vfork_breakpoint_ops
);
12035 error (_("unsupported or unknown fork kind; cannot catch it"));
12041 catch_exec_command_1 (char *arg
, int from_tty
,
12042 struct cmd_list_element
*command
)
12044 struct exec_catchpoint
*c
;
12045 struct gdbarch
*gdbarch
= get_current_arch ();
12047 char *cond_string
= NULL
;
12049 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12053 arg
= skip_spaces (arg
);
12055 /* The allowed syntax is:
12057 catch exec if <cond>
12059 First, check if there's an if clause. */
12060 cond_string
= ep_parse_optional_if_clause (&arg
);
12062 if ((*arg
!= '\0') && !isspace (*arg
))
12063 error (_("Junk at end of arguments."));
12065 c
= XNEW (struct exec_catchpoint
);
12066 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
12067 &catch_exec_breakpoint_ops
);
12068 c
->exec_pathname
= NULL
;
12070 install_breakpoint (0, &c
->base
, 1);
12074 init_ada_exception_breakpoint (struct breakpoint
*b
,
12075 struct gdbarch
*gdbarch
,
12076 struct symtab_and_line sal
,
12078 const struct breakpoint_ops
*ops
,
12085 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
12087 loc_gdbarch
= gdbarch
;
12089 describe_other_breakpoints (loc_gdbarch
,
12090 sal
.pspace
, sal
.pc
, sal
.section
, -1);
12091 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12092 version for exception catchpoints, because two catchpoints
12093 used for different exception names will use the same address.
12094 In this case, a "breakpoint ... also set at..." warning is
12095 unproductive. Besides, the warning phrasing is also a bit
12096 inappropriate, we should use the word catchpoint, and tell
12097 the user what type of catchpoint it is. The above is good
12098 enough for now, though. */
12101 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12103 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12104 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12105 b
->addr_string
= addr_string
;
12106 b
->language
= language_ada
;
12109 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12110 filter list, or NULL if no filtering is required. */
12112 catch_syscall_split_args (char *arg
)
12114 VEC(int) *result
= NULL
;
12115 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
12117 while (*arg
!= '\0')
12119 int i
, syscall_number
;
12121 char cur_name
[128];
12124 /* Skip whitespace. */
12125 arg
= skip_spaces (arg
);
12127 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
12128 cur_name
[i
] = arg
[i
];
12129 cur_name
[i
] = '\0';
12132 /* Check if the user provided a syscall name or a number. */
12133 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
12134 if (*endptr
== '\0')
12135 get_syscall_by_number (syscall_number
, &s
);
12138 /* We have a name. Let's check if it's valid and convert it
12140 get_syscall_by_name (cur_name
, &s
);
12142 if (s
.number
== UNKNOWN_SYSCALL
)
12143 /* Here we have to issue an error instead of a warning,
12144 because GDB cannot do anything useful if there's no
12145 syscall number to be caught. */
12146 error (_("Unknown syscall name '%s'."), cur_name
);
12149 /* Ok, it's valid. */
12150 VEC_safe_push (int, result
, s
.number
);
12153 discard_cleanups (cleanup
);
12157 /* Implement the "catch syscall" command. */
12160 catch_syscall_command_1 (char *arg
, int from_tty
,
12161 struct cmd_list_element
*command
)
12166 struct gdbarch
*gdbarch
= get_current_arch ();
12168 /* Checking if the feature if supported. */
12169 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
12170 error (_("The feature 'catch syscall' is not supported on \
12171 this architecture yet."));
12173 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12175 arg
= skip_spaces (arg
);
12177 /* We need to do this first "dummy" translation in order
12178 to get the syscall XML file loaded or, most important,
12179 to display a warning to the user if there's no XML file
12180 for his/her architecture. */
12181 get_syscall_by_number (0, &s
);
12183 /* The allowed syntax is:
12185 catch syscall <name | number> [<name | number> ... <name | number>]
12187 Let's check if there's a syscall name. */
12190 filter
= catch_syscall_split_args (arg
);
12194 create_syscall_event_catchpoint (tempflag
, filter
,
12195 &catch_syscall_breakpoint_ops
);
12199 catch_command (char *arg
, int from_tty
)
12201 error (_("Catch requires an event name."));
12206 tcatch_command (char *arg
, int from_tty
)
12208 error (_("Catch requires an event name."));
12211 /* A qsort comparison function that sorts breakpoints in order. */
12214 compare_breakpoints (const void *a
, const void *b
)
12216 const breakpoint_p
*ba
= a
;
12217 uintptr_t ua
= (uintptr_t) *ba
;
12218 const breakpoint_p
*bb
= b
;
12219 uintptr_t ub
= (uintptr_t) *bb
;
12221 if ((*ba
)->number
< (*bb
)->number
)
12223 else if ((*ba
)->number
> (*bb
)->number
)
12226 /* Now sort by address, in case we see, e..g, two breakpoints with
12230 return ua
> ub
? 1 : 0;
12233 /* Delete breakpoints by address or line. */
12236 clear_command (char *arg
, int from_tty
)
12238 struct breakpoint
*b
, *prev
;
12239 VEC(breakpoint_p
) *found
= 0;
12242 struct symtabs_and_lines sals
;
12243 struct symtab_and_line sal
;
12245 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12249 sals
= decode_line_with_current_source (arg
,
12250 (DECODE_LINE_FUNFIRSTLINE
12251 | DECODE_LINE_LIST_MODE
));
12252 make_cleanup (xfree
, sals
.sals
);
12257 sals
.sals
= (struct symtab_and_line
*)
12258 xmalloc (sizeof (struct symtab_and_line
));
12259 make_cleanup (xfree
, sals
.sals
);
12260 init_sal (&sal
); /* Initialize to zeroes. */
12262 /* Set sal's line, symtab, pc, and pspace to the values
12263 corresponding to the last call to print_frame_info. If the
12264 codepoint is not valid, this will set all the fields to 0. */
12265 get_last_displayed_sal (&sal
);
12266 if (sal
.symtab
== 0)
12267 error (_("No source file specified."));
12269 sals
.sals
[0] = sal
;
12275 /* We don't call resolve_sal_pc here. That's not as bad as it
12276 seems, because all existing breakpoints typically have both
12277 file/line and pc set. So, if clear is given file/line, we can
12278 match this to existing breakpoint without obtaining pc at all.
12280 We only support clearing given the address explicitly
12281 present in breakpoint table. Say, we've set breakpoint
12282 at file:line. There were several PC values for that file:line,
12283 due to optimization, all in one block.
12285 We've picked one PC value. If "clear" is issued with another
12286 PC corresponding to the same file:line, the breakpoint won't
12287 be cleared. We probably can still clear the breakpoint, but
12288 since the other PC value is never presented to user, user
12289 can only find it by guessing, and it does not seem important
12290 to support that. */
12292 /* For each line spec given, delete bps which correspond to it. Do
12293 it in two passes, solely to preserve the current behavior that
12294 from_tty is forced true if we delete more than one
12298 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12299 for (i
= 0; i
< sals
.nelts
; i
++)
12301 const char *sal_fullname
;
12303 /* If exact pc given, clear bpts at that pc.
12304 If line given (pc == 0), clear all bpts on specified line.
12305 If defaulting, clear all bpts on default line
12308 defaulting sal.pc != 0 tests to do
12313 1 0 <can't happen> */
12315 sal
= sals
.sals
[i
];
12316 sal_fullname
= (sal
.symtab
== NULL
12317 ? NULL
: symtab_to_fullname (sal
.symtab
));
12319 /* Find all matching breakpoints and add them to 'found'. */
12320 ALL_BREAKPOINTS (b
)
12323 /* Are we going to delete b? */
12324 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12326 struct bp_location
*loc
= b
->loc
;
12327 for (; loc
; loc
= loc
->next
)
12329 /* If the user specified file:line, don't allow a PC
12330 match. This matches historical gdb behavior. */
12331 int pc_match
= (!sal
.explicit_line
12333 && (loc
->pspace
== sal
.pspace
)
12334 && (loc
->address
== sal
.pc
)
12335 && (!section_is_overlay (loc
->section
)
12336 || loc
->section
== sal
.section
));
12337 int line_match
= 0;
12339 if ((default_match
|| sal
.explicit_line
)
12340 && loc
->symtab
!= NULL
12341 && sal_fullname
!= NULL
12342 && sal
.pspace
== loc
->pspace
12343 && loc
->line_number
== sal
.line
12344 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12345 sal_fullname
) == 0)
12348 if (pc_match
|| line_match
)
12357 VEC_safe_push(breakpoint_p
, found
, b
);
12361 /* Now go thru the 'found' chain and delete them. */
12362 if (VEC_empty(breakpoint_p
, found
))
12365 error (_("No breakpoint at %s."), arg
);
12367 error (_("No breakpoint at this line."));
12370 /* Remove duplicates from the vec. */
12371 qsort (VEC_address (breakpoint_p
, found
),
12372 VEC_length (breakpoint_p
, found
),
12373 sizeof (breakpoint_p
),
12374 compare_breakpoints
);
12375 prev
= VEC_index (breakpoint_p
, found
, 0);
12376 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12380 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12385 if (VEC_length(breakpoint_p
, found
) > 1)
12386 from_tty
= 1; /* Always report if deleted more than one. */
12389 if (VEC_length(breakpoint_p
, found
) == 1)
12390 printf_unfiltered (_("Deleted breakpoint "));
12392 printf_unfiltered (_("Deleted breakpoints "));
12395 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12398 printf_unfiltered ("%d ", b
->number
);
12399 delete_breakpoint (b
);
12402 putchar_unfiltered ('\n');
12404 do_cleanups (cleanups
);
12407 /* Delete breakpoint in BS if they are `delete' breakpoints and
12408 all breakpoints that are marked for deletion, whether hit or not.
12409 This is called after any breakpoint is hit, or after errors. */
12412 breakpoint_auto_delete (bpstat bs
)
12414 struct breakpoint
*b
, *b_tmp
;
12416 for (; bs
; bs
= bs
->next
)
12417 if (bs
->breakpoint_at
12418 && bs
->breakpoint_at
->disposition
== disp_del
12420 delete_breakpoint (bs
->breakpoint_at
);
12422 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12424 if (b
->disposition
== disp_del_at_next_stop
)
12425 delete_breakpoint (b
);
12429 /* A comparison function for bp_location AP and BP being interfaced to
12430 qsort. Sort elements primarily by their ADDRESS (no matter what
12431 does breakpoint_address_is_meaningful say for its OWNER),
12432 secondarily by ordering first bp_permanent OWNERed elements and
12433 terciarily just ensuring the array is sorted stable way despite
12434 qsort being an unstable algorithm. */
12437 bp_location_compare (const void *ap
, const void *bp
)
12439 struct bp_location
*a
= *(void **) ap
;
12440 struct bp_location
*b
= *(void **) bp
;
12441 /* A and B come from existing breakpoints having non-NULL OWNER. */
12442 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12443 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12445 if (a
->address
!= b
->address
)
12446 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12448 /* Sort locations at the same address by their pspace number, keeping
12449 locations of the same inferior (in a multi-inferior environment)
12452 if (a
->pspace
->num
!= b
->pspace
->num
)
12453 return ((a
->pspace
->num
> b
->pspace
->num
)
12454 - (a
->pspace
->num
< b
->pspace
->num
));
12456 /* Sort permanent breakpoints first. */
12457 if (a_perm
!= b_perm
)
12458 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12460 /* Make the internal GDB representation stable across GDB runs
12461 where A and B memory inside GDB can differ. Breakpoint locations of
12462 the same type at the same address can be sorted in arbitrary order. */
12464 if (a
->owner
->number
!= b
->owner
->number
)
12465 return ((a
->owner
->number
> b
->owner
->number
)
12466 - (a
->owner
->number
< b
->owner
->number
));
12468 return (a
> b
) - (a
< b
);
12471 /* Set bp_location_placed_address_before_address_max and
12472 bp_location_shadow_len_after_address_max according to the current
12473 content of the bp_location array. */
12476 bp_location_target_extensions_update (void)
12478 struct bp_location
*bl
, **blp_tmp
;
12480 bp_location_placed_address_before_address_max
= 0;
12481 bp_location_shadow_len_after_address_max
= 0;
12483 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12485 CORE_ADDR start
, end
, addr
;
12487 if (!bp_location_has_shadow (bl
))
12490 start
= bl
->target_info
.placed_address
;
12491 end
= start
+ bl
->target_info
.shadow_len
;
12493 gdb_assert (bl
->address
>= start
);
12494 addr
= bl
->address
- start
;
12495 if (addr
> bp_location_placed_address_before_address_max
)
12496 bp_location_placed_address_before_address_max
= addr
;
12498 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12500 gdb_assert (bl
->address
< end
);
12501 addr
= end
- bl
->address
;
12502 if (addr
> bp_location_shadow_len_after_address_max
)
12503 bp_location_shadow_len_after_address_max
= addr
;
12507 /* Download tracepoint locations if they haven't been. */
12510 download_tracepoint_locations (void)
12512 struct breakpoint
*b
;
12513 struct cleanup
*old_chain
;
12515 if (!target_can_download_tracepoint ())
12518 old_chain
= save_current_space_and_thread ();
12520 ALL_TRACEPOINTS (b
)
12522 struct bp_location
*bl
;
12523 struct tracepoint
*t
;
12524 int bp_location_downloaded
= 0;
12526 if ((b
->type
== bp_fast_tracepoint
12527 ? !may_insert_fast_tracepoints
12528 : !may_insert_tracepoints
))
12531 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12533 /* In tracepoint, locations are _never_ duplicated, so
12534 should_be_inserted is equivalent to
12535 unduplicated_should_be_inserted. */
12536 if (!should_be_inserted (bl
) || bl
->inserted
)
12539 switch_to_program_space_and_thread (bl
->pspace
);
12541 target_download_tracepoint (bl
);
12544 bp_location_downloaded
= 1;
12546 t
= (struct tracepoint
*) b
;
12547 t
->number_on_target
= b
->number
;
12548 if (bp_location_downloaded
)
12549 observer_notify_breakpoint_modified (b
);
12552 do_cleanups (old_chain
);
12555 /* Swap the insertion/duplication state between two locations. */
12558 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12560 const int left_inserted
= left
->inserted
;
12561 const int left_duplicate
= left
->duplicate
;
12562 const int left_needs_update
= left
->needs_update
;
12563 const struct bp_target_info left_target_info
= left
->target_info
;
12565 /* Locations of tracepoints can never be duplicated. */
12566 if (is_tracepoint (left
->owner
))
12567 gdb_assert (!left
->duplicate
);
12568 if (is_tracepoint (right
->owner
))
12569 gdb_assert (!right
->duplicate
);
12571 left
->inserted
= right
->inserted
;
12572 left
->duplicate
= right
->duplicate
;
12573 left
->needs_update
= right
->needs_update
;
12574 left
->target_info
= right
->target_info
;
12575 right
->inserted
= left_inserted
;
12576 right
->duplicate
= left_duplicate
;
12577 right
->needs_update
= left_needs_update
;
12578 right
->target_info
= left_target_info
;
12581 /* Force the re-insertion of the locations at ADDRESS. This is called
12582 once a new/deleted/modified duplicate location is found and we are evaluating
12583 conditions on the target's side. Such conditions need to be updated on
12587 force_breakpoint_reinsertion (struct bp_location
*bl
)
12589 struct bp_location
**locp
= NULL
, **loc2p
;
12590 struct bp_location
*loc
;
12591 CORE_ADDR address
= 0;
12594 address
= bl
->address
;
12595 pspace_num
= bl
->pspace
->num
;
12597 /* This is only meaningful if the target is
12598 evaluating conditions and if the user has
12599 opted for condition evaluation on the target's
12601 if (gdb_evaluates_breakpoint_condition_p ()
12602 || !target_supports_evaluation_of_breakpoint_conditions ())
12605 /* Flag all breakpoint locations with this address and
12606 the same program space as the location
12607 as "its condition has changed". We need to
12608 update the conditions on the target's side. */
12609 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12613 if (!is_breakpoint (loc
->owner
)
12614 || pspace_num
!= loc
->pspace
->num
)
12617 /* Flag the location appropriately. We use a different state to
12618 let everyone know that we already updated the set of locations
12619 with addr bl->address and program space bl->pspace. This is so
12620 we don't have to keep calling these functions just to mark locations
12621 that have already been marked. */
12622 loc
->condition_changed
= condition_updated
;
12624 /* Free the agent expression bytecode as well. We will compute
12626 if (loc
->cond_bytecode
)
12628 free_agent_expr (loc
->cond_bytecode
);
12629 loc
->cond_bytecode
= NULL
;
12633 /* Called whether new breakpoints are created, or existing breakpoints
12634 deleted, to update the global location list and recompute which
12635 locations are duplicate of which.
12637 The INSERT_MODE flag determines whether locations may not, may, or
12638 shall be inserted now. See 'enum ugll_insert_mode' for more
12642 update_global_location_list (enum ugll_insert_mode insert_mode
)
12644 struct breakpoint
*b
;
12645 struct bp_location
**locp
, *loc
;
12646 struct cleanup
*cleanups
;
12647 /* Last breakpoint location address that was marked for update. */
12648 CORE_ADDR last_addr
= 0;
12649 /* Last breakpoint location program space that was marked for update. */
12650 int last_pspace_num
= -1;
12652 /* Used in the duplicates detection below. When iterating over all
12653 bp_locations, points to the first bp_location of a given address.
12654 Breakpoints and watchpoints of different types are never
12655 duplicates of each other. Keep one pointer for each type of
12656 breakpoint/watchpoint, so we only need to loop over all locations
12658 struct bp_location
*bp_loc_first
; /* breakpoint */
12659 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12660 struct bp_location
*awp_loc_first
; /* access watchpoint */
12661 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12663 /* Saved former bp_location array which we compare against the newly
12664 built bp_location from the current state of ALL_BREAKPOINTS. */
12665 struct bp_location
**old_location
, **old_locp
;
12666 unsigned old_location_count
;
12668 old_location
= bp_location
;
12669 old_location_count
= bp_location_count
;
12670 bp_location
= NULL
;
12671 bp_location_count
= 0;
12672 cleanups
= make_cleanup (xfree
, old_location
);
12674 ALL_BREAKPOINTS (b
)
12675 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12676 bp_location_count
++;
12678 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12679 locp
= bp_location
;
12680 ALL_BREAKPOINTS (b
)
12681 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12683 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12684 bp_location_compare
);
12686 bp_location_target_extensions_update ();
12688 /* Identify bp_location instances that are no longer present in the
12689 new list, and therefore should be freed. Note that it's not
12690 necessary that those locations should be removed from inferior --
12691 if there's another location at the same address (previously
12692 marked as duplicate), we don't need to remove/insert the
12695 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12696 and former bp_location array state respectively. */
12698 locp
= bp_location
;
12699 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12702 struct bp_location
*old_loc
= *old_locp
;
12703 struct bp_location
**loc2p
;
12705 /* Tells if 'old_loc' is found among the new locations. If
12706 not, we have to free it. */
12707 int found_object
= 0;
12708 /* Tells if the location should remain inserted in the target. */
12709 int keep_in_target
= 0;
12712 /* Skip LOCP entries which will definitely never be needed.
12713 Stop either at or being the one matching OLD_LOC. */
12714 while (locp
< bp_location
+ bp_location_count
12715 && (*locp
)->address
< old_loc
->address
)
12719 (loc2p
< bp_location
+ bp_location_count
12720 && (*loc2p
)->address
== old_loc
->address
);
12723 /* Check if this is a new/duplicated location or a duplicated
12724 location that had its condition modified. If so, we want to send
12725 its condition to the target if evaluation of conditions is taking
12727 if ((*loc2p
)->condition_changed
== condition_modified
12728 && (last_addr
!= old_loc
->address
12729 || last_pspace_num
!= old_loc
->pspace
->num
))
12731 force_breakpoint_reinsertion (*loc2p
);
12732 last_pspace_num
= old_loc
->pspace
->num
;
12735 if (*loc2p
== old_loc
)
12739 /* We have already handled this address, update it so that we don't
12740 have to go through updates again. */
12741 last_addr
= old_loc
->address
;
12743 /* Target-side condition evaluation: Handle deleted locations. */
12745 force_breakpoint_reinsertion (old_loc
);
12747 /* If this location is no longer present, and inserted, look if
12748 there's maybe a new location at the same address. If so,
12749 mark that one inserted, and don't remove this one. This is
12750 needed so that we don't have a time window where a breakpoint
12751 at certain location is not inserted. */
12753 if (old_loc
->inserted
)
12755 /* If the location is inserted now, we might have to remove
12758 if (found_object
&& should_be_inserted (old_loc
))
12760 /* The location is still present in the location list,
12761 and still should be inserted. Don't do anything. */
12762 keep_in_target
= 1;
12766 /* This location still exists, but it won't be kept in the
12767 target since it may have been disabled. We proceed to
12768 remove its target-side condition. */
12770 /* The location is either no longer present, or got
12771 disabled. See if there's another location at the
12772 same address, in which case we don't need to remove
12773 this one from the target. */
12775 /* OLD_LOC comes from existing struct breakpoint. */
12776 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12779 (loc2p
< bp_location
+ bp_location_count
12780 && (*loc2p
)->address
== old_loc
->address
);
12783 struct bp_location
*loc2
= *loc2p
;
12785 if (breakpoint_locations_match (loc2
, old_loc
))
12787 /* Read watchpoint locations are switched to
12788 access watchpoints, if the former are not
12789 supported, but the latter are. */
12790 if (is_hardware_watchpoint (old_loc
->owner
))
12792 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12793 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12796 /* loc2 is a duplicated location. We need to check
12797 if it should be inserted in case it will be
12799 if (loc2
!= old_loc
12800 && unduplicated_should_be_inserted (loc2
))
12802 swap_insertion (old_loc
, loc2
);
12803 keep_in_target
= 1;
12811 if (!keep_in_target
)
12813 if (remove_breakpoint (old_loc
, mark_uninserted
))
12815 /* This is just about all we can do. We could keep
12816 this location on the global list, and try to
12817 remove it next time, but there's no particular
12818 reason why we will succeed next time.
12820 Note that at this point, old_loc->owner is still
12821 valid, as delete_breakpoint frees the breakpoint
12822 only after calling us. */
12823 printf_filtered (_("warning: Error removing "
12824 "breakpoint %d\n"),
12825 old_loc
->owner
->number
);
12833 if (removed
&& non_stop
12834 && breakpoint_address_is_meaningful (old_loc
->owner
)
12835 && !is_hardware_watchpoint (old_loc
->owner
))
12837 /* This location was removed from the target. In
12838 non-stop mode, a race condition is possible where
12839 we've removed a breakpoint, but stop events for that
12840 breakpoint are already queued and will arrive later.
12841 We apply an heuristic to be able to distinguish such
12842 SIGTRAPs from other random SIGTRAPs: we keep this
12843 breakpoint location for a bit, and will retire it
12844 after we see some number of events. The theory here
12845 is that reporting of events should, "on the average",
12846 be fair, so after a while we'll see events from all
12847 threads that have anything of interest, and no longer
12848 need to keep this breakpoint location around. We
12849 don't hold locations forever so to reduce chances of
12850 mistaking a non-breakpoint SIGTRAP for a breakpoint
12853 The heuristic failing can be disastrous on
12854 decr_pc_after_break targets.
12856 On decr_pc_after_break targets, like e.g., x86-linux,
12857 if we fail to recognize a late breakpoint SIGTRAP,
12858 because events_till_retirement has reached 0 too
12859 soon, we'll fail to do the PC adjustment, and report
12860 a random SIGTRAP to the user. When the user resumes
12861 the inferior, it will most likely immediately crash
12862 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12863 corrupted, because of being resumed e.g., in the
12864 middle of a multi-byte instruction, or skipped a
12865 one-byte instruction. This was actually seen happen
12866 on native x86-linux, and should be less rare on
12867 targets that do not support new thread events, like
12868 remote, due to the heuristic depending on
12871 Mistaking a random SIGTRAP for a breakpoint trap
12872 causes similar symptoms (PC adjustment applied when
12873 it shouldn't), but then again, playing with SIGTRAPs
12874 behind the debugger's back is asking for trouble.
12876 Since hardware watchpoint traps are always
12877 distinguishable from other traps, so we don't need to
12878 apply keep hardware watchpoint moribund locations
12879 around. We simply always ignore hardware watchpoint
12880 traps we can no longer explain. */
12882 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12883 old_loc
->owner
= NULL
;
12885 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12889 old_loc
->owner
= NULL
;
12890 decref_bp_location (&old_loc
);
12895 /* Rescan breakpoints at the same address and section, marking the
12896 first one as "first" and any others as "duplicates". This is so
12897 that the bpt instruction is only inserted once. If we have a
12898 permanent breakpoint at the same place as BPT, make that one the
12899 official one, and the rest as duplicates. Permanent breakpoints
12900 are sorted first for the same address.
12902 Do the same for hardware watchpoints, but also considering the
12903 watchpoint's type (regular/access/read) and length. */
12905 bp_loc_first
= NULL
;
12906 wp_loc_first
= NULL
;
12907 awp_loc_first
= NULL
;
12908 rwp_loc_first
= NULL
;
12909 ALL_BP_LOCATIONS (loc
, locp
)
12911 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12913 struct bp_location
**loc_first_p
;
12916 if (!unduplicated_should_be_inserted (loc
)
12917 || !breakpoint_address_is_meaningful (b
)
12918 /* Don't detect duplicate for tracepoint locations because they are
12919 never duplicated. See the comments in field `duplicate' of
12920 `struct bp_location'. */
12921 || is_tracepoint (b
))
12923 /* Clear the condition modification flag. */
12924 loc
->condition_changed
= condition_unchanged
;
12928 /* Permanent breakpoint should always be inserted. */
12929 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12930 internal_error (__FILE__
, __LINE__
,
12931 _("allegedly permanent breakpoint is not "
12932 "actually inserted"));
12934 if (b
->type
== bp_hardware_watchpoint
)
12935 loc_first_p
= &wp_loc_first
;
12936 else if (b
->type
== bp_read_watchpoint
)
12937 loc_first_p
= &rwp_loc_first
;
12938 else if (b
->type
== bp_access_watchpoint
)
12939 loc_first_p
= &awp_loc_first
;
12941 loc_first_p
= &bp_loc_first
;
12943 if (*loc_first_p
== NULL
12944 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12945 || !breakpoint_locations_match (loc
, *loc_first_p
))
12947 *loc_first_p
= loc
;
12948 loc
->duplicate
= 0;
12950 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12952 loc
->needs_update
= 1;
12953 /* Clear the condition modification flag. */
12954 loc
->condition_changed
= condition_unchanged
;
12960 /* This and the above ensure the invariant that the first location
12961 is not duplicated, and is the inserted one.
12962 All following are marked as duplicated, and are not inserted. */
12964 swap_insertion (loc
, *loc_first_p
);
12965 loc
->duplicate
= 1;
12967 /* Clear the condition modification flag. */
12968 loc
->condition_changed
= condition_unchanged
;
12970 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12971 && b
->enable_state
!= bp_permanent
)
12972 internal_error (__FILE__
, __LINE__
,
12973 _("another breakpoint was inserted on top of "
12974 "a permanent breakpoint"));
12977 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12979 if (insert_mode
!= UGLL_DONT_INSERT
)
12980 insert_breakpoint_locations ();
12983 /* Even though the caller told us to not insert new
12984 locations, we may still need to update conditions on the
12985 target's side of breakpoints that were already inserted
12986 if the target is evaluating breakpoint conditions. We
12987 only update conditions for locations that are marked
12989 update_inserted_breakpoint_locations ();
12993 if (insert_mode
!= UGLL_DONT_INSERT
)
12994 download_tracepoint_locations ();
12996 do_cleanups (cleanups
);
13000 breakpoint_retire_moribund (void)
13002 struct bp_location
*loc
;
13005 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
13006 if (--(loc
->events_till_retirement
) == 0)
13008 decref_bp_location (&loc
);
13009 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
13015 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
13017 volatile struct gdb_exception e
;
13019 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13020 update_global_location_list (insert_mode
);
13023 /* Clear BKP from a BPS. */
13026 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
13030 for (bs
= bps
; bs
; bs
= bs
->next
)
13031 if (bs
->breakpoint_at
== bpt
)
13033 bs
->breakpoint_at
= NULL
;
13034 bs
->old_val
= NULL
;
13035 /* bs->commands will be freed later. */
13039 /* Callback for iterate_over_threads. */
13041 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
13043 struct breakpoint
*bpt
= data
;
13045 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
13049 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
13053 say_where (struct breakpoint
*b
)
13055 struct value_print_options opts
;
13057 get_user_print_options (&opts
);
13059 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13061 if (b
->loc
== NULL
)
13063 printf_filtered (_(" (%s) pending."), b
->addr_string
);
13067 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
13069 printf_filtered (" at ");
13070 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
13073 if (b
->loc
->symtab
!= NULL
)
13075 /* If there is a single location, we can print the location
13077 if (b
->loc
->next
== NULL
)
13078 printf_filtered (": file %s, line %d.",
13079 symtab_to_filename_for_display (b
->loc
->symtab
),
13080 b
->loc
->line_number
);
13082 /* This is not ideal, but each location may have a
13083 different file name, and this at least reflects the
13084 real situation somewhat. */
13085 printf_filtered (": %s.", b
->addr_string
);
13090 struct bp_location
*loc
= b
->loc
;
13092 for (; loc
; loc
= loc
->next
)
13094 printf_filtered (" (%d locations)", n
);
13099 /* Default bp_location_ops methods. */
13102 bp_location_dtor (struct bp_location
*self
)
13104 xfree (self
->cond
);
13105 if (self
->cond_bytecode
)
13106 free_agent_expr (self
->cond_bytecode
);
13107 xfree (self
->function_name
);
13109 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
13110 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
13113 static const struct bp_location_ops bp_location_ops
=
13118 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13122 base_breakpoint_dtor (struct breakpoint
*self
)
13124 decref_counted_command_line (&self
->commands
);
13125 xfree (self
->cond_string
);
13126 xfree (self
->extra_string
);
13127 xfree (self
->addr_string
);
13128 xfree (self
->filter
);
13129 xfree (self
->addr_string_range_end
);
13132 static struct bp_location
*
13133 base_breakpoint_allocate_location (struct breakpoint
*self
)
13135 struct bp_location
*loc
;
13137 loc
= XNEW (struct bp_location
);
13138 init_bp_location (loc
, &bp_location_ops
, self
);
13143 base_breakpoint_re_set (struct breakpoint
*b
)
13145 /* Nothing to re-set. */
13148 #define internal_error_pure_virtual_called() \
13149 gdb_assert_not_reached ("pure virtual function called")
13152 base_breakpoint_insert_location (struct bp_location
*bl
)
13154 internal_error_pure_virtual_called ();
13158 base_breakpoint_remove_location (struct bp_location
*bl
)
13160 internal_error_pure_virtual_called ();
13164 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
13165 struct address_space
*aspace
,
13167 const struct target_waitstatus
*ws
)
13169 internal_error_pure_virtual_called ();
13173 base_breakpoint_check_status (bpstat bs
)
13178 /* A "works_in_software_mode" breakpoint_ops method that just internal
13182 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13184 internal_error_pure_virtual_called ();
13187 /* A "resources_needed" breakpoint_ops method that just internal
13191 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13193 internal_error_pure_virtual_called ();
13196 static enum print_stop_action
13197 base_breakpoint_print_it (bpstat bs
)
13199 internal_error_pure_virtual_called ();
13203 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13204 struct ui_out
*uiout
)
13210 base_breakpoint_print_mention (struct breakpoint
*b
)
13212 internal_error_pure_virtual_called ();
13216 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13218 internal_error_pure_virtual_called ();
13222 base_breakpoint_create_sals_from_address (char **arg
,
13223 struct linespec_result
*canonical
,
13224 enum bptype type_wanted
,
13228 internal_error_pure_virtual_called ();
13232 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13233 struct linespec_result
*c
,
13235 char *extra_string
,
13236 enum bptype type_wanted
,
13237 enum bpdisp disposition
,
13239 int task
, int ignore_count
,
13240 const struct breakpoint_ops
*o
,
13241 int from_tty
, int enabled
,
13242 int internal
, unsigned flags
)
13244 internal_error_pure_virtual_called ();
13248 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13249 struct symtabs_and_lines
*sals
)
13251 internal_error_pure_virtual_called ();
13254 /* The default 'explains_signal' method. */
13257 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13262 /* The default "after_condition_true" method. */
13265 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13267 /* Nothing to do. */
13270 struct breakpoint_ops base_breakpoint_ops
=
13272 base_breakpoint_dtor
,
13273 base_breakpoint_allocate_location
,
13274 base_breakpoint_re_set
,
13275 base_breakpoint_insert_location
,
13276 base_breakpoint_remove_location
,
13277 base_breakpoint_breakpoint_hit
,
13278 base_breakpoint_check_status
,
13279 base_breakpoint_resources_needed
,
13280 base_breakpoint_works_in_software_mode
,
13281 base_breakpoint_print_it
,
13283 base_breakpoint_print_one_detail
,
13284 base_breakpoint_print_mention
,
13285 base_breakpoint_print_recreate
,
13286 base_breakpoint_create_sals_from_address
,
13287 base_breakpoint_create_breakpoints_sal
,
13288 base_breakpoint_decode_linespec
,
13289 base_breakpoint_explains_signal
,
13290 base_breakpoint_after_condition_true
,
13293 /* Default breakpoint_ops methods. */
13296 bkpt_re_set (struct breakpoint
*b
)
13298 /* FIXME: is this still reachable? */
13299 if (b
->addr_string
== NULL
)
13301 /* Anything without a string can't be re-set. */
13302 delete_breakpoint (b
);
13306 breakpoint_re_set_default (b
);
13309 /* Copy SRC's shadow buffer and whatever else we'd set if we actually
13310 inserted DEST, so we can remove it later, in case SRC is removed
13314 bp_target_info_copy_insertion_state (struct bp_target_info
*dest
,
13315 const struct bp_target_info
*src
)
13317 dest
->shadow_len
= src
->shadow_len
;
13318 memcpy (dest
->shadow_contents
, src
->shadow_contents
, src
->shadow_len
);
13319 dest
->placed_address
= src
->placed_address
;
13320 dest
->placed_size
= src
->placed_size
;
13324 bkpt_insert_location (struct bp_location
*bl
)
13326 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13327 return target_insert_hw_breakpoint (bl
->gdbarch
,
13331 struct bp_target_info
*bp_tgt
= &bl
->target_info
;
13335 /* There is no need to insert a breakpoint if an unconditional
13336 raw/sss breakpoint is already inserted at that location. */
13337 sss_slot
= find_single_step_breakpoint (bp_tgt
->placed_address_space
,
13338 bp_tgt
->reqstd_address
);
13341 struct bp_target_info
*sss_bp_tgt
= single_step_breakpoints
[sss_slot
];
13343 bp_target_info_copy_insertion_state (bp_tgt
, sss_bp_tgt
);
13347 return target_insert_breakpoint (bl
->gdbarch
, bp_tgt
);
13352 bkpt_remove_location (struct bp_location
*bl
)
13354 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13355 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13358 struct bp_target_info
*bp_tgt
= &bl
->target_info
;
13359 struct address_space
*aspace
= bp_tgt
->placed_address_space
;
13360 CORE_ADDR address
= bp_tgt
->reqstd_address
;
13362 /* Only remove the breakpoint if there is no raw/sss breakpoint
13363 still inserted at this location. Otherwise, we would be
13364 effectively disabling the raw/sss breakpoint. */
13365 if (single_step_breakpoint_inserted_here_p (aspace
, address
))
13368 return target_remove_breakpoint (bl
->gdbarch
, bp_tgt
);
13373 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13374 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13375 const struct target_waitstatus
*ws
)
13377 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13378 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13381 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13385 if (overlay_debugging
/* unmapped overlay section */
13386 && section_is_overlay (bl
->section
)
13387 && !section_is_mapped (bl
->section
))
13394 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13395 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13396 const struct target_waitstatus
*ws
)
13398 if (dprintf_style
== dprintf_style_agent
13399 && target_can_run_breakpoint_commands ())
13401 /* An agent-style dprintf never causes a stop. If we see a trap
13402 for this address it must be for a breakpoint that happens to
13403 be set at the same address. */
13407 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13411 bkpt_resources_needed (const struct bp_location
*bl
)
13413 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13418 static enum print_stop_action
13419 bkpt_print_it (bpstat bs
)
13421 struct breakpoint
*b
;
13422 const struct bp_location
*bl
;
13424 struct ui_out
*uiout
= current_uiout
;
13426 gdb_assert (bs
->bp_location_at
!= NULL
);
13428 bl
= bs
->bp_location_at
;
13429 b
= bs
->breakpoint_at
;
13431 bp_temp
= b
->disposition
== disp_del
;
13432 if (bl
->address
!= bl
->requested_address
)
13433 breakpoint_adjustment_warning (bl
->requested_address
,
13436 annotate_breakpoint (b
->number
);
13438 ui_out_text (uiout
, "\nTemporary breakpoint ");
13440 ui_out_text (uiout
, "\nBreakpoint ");
13441 if (ui_out_is_mi_like_p (uiout
))
13443 ui_out_field_string (uiout
, "reason",
13444 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13445 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13447 ui_out_field_int (uiout
, "bkptno", b
->number
);
13448 ui_out_text (uiout
, ", ");
13450 return PRINT_SRC_AND_LOC
;
13454 bkpt_print_mention (struct breakpoint
*b
)
13456 if (ui_out_is_mi_like_p (current_uiout
))
13461 case bp_breakpoint
:
13462 case bp_gnu_ifunc_resolver
:
13463 if (b
->disposition
== disp_del
)
13464 printf_filtered (_("Temporary breakpoint"));
13466 printf_filtered (_("Breakpoint"));
13467 printf_filtered (_(" %d"), b
->number
);
13468 if (b
->type
== bp_gnu_ifunc_resolver
)
13469 printf_filtered (_(" at gnu-indirect-function resolver"));
13471 case bp_hardware_breakpoint
:
13472 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13475 printf_filtered (_("Dprintf %d"), b
->number
);
13483 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13485 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13486 fprintf_unfiltered (fp
, "tbreak");
13487 else if (tp
->type
== bp_breakpoint
)
13488 fprintf_unfiltered (fp
, "break");
13489 else if (tp
->type
== bp_hardware_breakpoint
13490 && tp
->disposition
== disp_del
)
13491 fprintf_unfiltered (fp
, "thbreak");
13492 else if (tp
->type
== bp_hardware_breakpoint
)
13493 fprintf_unfiltered (fp
, "hbreak");
13495 internal_error (__FILE__
, __LINE__
,
13496 _("unhandled breakpoint type %d"), (int) tp
->type
);
13498 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13499 print_recreate_thread (tp
, fp
);
13503 bkpt_create_sals_from_address (char **arg
,
13504 struct linespec_result
*canonical
,
13505 enum bptype type_wanted
,
13506 char *addr_start
, char **copy_arg
)
13508 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13509 addr_start
, copy_arg
);
13513 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13514 struct linespec_result
*canonical
,
13516 char *extra_string
,
13517 enum bptype type_wanted
,
13518 enum bpdisp disposition
,
13520 int task
, int ignore_count
,
13521 const struct breakpoint_ops
*ops
,
13522 int from_tty
, int enabled
,
13523 int internal
, unsigned flags
)
13525 create_breakpoints_sal_default (gdbarch
, canonical
,
13526 cond_string
, extra_string
,
13528 disposition
, thread
, task
,
13529 ignore_count
, ops
, from_tty
,
13530 enabled
, internal
, flags
);
13534 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13535 struct symtabs_and_lines
*sals
)
13537 decode_linespec_default (b
, s
, sals
);
13540 /* Virtual table for internal breakpoints. */
13543 internal_bkpt_re_set (struct breakpoint
*b
)
13547 /* Delete overlay event and longjmp master breakpoints; they
13548 will be reset later by breakpoint_re_set. */
13549 case bp_overlay_event
:
13550 case bp_longjmp_master
:
13551 case bp_std_terminate_master
:
13552 case bp_exception_master
:
13553 delete_breakpoint (b
);
13556 /* This breakpoint is special, it's set up when the inferior
13557 starts and we really don't want to touch it. */
13558 case bp_shlib_event
:
13560 /* Like bp_shlib_event, this breakpoint type is special. Once
13561 it is set up, we do not want to touch it. */
13562 case bp_thread_event
:
13568 internal_bkpt_check_status (bpstat bs
)
13570 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13572 /* If requested, stop when the dynamic linker notifies GDB of
13573 events. This allows the user to get control and place
13574 breakpoints in initializer routines for dynamically loaded
13575 objects (among other things). */
13576 bs
->stop
= stop_on_solib_events
;
13577 bs
->print
= stop_on_solib_events
;
13583 static enum print_stop_action
13584 internal_bkpt_print_it (bpstat bs
)
13586 struct breakpoint
*b
;
13588 b
= bs
->breakpoint_at
;
13592 case bp_shlib_event
:
13593 /* Did we stop because the user set the stop_on_solib_events
13594 variable? (If so, we report this as a generic, "Stopped due
13595 to shlib event" message.) */
13596 print_solib_event (0);
13599 case bp_thread_event
:
13600 /* Not sure how we will get here.
13601 GDB should not stop for these breakpoints. */
13602 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13605 case bp_overlay_event
:
13606 /* By analogy with the thread event, GDB should not stop for these. */
13607 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13610 case bp_longjmp_master
:
13611 /* These should never be enabled. */
13612 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13615 case bp_std_terminate_master
:
13616 /* These should never be enabled. */
13617 printf_filtered (_("std::terminate Master Breakpoint: "
13618 "gdb should not stop!\n"));
13621 case bp_exception_master
:
13622 /* These should never be enabled. */
13623 printf_filtered (_("Exception Master Breakpoint: "
13624 "gdb should not stop!\n"));
13628 return PRINT_NOTHING
;
13632 internal_bkpt_print_mention (struct breakpoint
*b
)
13634 /* Nothing to mention. These breakpoints are internal. */
13637 /* Virtual table for momentary breakpoints */
13640 momentary_bkpt_re_set (struct breakpoint
*b
)
13642 /* Keep temporary breakpoints, which can be encountered when we step
13643 over a dlopen call and solib_add is resetting the breakpoints.
13644 Otherwise these should have been blown away via the cleanup chain
13645 or by breakpoint_init_inferior when we rerun the executable. */
13649 momentary_bkpt_check_status (bpstat bs
)
13651 /* Nothing. The point of these breakpoints is causing a stop. */
13654 static enum print_stop_action
13655 momentary_bkpt_print_it (bpstat bs
)
13657 struct ui_out
*uiout
= current_uiout
;
13659 if (ui_out_is_mi_like_p (uiout
))
13661 struct breakpoint
*b
= bs
->breakpoint_at
;
13666 ui_out_field_string
13668 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13672 ui_out_field_string
13674 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13679 return PRINT_UNKNOWN
;
13683 momentary_bkpt_print_mention (struct breakpoint
*b
)
13685 /* Nothing to mention. These breakpoints are internal. */
13688 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13690 It gets cleared already on the removal of the first one of such placed
13691 breakpoints. This is OK as they get all removed altogether. */
13694 longjmp_bkpt_dtor (struct breakpoint
*self
)
13696 struct thread_info
*tp
= find_thread_id (self
->thread
);
13699 tp
->initiating_frame
= null_frame_id
;
13701 momentary_breakpoint_ops
.dtor (self
);
13704 /* Specific methods for probe breakpoints. */
13707 bkpt_probe_insert_location (struct bp_location
*bl
)
13709 int v
= bkpt_insert_location (bl
);
13713 /* The insertion was successful, now let's set the probe's semaphore
13715 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13716 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13725 bkpt_probe_remove_location (struct bp_location
*bl
)
13727 /* Let's clear the semaphore before removing the location. */
13728 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13729 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13733 return bkpt_remove_location (bl
);
13737 bkpt_probe_create_sals_from_address (char **arg
,
13738 struct linespec_result
*canonical
,
13739 enum bptype type_wanted
,
13740 char *addr_start
, char **copy_arg
)
13742 struct linespec_sals lsal
;
13744 lsal
.sals
= parse_probes (arg
, canonical
);
13746 *copy_arg
= xstrdup (canonical
->addr_string
);
13747 lsal
.canonical
= xstrdup (*copy_arg
);
13749 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13753 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13754 struct symtabs_and_lines
*sals
)
13756 *sals
= parse_probes (s
, NULL
);
13758 error (_("probe not found"));
13761 /* The breakpoint_ops structure to be used in tracepoints. */
13764 tracepoint_re_set (struct breakpoint
*b
)
13766 breakpoint_re_set_default (b
);
13770 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13771 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13772 const struct target_waitstatus
*ws
)
13774 /* By definition, the inferior does not report stops at
13780 tracepoint_print_one_detail (const struct breakpoint
*self
,
13781 struct ui_out
*uiout
)
13783 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13784 if (tp
->static_trace_marker_id
)
13786 gdb_assert (self
->type
== bp_static_tracepoint
);
13788 ui_out_text (uiout
, "\tmarker id is ");
13789 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13790 tp
->static_trace_marker_id
);
13791 ui_out_text (uiout
, "\n");
13796 tracepoint_print_mention (struct breakpoint
*b
)
13798 if (ui_out_is_mi_like_p (current_uiout
))
13803 case bp_tracepoint
:
13804 printf_filtered (_("Tracepoint"));
13805 printf_filtered (_(" %d"), b
->number
);
13807 case bp_fast_tracepoint
:
13808 printf_filtered (_("Fast tracepoint"));
13809 printf_filtered (_(" %d"), b
->number
);
13811 case bp_static_tracepoint
:
13812 printf_filtered (_("Static tracepoint"));
13813 printf_filtered (_(" %d"), b
->number
);
13816 internal_error (__FILE__
, __LINE__
,
13817 _("unhandled tracepoint type %d"), (int) b
->type
);
13824 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13826 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13828 if (self
->type
== bp_fast_tracepoint
)
13829 fprintf_unfiltered (fp
, "ftrace");
13830 if (self
->type
== bp_static_tracepoint
)
13831 fprintf_unfiltered (fp
, "strace");
13832 else if (self
->type
== bp_tracepoint
)
13833 fprintf_unfiltered (fp
, "trace");
13835 internal_error (__FILE__
, __LINE__
,
13836 _("unhandled tracepoint type %d"), (int) self
->type
);
13838 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13839 print_recreate_thread (self
, fp
);
13841 if (tp
->pass_count
)
13842 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13846 tracepoint_create_sals_from_address (char **arg
,
13847 struct linespec_result
*canonical
,
13848 enum bptype type_wanted
,
13849 char *addr_start
, char **copy_arg
)
13851 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13852 addr_start
, copy_arg
);
13856 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13857 struct linespec_result
*canonical
,
13859 char *extra_string
,
13860 enum bptype type_wanted
,
13861 enum bpdisp disposition
,
13863 int task
, int ignore_count
,
13864 const struct breakpoint_ops
*ops
,
13865 int from_tty
, int enabled
,
13866 int internal
, unsigned flags
)
13868 create_breakpoints_sal_default (gdbarch
, canonical
,
13869 cond_string
, extra_string
,
13871 disposition
, thread
, task
,
13872 ignore_count
, ops
, from_tty
,
13873 enabled
, internal
, flags
);
13877 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13878 struct symtabs_and_lines
*sals
)
13880 decode_linespec_default (b
, s
, sals
);
13883 struct breakpoint_ops tracepoint_breakpoint_ops
;
13885 /* The breakpoint_ops structure to be use on tracepoints placed in a
13889 tracepoint_probe_create_sals_from_address (char **arg
,
13890 struct linespec_result
*canonical
,
13891 enum bptype type_wanted
,
13892 char *addr_start
, char **copy_arg
)
13894 /* We use the same method for breakpoint on probes. */
13895 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13896 addr_start
, copy_arg
);
13900 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13901 struct symtabs_and_lines
*sals
)
13903 /* We use the same method for breakpoint on probes. */
13904 bkpt_probe_decode_linespec (b
, s
, sals
);
13907 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13909 /* Dprintf breakpoint_ops methods. */
13912 dprintf_re_set (struct breakpoint
*b
)
13914 breakpoint_re_set_default (b
);
13916 /* This breakpoint could have been pending, and be resolved now, and
13917 if so, we should now have the extra string. If we don't, the
13918 dprintf was malformed when created, but we couldn't tell because
13919 we can't extract the extra string until the location is
13921 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13922 error (_("Format string required"));
13924 /* 1 - connect to target 1, that can run breakpoint commands.
13925 2 - create a dprintf, which resolves fine.
13926 3 - disconnect from target 1
13927 4 - connect to target 2, that can NOT run breakpoint commands.
13929 After steps #3/#4, you'll want the dprintf command list to
13930 be updated, because target 1 and 2 may well return different
13931 answers for target_can_run_breakpoint_commands().
13932 Given absence of finer grained resetting, we get to do
13933 it all the time. */
13934 if (b
->extra_string
!= NULL
)
13935 update_dprintf_command_list (b
);
13938 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13941 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13943 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13945 print_recreate_thread (tp
, fp
);
13948 /* Implement the "after_condition_true" breakpoint_ops method for
13951 dprintf's are implemented with regular commands in their command
13952 list, but we run the commands here instead of before presenting the
13953 stop to the user, as dprintf's don't actually cause a stop. This
13954 also makes it so that the commands of multiple dprintfs at the same
13955 address are all handled. */
13958 dprintf_after_condition_true (struct bpstats
*bs
)
13960 struct cleanup
*old_chain
;
13961 struct bpstats tmp_bs
= { NULL
};
13962 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13964 /* dprintf's never cause a stop. This wasn't set in the
13965 check_status hook instead because that would make the dprintf's
13966 condition not be evaluated. */
13969 /* Run the command list here. Take ownership of it instead of
13970 copying. We never want these commands to run later in
13971 bpstat_do_actions, if a breakpoint that causes a stop happens to
13972 be set at same address as this dprintf, or even if running the
13973 commands here throws. */
13974 tmp_bs
.commands
= bs
->commands
;
13975 bs
->commands
= NULL
;
13976 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13978 bpstat_do_actions_1 (&tmp_bs_p
);
13980 /* 'tmp_bs.commands' will usually be NULL by now, but
13981 bpstat_do_actions_1 may return early without processing the whole
13983 do_cleanups (old_chain
);
13986 /* The breakpoint_ops structure to be used on static tracepoints with
13990 strace_marker_create_sals_from_address (char **arg
,
13991 struct linespec_result
*canonical
,
13992 enum bptype type_wanted
,
13993 char *addr_start
, char **copy_arg
)
13995 struct linespec_sals lsal
;
13997 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13999 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
14001 canonical
->addr_string
= xstrdup (*copy_arg
);
14002 lsal
.canonical
= xstrdup (*copy_arg
);
14003 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
14007 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
14008 struct linespec_result
*canonical
,
14010 char *extra_string
,
14011 enum bptype type_wanted
,
14012 enum bpdisp disposition
,
14014 int task
, int ignore_count
,
14015 const struct breakpoint_ops
*ops
,
14016 int from_tty
, int enabled
,
14017 int internal
, unsigned flags
)
14020 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
14021 canonical
->sals
, 0);
14023 /* If the user is creating a static tracepoint by marker id
14024 (strace -m MARKER_ID), then store the sals index, so that
14025 breakpoint_re_set can try to match up which of the newly
14026 found markers corresponds to this one, and, don't try to
14027 expand multiple locations for each sal, given than SALS
14028 already should contain all sals for MARKER_ID. */
14030 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
14032 struct symtabs_and_lines expanded
;
14033 struct tracepoint
*tp
;
14034 struct cleanup
*old_chain
;
14037 expanded
.nelts
= 1;
14038 expanded
.sals
= &lsal
->sals
.sals
[i
];
14040 addr_string
= xstrdup (canonical
->addr_string
);
14041 old_chain
= make_cleanup (xfree
, addr_string
);
14043 tp
= XCNEW (struct tracepoint
);
14044 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
14046 cond_string
, extra_string
,
14047 type_wanted
, disposition
,
14048 thread
, task
, ignore_count
, ops
,
14049 from_tty
, enabled
, internal
, flags
,
14050 canonical
->special_display
);
14051 /* Given that its possible to have multiple markers with
14052 the same string id, if the user is creating a static
14053 tracepoint by marker id ("strace -m MARKER_ID"), then
14054 store the sals index, so that breakpoint_re_set can
14055 try to match up which of the newly found markers
14056 corresponds to this one */
14057 tp
->static_trace_marker_id_idx
= i
;
14059 install_breakpoint (internal
, &tp
->base
, 0);
14061 discard_cleanups (old_chain
);
14066 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
14067 struct symtabs_and_lines
*sals
)
14069 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14071 *sals
= decode_static_tracepoint_spec (s
);
14072 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
14074 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
14078 error (_("marker %s not found"), tp
->static_trace_marker_id
);
14081 static struct breakpoint_ops strace_marker_breakpoint_ops
;
14084 strace_marker_p (struct breakpoint
*b
)
14086 return b
->ops
== &strace_marker_breakpoint_ops
;
14089 /* Delete a breakpoint and clean up all traces of it in the data
14093 delete_breakpoint (struct breakpoint
*bpt
)
14095 struct breakpoint
*b
;
14097 gdb_assert (bpt
!= NULL
);
14099 /* Has this bp already been deleted? This can happen because
14100 multiple lists can hold pointers to bp's. bpstat lists are
14103 One example of this happening is a watchpoint's scope bp. When
14104 the scope bp triggers, we notice that the watchpoint is out of
14105 scope, and delete it. We also delete its scope bp. But the
14106 scope bp is marked "auto-deleting", and is already on a bpstat.
14107 That bpstat is then checked for auto-deleting bp's, which are
14110 A real solution to this problem might involve reference counts in
14111 bp's, and/or giving them pointers back to their referencing
14112 bpstat's, and teaching delete_breakpoint to only free a bp's
14113 storage when no more references were extent. A cheaper bandaid
14115 if (bpt
->type
== bp_none
)
14118 /* At least avoid this stale reference until the reference counting
14119 of breakpoints gets resolved. */
14120 if (bpt
->related_breakpoint
!= bpt
)
14122 struct breakpoint
*related
;
14123 struct watchpoint
*w
;
14125 if (bpt
->type
== bp_watchpoint_scope
)
14126 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
14127 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
14128 w
= (struct watchpoint
*) bpt
;
14132 watchpoint_del_at_next_stop (w
);
14134 /* Unlink bpt from the bpt->related_breakpoint ring. */
14135 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
14136 related
= related
->related_breakpoint
);
14137 related
->related_breakpoint
= bpt
->related_breakpoint
;
14138 bpt
->related_breakpoint
= bpt
;
14141 /* watch_command_1 creates a watchpoint but only sets its number if
14142 update_watchpoint succeeds in creating its bp_locations. If there's
14143 a problem in that process, we'll be asked to delete the half-created
14144 watchpoint. In that case, don't announce the deletion. */
14146 observer_notify_breakpoint_deleted (bpt
);
14148 if (breakpoint_chain
== bpt
)
14149 breakpoint_chain
= bpt
->next
;
14151 ALL_BREAKPOINTS (b
)
14152 if (b
->next
== bpt
)
14154 b
->next
= bpt
->next
;
14158 /* Be sure no bpstat's are pointing at the breakpoint after it's
14160 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14161 in all threads for now. Note that we cannot just remove bpstats
14162 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14163 commands are associated with the bpstat; if we remove it here,
14164 then the later call to bpstat_do_actions (&stop_bpstat); in
14165 event-top.c won't do anything, and temporary breakpoints with
14166 commands won't work. */
14168 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
14170 /* Now that breakpoint is removed from breakpoint list, update the
14171 global location list. This will remove locations that used to
14172 belong to this breakpoint. Do this before freeing the breakpoint
14173 itself, since remove_breakpoint looks at location's owner. It
14174 might be better design to have location completely
14175 self-contained, but it's not the case now. */
14176 update_global_location_list (UGLL_DONT_INSERT
);
14178 bpt
->ops
->dtor (bpt
);
14179 /* On the chance that someone will soon try again to delete this
14180 same bp, we mark it as deleted before freeing its storage. */
14181 bpt
->type
= bp_none
;
14186 do_delete_breakpoint_cleanup (void *b
)
14188 delete_breakpoint (b
);
14192 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
14194 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
14197 /* Iterator function to call a user-provided callback function once
14198 for each of B and its related breakpoints. */
14201 iterate_over_related_breakpoints (struct breakpoint
*b
,
14202 void (*function
) (struct breakpoint
*,
14206 struct breakpoint
*related
;
14211 struct breakpoint
*next
;
14213 /* FUNCTION may delete RELATED. */
14214 next
= related
->related_breakpoint
;
14216 if (next
== related
)
14218 /* RELATED is the last ring entry. */
14219 function (related
, data
);
14221 /* FUNCTION may have deleted it, so we'd never reach back to
14222 B. There's nothing left to do anyway, so just break
14227 function (related
, data
);
14231 while (related
!= b
);
14235 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14237 delete_breakpoint (b
);
14240 /* A callback for map_breakpoint_numbers that calls
14241 delete_breakpoint. */
14244 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14246 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14250 delete_command (char *arg
, int from_tty
)
14252 struct breakpoint
*b
, *b_tmp
;
14258 int breaks_to_delete
= 0;
14260 /* Delete all breakpoints if no argument. Do not delete
14261 internal breakpoints, these have to be deleted with an
14262 explicit breakpoint number argument. */
14263 ALL_BREAKPOINTS (b
)
14264 if (user_breakpoint_p (b
))
14266 breaks_to_delete
= 1;
14270 /* Ask user only if there are some breakpoints to delete. */
14272 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14274 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14275 if (user_breakpoint_p (b
))
14276 delete_breakpoint (b
);
14280 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14284 all_locations_are_pending (struct bp_location
*loc
)
14286 for (; loc
; loc
= loc
->next
)
14287 if (!loc
->shlib_disabled
14288 && !loc
->pspace
->executing_startup
)
14293 /* Subroutine of update_breakpoint_locations to simplify it.
14294 Return non-zero if multiple fns in list LOC have the same name.
14295 Null names are ignored. */
14298 ambiguous_names_p (struct bp_location
*loc
)
14300 struct bp_location
*l
;
14301 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14302 (int (*) (const void *,
14303 const void *)) streq
,
14304 NULL
, xcalloc
, xfree
);
14306 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14309 const char *name
= l
->function_name
;
14311 /* Allow for some names to be NULL, ignore them. */
14315 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14317 /* NOTE: We can assume slot != NULL here because xcalloc never
14321 htab_delete (htab
);
14327 htab_delete (htab
);
14331 /* When symbols change, it probably means the sources changed as well,
14332 and it might mean the static tracepoint markers are no longer at
14333 the same address or line numbers they used to be at last we
14334 checked. Losing your static tracepoints whenever you rebuild is
14335 undesirable. This function tries to resync/rematch gdb static
14336 tracepoints with the markers on the target, for static tracepoints
14337 that have not been set by marker id. Static tracepoint that have
14338 been set by marker id are reset by marker id in breakpoint_re_set.
14341 1) For a tracepoint set at a specific address, look for a marker at
14342 the old PC. If one is found there, assume to be the same marker.
14343 If the name / string id of the marker found is different from the
14344 previous known name, assume that means the user renamed the marker
14345 in the sources, and output a warning.
14347 2) For a tracepoint set at a given line number, look for a marker
14348 at the new address of the old line number. If one is found there,
14349 assume to be the same marker. If the name / string id of the
14350 marker found is different from the previous known name, assume that
14351 means the user renamed the marker in the sources, and output a
14354 3) If a marker is no longer found at the same address or line, it
14355 may mean the marker no longer exists. But it may also just mean
14356 the code changed a bit. Maybe the user added a few lines of code
14357 that made the marker move up or down (in line number terms). Ask
14358 the target for info about the marker with the string id as we knew
14359 it. If found, update line number and address in the matching
14360 static tracepoint. This will get confused if there's more than one
14361 marker with the same ID (possible in UST, although unadvised
14362 precisely because it confuses tools). */
14364 static struct symtab_and_line
14365 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14367 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14368 struct static_tracepoint_marker marker
;
14373 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14375 if (target_static_tracepoint_marker_at (pc
, &marker
))
14377 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14378 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14380 tp
->static_trace_marker_id
, marker
.str_id
);
14382 xfree (tp
->static_trace_marker_id
);
14383 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14384 release_static_tracepoint_marker (&marker
);
14389 /* Old marker wasn't found on target at lineno. Try looking it up
14391 if (!sal
.explicit_pc
14393 && sal
.symtab
!= NULL
14394 && tp
->static_trace_marker_id
!= NULL
)
14396 VEC(static_tracepoint_marker_p
) *markers
;
14399 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14401 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14403 struct symtab_and_line sal2
;
14404 struct symbol
*sym
;
14405 struct static_tracepoint_marker
*tpmarker
;
14406 struct ui_out
*uiout
= current_uiout
;
14408 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14410 xfree (tp
->static_trace_marker_id
);
14411 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14413 warning (_("marker for static tracepoint %d (%s) not "
14414 "found at previous line number"),
14415 b
->number
, tp
->static_trace_marker_id
);
14419 sal2
.pc
= tpmarker
->address
;
14421 sal2
= find_pc_line (tpmarker
->address
, 0);
14422 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14423 ui_out_text (uiout
, "Now in ");
14426 ui_out_field_string (uiout
, "func",
14427 SYMBOL_PRINT_NAME (sym
));
14428 ui_out_text (uiout
, " at ");
14430 ui_out_field_string (uiout
, "file",
14431 symtab_to_filename_for_display (sal2
.symtab
));
14432 ui_out_text (uiout
, ":");
14434 if (ui_out_is_mi_like_p (uiout
))
14436 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14438 ui_out_field_string (uiout
, "fullname", fullname
);
14441 ui_out_field_int (uiout
, "line", sal2
.line
);
14442 ui_out_text (uiout
, "\n");
14444 b
->loc
->line_number
= sal2
.line
;
14445 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14447 xfree (b
->addr_string
);
14448 b
->addr_string
= xstrprintf ("%s:%d",
14449 symtab_to_filename_for_display (sal2
.symtab
),
14450 b
->loc
->line_number
);
14452 /* Might be nice to check if function changed, and warn if
14455 release_static_tracepoint_marker (tpmarker
);
14461 /* Returns 1 iff locations A and B are sufficiently same that
14462 we don't need to report breakpoint as changed. */
14465 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14469 if (a
->address
!= b
->address
)
14472 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14475 if (a
->enabled
!= b
->enabled
)
14482 if ((a
== NULL
) != (b
== NULL
))
14488 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14489 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14490 a ranged breakpoint. */
14493 update_breakpoint_locations (struct breakpoint
*b
,
14494 struct symtabs_and_lines sals
,
14495 struct symtabs_and_lines sals_end
)
14498 struct bp_location
*existing_locations
= b
->loc
;
14500 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14502 /* Ranged breakpoints have only one start location and one end
14504 b
->enable_state
= bp_disabled
;
14505 update_global_location_list (UGLL_MAY_INSERT
);
14506 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14507 "multiple locations found\n"),
14512 /* If there's no new locations, and all existing locations are
14513 pending, don't do anything. This optimizes the common case where
14514 all locations are in the same shared library, that was unloaded.
14515 We'd like to retain the location, so that when the library is
14516 loaded again, we don't loose the enabled/disabled status of the
14517 individual locations. */
14518 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14523 for (i
= 0; i
< sals
.nelts
; ++i
)
14525 struct bp_location
*new_loc
;
14527 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14529 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14531 /* Reparse conditions, they might contain references to the
14533 if (b
->cond_string
!= NULL
)
14536 volatile struct gdb_exception e
;
14538 s
= b
->cond_string
;
14539 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14541 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14542 block_for_pc (sals
.sals
[i
].pc
),
14547 warning (_("failed to reevaluate condition "
14548 "for breakpoint %d: %s"),
14549 b
->number
, e
.message
);
14550 new_loc
->enabled
= 0;
14554 if (sals_end
.nelts
)
14556 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14558 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14562 /* Update locations of permanent breakpoints. */
14563 if (b
->enable_state
== bp_permanent
)
14564 make_breakpoint_permanent (b
);
14566 /* If possible, carry over 'disable' status from existing
14569 struct bp_location
*e
= existing_locations
;
14570 /* If there are multiple breakpoints with the same function name,
14571 e.g. for inline functions, comparing function names won't work.
14572 Instead compare pc addresses; this is just a heuristic as things
14573 may have moved, but in practice it gives the correct answer
14574 often enough until a better solution is found. */
14575 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14577 for (; e
; e
= e
->next
)
14579 if (!e
->enabled
&& e
->function_name
)
14581 struct bp_location
*l
= b
->loc
;
14582 if (have_ambiguous_names
)
14584 for (; l
; l
= l
->next
)
14585 if (breakpoint_locations_match (e
, l
))
14593 for (; l
; l
= l
->next
)
14594 if (l
->function_name
14595 && strcmp (e
->function_name
, l
->function_name
) == 0)
14605 if (!locations_are_equal (existing_locations
, b
->loc
))
14606 observer_notify_breakpoint_modified (b
);
14608 update_global_location_list (UGLL_MAY_INSERT
);
14611 /* Find the SaL locations corresponding to the given ADDR_STRING.
14612 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14614 static struct symtabs_and_lines
14615 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14618 struct symtabs_and_lines sals
= {0};
14619 volatile struct gdb_exception e
;
14621 gdb_assert (b
->ops
!= NULL
);
14624 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14626 b
->ops
->decode_linespec (b
, &s
, &sals
);
14630 int not_found_and_ok
= 0;
14631 /* For pending breakpoints, it's expected that parsing will
14632 fail until the right shared library is loaded. User has
14633 already told to create pending breakpoints and don't need
14634 extra messages. If breakpoint is in bp_shlib_disabled
14635 state, then user already saw the message about that
14636 breakpoint being disabled, and don't want to see more
14638 if (e
.error
== NOT_FOUND_ERROR
14639 && (b
->condition_not_parsed
14640 || (b
->loc
&& b
->loc
->shlib_disabled
)
14641 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14642 || b
->enable_state
== bp_disabled
))
14643 not_found_and_ok
= 1;
14645 if (!not_found_and_ok
)
14647 /* We surely don't want to warn about the same breakpoint
14648 10 times. One solution, implemented here, is disable
14649 the breakpoint on error. Another solution would be to
14650 have separate 'warning emitted' flag. Since this
14651 happens only when a binary has changed, I don't know
14652 which approach is better. */
14653 b
->enable_state
= bp_disabled
;
14654 throw_exception (e
);
14658 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14662 for (i
= 0; i
< sals
.nelts
; ++i
)
14663 resolve_sal_pc (&sals
.sals
[i
]);
14664 if (b
->condition_not_parsed
&& s
&& s
[0])
14666 char *cond_string
, *extra_string
;
14669 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14670 &cond_string
, &thread
, &task
,
14673 b
->cond_string
= cond_string
;
14674 b
->thread
= thread
;
14677 b
->extra_string
= extra_string
;
14678 b
->condition_not_parsed
= 0;
14681 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14682 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14692 /* The default re_set method, for typical hardware or software
14693 breakpoints. Reevaluate the breakpoint and recreate its
14697 breakpoint_re_set_default (struct breakpoint
*b
)
14700 struct symtabs_and_lines sals
, sals_end
;
14701 struct symtabs_and_lines expanded
= {0};
14702 struct symtabs_and_lines expanded_end
= {0};
14704 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14707 make_cleanup (xfree
, sals
.sals
);
14711 if (b
->addr_string_range_end
)
14713 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14716 make_cleanup (xfree
, sals_end
.sals
);
14717 expanded_end
= sals_end
;
14721 update_breakpoint_locations (b
, expanded
, expanded_end
);
14724 /* Default method for creating SALs from an address string. It basically
14725 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14728 create_sals_from_address_default (char **arg
,
14729 struct linespec_result
*canonical
,
14730 enum bptype type_wanted
,
14731 char *addr_start
, char **copy_arg
)
14733 parse_breakpoint_sals (arg
, canonical
);
14736 /* Call create_breakpoints_sal for the given arguments. This is the default
14737 function for the `create_breakpoints_sal' method of
14741 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14742 struct linespec_result
*canonical
,
14744 char *extra_string
,
14745 enum bptype type_wanted
,
14746 enum bpdisp disposition
,
14748 int task
, int ignore_count
,
14749 const struct breakpoint_ops
*ops
,
14750 int from_tty
, int enabled
,
14751 int internal
, unsigned flags
)
14753 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14755 type_wanted
, disposition
,
14756 thread
, task
, ignore_count
, ops
, from_tty
,
14757 enabled
, internal
, flags
);
14760 /* Decode the line represented by S by calling decode_line_full. This is the
14761 default function for the `decode_linespec' method of breakpoint_ops. */
14764 decode_linespec_default (struct breakpoint
*b
, char **s
,
14765 struct symtabs_and_lines
*sals
)
14767 struct linespec_result canonical
;
14769 init_linespec_result (&canonical
);
14770 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14771 (struct symtab
*) NULL
, 0,
14772 &canonical
, multiple_symbols_all
,
14775 /* We should get 0 or 1 resulting SALs. */
14776 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14778 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14780 struct linespec_sals
*lsal
;
14782 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14783 *sals
= lsal
->sals
;
14784 /* Arrange it so the destructor does not free the
14786 lsal
->sals
.sals
= NULL
;
14789 destroy_linespec_result (&canonical
);
14792 /* Prepare the global context for a re-set of breakpoint B. */
14794 static struct cleanup
*
14795 prepare_re_set_context (struct breakpoint
*b
)
14797 struct cleanup
*cleanups
;
14799 input_radix
= b
->input_radix
;
14800 cleanups
= save_current_space_and_thread ();
14801 if (b
->pspace
!= NULL
)
14802 switch_to_program_space_and_thread (b
->pspace
);
14803 set_language (b
->language
);
14808 /* Reset a breakpoint given it's struct breakpoint * BINT.
14809 The value we return ends up being the return value from catch_errors.
14810 Unused in this case. */
14813 breakpoint_re_set_one (void *bint
)
14815 /* Get past catch_errs. */
14816 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14817 struct cleanup
*cleanups
;
14819 cleanups
= prepare_re_set_context (b
);
14820 b
->ops
->re_set (b
);
14821 do_cleanups (cleanups
);
14825 /* Re-set all breakpoints after symbols have been re-loaded. */
14827 breakpoint_re_set (void)
14829 struct breakpoint
*b
, *b_tmp
;
14830 enum language save_language
;
14831 int save_input_radix
;
14832 struct cleanup
*old_chain
;
14834 save_language
= current_language
->la_language
;
14835 save_input_radix
= input_radix
;
14836 old_chain
= save_current_program_space ();
14838 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14840 /* Format possible error msg. */
14841 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14843 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14844 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14845 do_cleanups (cleanups
);
14847 set_language (save_language
);
14848 input_radix
= save_input_radix
;
14850 jit_breakpoint_re_set ();
14852 do_cleanups (old_chain
);
14854 create_overlay_event_breakpoint ();
14855 create_longjmp_master_breakpoint ();
14856 create_std_terminate_master_breakpoint ();
14857 create_exception_master_breakpoint ();
14860 /* Reset the thread number of this breakpoint:
14862 - If the breakpoint is for all threads, leave it as-is.
14863 - Else, reset it to the current thread for inferior_ptid. */
14865 breakpoint_re_set_thread (struct breakpoint
*b
)
14867 if (b
->thread
!= -1)
14869 if (in_thread_list (inferior_ptid
))
14870 b
->thread
= pid_to_thread_id (inferior_ptid
);
14872 /* We're being called after following a fork. The new fork is
14873 selected as current, and unless this was a vfork will have a
14874 different program space from the original thread. Reset that
14876 b
->loc
->pspace
= current_program_space
;
14880 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14881 If from_tty is nonzero, it prints a message to that effect,
14882 which ends with a period (no newline). */
14885 set_ignore_count (int bptnum
, int count
, int from_tty
)
14887 struct breakpoint
*b
;
14892 ALL_BREAKPOINTS (b
)
14893 if (b
->number
== bptnum
)
14895 if (is_tracepoint (b
))
14897 if (from_tty
&& count
!= 0)
14898 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14903 b
->ignore_count
= count
;
14907 printf_filtered (_("Will stop next time "
14908 "breakpoint %d is reached."),
14910 else if (count
== 1)
14911 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14914 printf_filtered (_("Will ignore next %d "
14915 "crossings of breakpoint %d."),
14918 observer_notify_breakpoint_modified (b
);
14922 error (_("No breakpoint number %d."), bptnum
);
14925 /* Command to set ignore-count of breakpoint N to COUNT. */
14928 ignore_command (char *args
, int from_tty
)
14934 error_no_arg (_("a breakpoint number"));
14936 num
= get_number (&p
);
14938 error (_("bad breakpoint number: '%s'"), args
);
14940 error (_("Second argument (specified ignore-count) is missing."));
14942 set_ignore_count (num
,
14943 longest_to_int (value_as_long (parse_and_eval (p
))),
14946 printf_filtered ("\n");
14949 /* Call FUNCTION on each of the breakpoints
14950 whose numbers are given in ARGS. */
14953 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14958 struct breakpoint
*b
, *tmp
;
14960 struct get_number_or_range_state state
;
14963 error_no_arg (_("one or more breakpoint numbers"));
14965 init_number_or_range (&state
, args
);
14967 while (!state
.finished
)
14969 const char *p
= state
.string
;
14973 num
= get_number_or_range (&state
);
14976 warning (_("bad breakpoint number at or near '%s'"), p
);
14980 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14981 if (b
->number
== num
)
14984 function (b
, data
);
14988 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14993 static struct bp_location
*
14994 find_location_by_number (char *number
)
14996 char *dot
= strchr (number
, '.');
15000 struct breakpoint
*b
;
15001 struct bp_location
*loc
;
15006 bp_num
= get_number (&p1
);
15008 error (_("Bad breakpoint number '%s'"), number
);
15010 ALL_BREAKPOINTS (b
)
15011 if (b
->number
== bp_num
)
15016 if (!b
|| b
->number
!= bp_num
)
15017 error (_("Bad breakpoint number '%s'"), number
);
15020 loc_num
= get_number (&p1
);
15022 error (_("Bad breakpoint location number '%s'"), number
);
15026 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
15029 error (_("Bad breakpoint location number '%s'"), dot
+1);
15035 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
15036 If from_tty is nonzero, it prints a message to that effect,
15037 which ends with a period (no newline). */
15040 disable_breakpoint (struct breakpoint
*bpt
)
15042 /* Never disable a watchpoint scope breakpoint; we want to
15043 hit them when we leave scope so we can delete both the
15044 watchpoint and its scope breakpoint at that time. */
15045 if (bpt
->type
== bp_watchpoint_scope
)
15048 /* You can't disable permanent breakpoints. */
15049 if (bpt
->enable_state
== bp_permanent
)
15052 bpt
->enable_state
= bp_disabled
;
15054 /* Mark breakpoint locations modified. */
15055 mark_breakpoint_modified (bpt
);
15057 if (target_supports_enable_disable_tracepoint ()
15058 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15060 struct bp_location
*location
;
15062 for (location
= bpt
->loc
; location
; location
= location
->next
)
15063 target_disable_tracepoint (location
);
15066 update_global_location_list (UGLL_DONT_INSERT
);
15068 observer_notify_breakpoint_modified (bpt
);
15071 /* A callback for iterate_over_related_breakpoints. */
15074 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
15076 disable_breakpoint (b
);
15079 /* A callback for map_breakpoint_numbers that calls
15080 disable_breakpoint. */
15083 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
15085 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
15089 disable_command (char *args
, int from_tty
)
15093 struct breakpoint
*bpt
;
15095 ALL_BREAKPOINTS (bpt
)
15096 if (user_breakpoint_p (bpt
))
15097 disable_breakpoint (bpt
);
15101 char *num
= extract_arg (&args
);
15105 if (strchr (num
, '.'))
15107 struct bp_location
*loc
= find_location_by_number (num
);
15114 mark_breakpoint_location_modified (loc
);
15116 if (target_supports_enable_disable_tracepoint ()
15117 && current_trace_status ()->running
&& loc
->owner
15118 && is_tracepoint (loc
->owner
))
15119 target_disable_tracepoint (loc
);
15121 update_global_location_list (UGLL_DONT_INSERT
);
15124 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
15125 num
= extract_arg (&args
);
15131 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
15134 int target_resources_ok
;
15136 if (bpt
->type
== bp_hardware_breakpoint
)
15139 i
= hw_breakpoint_used_count ();
15140 target_resources_ok
=
15141 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
15143 if (target_resources_ok
== 0)
15144 error (_("No hardware breakpoint support in the target."));
15145 else if (target_resources_ok
< 0)
15146 error (_("Hardware breakpoints used exceeds limit."));
15149 if (is_watchpoint (bpt
))
15151 /* Initialize it just to avoid a GCC false warning. */
15152 enum enable_state orig_enable_state
= 0;
15153 volatile struct gdb_exception e
;
15155 TRY_CATCH (e
, RETURN_MASK_ALL
)
15157 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
15159 orig_enable_state
= bpt
->enable_state
;
15160 bpt
->enable_state
= bp_enabled
;
15161 update_watchpoint (w
, 1 /* reparse */);
15165 bpt
->enable_state
= orig_enable_state
;
15166 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15172 if (bpt
->enable_state
!= bp_permanent
)
15173 bpt
->enable_state
= bp_enabled
;
15175 bpt
->enable_state
= bp_enabled
;
15177 /* Mark breakpoint locations modified. */
15178 mark_breakpoint_modified (bpt
);
15180 if (target_supports_enable_disable_tracepoint ()
15181 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15183 struct bp_location
*location
;
15185 for (location
= bpt
->loc
; location
; location
= location
->next
)
15186 target_enable_tracepoint (location
);
15189 bpt
->disposition
= disposition
;
15190 bpt
->enable_count
= count
;
15191 update_global_location_list (UGLL_MAY_INSERT
);
15193 observer_notify_breakpoint_modified (bpt
);
15198 enable_breakpoint (struct breakpoint
*bpt
)
15200 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15204 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15206 enable_breakpoint (bpt
);
15209 /* A callback for map_breakpoint_numbers that calls
15210 enable_breakpoint. */
15213 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15215 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15218 /* The enable command enables the specified breakpoints (or all defined
15219 breakpoints) so they once again become (or continue to be) effective
15220 in stopping the inferior. */
15223 enable_command (char *args
, int from_tty
)
15227 struct breakpoint
*bpt
;
15229 ALL_BREAKPOINTS (bpt
)
15230 if (user_breakpoint_p (bpt
))
15231 enable_breakpoint (bpt
);
15235 char *num
= extract_arg (&args
);
15239 if (strchr (num
, '.'))
15241 struct bp_location
*loc
= find_location_by_number (num
);
15248 mark_breakpoint_location_modified (loc
);
15250 if (target_supports_enable_disable_tracepoint ()
15251 && current_trace_status ()->running
&& loc
->owner
15252 && is_tracepoint (loc
->owner
))
15253 target_enable_tracepoint (loc
);
15255 update_global_location_list (UGLL_MAY_INSERT
);
15258 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15259 num
= extract_arg (&args
);
15264 /* This struct packages up disposition data for application to multiple
15274 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15276 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15278 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15282 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15284 struct disp_data disp
= { disp_disable
, 1 };
15286 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15290 enable_once_command (char *args
, int from_tty
)
15292 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15296 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15298 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15300 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15304 enable_count_command (char *args
, int from_tty
)
15306 int count
= get_number (&args
);
15308 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15312 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15314 struct disp_data disp
= { disp_del
, 1 };
15316 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15320 enable_delete_command (char *args
, int from_tty
)
15322 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15326 set_breakpoint_cmd (char *args
, int from_tty
)
15331 show_breakpoint_cmd (char *args
, int from_tty
)
15335 /* Invalidate last known value of any hardware watchpoint if
15336 the memory which that value represents has been written to by
15340 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15341 CORE_ADDR addr
, ssize_t len
,
15342 const bfd_byte
*data
)
15344 struct breakpoint
*bp
;
15346 ALL_BREAKPOINTS (bp
)
15347 if (bp
->enable_state
== bp_enabled
15348 && bp
->type
== bp_hardware_watchpoint
)
15350 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15352 if (wp
->val_valid
&& wp
->val
)
15354 struct bp_location
*loc
;
15356 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15357 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15358 && loc
->address
+ loc
->length
> addr
15359 && addr
+ len
> loc
->address
)
15361 value_free (wp
->val
);
15369 /* Create and insert a raw software breakpoint at PC. Return an
15370 identifier, which should be used to remove the breakpoint later.
15371 In general, places which call this should be using something on the
15372 breakpoint chain instead; this function should be eliminated
15376 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
15377 struct address_space
*aspace
, CORE_ADDR pc
)
15379 struct bp_target_info
*bp_tgt
;
15380 struct bp_location
*bl
;
15382 bp_tgt
= XCNEW (struct bp_target_info
);
15384 bp_tgt
->placed_address_space
= aspace
;
15385 bp_tgt
->reqstd_address
= pc
;
15387 /* If an unconditional non-raw breakpoint is already inserted at
15388 that location, there's no need to insert another. However, with
15389 target-side evaluation of breakpoint conditions, if the
15390 breakpoint that is currently inserted on the target is
15391 conditional, we need to make it unconditional. Note that a
15392 breakpoint with target-side commands is not reported even if
15393 unconditional, so we need to remove the commands from the target
15395 bl
= find_non_raw_software_breakpoint_inserted_here (aspace
, pc
);
15397 && VEC_empty (agent_expr_p
, bl
->target_info
.conditions
)
15398 && VEC_empty (agent_expr_p
, bl
->target_info
.tcommands
))
15400 bp_target_info_copy_insertion_state (bp_tgt
, &bl
->target_info
);
15404 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
15406 /* Could not insert the breakpoint. */
15414 /* Remove a breakpoint BP inserted by
15415 deprecated_insert_raw_breakpoint. */
15418 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
15420 struct bp_target_info
*bp_tgt
= bp
;
15421 struct address_space
*aspace
= bp_tgt
->placed_address_space
;
15422 CORE_ADDR address
= bp_tgt
->reqstd_address
;
15423 struct bp_location
*bl
;
15426 bl
= find_non_raw_software_breakpoint_inserted_here (aspace
, address
);
15428 /* Only remove the raw breakpoint if there are no other non-raw
15429 breakpoints still inserted at this location. Otherwise, we would
15430 be effectively disabling those breakpoints. */
15432 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
15433 else if (!VEC_empty (agent_expr_p
, bl
->target_info
.conditions
)
15434 || !VEC_empty (agent_expr_p
, bl
->target_info
.tcommands
))
15436 /* The target is evaluating conditions, and when we inserted the
15437 software single-step breakpoint, we had made the breakpoint
15438 unconditional and command-less on the target side. Reinsert
15439 to restore the conditions/commands. */
15440 ret
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
15450 /* Create and insert a breakpoint for software single step. */
15453 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15454 struct address_space
*aspace
,
15459 if (single_step_breakpoints
[0] == NULL
)
15461 bpt_p
= &single_step_breakpoints
[0];
15462 single_step_gdbarch
[0] = gdbarch
;
15466 gdb_assert (single_step_breakpoints
[1] == NULL
);
15467 bpt_p
= &single_step_breakpoints
[1];
15468 single_step_gdbarch
[1] = gdbarch
;
15471 /* NOTE drow/2006-04-11: A future improvement to this function would
15472 be to only create the breakpoints once, and actually put them on
15473 the breakpoint chain. That would let us use set_raw_breakpoint.
15474 We could adjust the addresses each time they were needed. Doing
15475 this requires corresponding changes elsewhere where single step
15476 breakpoints are handled, however. So, for now, we use this. */
15478 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15479 if (*bpt_p
== NULL
)
15480 error (_("Could not insert single-step breakpoint at %s"),
15481 paddress (gdbarch
, next_pc
));
15484 /* Check if the breakpoints used for software single stepping
15485 were inserted or not. */
15488 single_step_breakpoints_inserted (void)
15490 return (single_step_breakpoints
[0] != NULL
15491 || single_step_breakpoints
[1] != NULL
);
15494 /* Remove and delete any breakpoints used for software single step. */
15497 remove_single_step_breakpoints (void)
15499 gdb_assert (single_step_breakpoints
[0] != NULL
);
15501 /* See insert_single_step_breakpoint for more about this deprecated
15503 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15504 single_step_breakpoints
[0]);
15505 single_step_gdbarch
[0] = NULL
;
15506 single_step_breakpoints
[0] = NULL
;
15508 if (single_step_breakpoints
[1] != NULL
)
15510 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15511 single_step_breakpoints
[1]);
15512 single_step_gdbarch
[1] = NULL
;
15513 single_step_breakpoints
[1] = NULL
;
15517 /* Delete software single step breakpoints without removing them from
15518 the inferior. This is intended to be used if the inferior's address
15519 space where they were inserted is already gone, e.g. after exit or
15523 cancel_single_step_breakpoints (void)
15527 for (i
= 0; i
< 2; i
++)
15528 if (single_step_breakpoints
[i
])
15530 xfree (single_step_breakpoints
[i
]);
15531 single_step_breakpoints
[i
] = NULL
;
15532 single_step_gdbarch
[i
] = NULL
;
15536 /* Detach software single-step breakpoints from INFERIOR_PTID without
15540 detach_single_step_breakpoints (void)
15544 for (i
= 0; i
< 2; i
++)
15545 if (single_step_breakpoints
[i
])
15546 target_remove_breakpoint (single_step_gdbarch
[i
],
15547 single_step_breakpoints
[i
]);
15550 /* Find the software single-step breakpoint that inserted at PC.
15551 Returns its slot if found, and -1 if not found. */
15554 find_single_step_breakpoint (struct address_space
*aspace
,
15559 for (i
= 0; i
< 2; i
++)
15561 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15563 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15564 bp_tgt
->reqstd_address
,
15572 /* Check whether a software single-step breakpoint is inserted at
15576 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15579 return find_single_step_breakpoint (aspace
, pc
) >= 0;
15582 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15583 non-zero otherwise. */
15585 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15587 if (syscall_catchpoint_p (bp
)
15588 && bp
->enable_state
!= bp_disabled
15589 && bp
->enable_state
!= bp_call_disabled
)
15596 catch_syscall_enabled (void)
15598 struct catch_syscall_inferior_data
*inf_data
15599 = get_catch_syscall_inferior_data (current_inferior ());
15601 return inf_data
->total_syscalls_count
!= 0;
15605 catching_syscall_number (int syscall_number
)
15607 struct breakpoint
*bp
;
15609 ALL_BREAKPOINTS (bp
)
15610 if (is_syscall_catchpoint_enabled (bp
))
15612 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15614 if (c
->syscalls_to_be_caught
)
15618 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15620 if (syscall_number
== iter
)
15630 /* Complete syscall names. Used by "catch syscall". */
15631 static VEC (char_ptr
) *
15632 catch_syscall_completer (struct cmd_list_element
*cmd
,
15633 const char *text
, const char *word
)
15635 const char **list
= get_syscall_names ();
15636 VEC (char_ptr
) *retlist
15637 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15643 /* Tracepoint-specific operations. */
15645 /* Set tracepoint count to NUM. */
15647 set_tracepoint_count (int num
)
15649 tracepoint_count
= num
;
15650 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15654 trace_command (char *arg
, int from_tty
)
15656 struct breakpoint_ops
*ops
;
15657 const char *arg_cp
= arg
;
15659 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15660 ops
= &tracepoint_probe_breakpoint_ops
;
15662 ops
= &tracepoint_breakpoint_ops
;
15664 create_breakpoint (get_current_arch (),
15666 NULL
, 0, NULL
, 1 /* parse arg */,
15668 bp_tracepoint
/* type_wanted */,
15669 0 /* Ignore count */,
15670 pending_break_support
,
15674 0 /* internal */, 0);
15678 ftrace_command (char *arg
, int from_tty
)
15680 create_breakpoint (get_current_arch (),
15682 NULL
, 0, NULL
, 1 /* parse arg */,
15684 bp_fast_tracepoint
/* type_wanted */,
15685 0 /* Ignore count */,
15686 pending_break_support
,
15687 &tracepoint_breakpoint_ops
,
15690 0 /* internal */, 0);
15693 /* strace command implementation. Creates a static tracepoint. */
15696 strace_command (char *arg
, int from_tty
)
15698 struct breakpoint_ops
*ops
;
15700 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15701 or with a normal static tracepoint. */
15702 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15703 ops
= &strace_marker_breakpoint_ops
;
15705 ops
= &tracepoint_breakpoint_ops
;
15707 create_breakpoint (get_current_arch (),
15709 NULL
, 0, NULL
, 1 /* parse arg */,
15711 bp_static_tracepoint
/* type_wanted */,
15712 0 /* Ignore count */,
15713 pending_break_support
,
15717 0 /* internal */, 0);
15720 /* Set up a fake reader function that gets command lines from a linked
15721 list that was acquired during tracepoint uploading. */
15723 static struct uploaded_tp
*this_utp
;
15724 static int next_cmd
;
15727 read_uploaded_action (void)
15731 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15738 /* Given information about a tracepoint as recorded on a target (which
15739 can be either a live system or a trace file), attempt to create an
15740 equivalent GDB tracepoint. This is not a reliable process, since
15741 the target does not necessarily have all the information used when
15742 the tracepoint was originally defined. */
15744 struct tracepoint
*
15745 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15747 char *addr_str
, small_buf
[100];
15748 struct tracepoint
*tp
;
15750 if (utp
->at_string
)
15751 addr_str
= utp
->at_string
;
15754 /* In the absence of a source location, fall back to raw
15755 address. Since there is no way to confirm that the address
15756 means the same thing as when the trace was started, warn the
15758 warning (_("Uploaded tracepoint %d has no "
15759 "source location, using raw address"),
15761 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15762 addr_str
= small_buf
;
15765 /* There's not much we can do with a sequence of bytecodes. */
15766 if (utp
->cond
&& !utp
->cond_string
)
15767 warning (_("Uploaded tracepoint %d condition "
15768 "has no source form, ignoring it"),
15771 if (!create_breakpoint (get_current_arch (),
15773 utp
->cond_string
, -1, NULL
,
15774 0 /* parse cond/thread */,
15776 utp
->type
/* type_wanted */,
15777 0 /* Ignore count */,
15778 pending_break_support
,
15779 &tracepoint_breakpoint_ops
,
15781 utp
->enabled
/* enabled */,
15783 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15786 /* Get the tracepoint we just created. */
15787 tp
= get_tracepoint (tracepoint_count
);
15788 gdb_assert (tp
!= NULL
);
15792 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15795 trace_pass_command (small_buf
, 0);
15798 /* If we have uploaded versions of the original commands, set up a
15799 special-purpose "reader" function and call the usual command line
15800 reader, then pass the result to the breakpoint command-setting
15802 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15804 struct command_line
*cmd_list
;
15809 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15811 breakpoint_set_commands (&tp
->base
, cmd_list
);
15813 else if (!VEC_empty (char_ptr
, utp
->actions
)
15814 || !VEC_empty (char_ptr
, utp
->step_actions
))
15815 warning (_("Uploaded tracepoint %d actions "
15816 "have no source form, ignoring them"),
15819 /* Copy any status information that might be available. */
15820 tp
->base
.hit_count
= utp
->hit_count
;
15821 tp
->traceframe_usage
= utp
->traceframe_usage
;
15826 /* Print information on tracepoint number TPNUM_EXP, or all if
15830 tracepoints_info (char *args
, int from_tty
)
15832 struct ui_out
*uiout
= current_uiout
;
15835 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15837 if (num_printed
== 0)
15839 if (args
== NULL
|| *args
== '\0')
15840 ui_out_message (uiout
, 0, "No tracepoints.\n");
15842 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15845 default_collect_info ();
15848 /* The 'enable trace' command enables tracepoints.
15849 Not supported by all targets. */
15851 enable_trace_command (char *args
, int from_tty
)
15853 enable_command (args
, from_tty
);
15856 /* The 'disable trace' command disables tracepoints.
15857 Not supported by all targets. */
15859 disable_trace_command (char *args
, int from_tty
)
15861 disable_command (args
, from_tty
);
15864 /* Remove a tracepoint (or all if no argument). */
15866 delete_trace_command (char *arg
, int from_tty
)
15868 struct breakpoint
*b
, *b_tmp
;
15874 int breaks_to_delete
= 0;
15876 /* Delete all breakpoints if no argument.
15877 Do not delete internal or call-dummy breakpoints, these
15878 have to be deleted with an explicit breakpoint number
15880 ALL_TRACEPOINTS (b
)
15881 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15883 breaks_to_delete
= 1;
15887 /* Ask user only if there are some breakpoints to delete. */
15889 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15891 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15892 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15893 delete_breakpoint (b
);
15897 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15900 /* Helper function for trace_pass_command. */
15903 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15905 tp
->pass_count
= count
;
15906 observer_notify_breakpoint_modified (&tp
->base
);
15908 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15909 tp
->base
.number
, count
);
15912 /* Set passcount for tracepoint.
15914 First command argument is passcount, second is tracepoint number.
15915 If tracepoint number omitted, apply to most recently defined.
15916 Also accepts special argument "all". */
15919 trace_pass_command (char *args
, int from_tty
)
15921 struct tracepoint
*t1
;
15922 unsigned int count
;
15924 if (args
== 0 || *args
== 0)
15925 error (_("passcount command requires an "
15926 "argument (count + optional TP num)"));
15928 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15930 args
= skip_spaces (args
);
15931 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15933 struct breakpoint
*b
;
15935 args
+= 3; /* Skip special argument "all". */
15937 error (_("Junk at end of arguments."));
15939 ALL_TRACEPOINTS (b
)
15941 t1
= (struct tracepoint
*) b
;
15942 trace_pass_set_count (t1
, count
, from_tty
);
15945 else if (*args
== '\0')
15947 t1
= get_tracepoint_by_number (&args
, NULL
);
15949 trace_pass_set_count (t1
, count
, from_tty
);
15953 struct get_number_or_range_state state
;
15955 init_number_or_range (&state
, args
);
15956 while (!state
.finished
)
15958 t1
= get_tracepoint_by_number (&args
, &state
);
15960 trace_pass_set_count (t1
, count
, from_tty
);
15965 struct tracepoint
*
15966 get_tracepoint (int num
)
15968 struct breakpoint
*t
;
15970 ALL_TRACEPOINTS (t
)
15971 if (t
->number
== num
)
15972 return (struct tracepoint
*) t
;
15977 /* Find the tracepoint with the given target-side number (which may be
15978 different from the tracepoint number after disconnecting and
15981 struct tracepoint
*
15982 get_tracepoint_by_number_on_target (int num
)
15984 struct breakpoint
*b
;
15986 ALL_TRACEPOINTS (b
)
15988 struct tracepoint
*t
= (struct tracepoint
*) b
;
15990 if (t
->number_on_target
== num
)
15997 /* Utility: parse a tracepoint number and look it up in the list.
15998 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15999 If the argument is missing, the most recent tracepoint
16000 (tracepoint_count) is returned. */
16002 struct tracepoint
*
16003 get_tracepoint_by_number (char **arg
,
16004 struct get_number_or_range_state
*state
)
16006 struct breakpoint
*t
;
16008 char *instring
= arg
== NULL
? NULL
: *arg
;
16012 gdb_assert (!state
->finished
);
16013 tpnum
= get_number_or_range (state
);
16015 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
16016 tpnum
= tracepoint_count
;
16018 tpnum
= get_number (arg
);
16022 if (instring
&& *instring
)
16023 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
16026 printf_filtered (_("No previous tracepoint\n"));
16030 ALL_TRACEPOINTS (t
)
16031 if (t
->number
== tpnum
)
16033 return (struct tracepoint
*) t
;
16036 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
16041 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
16043 if (b
->thread
!= -1)
16044 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
16047 fprintf_unfiltered (fp
, " task %d", b
->task
);
16049 fprintf_unfiltered (fp
, "\n");
16052 /* Save information on user settable breakpoints (watchpoints, etc) to
16053 a new script file named FILENAME. If FILTER is non-NULL, call it
16054 on each breakpoint and only include the ones for which it returns
16058 save_breakpoints (char *filename
, int from_tty
,
16059 int (*filter
) (const struct breakpoint
*))
16061 struct breakpoint
*tp
;
16063 struct cleanup
*cleanup
;
16064 struct ui_file
*fp
;
16065 int extra_trace_bits
= 0;
16067 if (filename
== 0 || *filename
== 0)
16068 error (_("Argument required (file name in which to save)"));
16070 /* See if we have anything to save. */
16071 ALL_BREAKPOINTS (tp
)
16073 /* Skip internal and momentary breakpoints. */
16074 if (!user_breakpoint_p (tp
))
16077 /* If we have a filter, only save the breakpoints it accepts. */
16078 if (filter
&& !filter (tp
))
16083 if (is_tracepoint (tp
))
16085 extra_trace_bits
= 1;
16087 /* We can stop searching. */
16094 warning (_("Nothing to save."));
16098 filename
= tilde_expand (filename
);
16099 cleanup
= make_cleanup (xfree
, filename
);
16100 fp
= gdb_fopen (filename
, "w");
16102 error (_("Unable to open file '%s' for saving (%s)"),
16103 filename
, safe_strerror (errno
));
16104 make_cleanup_ui_file_delete (fp
);
16106 if (extra_trace_bits
)
16107 save_trace_state_variables (fp
);
16109 ALL_BREAKPOINTS (tp
)
16111 /* Skip internal and momentary breakpoints. */
16112 if (!user_breakpoint_p (tp
))
16115 /* If we have a filter, only save the breakpoints it accepts. */
16116 if (filter
&& !filter (tp
))
16119 tp
->ops
->print_recreate (tp
, fp
);
16121 /* Note, we can't rely on tp->number for anything, as we can't
16122 assume the recreated breakpoint numbers will match. Use $bpnum
16125 if (tp
->cond_string
)
16126 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
16128 if (tp
->ignore_count
)
16129 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
16131 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
16133 volatile struct gdb_exception ex
;
16135 fprintf_unfiltered (fp
, " commands\n");
16137 ui_out_redirect (current_uiout
, fp
);
16138 TRY_CATCH (ex
, RETURN_MASK_ALL
)
16140 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
16142 ui_out_redirect (current_uiout
, NULL
);
16145 throw_exception (ex
);
16147 fprintf_unfiltered (fp
, " end\n");
16150 if (tp
->enable_state
== bp_disabled
)
16151 fprintf_unfiltered (fp
, "disable $bpnum\n");
16153 /* If this is a multi-location breakpoint, check if the locations
16154 should be individually disabled. Watchpoint locations are
16155 special, and not user visible. */
16156 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
16158 struct bp_location
*loc
;
16161 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
16163 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
16167 if (extra_trace_bits
&& *default_collect
)
16168 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
16171 printf_filtered (_("Saved to file '%s'.\n"), filename
);
16172 do_cleanups (cleanup
);
16175 /* The `save breakpoints' command. */
16178 save_breakpoints_command (char *args
, int from_tty
)
16180 save_breakpoints (args
, from_tty
, NULL
);
16183 /* The `save tracepoints' command. */
16186 save_tracepoints_command (char *args
, int from_tty
)
16188 save_breakpoints (args
, from_tty
, is_tracepoint
);
16191 /* Create a vector of all tracepoints. */
16193 VEC(breakpoint_p
) *
16194 all_tracepoints (void)
16196 VEC(breakpoint_p
) *tp_vec
= 0;
16197 struct breakpoint
*tp
;
16199 ALL_TRACEPOINTS (tp
)
16201 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
16208 /* This help string is used for the break, hbreak, tbreak and thbreak
16209 commands. It is defined as a macro to prevent duplication.
16210 COMMAND should be a string constant containing the name of the
16212 #define BREAK_ARGS_HELP(command) \
16213 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16214 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16215 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16216 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
16217 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16218 If a line number is specified, break at start of code for that line.\n\
16219 If a function is specified, break at start of code for that function.\n\
16220 If an address is specified, break at that exact address.\n\
16221 With no LOCATION, uses current execution address of the selected\n\
16222 stack frame. This is useful for breaking on return to a stack frame.\n\
16224 THREADNUM is the number from \"info threads\".\n\
16225 CONDITION is a boolean expression.\n\
16227 Multiple breakpoints at one place are permitted, and useful if their\n\
16228 conditions are different.\n\
16230 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16232 /* List of subcommands for "catch". */
16233 static struct cmd_list_element
*catch_cmdlist
;
16235 /* List of subcommands for "tcatch". */
16236 static struct cmd_list_element
*tcatch_cmdlist
;
16239 add_catch_command (char *name
, char *docstring
,
16240 cmd_sfunc_ftype
*sfunc
,
16241 completer_ftype
*completer
,
16242 void *user_data_catch
,
16243 void *user_data_tcatch
)
16245 struct cmd_list_element
*command
;
16247 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16249 set_cmd_sfunc (command
, sfunc
);
16250 set_cmd_context (command
, user_data_catch
);
16251 set_cmd_completer (command
, completer
);
16253 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16255 set_cmd_sfunc (command
, sfunc
);
16256 set_cmd_context (command
, user_data_tcatch
);
16257 set_cmd_completer (command
, completer
);
16261 clear_syscall_counts (struct inferior
*inf
)
16263 struct catch_syscall_inferior_data
*inf_data
16264 = get_catch_syscall_inferior_data (inf
);
16266 inf_data
->total_syscalls_count
= 0;
16267 inf_data
->any_syscall_count
= 0;
16268 VEC_free (int, inf_data
->syscalls_counts
);
16272 save_command (char *arg
, int from_tty
)
16274 printf_unfiltered (_("\"save\" must be followed by "
16275 "the name of a save subcommand.\n"));
16276 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
16279 struct breakpoint
*
16280 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
16283 struct breakpoint
*b
, *b_tmp
;
16285 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
16287 if ((*callback
) (b
, data
))
16294 /* Zero if any of the breakpoint's locations could be a location where
16295 functions have been inlined, nonzero otherwise. */
16298 is_non_inline_function (struct breakpoint
*b
)
16300 /* The shared library event breakpoint is set on the address of a
16301 non-inline function. */
16302 if (b
->type
== bp_shlib_event
)
16308 /* Nonzero if the specified PC cannot be a location where functions
16309 have been inlined. */
16312 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
16313 const struct target_waitstatus
*ws
)
16315 struct breakpoint
*b
;
16316 struct bp_location
*bl
;
16318 ALL_BREAKPOINTS (b
)
16320 if (!is_non_inline_function (b
))
16323 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16325 if (!bl
->shlib_disabled
16326 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16334 /* Remove any references to OBJFILE which is going to be freed. */
16337 breakpoint_free_objfile (struct objfile
*objfile
)
16339 struct bp_location
**locp
, *loc
;
16341 ALL_BP_LOCATIONS (loc
, locp
)
16342 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
16343 loc
->symtab
= NULL
;
16347 initialize_breakpoint_ops (void)
16349 static int initialized
= 0;
16351 struct breakpoint_ops
*ops
;
16357 /* The breakpoint_ops structure to be inherit by all kinds of
16358 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16359 internal and momentary breakpoints, etc.). */
16360 ops
= &bkpt_base_breakpoint_ops
;
16361 *ops
= base_breakpoint_ops
;
16362 ops
->re_set
= bkpt_re_set
;
16363 ops
->insert_location
= bkpt_insert_location
;
16364 ops
->remove_location
= bkpt_remove_location
;
16365 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16366 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16367 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16368 ops
->decode_linespec
= bkpt_decode_linespec
;
16370 /* The breakpoint_ops structure to be used in regular breakpoints. */
16371 ops
= &bkpt_breakpoint_ops
;
16372 *ops
= bkpt_base_breakpoint_ops
;
16373 ops
->re_set
= bkpt_re_set
;
16374 ops
->resources_needed
= bkpt_resources_needed
;
16375 ops
->print_it
= bkpt_print_it
;
16376 ops
->print_mention
= bkpt_print_mention
;
16377 ops
->print_recreate
= bkpt_print_recreate
;
16379 /* Ranged breakpoints. */
16380 ops
= &ranged_breakpoint_ops
;
16381 *ops
= bkpt_breakpoint_ops
;
16382 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16383 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16384 ops
->print_it
= print_it_ranged_breakpoint
;
16385 ops
->print_one
= print_one_ranged_breakpoint
;
16386 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16387 ops
->print_mention
= print_mention_ranged_breakpoint
;
16388 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16390 /* Internal breakpoints. */
16391 ops
= &internal_breakpoint_ops
;
16392 *ops
= bkpt_base_breakpoint_ops
;
16393 ops
->re_set
= internal_bkpt_re_set
;
16394 ops
->check_status
= internal_bkpt_check_status
;
16395 ops
->print_it
= internal_bkpt_print_it
;
16396 ops
->print_mention
= internal_bkpt_print_mention
;
16398 /* Momentary breakpoints. */
16399 ops
= &momentary_breakpoint_ops
;
16400 *ops
= bkpt_base_breakpoint_ops
;
16401 ops
->re_set
= momentary_bkpt_re_set
;
16402 ops
->check_status
= momentary_bkpt_check_status
;
16403 ops
->print_it
= momentary_bkpt_print_it
;
16404 ops
->print_mention
= momentary_bkpt_print_mention
;
16406 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16407 ops
= &longjmp_breakpoint_ops
;
16408 *ops
= momentary_breakpoint_ops
;
16409 ops
->dtor
= longjmp_bkpt_dtor
;
16411 /* Probe breakpoints. */
16412 ops
= &bkpt_probe_breakpoint_ops
;
16413 *ops
= bkpt_breakpoint_ops
;
16414 ops
->insert_location
= bkpt_probe_insert_location
;
16415 ops
->remove_location
= bkpt_probe_remove_location
;
16416 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16417 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16420 ops
= &watchpoint_breakpoint_ops
;
16421 *ops
= base_breakpoint_ops
;
16422 ops
->dtor
= dtor_watchpoint
;
16423 ops
->re_set
= re_set_watchpoint
;
16424 ops
->insert_location
= insert_watchpoint
;
16425 ops
->remove_location
= remove_watchpoint
;
16426 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16427 ops
->check_status
= check_status_watchpoint
;
16428 ops
->resources_needed
= resources_needed_watchpoint
;
16429 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16430 ops
->print_it
= print_it_watchpoint
;
16431 ops
->print_mention
= print_mention_watchpoint
;
16432 ops
->print_recreate
= print_recreate_watchpoint
;
16433 ops
->explains_signal
= explains_signal_watchpoint
;
16435 /* Masked watchpoints. */
16436 ops
= &masked_watchpoint_breakpoint_ops
;
16437 *ops
= watchpoint_breakpoint_ops
;
16438 ops
->insert_location
= insert_masked_watchpoint
;
16439 ops
->remove_location
= remove_masked_watchpoint
;
16440 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16441 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16442 ops
->print_it
= print_it_masked_watchpoint
;
16443 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16444 ops
->print_mention
= print_mention_masked_watchpoint
;
16445 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16448 ops
= &tracepoint_breakpoint_ops
;
16449 *ops
= base_breakpoint_ops
;
16450 ops
->re_set
= tracepoint_re_set
;
16451 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16452 ops
->print_one_detail
= tracepoint_print_one_detail
;
16453 ops
->print_mention
= tracepoint_print_mention
;
16454 ops
->print_recreate
= tracepoint_print_recreate
;
16455 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16456 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16457 ops
->decode_linespec
= tracepoint_decode_linespec
;
16459 /* Probe tracepoints. */
16460 ops
= &tracepoint_probe_breakpoint_ops
;
16461 *ops
= tracepoint_breakpoint_ops
;
16462 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16463 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16465 /* Static tracepoints with marker (`-m'). */
16466 ops
= &strace_marker_breakpoint_ops
;
16467 *ops
= tracepoint_breakpoint_ops
;
16468 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16469 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16470 ops
->decode_linespec
= strace_marker_decode_linespec
;
16472 /* Fork catchpoints. */
16473 ops
= &catch_fork_breakpoint_ops
;
16474 *ops
= base_breakpoint_ops
;
16475 ops
->insert_location
= insert_catch_fork
;
16476 ops
->remove_location
= remove_catch_fork
;
16477 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16478 ops
->print_it
= print_it_catch_fork
;
16479 ops
->print_one
= print_one_catch_fork
;
16480 ops
->print_mention
= print_mention_catch_fork
;
16481 ops
->print_recreate
= print_recreate_catch_fork
;
16483 /* Vfork catchpoints. */
16484 ops
= &catch_vfork_breakpoint_ops
;
16485 *ops
= base_breakpoint_ops
;
16486 ops
->insert_location
= insert_catch_vfork
;
16487 ops
->remove_location
= remove_catch_vfork
;
16488 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16489 ops
->print_it
= print_it_catch_vfork
;
16490 ops
->print_one
= print_one_catch_vfork
;
16491 ops
->print_mention
= print_mention_catch_vfork
;
16492 ops
->print_recreate
= print_recreate_catch_vfork
;
16494 /* Exec catchpoints. */
16495 ops
= &catch_exec_breakpoint_ops
;
16496 *ops
= base_breakpoint_ops
;
16497 ops
->dtor
= dtor_catch_exec
;
16498 ops
->insert_location
= insert_catch_exec
;
16499 ops
->remove_location
= remove_catch_exec
;
16500 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16501 ops
->print_it
= print_it_catch_exec
;
16502 ops
->print_one
= print_one_catch_exec
;
16503 ops
->print_mention
= print_mention_catch_exec
;
16504 ops
->print_recreate
= print_recreate_catch_exec
;
16506 /* Syscall catchpoints. */
16507 ops
= &catch_syscall_breakpoint_ops
;
16508 *ops
= base_breakpoint_ops
;
16509 ops
->dtor
= dtor_catch_syscall
;
16510 ops
->insert_location
= insert_catch_syscall
;
16511 ops
->remove_location
= remove_catch_syscall
;
16512 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16513 ops
->print_it
= print_it_catch_syscall
;
16514 ops
->print_one
= print_one_catch_syscall
;
16515 ops
->print_mention
= print_mention_catch_syscall
;
16516 ops
->print_recreate
= print_recreate_catch_syscall
;
16518 /* Solib-related catchpoints. */
16519 ops
= &catch_solib_breakpoint_ops
;
16520 *ops
= base_breakpoint_ops
;
16521 ops
->dtor
= dtor_catch_solib
;
16522 ops
->insert_location
= insert_catch_solib
;
16523 ops
->remove_location
= remove_catch_solib
;
16524 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16525 ops
->check_status
= check_status_catch_solib
;
16526 ops
->print_it
= print_it_catch_solib
;
16527 ops
->print_one
= print_one_catch_solib
;
16528 ops
->print_mention
= print_mention_catch_solib
;
16529 ops
->print_recreate
= print_recreate_catch_solib
;
16531 ops
= &dprintf_breakpoint_ops
;
16532 *ops
= bkpt_base_breakpoint_ops
;
16533 ops
->re_set
= dprintf_re_set
;
16534 ops
->resources_needed
= bkpt_resources_needed
;
16535 ops
->print_it
= bkpt_print_it
;
16536 ops
->print_mention
= bkpt_print_mention
;
16537 ops
->print_recreate
= dprintf_print_recreate
;
16538 ops
->after_condition_true
= dprintf_after_condition_true
;
16539 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16542 /* Chain containing all defined "enable breakpoint" subcommands. */
16544 static struct cmd_list_element
*enablebreaklist
= NULL
;
16547 _initialize_breakpoint (void)
16549 struct cmd_list_element
*c
;
16551 initialize_breakpoint_ops ();
16553 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16554 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16555 observer_attach_inferior_exit (clear_syscall_counts
);
16556 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16558 breakpoint_objfile_key
16559 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16561 catch_syscall_inferior_data
16562 = register_inferior_data_with_cleanup (NULL
,
16563 catch_syscall_inferior_data_cleanup
);
16565 breakpoint_chain
= 0;
16566 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16567 before a breakpoint is set. */
16568 breakpoint_count
= 0;
16570 tracepoint_count
= 0;
16572 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16573 Set ignore-count of breakpoint number N to COUNT.\n\
16574 Usage is `ignore N COUNT'."));
16576 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16578 add_com ("commands", class_breakpoint
, commands_command
, _("\
16579 Set commands to be executed when a breakpoint is hit.\n\
16580 Give breakpoint number as argument after \"commands\".\n\
16581 With no argument, the targeted breakpoint is the last one set.\n\
16582 The commands themselves follow starting on the next line.\n\
16583 Type a line containing \"end\" to indicate the end of them.\n\
16584 Give \"silent\" as the first line to make the breakpoint silent;\n\
16585 then no output is printed when it is hit, except what the commands print."));
16587 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16588 Specify breakpoint number N to break only if COND is true.\n\
16589 Usage is `condition N COND', where N is an integer and COND is an\n\
16590 expression to be evaluated whenever breakpoint N is reached."));
16591 set_cmd_completer (c
, condition_completer
);
16593 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16594 Set a temporary breakpoint.\n\
16595 Like \"break\" except the breakpoint is only temporary,\n\
16596 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16597 by using \"enable delete\" on the breakpoint number.\n\
16599 BREAK_ARGS_HELP ("tbreak")));
16600 set_cmd_completer (c
, location_completer
);
16602 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16603 Set a hardware assisted breakpoint.\n\
16604 Like \"break\" except the breakpoint requires hardware support,\n\
16605 some target hardware may not have this support.\n\
16607 BREAK_ARGS_HELP ("hbreak")));
16608 set_cmd_completer (c
, location_completer
);
16610 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16611 Set a temporary hardware assisted breakpoint.\n\
16612 Like \"hbreak\" except the breakpoint is only temporary,\n\
16613 so it will be deleted when hit.\n\
16615 BREAK_ARGS_HELP ("thbreak")));
16616 set_cmd_completer (c
, location_completer
);
16618 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16619 Enable some breakpoints.\n\
16620 Give breakpoint numbers (separated by spaces) as arguments.\n\
16621 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16622 This is used to cancel the effect of the \"disable\" command.\n\
16623 With a subcommand you can enable temporarily."),
16624 &enablelist
, "enable ", 1, &cmdlist
);
16626 add_com ("ab", class_breakpoint
, enable_command
, _("\
16627 Enable some breakpoints.\n\
16628 Give breakpoint numbers (separated by spaces) as arguments.\n\
16629 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16630 This is used to cancel the effect of the \"disable\" command.\n\
16631 With a subcommand you can enable temporarily."));
16633 add_com_alias ("en", "enable", class_breakpoint
, 1);
16635 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16636 Enable some breakpoints.\n\
16637 Give breakpoint numbers (separated by spaces) as arguments.\n\
16638 This is used to cancel the effect of the \"disable\" command.\n\
16639 May be abbreviated to simply \"enable\".\n"),
16640 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16642 add_cmd ("once", no_class
, enable_once_command
, _("\
16643 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16644 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16647 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16648 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16649 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16652 add_cmd ("count", no_class
, enable_count_command
, _("\
16653 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16654 If a breakpoint is hit while enabled in this fashion,\n\
16655 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16658 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16659 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16660 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16663 add_cmd ("once", no_class
, enable_once_command
, _("\
16664 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16665 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16668 add_cmd ("count", no_class
, enable_count_command
, _("\
16669 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16670 If a breakpoint is hit while enabled in this fashion,\n\
16671 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16674 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16675 Disable some breakpoints.\n\
16676 Arguments are breakpoint numbers with spaces in between.\n\
16677 To disable all breakpoints, give no argument.\n\
16678 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16679 &disablelist
, "disable ", 1, &cmdlist
);
16680 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16681 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16683 add_com ("sb", class_breakpoint
, disable_command
, _("\
16684 Disable some breakpoints.\n\
16685 Arguments are breakpoint numbers with spaces in between.\n\
16686 To disable all breakpoints, give no argument.\n\
16687 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16689 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16690 Disable some breakpoints.\n\
16691 Arguments are breakpoint numbers with spaces in between.\n\
16692 To disable all breakpoints, give no argument.\n\
16693 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16694 This command may be abbreviated \"disable\"."),
16697 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16698 Delete some breakpoints or auto-display expressions.\n\
16699 Arguments are breakpoint numbers with spaces in between.\n\
16700 To delete all breakpoints, give no argument.\n\
16702 Also a prefix command for deletion of other GDB objects.\n\
16703 The \"unset\" command is also an alias for \"delete\"."),
16704 &deletelist
, "delete ", 1, &cmdlist
);
16705 add_com_alias ("d", "delete", class_breakpoint
, 1);
16706 add_com_alias ("del", "delete", class_breakpoint
, 1);
16708 add_com ("db", class_breakpoint
, delete_command
, _("\
16709 Delete some breakpoints.\n\
16710 Arguments are breakpoint numbers with spaces in between.\n\
16711 To delete all breakpoints, give no argument.\n"));
16713 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16714 Delete some breakpoints or auto-display expressions.\n\
16715 Arguments are breakpoint numbers with spaces in between.\n\
16716 To delete all breakpoints, give no argument.\n\
16717 This command may be abbreviated \"delete\"."),
16720 add_com ("clear", class_breakpoint
, clear_command
, _("\
16721 Clear breakpoint at specified line or function.\n\
16722 Argument may be line number, function name, or \"*\" and an address.\n\
16723 If line number is specified, all breakpoints in that line are cleared.\n\
16724 If function is specified, breakpoints at beginning of function are cleared.\n\
16725 If an address is specified, breakpoints at that address are cleared.\n\
16727 With no argument, clears all breakpoints in the line that the selected frame\n\
16728 is executing in.\n\
16730 See also the \"delete\" command which clears breakpoints by number."));
16731 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16733 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16734 Set breakpoint at specified line or function.\n"
16735 BREAK_ARGS_HELP ("break")));
16736 set_cmd_completer (c
, location_completer
);
16738 add_com_alias ("b", "break", class_run
, 1);
16739 add_com_alias ("br", "break", class_run
, 1);
16740 add_com_alias ("bre", "break", class_run
, 1);
16741 add_com_alias ("brea", "break", class_run
, 1);
16744 add_com_alias ("ba", "break", class_breakpoint
, 1);
16748 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16749 Break in function/address or break at a line in the current file."),
16750 &stoplist
, "stop ", 1, &cmdlist
);
16751 add_cmd ("in", class_breakpoint
, stopin_command
,
16752 _("Break in function or address."), &stoplist
);
16753 add_cmd ("at", class_breakpoint
, stopat_command
,
16754 _("Break at a line in the current file."), &stoplist
);
16755 add_com ("status", class_info
, breakpoints_info
, _("\
16756 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16757 The \"Type\" column indicates one of:\n\
16758 \tbreakpoint - normal breakpoint\n\
16759 \twatchpoint - watchpoint\n\
16760 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16761 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16762 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16763 address and file/line number respectively.\n\
16765 Convenience variable \"$_\" and default examine address for \"x\"\n\
16766 are set to the address of the last breakpoint listed unless the command\n\
16767 is prefixed with \"server \".\n\n\
16768 Convenience variable \"$bpnum\" contains the number of the last\n\
16769 breakpoint set."));
16772 add_info ("breakpoints", breakpoints_info
, _("\
16773 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16774 The \"Type\" column indicates one of:\n\
16775 \tbreakpoint - normal breakpoint\n\
16776 \twatchpoint - watchpoint\n\
16777 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16778 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16779 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16780 address and file/line number respectively.\n\
16782 Convenience variable \"$_\" and default examine address for \"x\"\n\
16783 are set to the address of the last breakpoint listed unless the command\n\
16784 is prefixed with \"server \".\n\n\
16785 Convenience variable \"$bpnum\" contains the number of the last\n\
16786 breakpoint set."));
16788 add_info_alias ("b", "breakpoints", 1);
16791 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16792 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16793 The \"Type\" column indicates one of:\n\
16794 \tbreakpoint - normal breakpoint\n\
16795 \twatchpoint - watchpoint\n\
16796 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16797 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16798 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16799 address and file/line number respectively.\n\
16801 Convenience variable \"$_\" and default examine address for \"x\"\n\
16802 are set to the address of the last breakpoint listed unless the command\n\
16803 is prefixed with \"server \".\n\n\
16804 Convenience variable \"$bpnum\" contains the number of the last\n\
16805 breakpoint set."));
16807 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16808 Status of all breakpoints, or breakpoint number NUMBER.\n\
16809 The \"Type\" column indicates one of:\n\
16810 \tbreakpoint - normal breakpoint\n\
16811 \twatchpoint - watchpoint\n\
16812 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16813 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16814 \tuntil - internal breakpoint used by the \"until\" command\n\
16815 \tfinish - internal breakpoint used by the \"finish\" command\n\
16816 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16817 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16818 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16819 address and file/line number respectively.\n\
16821 Convenience variable \"$_\" and default examine address for \"x\"\n\
16822 are set to the address of the last breakpoint listed unless the command\n\
16823 is prefixed with \"server \".\n\n\
16824 Convenience variable \"$bpnum\" contains the number of the last\n\
16826 &maintenanceinfolist
);
16828 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16829 Set catchpoints to catch events."),
16830 &catch_cmdlist
, "catch ",
16831 0/*allow-unknown*/, &cmdlist
);
16833 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16834 Set temporary catchpoints to catch events."),
16835 &tcatch_cmdlist
, "tcatch ",
16836 0/*allow-unknown*/, &cmdlist
);
16838 add_catch_command ("fork", _("Catch calls to fork."),
16839 catch_fork_command_1
,
16841 (void *) (uintptr_t) catch_fork_permanent
,
16842 (void *) (uintptr_t) catch_fork_temporary
);
16843 add_catch_command ("vfork", _("Catch calls to vfork."),
16844 catch_fork_command_1
,
16846 (void *) (uintptr_t) catch_vfork_permanent
,
16847 (void *) (uintptr_t) catch_vfork_temporary
);
16848 add_catch_command ("exec", _("Catch calls to exec."),
16849 catch_exec_command_1
,
16853 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16854 Usage: catch load [REGEX]\n\
16855 If REGEX is given, only stop for libraries matching the regular expression."),
16856 catch_load_command_1
,
16860 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16861 Usage: catch unload [REGEX]\n\
16862 If REGEX is given, only stop for libraries matching the regular expression."),
16863 catch_unload_command_1
,
16867 add_catch_command ("syscall", _("\
16868 Catch system calls by their names and/or numbers.\n\
16869 Arguments say which system calls to catch. If no arguments\n\
16870 are given, every system call will be caught.\n\
16871 Arguments, if given, should be one or more system call names\n\
16872 (if your system supports that), or system call numbers."),
16873 catch_syscall_command_1
,
16874 catch_syscall_completer
,
16878 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16879 Set a watchpoint for an expression.\n\
16880 Usage: watch [-l|-location] EXPRESSION\n\
16881 A watchpoint stops execution of your program whenever the value of\n\
16882 an expression changes.\n\
16883 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16884 the memory to which it refers."));
16885 set_cmd_completer (c
, expression_completer
);
16887 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16888 Set a read watchpoint for an expression.\n\
16889 Usage: rwatch [-l|-location] EXPRESSION\n\
16890 A watchpoint stops execution of your program whenever the value of\n\
16891 an expression is read.\n\
16892 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16893 the memory to which it refers."));
16894 set_cmd_completer (c
, expression_completer
);
16896 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16897 Set a watchpoint for an expression.\n\
16898 Usage: awatch [-l|-location] EXPRESSION\n\
16899 A watchpoint stops execution of your program whenever the value of\n\
16900 an expression is either read or written.\n\
16901 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16902 the memory to which it refers."));
16903 set_cmd_completer (c
, expression_completer
);
16905 add_info ("watchpoints", watchpoints_info
, _("\
16906 Status of specified watchpoints (all watchpoints if no argument)."));
16908 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16909 respond to changes - contrary to the description. */
16910 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16911 &can_use_hw_watchpoints
, _("\
16912 Set debugger's willingness to use watchpoint hardware."), _("\
16913 Show debugger's willingness to use watchpoint hardware."), _("\
16914 If zero, gdb will not use hardware for new watchpoints, even if\n\
16915 such is available. (However, any hardware watchpoints that were\n\
16916 created before setting this to nonzero, will continue to use watchpoint\n\
16919 show_can_use_hw_watchpoints
,
16920 &setlist
, &showlist
);
16922 can_use_hw_watchpoints
= 1;
16924 /* Tracepoint manipulation commands. */
16926 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16927 Set a tracepoint at specified line or function.\n\
16929 BREAK_ARGS_HELP ("trace") "\n\
16930 Do \"help tracepoints\" for info on other tracepoint commands."));
16931 set_cmd_completer (c
, location_completer
);
16933 add_com_alias ("tp", "trace", class_alias
, 0);
16934 add_com_alias ("tr", "trace", class_alias
, 1);
16935 add_com_alias ("tra", "trace", class_alias
, 1);
16936 add_com_alias ("trac", "trace", class_alias
, 1);
16938 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16939 Set a fast tracepoint at specified line or function.\n\
16941 BREAK_ARGS_HELP ("ftrace") "\n\
16942 Do \"help tracepoints\" for info on other tracepoint commands."));
16943 set_cmd_completer (c
, location_completer
);
16945 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16946 Set a static tracepoint at specified line, function or marker.\n\
16948 strace [LOCATION] [if CONDITION]\n\
16949 LOCATION may be a line number, function name, \"*\" and an address,\n\
16950 or -m MARKER_ID.\n\
16951 If a line number is specified, probe the marker at start of code\n\
16952 for that line. If a function is specified, probe the marker at start\n\
16953 of code for that function. If an address is specified, probe the marker\n\
16954 at that exact address. If a marker id is specified, probe the marker\n\
16955 with that name. With no LOCATION, uses current execution address of\n\
16956 the selected stack frame.\n\
16957 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16958 This collects arbitrary user data passed in the probe point call to the\n\
16959 tracing library. You can inspect it when analyzing the trace buffer,\n\
16960 by printing the $_sdata variable like any other convenience variable.\n\
16962 CONDITION is a boolean expression.\n\
16964 Multiple tracepoints at one place are permitted, and useful if their\n\
16965 conditions are different.\n\
16967 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16968 Do \"help tracepoints\" for info on other tracepoint commands."));
16969 set_cmd_completer (c
, location_completer
);
16971 add_info ("tracepoints", tracepoints_info
, _("\
16972 Status of specified tracepoints (all tracepoints if no argument).\n\
16973 Convenience variable \"$tpnum\" contains the number of the\n\
16974 last tracepoint set."));
16976 add_info_alias ("tp", "tracepoints", 1);
16978 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16979 Delete specified tracepoints.\n\
16980 Arguments are tracepoint numbers, separated by spaces.\n\
16981 No argument means delete all tracepoints."),
16983 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16985 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16986 Disable specified tracepoints.\n\
16987 Arguments are tracepoint numbers, separated by spaces.\n\
16988 No argument means disable all tracepoints."),
16990 deprecate_cmd (c
, "disable");
16992 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16993 Enable specified tracepoints.\n\
16994 Arguments are tracepoint numbers, separated by spaces.\n\
16995 No argument means enable all tracepoints."),
16997 deprecate_cmd (c
, "enable");
16999 add_com ("passcount", class_trace
, trace_pass_command
, _("\
17000 Set the passcount for a tracepoint.\n\
17001 The trace will end when the tracepoint has been passed 'count' times.\n\
17002 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
17003 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
17005 add_prefix_cmd ("save", class_breakpoint
, save_command
,
17006 _("Save breakpoint definitions as a script."),
17007 &save_cmdlist
, "save ",
17008 0/*allow-unknown*/, &cmdlist
);
17010 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
17011 Save current breakpoint definitions as a script.\n\
17012 This includes all types of breakpoints (breakpoints, watchpoints,\n\
17013 catchpoints, tracepoints). Use the 'source' command in another debug\n\
17014 session to restore them."),
17016 set_cmd_completer (c
, filename_completer
);
17018 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
17019 Save current tracepoint definitions as a script.\n\
17020 Use the 'source' command in another debug session to restore them."),
17022 set_cmd_completer (c
, filename_completer
);
17024 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
17025 deprecate_cmd (c
, "save tracepoints");
17027 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
17028 Breakpoint specific settings\n\
17029 Configure various breakpoint-specific variables such as\n\
17030 pending breakpoint behavior"),
17031 &breakpoint_set_cmdlist
, "set breakpoint ",
17032 0/*allow-unknown*/, &setlist
);
17033 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
17034 Breakpoint specific settings\n\
17035 Configure various breakpoint-specific variables such as\n\
17036 pending breakpoint behavior"),
17037 &breakpoint_show_cmdlist
, "show breakpoint ",
17038 0/*allow-unknown*/, &showlist
);
17040 add_setshow_auto_boolean_cmd ("pending", no_class
,
17041 &pending_break_support
, _("\
17042 Set debugger's behavior regarding pending breakpoints."), _("\
17043 Show debugger's behavior regarding pending breakpoints."), _("\
17044 If on, an unrecognized breakpoint location will cause gdb to create a\n\
17045 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
17046 an error. If auto, an unrecognized breakpoint location results in a\n\
17047 user-query to see if a pending breakpoint should be created."),
17049 show_pending_break_support
,
17050 &breakpoint_set_cmdlist
,
17051 &breakpoint_show_cmdlist
);
17053 pending_break_support
= AUTO_BOOLEAN_AUTO
;
17055 add_setshow_boolean_cmd ("auto-hw", no_class
,
17056 &automatic_hardware_breakpoints
, _("\
17057 Set automatic usage of hardware breakpoints."), _("\
17058 Show automatic usage of hardware breakpoints."), _("\
17059 If set, the debugger will automatically use hardware breakpoints for\n\
17060 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
17061 a warning will be emitted for such breakpoints."),
17063 show_automatic_hardware_breakpoints
,
17064 &breakpoint_set_cmdlist
,
17065 &breakpoint_show_cmdlist
);
17067 add_setshow_boolean_cmd ("always-inserted", class_support
,
17068 &always_inserted_mode
, _("\
17069 Set mode for inserting breakpoints."), _("\
17070 Show mode for inserting breakpoints."), _("\
17071 When this mode is on, breakpoints are inserted immediately as soon as\n\
17072 they're created, kept inserted even when execution stops, and removed\n\
17073 only when the user deletes them. When this mode is off (the default),\n\
17074 breakpoints are inserted only when execution continues, and removed\n\
17075 when execution stops."),
17077 &show_always_inserted_mode
,
17078 &breakpoint_set_cmdlist
,
17079 &breakpoint_show_cmdlist
);
17081 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
17082 condition_evaluation_enums
,
17083 &condition_evaluation_mode_1
, _("\
17084 Set mode of breakpoint condition evaluation."), _("\
17085 Show mode of breakpoint condition evaluation."), _("\
17086 When this is set to \"host\", breakpoint conditions will be\n\
17087 evaluated on the host's side by GDB. When it is set to \"target\",\n\
17088 breakpoint conditions will be downloaded to the target (if the target\n\
17089 supports such feature) and conditions will be evaluated on the target's side.\n\
17090 If this is set to \"auto\" (default), this will be automatically set to\n\
17091 \"target\" if it supports condition evaluation, otherwise it will\n\
17092 be set to \"gdb\""),
17093 &set_condition_evaluation_mode
,
17094 &show_condition_evaluation_mode
,
17095 &breakpoint_set_cmdlist
,
17096 &breakpoint_show_cmdlist
);
17098 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
17099 Set a breakpoint for an address range.\n\
17100 break-range START-LOCATION, END-LOCATION\n\
17101 where START-LOCATION and END-LOCATION can be one of the following:\n\
17102 LINENUM, for that line in the current file,\n\
17103 FILE:LINENUM, for that line in that file,\n\
17104 +OFFSET, for that number of lines after the current line\n\
17105 or the start of the range\n\
17106 FUNCTION, for the first line in that function,\n\
17107 FILE:FUNCTION, to distinguish among like-named static functions.\n\
17108 *ADDRESS, for the instruction at that address.\n\
17110 The breakpoint will stop execution of the inferior whenever it executes\n\
17111 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
17112 range (including START-LOCATION and END-LOCATION)."));
17114 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
17115 Set a dynamic printf at specified line or function.\n\
17116 dprintf location,format string,arg1,arg2,...\n\
17117 location may be a line number, function name, or \"*\" and an address.\n\
17118 If a line number is specified, break at start of code for that line.\n\
17119 If a function is specified, break at start of code for that function."));
17120 set_cmd_completer (c
, location_completer
);
17122 add_setshow_enum_cmd ("dprintf-style", class_support
,
17123 dprintf_style_enums
, &dprintf_style
, _("\
17124 Set the style of usage for dynamic printf."), _("\
17125 Show the style of usage for dynamic printf."), _("\
17126 This setting chooses how GDB will do a dynamic printf.\n\
17127 If the value is \"gdb\", then the printing is done by GDB to its own\n\
17128 console, as with the \"printf\" command.\n\
17129 If the value is \"call\", the print is done by calling a function in your\n\
17130 program; by default printf(), but you can choose a different function or\n\
17131 output stream by setting dprintf-function and dprintf-channel."),
17132 update_dprintf_commands
, NULL
,
17133 &setlist
, &showlist
);
17135 dprintf_function
= xstrdup ("printf");
17136 add_setshow_string_cmd ("dprintf-function", class_support
,
17137 &dprintf_function
, _("\
17138 Set the function to use for dynamic printf"), _("\
17139 Show the function to use for dynamic printf"), NULL
,
17140 update_dprintf_commands
, NULL
,
17141 &setlist
, &showlist
);
17143 dprintf_channel
= xstrdup ("");
17144 add_setshow_string_cmd ("dprintf-channel", class_support
,
17145 &dprintf_channel
, _("\
17146 Set the channel to use for dynamic printf"), _("\
17147 Show the channel to use for dynamic printf"), NULL
,
17148 update_dprintf_commands
, NULL
,
17149 &setlist
, &showlist
);
17151 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
17152 &disconnected_dprintf
, _("\
17153 Set whether dprintf continues after GDB disconnects."), _("\
17154 Show whether dprintf continues after GDB disconnects."), _("\
17155 Use this to let dprintf commands continue to hit and produce output\n\
17156 even if GDB disconnects or detaches from the target."),
17159 &setlist
, &showlist
);
17161 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
17162 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
17163 (target agent only) This is useful for formatted output in user-defined commands."));
17165 automatic_hardware_breakpoints
= 1;
17167 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
17168 observer_attach_thread_exit (remove_threaded_breakpoints
);