1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2016 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 "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
71 #include "thread-fsm.h"
72 #include "tid-parse.h"
74 /* readline include files */
75 #include "readline/readline.h"
76 #include "readline/history.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "extension.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
108 static void ignore_command (char *, int);
110 static int breakpoint_re_set_one (void *);
112 static void breakpoint_re_set_default (struct breakpoint
*);
115 create_sals_from_location_default (const struct event_location
*location
,
116 struct linespec_result
*canonical
,
117 enum bptype type_wanted
);
119 static void create_breakpoints_sal_default (struct gdbarch
*,
120 struct linespec_result
*,
121 char *, char *, enum bptype
,
122 enum bpdisp
, int, int,
124 const struct breakpoint_ops
*,
125 int, int, int, unsigned);
127 static void decode_location_default (struct breakpoint
*b
,
128 const struct event_location
*location
,
129 struct program_space
*search_pspace
,
130 struct symtabs_and_lines
*sals
);
132 static void clear_command (char *, int);
134 static void catch_command (char *, int);
136 static int can_use_hardware_watchpoint (struct value
*);
138 static void break_command_1 (char *, int, int);
140 static void mention (struct breakpoint
*);
142 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
144 const struct breakpoint_ops
*);
145 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
146 const struct symtab_and_line
*);
148 /* This function is used in gdbtk sources and thus can not be made
150 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
151 struct symtab_and_line
,
153 const struct breakpoint_ops
*);
155 static struct breakpoint
*
156 momentary_breakpoint_from_master (struct breakpoint
*orig
,
158 const struct breakpoint_ops
*ops
,
161 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
163 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
167 static void describe_other_breakpoints (struct gdbarch
*,
168 struct program_space
*, CORE_ADDR
,
169 struct obj_section
*, int);
171 static int watchpoint_locations_match (struct bp_location
*loc1
,
172 struct bp_location
*loc2
);
174 static int breakpoint_location_address_match (struct bp_location
*bl
,
175 struct address_space
*aspace
,
178 static int breakpoint_location_address_range_overlap (struct bp_location
*,
179 struct address_space
*,
182 static void breakpoints_info (char *, int);
184 static void watchpoints_info (char *, int);
186 static int breakpoint_1 (char *, int,
187 int (*) (const struct breakpoint
*));
189 static int breakpoint_cond_eval (void *);
191 static void cleanup_executing_breakpoints (void *);
193 static void commands_command (char *, int);
195 static void condition_command (char *, int);
204 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
205 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
207 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
209 static int watchpoint_check (void *);
211 static void maintenance_info_breakpoints (char *, int);
213 static int hw_breakpoint_used_count (void);
215 static int hw_watchpoint_use_count (struct breakpoint
*);
217 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
219 int *other_type_used
);
221 static void hbreak_command (char *, int);
223 static void thbreak_command (char *, int);
225 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
228 static void stop_command (char *arg
, int from_tty
);
230 static void stopin_command (char *arg
, int from_tty
);
232 static void stopat_command (char *arg
, int from_tty
);
234 static void tcatch_command (char *arg
, int from_tty
);
236 static void free_bp_location (struct bp_location
*loc
);
237 static void incref_bp_location (struct bp_location
*loc
);
238 static void decref_bp_location (struct bp_location
**loc
);
240 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
242 /* update_global_location_list's modes of operation wrt to whether to
243 insert locations now. */
244 enum ugll_insert_mode
246 /* Don't insert any breakpoint locations into the inferior, only
247 remove already-inserted locations that no longer should be
248 inserted. Functions that delete a breakpoint or breakpoints
249 should specify this mode, so that deleting a breakpoint doesn't
250 have the side effect of inserting the locations of other
251 breakpoints that are marked not-inserted, but should_be_inserted
252 returns true on them.
254 This behavior is useful is situations close to tear-down -- e.g.,
255 after an exec, while the target still has execution, but
256 breakpoint shadows of the previous executable image should *NOT*
257 be restored to the new image; or before detaching, where the
258 target still has execution and wants to delete breakpoints from
259 GDB's lists, and all breakpoints had already been removed from
263 /* May insert breakpoints iff breakpoints_should_be_inserted_now
264 claims breakpoints should be inserted now. */
267 /* Insert locations now, irrespective of
268 breakpoints_should_be_inserted_now. E.g., say all threads are
269 stopped right now, and the user did "continue". We need to
270 insert breakpoints _before_ resuming the target, but
271 UGLL_MAY_INSERT wouldn't insert them, because
272 breakpoints_should_be_inserted_now returns false at that point,
273 as no thread is running yet. */
277 static void update_global_location_list (enum ugll_insert_mode
);
279 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
281 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
283 static void insert_breakpoint_locations (void);
285 static void tracepoints_info (char *, int);
287 static void delete_trace_command (char *, int);
289 static void enable_trace_command (char *, int);
291 static void disable_trace_command (char *, int);
293 static void trace_pass_command (char *, int);
295 static void set_tracepoint_count (int num
);
297 static int is_masked_watchpoint (const struct breakpoint
*b
);
299 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
301 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
304 static int strace_marker_p (struct breakpoint
*b
);
306 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
307 that are implemented on top of software or hardware breakpoints
308 (user breakpoints, internal and momentary breakpoints, etc.). */
309 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
311 /* Internal breakpoints class type. */
312 static struct breakpoint_ops internal_breakpoint_ops
;
314 /* Momentary breakpoints class type. */
315 static struct breakpoint_ops momentary_breakpoint_ops
;
317 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
318 static struct breakpoint_ops longjmp_breakpoint_ops
;
320 /* The breakpoint_ops structure to be used in regular user created
322 struct breakpoint_ops bkpt_breakpoint_ops
;
324 /* Breakpoints set on probes. */
325 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
327 /* Dynamic printf class type. */
328 struct breakpoint_ops dprintf_breakpoint_ops
;
330 /* The style in which to perform a dynamic printf. This is a user
331 option because different output options have different tradeoffs;
332 if GDB does the printing, there is better error handling if there
333 is a problem with any of the arguments, but using an inferior
334 function lets you have special-purpose printers and sending of
335 output to the same place as compiled-in print functions. */
337 static const char dprintf_style_gdb
[] = "gdb";
338 static const char dprintf_style_call
[] = "call";
339 static const char dprintf_style_agent
[] = "agent";
340 static const char *const dprintf_style_enums
[] = {
346 static const char *dprintf_style
= dprintf_style_gdb
;
348 /* The function to use for dynamic printf if the preferred style is to
349 call into the inferior. The value is simply a string that is
350 copied into the command, so it can be anything that GDB can
351 evaluate to a callable address, not necessarily a function name. */
353 static char *dprintf_function
= "";
355 /* The channel to use for dynamic printf if the preferred style is to
356 call into the inferior; if a nonempty string, it will be passed to
357 the call as the first argument, with the format string as the
358 second. As with the dprintf function, this can be anything that
359 GDB knows how to evaluate, so in addition to common choices like
360 "stderr", this could be an app-specific expression like
361 "mystreams[curlogger]". */
363 static char *dprintf_channel
= "";
365 /* True if dprintf commands should continue to operate even if GDB
367 static int disconnected_dprintf
= 1;
369 /* A reference-counted struct command_line. This lets multiple
370 breakpoints share a single command list. */
371 struct counted_command_line
373 /* The reference count. */
376 /* The command list. */
377 struct command_line
*commands
;
380 struct command_line
*
381 breakpoint_commands (struct breakpoint
*b
)
383 return b
->commands
? b
->commands
->commands
: NULL
;
386 /* Flag indicating that a command has proceeded the inferior past the
387 current breakpoint. */
389 static int breakpoint_proceeded
;
392 bpdisp_text (enum bpdisp disp
)
394 /* NOTE: the following values are a part of MI protocol and
395 represent values of 'disp' field returned when inferior stops at
397 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
399 return bpdisps
[(int) disp
];
402 /* Prototypes for exported functions. */
403 /* If FALSE, gdb will not use hardware support for watchpoints, even
404 if such is available. */
405 static int can_use_hw_watchpoints
;
408 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
409 struct cmd_list_element
*c
,
412 fprintf_filtered (file
,
413 _("Debugger's willingness to use "
414 "watchpoint hardware is %s.\n"),
418 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
419 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
420 for unrecognized breakpoint locations.
421 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
422 static enum auto_boolean pending_break_support
;
424 show_pending_break_support (struct ui_file
*file
, int from_tty
,
425 struct cmd_list_element
*c
,
428 fprintf_filtered (file
,
429 _("Debugger's behavior regarding "
430 "pending breakpoints is %s.\n"),
434 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
435 set with "break" but falling in read-only memory.
436 If 0, gdb will warn about such breakpoints, but won't automatically
437 use hardware breakpoints. */
438 static int automatic_hardware_breakpoints
;
440 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
441 struct cmd_list_element
*c
,
444 fprintf_filtered (file
,
445 _("Automatic usage of hardware breakpoints is %s.\n"),
449 /* If on, GDB keeps breakpoints inserted even if the inferior is
450 stopped, and immediately inserts any new breakpoints as soon as
451 they're created. If off (default), GDB keeps breakpoints off of
452 the target as long as possible. That is, it delays inserting
453 breakpoints until the next resume, and removes them again when the
454 target fully stops. This is a bit safer in case GDB crashes while
455 processing user input. */
456 static int always_inserted_mode
= 0;
459 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
460 struct cmd_list_element
*c
, const char *value
)
462 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
466 /* See breakpoint.h. */
469 breakpoints_should_be_inserted_now (void)
471 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
473 /* If breakpoints are global, they should be inserted even if no
474 thread under gdb's control is running, or even if there are
475 no threads under GDB's control yet. */
478 else if (target_has_execution
)
480 struct thread_info
*tp
;
482 if (always_inserted_mode
)
484 /* The user wants breakpoints inserted even if all threads
489 if (threads_are_executing ())
492 /* Don't remove breakpoints yet if, even though all threads are
493 stopped, we still have events to process. */
494 ALL_NON_EXITED_THREADS (tp
)
496 && tp
->suspend
.waitstatus_pending_p
)
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 /* See declaration at breakpoint.h. */
665 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
668 struct breakpoint
*b
= NULL
;
672 if (func (b
, user_data
) != 0)
679 /* Return whether a breakpoint is an active enabled breakpoint. */
681 breakpoint_enabled (struct breakpoint
*b
)
683 return (b
->enable_state
== bp_enabled
);
686 /* Set breakpoint count to NUM. */
689 set_breakpoint_count (int num
)
691 prev_breakpoint_count
= breakpoint_count
;
692 breakpoint_count
= num
;
693 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
696 /* Used by `start_rbreak_breakpoints' below, to record the current
697 breakpoint count before "rbreak" creates any breakpoint. */
698 static int rbreak_start_breakpoint_count
;
700 /* Called at the start an "rbreak" command to record the first
704 start_rbreak_breakpoints (void)
706 rbreak_start_breakpoint_count
= breakpoint_count
;
709 /* Called at the end of an "rbreak" command to record the last
713 end_rbreak_breakpoints (void)
715 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
718 /* Used in run_command to zero the hit count when a new run starts. */
721 clear_breakpoint_hit_counts (void)
723 struct breakpoint
*b
;
729 /* Allocate a new counted_command_line with reference count of 1.
730 The new structure owns COMMANDS. */
732 static struct counted_command_line
*
733 alloc_counted_command_line (struct command_line
*commands
)
735 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
738 result
->commands
= commands
;
743 /* Increment reference count. This does nothing if CMD is NULL. */
746 incref_counted_command_line (struct counted_command_line
*cmd
)
752 /* Decrement reference count. If the reference count reaches 0,
753 destroy the counted_command_line. Sets *CMDP to NULL. This does
754 nothing if *CMDP is NULL. */
757 decref_counted_command_line (struct counted_command_line
**cmdp
)
761 if (--(*cmdp
)->refc
== 0)
763 free_command_lines (&(*cmdp
)->commands
);
770 /* A cleanup function that calls decref_counted_command_line. */
773 do_cleanup_counted_command_line (void *arg
)
775 decref_counted_command_line ((struct counted_command_line
**) arg
);
778 /* Create a cleanup that calls decref_counted_command_line on the
781 static struct cleanup
*
782 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
784 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
788 /* Return the breakpoint with the specified number, or NULL
789 if the number does not refer to an existing breakpoint. */
792 get_breakpoint (int num
)
794 struct breakpoint
*b
;
797 if (b
->number
== num
)
805 /* Mark locations as "conditions have changed" in case the target supports
806 evaluating conditions on its side. */
809 mark_breakpoint_modified (struct breakpoint
*b
)
811 struct bp_location
*loc
;
813 /* This is only meaningful if the target is
814 evaluating conditions and if the user has
815 opted for condition evaluation on the target's
817 if (gdb_evaluates_breakpoint_condition_p ()
818 || !target_supports_evaluation_of_breakpoint_conditions ())
821 if (!is_breakpoint (b
))
824 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
825 loc
->condition_changed
= condition_modified
;
828 /* Mark location as "conditions have changed" in case the target supports
829 evaluating conditions on its side. */
832 mark_breakpoint_location_modified (struct bp_location
*loc
)
834 /* This is only meaningful if the target is
835 evaluating conditions and if the user has
836 opted for condition evaluation on the target's
838 if (gdb_evaluates_breakpoint_condition_p ()
839 || !target_supports_evaluation_of_breakpoint_conditions ())
843 if (!is_breakpoint (loc
->owner
))
846 loc
->condition_changed
= condition_modified
;
849 /* Sets the condition-evaluation mode using the static global
850 condition_evaluation_mode. */
853 set_condition_evaluation_mode (char *args
, int from_tty
,
854 struct cmd_list_element
*c
)
856 const char *old_mode
, *new_mode
;
858 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
859 && !target_supports_evaluation_of_breakpoint_conditions ())
861 condition_evaluation_mode_1
= condition_evaluation_mode
;
862 warning (_("Target does not support breakpoint condition evaluation.\n"
863 "Using host evaluation mode instead."));
867 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
868 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
870 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
871 settings was "auto". */
872 condition_evaluation_mode
= condition_evaluation_mode_1
;
874 /* Only update the mode if the user picked a different one. */
875 if (new_mode
!= old_mode
)
877 struct bp_location
*loc
, **loc_tmp
;
878 /* If the user switched to a different evaluation mode, we
879 need to synch the changes with the target as follows:
881 "host" -> "target": Send all (valid) conditions to the target.
882 "target" -> "host": Remove all the conditions from the target.
885 if (new_mode
== condition_evaluation_target
)
887 /* Mark everything modified and synch conditions with the
889 ALL_BP_LOCATIONS (loc
, loc_tmp
)
890 mark_breakpoint_location_modified (loc
);
894 /* Manually mark non-duplicate locations to synch conditions
895 with the target. We do this to remove all the conditions the
896 target knows about. */
897 ALL_BP_LOCATIONS (loc
, loc_tmp
)
898 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
899 loc
->needs_update
= 1;
903 update_global_location_list (UGLL_MAY_INSERT
);
909 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
910 what "auto" is translating to. */
913 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
914 struct cmd_list_element
*c
, const char *value
)
916 if (condition_evaluation_mode
== condition_evaluation_auto
)
917 fprintf_filtered (file
,
918 _("Breakpoint condition evaluation "
919 "mode is %s (currently %s).\n"),
921 breakpoint_condition_evaluation_mode ());
923 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
927 /* A comparison function for bp_location AP and BP that is used by
928 bsearch. This comparison function only cares about addresses, unlike
929 the more general bp_location_compare function. */
932 bp_location_compare_addrs (const void *ap
, const void *bp
)
934 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
935 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
937 if (a
->address
== b
->address
)
940 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
943 /* Helper function to skip all bp_locations with addresses
944 less than ADDRESS. It returns the first bp_location that
945 is greater than or equal to ADDRESS. If none is found, just
948 static struct bp_location
**
949 get_first_locp_gte_addr (CORE_ADDR address
)
951 struct bp_location dummy_loc
;
952 struct bp_location
*dummy_locp
= &dummy_loc
;
953 struct bp_location
**locp_found
= NULL
;
955 /* Initialize the dummy location's address field. */
956 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
957 dummy_loc
.address
= address
;
959 /* Find a close match to the first location at ADDRESS. */
960 locp_found
= ((struct bp_location
**)
961 bsearch (&dummy_locp
, bp_location
, bp_location_count
,
962 sizeof (struct bp_location
**),
963 bp_location_compare_addrs
));
965 /* Nothing was found, nothing left to do. */
966 if (locp_found
== NULL
)
969 /* We may have found a location that is at ADDRESS but is not the first in the
970 location's list. Go backwards (if possible) and locate the first one. */
971 while ((locp_found
- 1) >= bp_location
972 && (*(locp_found
- 1))->address
== address
)
979 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
982 xfree (b
->cond_string
);
983 b
->cond_string
= NULL
;
985 if (is_watchpoint (b
))
987 struct watchpoint
*w
= (struct watchpoint
*) b
;
994 struct bp_location
*loc
;
996 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1001 /* No need to free the condition agent expression
1002 bytecode (if we have one). We will handle this
1003 when we go through update_global_location_list. */
1010 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1014 const char *arg
= exp
;
1016 /* I don't know if it matters whether this is the string the user
1017 typed in or the decompiled expression. */
1018 b
->cond_string
= xstrdup (arg
);
1019 b
->condition_not_parsed
= 0;
1021 if (is_watchpoint (b
))
1023 struct watchpoint
*w
= (struct watchpoint
*) b
;
1025 innermost_block
= NULL
;
1027 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1029 error (_("Junk at end of expression"));
1030 w
->cond_exp_valid_block
= innermost_block
;
1034 struct bp_location
*loc
;
1036 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1040 parse_exp_1 (&arg
, loc
->address
,
1041 block_for_pc (loc
->address
), 0);
1043 error (_("Junk at end of expression"));
1047 mark_breakpoint_modified (b
);
1049 observer_notify_breakpoint_modified (b
);
1052 /* Completion for the "condition" command. */
1054 static VEC (char_ptr
) *
1055 condition_completer (struct cmd_list_element
*cmd
,
1056 const char *text
, const char *word
)
1060 text
= skip_spaces_const (text
);
1061 space
= skip_to_space_const (text
);
1065 struct breakpoint
*b
;
1066 VEC (char_ptr
) *result
= NULL
;
1070 /* We don't support completion of history indices. */
1071 if (isdigit (text
[1]))
1073 return complete_internalvar (&text
[1]);
1076 /* We're completing the breakpoint number. */
1077 len
= strlen (text
);
1083 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1085 if (strncmp (number
, text
, len
) == 0)
1086 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1092 /* We're completing the expression part. */
1093 text
= skip_spaces_const (space
);
1094 return expression_completer (cmd
, text
, word
);
1097 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1100 condition_command (char *arg
, int from_tty
)
1102 struct breakpoint
*b
;
1107 error_no_arg (_("breakpoint number"));
1110 bnum
= get_number (&p
);
1112 error (_("Bad breakpoint argument: '%s'"), arg
);
1115 if (b
->number
== bnum
)
1117 /* Check if this breakpoint has a "stop" method implemented in an
1118 extension language. This method and conditions entered into GDB
1119 from the CLI are mutually exclusive. */
1120 const struct extension_language_defn
*extlang
1121 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1123 if (extlang
!= NULL
)
1125 error (_("Only one stop condition allowed. There is currently"
1126 " a %s stop condition defined for this breakpoint."),
1127 ext_lang_capitalized_name (extlang
));
1129 set_breakpoint_condition (b
, p
, from_tty
);
1131 if (is_breakpoint (b
))
1132 update_global_location_list (UGLL_MAY_INSERT
);
1137 error (_("No breakpoint number %d."), bnum
);
1140 /* Check that COMMAND do not contain commands that are suitable
1141 only for tracepoints and not suitable for ordinary breakpoints.
1142 Throw if any such commands is found. */
1145 check_no_tracepoint_commands (struct command_line
*commands
)
1147 struct command_line
*c
;
1149 for (c
= commands
; c
; c
= c
->next
)
1153 if (c
->control_type
== while_stepping_control
)
1154 error (_("The 'while-stepping' command can "
1155 "only be used for tracepoints"));
1157 for (i
= 0; i
< c
->body_count
; ++i
)
1158 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1160 /* Not that command parsing removes leading whitespace and comment
1161 lines and also empty lines. So, we only need to check for
1162 command directly. */
1163 if (strstr (c
->line
, "collect ") == c
->line
)
1164 error (_("The 'collect' command can only be used for tracepoints"));
1166 if (strstr (c
->line
, "teval ") == c
->line
)
1167 error (_("The 'teval' command can only be used for tracepoints"));
1171 /* Encapsulate tests for different types of tracepoints. */
1174 is_tracepoint_type (enum bptype type
)
1176 return (type
== bp_tracepoint
1177 || type
== bp_fast_tracepoint
1178 || type
== bp_static_tracepoint
);
1182 is_tracepoint (const struct breakpoint
*b
)
1184 return is_tracepoint_type (b
->type
);
1187 /* A helper function that validates that COMMANDS are valid for a
1188 breakpoint. This function will throw an exception if a problem is
1192 validate_commands_for_breakpoint (struct breakpoint
*b
,
1193 struct command_line
*commands
)
1195 if (is_tracepoint (b
))
1197 struct tracepoint
*t
= (struct tracepoint
*) b
;
1198 struct command_line
*c
;
1199 struct command_line
*while_stepping
= 0;
1201 /* Reset the while-stepping step count. The previous commands
1202 might have included a while-stepping action, while the new
1206 /* We need to verify that each top-level element of commands is
1207 valid for tracepoints, that there's at most one
1208 while-stepping element, and that the while-stepping's body
1209 has valid tracing commands excluding nested while-stepping.
1210 We also need to validate the tracepoint action line in the
1211 context of the tracepoint --- validate_actionline actually
1212 has side effects, like setting the tracepoint's
1213 while-stepping STEP_COUNT, in addition to checking if the
1214 collect/teval actions parse and make sense in the
1215 tracepoint's context. */
1216 for (c
= commands
; c
; c
= c
->next
)
1218 if (c
->control_type
== while_stepping_control
)
1220 if (b
->type
== bp_fast_tracepoint
)
1221 error (_("The 'while-stepping' command "
1222 "cannot be used for fast tracepoint"));
1223 else if (b
->type
== bp_static_tracepoint
)
1224 error (_("The 'while-stepping' command "
1225 "cannot be used for static tracepoint"));
1228 error (_("The 'while-stepping' command "
1229 "can be used only once"));
1234 validate_actionline (c
->line
, b
);
1238 struct command_line
*c2
;
1240 gdb_assert (while_stepping
->body_count
== 1);
1241 c2
= while_stepping
->body_list
[0];
1242 for (; c2
; c2
= c2
->next
)
1244 if (c2
->control_type
== while_stepping_control
)
1245 error (_("The 'while-stepping' command cannot be nested"));
1251 check_no_tracepoint_commands (commands
);
1255 /* Return a vector of all the static tracepoints set at ADDR. The
1256 caller is responsible for releasing the vector. */
1259 static_tracepoints_here (CORE_ADDR addr
)
1261 struct breakpoint
*b
;
1262 VEC(breakpoint_p
) *found
= 0;
1263 struct bp_location
*loc
;
1266 if (b
->type
== bp_static_tracepoint
)
1268 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1269 if (loc
->address
== addr
)
1270 VEC_safe_push(breakpoint_p
, found
, b
);
1276 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1277 validate that only allowed commands are included. */
1280 breakpoint_set_commands (struct breakpoint
*b
,
1281 struct command_line
*commands
)
1283 validate_commands_for_breakpoint (b
, commands
);
1285 decref_counted_command_line (&b
->commands
);
1286 b
->commands
= alloc_counted_command_line (commands
);
1287 observer_notify_breakpoint_modified (b
);
1290 /* Set the internal `silent' flag on the breakpoint. Note that this
1291 is not the same as the "silent" that may appear in the breakpoint's
1295 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1297 int old_silent
= b
->silent
;
1300 if (old_silent
!= silent
)
1301 observer_notify_breakpoint_modified (b
);
1304 /* Set the thread for this breakpoint. If THREAD is -1, make the
1305 breakpoint work for any thread. */
1308 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1310 int old_thread
= b
->thread
;
1313 if (old_thread
!= thread
)
1314 observer_notify_breakpoint_modified (b
);
1317 /* Set the task for this breakpoint. If TASK is 0, make the
1318 breakpoint work for any task. */
1321 breakpoint_set_task (struct breakpoint
*b
, int task
)
1323 int old_task
= b
->task
;
1326 if (old_task
!= task
)
1327 observer_notify_breakpoint_modified (b
);
1331 check_tracepoint_command (char *line
, void *closure
)
1333 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1335 validate_actionline (line
, b
);
1338 /* A structure used to pass information through
1339 map_breakpoint_numbers. */
1341 struct commands_info
1343 /* True if the command was typed at a tty. */
1346 /* The breakpoint range spec. */
1349 /* Non-NULL if the body of the commands are being read from this
1350 already-parsed command. */
1351 struct command_line
*control
;
1353 /* The command lines read from the user, or NULL if they have not
1355 struct counted_command_line
*cmd
;
1358 /* A callback for map_breakpoint_numbers that sets the commands for
1359 commands_command. */
1362 do_map_commands_command (struct breakpoint
*b
, void *data
)
1364 struct commands_info
*info
= (struct commands_info
*) data
;
1366 if (info
->cmd
== NULL
)
1368 struct command_line
*l
;
1370 if (info
->control
!= NULL
)
1371 l
= copy_command_lines (info
->control
->body_list
[0]);
1374 struct cleanup
*old_chain
;
1377 str
= xstrprintf (_("Type commands for breakpoint(s) "
1378 "%s, one per line."),
1381 old_chain
= make_cleanup (xfree
, str
);
1383 l
= read_command_lines (str
,
1386 ? check_tracepoint_command
: 0),
1389 do_cleanups (old_chain
);
1392 info
->cmd
= alloc_counted_command_line (l
);
1395 /* If a breakpoint was on the list more than once, we don't need to
1397 if (b
->commands
!= info
->cmd
)
1399 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1400 incref_counted_command_line (info
->cmd
);
1401 decref_counted_command_line (&b
->commands
);
1402 b
->commands
= info
->cmd
;
1403 observer_notify_breakpoint_modified (b
);
1408 commands_command_1 (char *arg
, int from_tty
,
1409 struct command_line
*control
)
1411 struct cleanup
*cleanups
;
1412 struct commands_info info
;
1414 info
.from_tty
= from_tty
;
1415 info
.control
= control
;
1417 /* If we read command lines from the user, then `info' will hold an
1418 extra reference to the commands that we must clean up. */
1419 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1421 if (arg
== NULL
|| !*arg
)
1423 if (breakpoint_count
- prev_breakpoint_count
> 1)
1424 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1426 else if (breakpoint_count
> 0)
1427 arg
= xstrprintf ("%d", breakpoint_count
);
1430 /* So that we don't try to free the incoming non-NULL
1431 argument in the cleanup below. Mapping breakpoint
1432 numbers will fail in this case. */
1437 /* The command loop has some static state, so we need to preserve
1439 arg
= xstrdup (arg
);
1442 make_cleanup (xfree
, arg
);
1446 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1448 if (info
.cmd
== NULL
)
1449 error (_("No breakpoints specified."));
1451 do_cleanups (cleanups
);
1455 commands_command (char *arg
, int from_tty
)
1457 commands_command_1 (arg
, from_tty
, NULL
);
1460 /* Like commands_command, but instead of reading the commands from
1461 input stream, takes them from an already parsed command structure.
1463 This is used by cli-script.c to DTRT with breakpoint commands
1464 that are part of if and while bodies. */
1465 enum command_control_type
1466 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1468 commands_command_1 (arg
, 0, cmd
);
1469 return simple_control
;
1472 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1475 bp_location_has_shadow (struct bp_location
*bl
)
1477 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1481 if (bl
->target_info
.shadow_len
== 0)
1482 /* BL isn't valid, or doesn't shadow memory. */
1487 /* Update BUF, which is LEN bytes read from the target address
1488 MEMADDR, by replacing a memory breakpoint with its shadowed
1491 If READBUF is not NULL, this buffer must not overlap with the of
1492 the breakpoint location's shadow_contents buffer. Otherwise, a
1493 failed assertion internal error will be raised. */
1496 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1497 const gdb_byte
*writebuf_org
,
1498 ULONGEST memaddr
, LONGEST len
,
1499 struct bp_target_info
*target_info
,
1500 struct gdbarch
*gdbarch
)
1502 /* Now do full processing of the found relevant range of elements. */
1503 CORE_ADDR bp_addr
= 0;
1507 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1508 current_program_space
->aspace
, 0))
1510 /* The breakpoint is inserted in a different address space. */
1514 /* Addresses and length of the part of the breakpoint that
1516 bp_addr
= target_info
->placed_address
;
1517 bp_size
= target_info
->shadow_len
;
1519 if (bp_addr
+ bp_size
<= memaddr
)
1521 /* The breakpoint is entirely before the chunk of memory we are
1526 if (bp_addr
>= memaddr
+ len
)
1528 /* The breakpoint is entirely after the chunk of memory we are
1533 /* Offset within shadow_contents. */
1534 if (bp_addr
< memaddr
)
1536 /* Only copy the second part of the breakpoint. */
1537 bp_size
-= memaddr
- bp_addr
;
1538 bptoffset
= memaddr
- bp_addr
;
1542 if (bp_addr
+ bp_size
> memaddr
+ len
)
1544 /* Only copy the first part of the breakpoint. */
1545 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1548 if (readbuf
!= NULL
)
1550 /* Verify that the readbuf buffer does not overlap with the
1551 shadow_contents buffer. */
1552 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1553 || readbuf
>= (target_info
->shadow_contents
1554 + target_info
->shadow_len
));
1556 /* Update the read buffer with this inserted breakpoint's
1558 memcpy (readbuf
+ bp_addr
- memaddr
,
1559 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1563 const unsigned char *bp
;
1564 CORE_ADDR addr
= target_info
->reqstd_address
;
1567 /* Update the shadow with what we want to write to memory. */
1568 memcpy (target_info
->shadow_contents
+ bptoffset
,
1569 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1571 /* Determine appropriate breakpoint contents and size for this
1573 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1575 /* Update the final write buffer with this inserted
1576 breakpoint's INSN. */
1577 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1581 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1582 by replacing any memory breakpoints with their shadowed contents.
1584 If READBUF is not NULL, this buffer must not overlap with any of
1585 the breakpoint location's shadow_contents buffers. Otherwise,
1586 a failed assertion internal error will be raised.
1588 The range of shadowed area by each bp_location is:
1589 bl->address - bp_location_placed_address_before_address_max
1590 up to bl->address + bp_location_shadow_len_after_address_max
1591 The range we were requested to resolve shadows for is:
1592 memaddr ... memaddr + len
1593 Thus the safe cutoff boundaries for performance optimization are
1594 memaddr + len <= (bl->address
1595 - bp_location_placed_address_before_address_max)
1597 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1600 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1601 const gdb_byte
*writebuf_org
,
1602 ULONGEST memaddr
, LONGEST len
)
1604 /* Left boundary, right boundary and median element of our binary
1606 unsigned bc_l
, bc_r
, bc
;
1609 /* Find BC_L which is a leftmost element which may affect BUF
1610 content. It is safe to report lower value but a failure to
1611 report higher one. */
1614 bc_r
= bp_location_count
;
1615 while (bc_l
+ 1 < bc_r
)
1617 struct bp_location
*bl
;
1619 bc
= (bc_l
+ bc_r
) / 2;
1620 bl
= bp_location
[bc
];
1622 /* Check first BL->ADDRESS will not overflow due to the added
1623 constant. Then advance the left boundary only if we are sure
1624 the BC element can in no way affect the BUF content (MEMADDR
1625 to MEMADDR + LEN range).
1627 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1628 offset so that we cannot miss a breakpoint with its shadow
1629 range tail still reaching MEMADDR. */
1631 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1633 && (bl
->address
+ bp_location_shadow_len_after_address_max
1640 /* Due to the binary search above, we need to make sure we pick the
1641 first location that's at BC_L's address. E.g., if there are
1642 multiple locations at the same address, BC_L may end up pointing
1643 at a duplicate location, and miss the "master"/"inserted"
1644 location. Say, given locations L1, L2 and L3 at addresses A and
1647 L1@A, L2@A, L3@B, ...
1649 BC_L could end up pointing at location L2, while the "master"
1650 location could be L1. Since the `loc->inserted' flag is only set
1651 on "master" locations, we'd forget to restore the shadow of L1
1654 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1657 /* Now do full processing of the found relevant range of elements. */
1659 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1661 struct bp_location
*bl
= bp_location
[bc
];
1662 CORE_ADDR bp_addr
= 0;
1666 /* bp_location array has BL->OWNER always non-NULL. */
1667 if (bl
->owner
->type
== bp_none
)
1668 warning (_("reading through apparently deleted breakpoint #%d?"),
1671 /* Performance optimization: any further element can no longer affect BUF
1674 if (bl
->address
>= bp_location_placed_address_before_address_max
1675 && memaddr
+ len
<= (bl
->address
1676 - bp_location_placed_address_before_address_max
))
1679 if (!bp_location_has_shadow (bl
))
1682 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1683 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1689 /* Return true if BPT is either a software breakpoint or a hardware
1693 is_breakpoint (const struct breakpoint
*bpt
)
1695 return (bpt
->type
== bp_breakpoint
1696 || bpt
->type
== bp_hardware_breakpoint
1697 || bpt
->type
== bp_dprintf
);
1700 /* Return true if BPT is of any hardware watchpoint kind. */
1703 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1705 return (bpt
->type
== bp_hardware_watchpoint
1706 || bpt
->type
== bp_read_watchpoint
1707 || bpt
->type
== bp_access_watchpoint
);
1710 /* Return true if BPT is of any watchpoint kind, hardware or
1714 is_watchpoint (const struct breakpoint
*bpt
)
1716 return (is_hardware_watchpoint (bpt
)
1717 || bpt
->type
== bp_watchpoint
);
1720 /* Returns true if the current thread and its running state are safe
1721 to evaluate or update watchpoint B. Watchpoints on local
1722 expressions need to be evaluated in the context of the thread that
1723 was current when the watchpoint was created, and, that thread needs
1724 to be stopped to be able to select the correct frame context.
1725 Watchpoints on global expressions can be evaluated on any thread,
1726 and in any state. It is presently left to the target allowing
1727 memory accesses when threads are running. */
1730 watchpoint_in_thread_scope (struct watchpoint
*b
)
1732 return (b
->base
.pspace
== current_program_space
1733 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1734 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1735 && !is_executing (inferior_ptid
))));
1738 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1739 associated bp_watchpoint_scope breakpoint. */
1742 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1744 struct breakpoint
*b
= &w
->base
;
1746 if (b
->related_breakpoint
!= b
)
1748 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1749 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1750 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1751 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1752 b
->related_breakpoint
= b
;
1754 b
->disposition
= disp_del_at_next_stop
;
1757 /* Extract a bitfield value from value VAL using the bit parameters contained in
1760 static struct value
*
1761 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1763 struct value
*bit_val
;
1768 bit_val
= allocate_value (value_type (val
));
1770 unpack_value_bitfield (bit_val
,
1773 value_contents_for_printing (val
),
1780 /* Allocate a dummy location and add it to B, which must be a software
1781 watchpoint. This is required because even if a software watchpoint
1782 is not watching any memory, bpstat_stop_status requires a location
1783 to be able to report stops. */
1786 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1787 struct program_space
*pspace
)
1789 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1791 b
->loc
= allocate_bp_location (b
);
1792 b
->loc
->pspace
= pspace
;
1793 b
->loc
->address
= -1;
1794 b
->loc
->length
= -1;
1797 /* Returns true if B is a software watchpoint that is not watching any
1798 memory (e.g., "watch $pc"). */
1801 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1803 return (b
->type
== bp_watchpoint
1805 && b
->loc
->next
== NULL
1806 && b
->loc
->address
== -1
1807 && b
->loc
->length
== -1);
1810 /* Assuming that B is a watchpoint:
1811 - Reparse watchpoint expression, if REPARSE is non-zero
1812 - Evaluate expression and store the result in B->val
1813 - Evaluate the condition if there is one, and store the result
1815 - Update the list of values that must be watched in B->loc.
1817 If the watchpoint disposition is disp_del_at_next_stop, then do
1818 nothing. If this is local watchpoint that is out of scope, delete
1821 Even with `set breakpoint always-inserted on' the watchpoints are
1822 removed + inserted on each stop here. Normal breakpoints must
1823 never be removed because they might be missed by a running thread
1824 when debugging in non-stop mode. On the other hand, hardware
1825 watchpoints (is_hardware_watchpoint; processed here) are specific
1826 to each LWP since they are stored in each LWP's hardware debug
1827 registers. Therefore, such LWP must be stopped first in order to
1828 be able to modify its hardware watchpoints.
1830 Hardware watchpoints must be reset exactly once after being
1831 presented to the user. It cannot be done sooner, because it would
1832 reset the data used to present the watchpoint hit to the user. And
1833 it must not be done later because it could display the same single
1834 watchpoint hit during multiple GDB stops. Note that the latter is
1835 relevant only to the hardware watchpoint types bp_read_watchpoint
1836 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1837 not user-visible - its hit is suppressed if the memory content has
1840 The following constraints influence the location where we can reset
1841 hardware watchpoints:
1843 * target_stopped_by_watchpoint and target_stopped_data_address are
1844 called several times when GDB stops.
1847 * Multiple hardware watchpoints can be hit at the same time,
1848 causing GDB to stop. GDB only presents one hardware watchpoint
1849 hit at a time as the reason for stopping, and all the other hits
1850 are presented later, one after the other, each time the user
1851 requests the execution to be resumed. Execution is not resumed
1852 for the threads still having pending hit event stored in
1853 LWP_INFO->STATUS. While the watchpoint is already removed from
1854 the inferior on the first stop the thread hit event is kept being
1855 reported from its cached value by linux_nat_stopped_data_address
1856 until the real thread resume happens after the watchpoint gets
1857 presented and thus its LWP_INFO->STATUS gets reset.
1859 Therefore the hardware watchpoint hit can get safely reset on the
1860 watchpoint removal from inferior. */
1863 update_watchpoint (struct watchpoint
*b
, int reparse
)
1865 int within_current_scope
;
1866 struct frame_id saved_frame_id
;
1869 /* If this is a local watchpoint, we only want to check if the
1870 watchpoint frame is in scope if the current thread is the thread
1871 that was used to create the watchpoint. */
1872 if (!watchpoint_in_thread_scope (b
))
1875 if (b
->base
.disposition
== disp_del_at_next_stop
)
1880 /* Determine if the watchpoint is within scope. */
1881 if (b
->exp_valid_block
== NULL
)
1882 within_current_scope
= 1;
1885 struct frame_info
*fi
= get_current_frame ();
1886 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1887 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1889 /* If we're at a point where the stack has been destroyed
1890 (e.g. in a function epilogue), unwinding may not work
1891 properly. Do not attempt to recreate locations at this
1892 point. See similar comments in watchpoint_check. */
1893 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1896 /* Save the current frame's ID so we can restore it after
1897 evaluating the watchpoint expression on its own frame. */
1898 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1899 took a frame parameter, so that we didn't have to change the
1902 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1904 fi
= frame_find_by_id (b
->watchpoint_frame
);
1905 within_current_scope
= (fi
!= NULL
);
1906 if (within_current_scope
)
1910 /* We don't free locations. They are stored in the bp_location array
1911 and update_global_location_list will eventually delete them and
1912 remove breakpoints if needed. */
1915 if (within_current_scope
&& reparse
)
1924 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1925 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1926 /* If the meaning of expression itself changed, the old value is
1927 no longer relevant. We don't want to report a watchpoint hit
1928 to the user when the old value and the new value may actually
1929 be completely different objects. */
1930 value_free (b
->val
);
1934 /* Note that unlike with breakpoints, the watchpoint's condition
1935 expression is stored in the breakpoint object, not in the
1936 locations (re)created below. */
1937 if (b
->base
.cond_string
!= NULL
)
1939 if (b
->cond_exp
!= NULL
)
1941 xfree (b
->cond_exp
);
1945 s
= b
->base
.cond_string
;
1946 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1950 /* If we failed to parse the expression, for example because
1951 it refers to a global variable in a not-yet-loaded shared library,
1952 don't try to insert watchpoint. We don't automatically delete
1953 such watchpoint, though, since failure to parse expression
1954 is different from out-of-scope watchpoint. */
1955 if (!target_has_execution
)
1957 /* Without execution, memory can't change. No use to try and
1958 set watchpoint locations. The watchpoint will be reset when
1959 the target gains execution, through breakpoint_re_set. */
1960 if (!can_use_hw_watchpoints
)
1962 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1963 b
->base
.type
= bp_watchpoint
;
1965 error (_("Can't set read/access watchpoint when "
1966 "hardware watchpoints are disabled."));
1969 else if (within_current_scope
&& b
->exp
)
1972 struct value
*val_chain
, *v
, *result
, *next
;
1973 struct program_space
*frame_pspace
;
1975 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1977 /* Avoid setting b->val if it's already set. The meaning of
1978 b->val is 'the last value' user saw, and we should update
1979 it only if we reported that last value to user. As it
1980 happens, the code that reports it updates b->val directly.
1981 We don't keep track of the memory value for masked
1983 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1985 if (b
->val_bitsize
!= 0)
1987 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1995 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1997 /* Look at each value on the value chain. */
1998 for (v
= val_chain
; v
; v
= value_next (v
))
2000 /* If it's a memory location, and GDB actually needed
2001 its contents to evaluate the expression, then we
2002 must watch it. If the first value returned is
2003 still lazy, that means an error occurred reading it;
2004 watch it anyway in case it becomes readable. */
2005 if (VALUE_LVAL (v
) == lval_memory
2006 && (v
== val_chain
|| ! value_lazy (v
)))
2008 struct type
*vtype
= check_typedef (value_type (v
));
2010 /* We only watch structs and arrays if user asked
2011 for it explicitly, never if they just happen to
2012 appear in the middle of some value chain. */
2014 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2015 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2018 enum target_hw_bp_type type
;
2019 struct bp_location
*loc
, **tmp
;
2020 int bitpos
= 0, bitsize
= 0;
2022 if (value_bitsize (v
) != 0)
2024 /* Extract the bit parameters out from the bitfield
2026 bitpos
= value_bitpos (v
);
2027 bitsize
= value_bitsize (v
);
2029 else if (v
== result
&& b
->val_bitsize
!= 0)
2031 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2032 lvalue whose bit parameters are saved in the fields
2033 VAL_BITPOS and VAL_BITSIZE. */
2034 bitpos
= b
->val_bitpos
;
2035 bitsize
= b
->val_bitsize
;
2038 addr
= value_address (v
);
2041 /* Skip the bytes that don't contain the bitfield. */
2046 if (b
->base
.type
== bp_read_watchpoint
)
2048 else if (b
->base
.type
== bp_access_watchpoint
)
2051 loc
= allocate_bp_location (&b
->base
);
2052 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2055 loc
->gdbarch
= get_type_arch (value_type (v
));
2057 loc
->pspace
= frame_pspace
;
2058 loc
->address
= addr
;
2062 /* Just cover the bytes that make up the bitfield. */
2063 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2066 loc
->length
= TYPE_LENGTH (value_type (v
));
2068 loc
->watchpoint_type
= type
;
2073 /* Change the type of breakpoint between hardware assisted or
2074 an ordinary watchpoint depending on the hardware support
2075 and free hardware slots. REPARSE is set when the inferior
2080 enum bp_loc_type loc_type
;
2081 struct bp_location
*bl
;
2083 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2087 int i
, target_resources_ok
, other_type_used
;
2090 /* Use an exact watchpoint when there's only one memory region to be
2091 watched, and only one debug register is needed to watch it. */
2092 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2094 /* We need to determine how many resources are already
2095 used for all other hardware watchpoints plus this one
2096 to see if we still have enough resources to also fit
2097 this watchpoint in as well. */
2099 /* If this is a software watchpoint, we try to turn it
2100 to a hardware one -- count resources as if B was of
2101 hardware watchpoint type. */
2102 type
= b
->base
.type
;
2103 if (type
== bp_watchpoint
)
2104 type
= bp_hardware_watchpoint
;
2106 /* This watchpoint may or may not have been placed on
2107 the list yet at this point (it won't be in the list
2108 if we're trying to create it for the first time,
2109 through watch_command), so always account for it
2112 /* Count resources used by all watchpoints except B. */
2113 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2115 /* Add in the resources needed for B. */
2116 i
+= hw_watchpoint_use_count (&b
->base
);
2119 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2120 if (target_resources_ok
<= 0)
2122 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2124 if (target_resources_ok
== 0 && !sw_mode
)
2125 error (_("Target does not support this type of "
2126 "hardware watchpoint."));
2127 else if (target_resources_ok
< 0 && !sw_mode
)
2128 error (_("There are not enough available hardware "
2129 "resources for this watchpoint."));
2131 /* Downgrade to software watchpoint. */
2132 b
->base
.type
= bp_watchpoint
;
2136 /* If this was a software watchpoint, we've just
2137 found we have enough resources to turn it to a
2138 hardware watchpoint. Otherwise, this is a
2140 b
->base
.type
= type
;
2143 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2145 if (!can_use_hw_watchpoints
)
2146 error (_("Can't set read/access watchpoint when "
2147 "hardware watchpoints are disabled."));
2149 error (_("Expression cannot be implemented with "
2150 "read/access watchpoint."));
2153 b
->base
.type
= bp_watchpoint
;
2155 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2156 : bp_loc_hardware_watchpoint
);
2157 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2158 bl
->loc_type
= loc_type
;
2161 for (v
= val_chain
; v
; v
= next
)
2163 next
= value_next (v
);
2168 /* If a software watchpoint is not watching any memory, then the
2169 above left it without any location set up. But,
2170 bpstat_stop_status requires a location to be able to report
2171 stops, so make sure there's at least a dummy one. */
2172 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2173 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2175 else if (!within_current_scope
)
2177 printf_filtered (_("\
2178 Watchpoint %d deleted because the program has left the block\n\
2179 in which its expression is valid.\n"),
2181 watchpoint_del_at_next_stop (b
);
2184 /* Restore the selected frame. */
2186 select_frame (frame_find_by_id (saved_frame_id
));
2190 /* Returns 1 iff breakpoint location should be
2191 inserted in the inferior. We don't differentiate the type of BL's owner
2192 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2193 breakpoint_ops is not defined, because in insert_bp_location,
2194 tracepoint's insert_location will not be called. */
2196 should_be_inserted (struct bp_location
*bl
)
2198 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2201 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2204 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2207 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2210 /* This is set for example, when we're attached to the parent of a
2211 vfork, and have detached from the child. The child is running
2212 free, and we expect it to do an exec or exit, at which point the
2213 OS makes the parent schedulable again (and the target reports
2214 that the vfork is done). Until the child is done with the shared
2215 memory region, do not insert breakpoints in the parent, otherwise
2216 the child could still trip on the parent's breakpoints. Since
2217 the parent is blocked anyway, it won't miss any breakpoint. */
2218 if (bl
->pspace
->breakpoints_not_allowed
)
2221 /* Don't insert a breakpoint if we're trying to step past its
2223 if ((bl
->loc_type
== bp_loc_software_breakpoint
2224 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2225 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2230 fprintf_unfiltered (gdb_stdlog
,
2231 "infrun: skipping breakpoint: "
2232 "stepping past insn at: %s\n",
2233 paddress (bl
->gdbarch
, bl
->address
));
2238 /* Don't insert watchpoints if we're trying to step past the
2239 instruction that triggered one. */
2240 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2241 && stepping_past_nonsteppable_watchpoint ())
2245 fprintf_unfiltered (gdb_stdlog
,
2246 "infrun: stepping past non-steppable watchpoint. "
2247 "skipping watchpoint at %s:%d\n",
2248 paddress (bl
->gdbarch
, bl
->address
),
2257 /* Same as should_be_inserted but does the check assuming
2258 that the location is not duplicated. */
2261 unduplicated_should_be_inserted (struct bp_location
*bl
)
2264 const int save_duplicate
= bl
->duplicate
;
2267 result
= should_be_inserted (bl
);
2268 bl
->duplicate
= save_duplicate
;
2272 /* Parses a conditional described by an expression COND into an
2273 agent expression bytecode suitable for evaluation
2274 by the bytecode interpreter. Return NULL if there was
2275 any error during parsing. */
2277 static struct agent_expr
*
2278 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2280 struct agent_expr
*aexpr
= NULL
;
2285 /* We don't want to stop processing, so catch any errors
2286 that may show up. */
2289 aexpr
= gen_eval_for_expr (scope
, cond
);
2292 CATCH (ex
, RETURN_MASK_ERROR
)
2294 /* If we got here, it means the condition could not be parsed to a valid
2295 bytecode expression and thus can't be evaluated on the target's side.
2296 It's no use iterating through the conditions. */
2301 /* We have a valid agent expression. */
2305 /* Based on location BL, create a list of breakpoint conditions to be
2306 passed on to the target. If we have duplicated locations with different
2307 conditions, we will add such conditions to the list. The idea is that the
2308 target will evaluate the list of conditions and will only notify GDB when
2309 one of them is true. */
2312 build_target_condition_list (struct bp_location
*bl
)
2314 struct bp_location
**locp
= NULL
, **loc2p
;
2315 int null_condition_or_parse_error
= 0;
2316 int modified
= bl
->needs_update
;
2317 struct bp_location
*loc
;
2319 /* Release conditions left over from a previous insert. */
2320 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2322 /* This is only meaningful if the target is
2323 evaluating conditions and if the user has
2324 opted for condition evaluation on the target's
2326 if (gdb_evaluates_breakpoint_condition_p ()
2327 || !target_supports_evaluation_of_breakpoint_conditions ())
2330 /* Do a first pass to check for locations with no assigned
2331 conditions or conditions that fail to parse to a valid agent expression
2332 bytecode. If any of these happen, then it's no use to send conditions
2333 to the target since this location will always trigger and generate a
2334 response back to GDB. */
2335 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2338 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2342 struct agent_expr
*aexpr
;
2344 /* Re-parse the conditions since something changed. In that
2345 case we already freed the condition bytecodes (see
2346 force_breakpoint_reinsertion). We just
2347 need to parse the condition to bytecodes again. */
2348 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2349 loc
->cond_bytecode
= aexpr
;
2351 /* Check if we managed to parse the conditional expression
2352 correctly. If not, we will not send this condition
2358 /* If we have a NULL bytecode expression, it means something
2359 went wrong or we have a null condition expression. */
2360 if (!loc
->cond_bytecode
)
2362 null_condition_or_parse_error
= 1;
2368 /* If any of these happened, it means we will have to evaluate the conditions
2369 for the location's address on gdb's side. It is no use keeping bytecodes
2370 for all the other duplicate locations, thus we free all of them here.
2372 This is so we have a finer control over which locations' conditions are
2373 being evaluated by GDB or the remote stub. */
2374 if (null_condition_or_parse_error
)
2376 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2379 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2381 /* Only go as far as the first NULL bytecode is
2383 if (!loc
->cond_bytecode
)
2386 free_agent_expr (loc
->cond_bytecode
);
2387 loc
->cond_bytecode
= NULL
;
2392 /* No NULL conditions or failed bytecode generation. Build a condition list
2393 for this location's address. */
2394 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2398 && is_breakpoint (loc
->owner
)
2399 && loc
->pspace
->num
== bl
->pspace
->num
2400 && loc
->owner
->enable_state
== bp_enabled
2402 /* Add the condition to the vector. This will be used later to send the
2403 conditions to the target. */
2404 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2405 loc
->cond_bytecode
);
2411 /* Parses a command described by string CMD into an agent expression
2412 bytecode suitable for evaluation by the bytecode interpreter.
2413 Return NULL if there was any error during parsing. */
2415 static struct agent_expr
*
2416 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2418 struct cleanup
*old_cleanups
= 0;
2419 struct expression
*expr
, **argvec
;
2420 struct agent_expr
*aexpr
= NULL
;
2421 const char *cmdrest
;
2422 const char *format_start
, *format_end
;
2423 struct format_piece
*fpieces
;
2425 struct gdbarch
*gdbarch
= get_current_arch ();
2432 if (*cmdrest
== ',')
2434 cmdrest
= skip_spaces_const (cmdrest
);
2436 if (*cmdrest
++ != '"')
2437 error (_("No format string following the location"));
2439 format_start
= cmdrest
;
2441 fpieces
= parse_format_string (&cmdrest
);
2443 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2445 format_end
= cmdrest
;
2447 if (*cmdrest
++ != '"')
2448 error (_("Bad format string, non-terminated '\"'."));
2450 cmdrest
= skip_spaces_const (cmdrest
);
2452 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2453 error (_("Invalid argument syntax"));
2455 if (*cmdrest
== ',')
2457 cmdrest
= skip_spaces_const (cmdrest
);
2459 /* For each argument, make an expression. */
2461 argvec
= (struct expression
**) alloca (strlen (cmd
)
2462 * sizeof (struct expression
*));
2465 while (*cmdrest
!= '\0')
2470 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2471 argvec
[nargs
++] = expr
;
2473 if (*cmdrest
== ',')
2477 /* We don't want to stop processing, so catch any errors
2478 that may show up. */
2481 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2482 format_start
, format_end
- format_start
,
2483 fpieces
, nargs
, argvec
);
2485 CATCH (ex
, RETURN_MASK_ERROR
)
2487 /* If we got here, it means the command could not be parsed to a valid
2488 bytecode expression and thus can't be evaluated on the target's side.
2489 It's no use iterating through the other commands. */
2494 do_cleanups (old_cleanups
);
2496 /* We have a valid agent expression, return it. */
2500 /* Based on location BL, create a list of breakpoint commands to be
2501 passed on to the target. If we have duplicated locations with
2502 different commands, we will add any such to the list. */
2505 build_target_command_list (struct bp_location
*bl
)
2507 struct bp_location
**locp
= NULL
, **loc2p
;
2508 int null_command_or_parse_error
= 0;
2509 int modified
= bl
->needs_update
;
2510 struct bp_location
*loc
;
2512 /* Release commands left over from a previous insert. */
2513 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2515 if (!target_can_run_breakpoint_commands ())
2518 /* For now, limit to agent-style dprintf breakpoints. */
2519 if (dprintf_style
!= dprintf_style_agent
)
2522 /* For now, if we have any duplicate location that isn't a dprintf,
2523 don't install the target-side commands, as that would make the
2524 breakpoint not be reported to the core, and we'd lose
2526 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2529 if (is_breakpoint (loc
->owner
)
2530 && loc
->pspace
->num
== bl
->pspace
->num
2531 && loc
->owner
->type
!= bp_dprintf
)
2535 /* Do a first pass to check for locations with no assigned
2536 conditions or conditions that fail to parse to a valid agent expression
2537 bytecode. If any of these happen, then it's no use to send conditions
2538 to the target since this location will always trigger and generate a
2539 response back to GDB. */
2540 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2543 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2547 struct agent_expr
*aexpr
;
2549 /* Re-parse the commands since something changed. In that
2550 case we already freed the command bytecodes (see
2551 force_breakpoint_reinsertion). We just
2552 need to parse the command to bytecodes again. */
2553 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2554 loc
->owner
->extra_string
);
2555 loc
->cmd_bytecode
= aexpr
;
2561 /* If we have a NULL bytecode expression, it means something
2562 went wrong or we have a null command expression. */
2563 if (!loc
->cmd_bytecode
)
2565 null_command_or_parse_error
= 1;
2571 /* If anything failed, then we're not doing target-side commands,
2573 if (null_command_or_parse_error
)
2575 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2578 if (is_breakpoint (loc
->owner
)
2579 && loc
->pspace
->num
== bl
->pspace
->num
)
2581 /* Only go as far as the first NULL bytecode is
2583 if (loc
->cmd_bytecode
== NULL
)
2586 free_agent_expr (loc
->cmd_bytecode
);
2587 loc
->cmd_bytecode
= NULL
;
2592 /* No NULL commands or failed bytecode generation. Build a command list
2593 for this location's address. */
2594 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2597 if (loc
->owner
->extra_string
2598 && is_breakpoint (loc
->owner
)
2599 && loc
->pspace
->num
== bl
->pspace
->num
2600 && loc
->owner
->enable_state
== bp_enabled
2602 /* Add the command to the vector. This will be used later
2603 to send the commands to the target. */
2604 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2608 bl
->target_info
.persist
= 0;
2609 /* Maybe flag this location as persistent. */
2610 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2611 bl
->target_info
.persist
= 1;
2614 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2615 location. Any error messages are printed to TMP_ERROR_STREAM; and
2616 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2617 Returns 0 for success, 1 if the bp_location type is not supported or
2620 NOTE drow/2003-09-09: This routine could be broken down to an
2621 object-style method for each breakpoint or catchpoint type. */
2623 insert_bp_location (struct bp_location
*bl
,
2624 struct ui_file
*tmp_error_stream
,
2625 int *disabled_breaks
,
2626 int *hw_breakpoint_error
,
2627 int *hw_bp_error_explained_already
)
2629 enum errors bp_err
= GDB_NO_ERROR
;
2630 const char *bp_err_message
= NULL
;
2632 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2635 /* Note we don't initialize bl->target_info, as that wipes out
2636 the breakpoint location's shadow_contents if the breakpoint
2637 is still inserted at that location. This in turn breaks
2638 target_read_memory which depends on these buffers when
2639 a memory read is requested at the breakpoint location:
2640 Once the target_info has been wiped, we fail to see that
2641 we have a breakpoint inserted at that address and thus
2642 read the breakpoint instead of returning the data saved in
2643 the breakpoint location's shadow contents. */
2644 bl
->target_info
.reqstd_address
= bl
->address
;
2645 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2646 bl
->target_info
.length
= bl
->length
;
2648 /* When working with target-side conditions, we must pass all the conditions
2649 for the same breakpoint address down to the target since GDB will not
2650 insert those locations. With a list of breakpoint conditions, the target
2651 can decide when to stop and notify GDB. */
2653 if (is_breakpoint (bl
->owner
))
2655 build_target_condition_list (bl
);
2656 build_target_command_list (bl
);
2657 /* Reset the modification marker. */
2658 bl
->needs_update
= 0;
2661 if (bl
->loc_type
== bp_loc_software_breakpoint
2662 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2664 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2666 /* If the explicitly specified breakpoint type
2667 is not hardware breakpoint, check the memory map to see
2668 if the breakpoint address is in read only memory or not.
2670 Two important cases are:
2671 - location type is not hardware breakpoint, memory
2672 is readonly. We change the type of the location to
2673 hardware breakpoint.
2674 - location type is hardware breakpoint, memory is
2675 read-write. This means we've previously made the
2676 location hardware one, but then the memory map changed,
2679 When breakpoints are removed, remove_breakpoints will use
2680 location types we've just set here, the only possible
2681 problem is that memory map has changed during running
2682 program, but it's not going to work anyway with current
2684 struct mem_region
*mr
2685 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2689 if (automatic_hardware_breakpoints
)
2691 enum bp_loc_type new_type
;
2693 if (mr
->attrib
.mode
!= MEM_RW
)
2694 new_type
= bp_loc_hardware_breakpoint
;
2696 new_type
= bp_loc_software_breakpoint
;
2698 if (new_type
!= bl
->loc_type
)
2700 static int said
= 0;
2702 bl
->loc_type
= new_type
;
2705 fprintf_filtered (gdb_stdout
,
2706 _("Note: automatically using "
2707 "hardware breakpoints for "
2708 "read-only addresses.\n"));
2713 else if (bl
->loc_type
== bp_loc_software_breakpoint
2714 && mr
->attrib
.mode
!= MEM_RW
)
2716 fprintf_unfiltered (tmp_error_stream
,
2717 _("Cannot insert breakpoint %d.\n"
2718 "Cannot set software breakpoint "
2719 "at read-only address %s\n"),
2721 paddress (bl
->gdbarch
, bl
->address
));
2727 /* First check to see if we have to handle an overlay. */
2728 if (overlay_debugging
== ovly_off
2729 || bl
->section
== NULL
2730 || !(section_is_overlay (bl
->section
)))
2732 /* No overlay handling: just set the breakpoint. */
2737 val
= bl
->owner
->ops
->insert_location (bl
);
2739 bp_err
= GENERIC_ERROR
;
2741 CATCH (e
, RETURN_MASK_ALL
)
2744 bp_err_message
= e
.message
;
2750 /* This breakpoint is in an overlay section.
2751 Shall we set a breakpoint at the LMA? */
2752 if (!overlay_events_enabled
)
2754 /* Yes -- overlay event support is not active,
2755 so we must try to set a breakpoint at the LMA.
2756 This will not work for a hardware breakpoint. */
2757 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2758 warning (_("hardware breakpoint %d not supported in overlay!"),
2762 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2764 /* Set a software (trap) breakpoint at the LMA. */
2765 bl
->overlay_target_info
= bl
->target_info
;
2766 bl
->overlay_target_info
.reqstd_address
= addr
;
2768 /* No overlay handling: just set the breakpoint. */
2773 val
= target_insert_breakpoint (bl
->gdbarch
,
2774 &bl
->overlay_target_info
);
2776 bp_err
= GENERIC_ERROR
;
2778 CATCH (e
, RETURN_MASK_ALL
)
2781 bp_err_message
= e
.message
;
2785 if (bp_err
!= GDB_NO_ERROR
)
2786 fprintf_unfiltered (tmp_error_stream
,
2787 "Overlay breakpoint %d "
2788 "failed: in ROM?\n",
2792 /* Shall we set a breakpoint at the VMA? */
2793 if (section_is_mapped (bl
->section
))
2795 /* Yes. This overlay section is mapped into memory. */
2800 val
= bl
->owner
->ops
->insert_location (bl
);
2802 bp_err
= GENERIC_ERROR
;
2804 CATCH (e
, RETURN_MASK_ALL
)
2807 bp_err_message
= e
.message
;
2813 /* No. This breakpoint will not be inserted.
2814 No error, but do not mark the bp as 'inserted'. */
2819 if (bp_err
!= GDB_NO_ERROR
)
2821 /* Can't set the breakpoint. */
2823 /* In some cases, we might not be able to insert a
2824 breakpoint in a shared library that has already been
2825 removed, but we have not yet processed the shlib unload
2826 event. Unfortunately, some targets that implement
2827 breakpoint insertion themselves can't tell why the
2828 breakpoint insertion failed (e.g., the remote target
2829 doesn't define error codes), so we must treat generic
2830 errors as memory errors. */
2831 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2832 && bl
->loc_type
== bp_loc_software_breakpoint
2833 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2834 || shared_objfile_contains_address_p (bl
->pspace
,
2837 /* See also: disable_breakpoints_in_shlibs. */
2838 bl
->shlib_disabled
= 1;
2839 observer_notify_breakpoint_modified (bl
->owner
);
2840 if (!*disabled_breaks
)
2842 fprintf_unfiltered (tmp_error_stream
,
2843 "Cannot insert breakpoint %d.\n",
2845 fprintf_unfiltered (tmp_error_stream
,
2846 "Temporarily disabling shared "
2847 "library breakpoints:\n");
2849 *disabled_breaks
= 1;
2850 fprintf_unfiltered (tmp_error_stream
,
2851 "breakpoint #%d\n", bl
->owner
->number
);
2856 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2858 *hw_breakpoint_error
= 1;
2859 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2860 fprintf_unfiltered (tmp_error_stream
,
2861 "Cannot insert hardware breakpoint %d%s",
2862 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2863 if (bp_err_message
!= NULL
)
2864 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2868 if (bp_err_message
== NULL
)
2871 = memory_error_message (TARGET_XFER_E_IO
,
2872 bl
->gdbarch
, bl
->address
);
2873 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2875 fprintf_unfiltered (tmp_error_stream
,
2876 "Cannot insert breakpoint %d.\n"
2878 bl
->owner
->number
, message
);
2879 do_cleanups (old_chain
);
2883 fprintf_unfiltered (tmp_error_stream
,
2884 "Cannot insert breakpoint %d: %s\n",
2899 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2900 /* NOTE drow/2003-09-08: This state only exists for removing
2901 watchpoints. It's not clear that it's necessary... */
2902 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2906 gdb_assert (bl
->owner
->ops
!= NULL
2907 && bl
->owner
->ops
->insert_location
!= NULL
);
2909 val
= bl
->owner
->ops
->insert_location (bl
);
2911 /* If trying to set a read-watchpoint, and it turns out it's not
2912 supported, try emulating one with an access watchpoint. */
2913 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2915 struct bp_location
*loc
, **loc_temp
;
2917 /* But don't try to insert it, if there's already another
2918 hw_access location that would be considered a duplicate
2920 ALL_BP_LOCATIONS (loc
, loc_temp
)
2922 && loc
->watchpoint_type
== hw_access
2923 && watchpoint_locations_match (bl
, loc
))
2927 bl
->target_info
= loc
->target_info
;
2928 bl
->watchpoint_type
= hw_access
;
2935 bl
->watchpoint_type
= hw_access
;
2936 val
= bl
->owner
->ops
->insert_location (bl
);
2939 /* Back to the original value. */
2940 bl
->watchpoint_type
= hw_read
;
2944 bl
->inserted
= (val
== 0);
2947 else if (bl
->owner
->type
== bp_catchpoint
)
2951 gdb_assert (bl
->owner
->ops
!= NULL
2952 && bl
->owner
->ops
->insert_location
!= NULL
);
2954 val
= bl
->owner
->ops
->insert_location (bl
);
2957 bl
->owner
->enable_state
= bp_disabled
;
2961 Error inserting catchpoint %d: Your system does not support this type\n\
2962 of catchpoint."), bl
->owner
->number
);
2964 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2967 bl
->inserted
= (val
== 0);
2969 /* We've already printed an error message if there was a problem
2970 inserting this catchpoint, and we've disabled the catchpoint,
2971 so just return success. */
2978 /* This function is called when program space PSPACE is about to be
2979 deleted. It takes care of updating breakpoints to not reference
2983 breakpoint_program_space_exit (struct program_space
*pspace
)
2985 struct breakpoint
*b
, *b_temp
;
2986 struct bp_location
*loc
, **loc_temp
;
2988 /* Remove any breakpoint that was set through this program space. */
2989 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2991 if (b
->pspace
== pspace
)
2992 delete_breakpoint (b
);
2995 /* Breakpoints set through other program spaces could have locations
2996 bound to PSPACE as well. Remove those. */
2997 ALL_BP_LOCATIONS (loc
, loc_temp
)
2999 struct bp_location
*tmp
;
3001 if (loc
->pspace
== pspace
)
3003 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3004 if (loc
->owner
->loc
== loc
)
3005 loc
->owner
->loc
= loc
->next
;
3007 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3008 if (tmp
->next
== loc
)
3010 tmp
->next
= loc
->next
;
3016 /* Now update the global location list to permanently delete the
3017 removed locations above. */
3018 update_global_location_list (UGLL_DONT_INSERT
);
3021 /* Make sure all breakpoints are inserted in inferior.
3022 Throws exception on any error.
3023 A breakpoint that is already inserted won't be inserted
3024 again, so calling this function twice is safe. */
3026 insert_breakpoints (void)
3028 struct breakpoint
*bpt
;
3030 ALL_BREAKPOINTS (bpt
)
3031 if (is_hardware_watchpoint (bpt
))
3033 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3035 update_watchpoint (w
, 0 /* don't reparse. */);
3038 /* Updating watchpoints creates new locations, so update the global
3039 location list. Explicitly tell ugll to insert locations and
3040 ignore breakpoints_always_inserted_mode. */
3041 update_global_location_list (UGLL_INSERT
);
3044 /* Invoke CALLBACK for each of bp_location. */
3047 iterate_over_bp_locations (walk_bp_location_callback callback
)
3049 struct bp_location
*loc
, **loc_tmp
;
3051 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3053 callback (loc
, NULL
);
3057 /* This is used when we need to synch breakpoint conditions between GDB and the
3058 target. It is the case with deleting and disabling of breakpoints when using
3059 always-inserted mode. */
3062 update_inserted_breakpoint_locations (void)
3064 struct bp_location
*bl
, **blp_tmp
;
3067 int disabled_breaks
= 0;
3068 int hw_breakpoint_error
= 0;
3069 int hw_bp_details_reported
= 0;
3071 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3072 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3074 /* Explicitly mark the warning -- this will only be printed if
3075 there was an error. */
3076 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3078 save_current_space_and_thread ();
3080 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3082 /* We only want to update software breakpoints and hardware
3084 if (!is_breakpoint (bl
->owner
))
3087 /* We only want to update locations that are already inserted
3088 and need updating. This is to avoid unwanted insertion during
3089 deletion of breakpoints. */
3090 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3093 switch_to_program_space_and_thread (bl
->pspace
);
3095 /* For targets that support global breakpoints, there's no need
3096 to select an inferior to insert breakpoint to. In fact, even
3097 if we aren't attached to any process yet, we should still
3098 insert breakpoints. */
3099 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3100 && ptid_equal (inferior_ptid
, null_ptid
))
3103 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3104 &hw_breakpoint_error
, &hw_bp_details_reported
);
3111 target_terminal_ours_for_output ();
3112 error_stream (tmp_error_stream
);
3115 do_cleanups (cleanups
);
3118 /* Used when starting or continuing the program. */
3121 insert_breakpoint_locations (void)
3123 struct breakpoint
*bpt
;
3124 struct bp_location
*bl
, **blp_tmp
;
3127 int disabled_breaks
= 0;
3128 int hw_breakpoint_error
= 0;
3129 int hw_bp_error_explained_already
= 0;
3131 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3132 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3134 /* Explicitly mark the warning -- this will only be printed if
3135 there was an error. */
3136 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3138 save_current_space_and_thread ();
3140 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3142 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3145 /* There is no point inserting thread-specific breakpoints if
3146 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3147 has BL->OWNER always non-NULL. */
3148 if (bl
->owner
->thread
!= -1
3149 && !valid_global_thread_id (bl
->owner
->thread
))
3152 switch_to_program_space_and_thread (bl
->pspace
);
3154 /* For targets that support global breakpoints, there's no need
3155 to select an inferior to insert breakpoint to. In fact, even
3156 if we aren't attached to any process yet, we should still
3157 insert breakpoints. */
3158 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3159 && ptid_equal (inferior_ptid
, null_ptid
))
3162 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3163 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3168 /* If we failed to insert all locations of a watchpoint, remove
3169 them, as half-inserted watchpoint is of limited use. */
3170 ALL_BREAKPOINTS (bpt
)
3172 int some_failed
= 0;
3173 struct bp_location
*loc
;
3175 if (!is_hardware_watchpoint (bpt
))
3178 if (!breakpoint_enabled (bpt
))
3181 if (bpt
->disposition
== disp_del_at_next_stop
)
3184 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3185 if (!loc
->inserted
&& should_be_inserted (loc
))
3192 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3194 remove_breakpoint (loc
, mark_uninserted
);
3196 hw_breakpoint_error
= 1;
3197 fprintf_unfiltered (tmp_error_stream
,
3198 "Could not insert hardware watchpoint %d.\n",
3206 /* If a hardware breakpoint or watchpoint was inserted, add a
3207 message about possibly exhausted resources. */
3208 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3210 fprintf_unfiltered (tmp_error_stream
,
3211 "Could not insert hardware breakpoints:\n\
3212 You may have requested too many hardware breakpoints/watchpoints.\n");
3214 target_terminal_ours_for_output ();
3215 error_stream (tmp_error_stream
);
3218 do_cleanups (cleanups
);
3221 /* Used when the program stops.
3222 Returns zero if successful, or non-zero if there was a problem
3223 removing a breakpoint location. */
3226 remove_breakpoints (void)
3228 struct bp_location
*bl
, **blp_tmp
;
3231 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3233 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3234 val
|= remove_breakpoint (bl
, mark_uninserted
);
3239 /* When a thread exits, remove breakpoints that are related to
3243 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3245 struct breakpoint
*b
, *b_tmp
;
3247 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3249 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3251 b
->disposition
= disp_del_at_next_stop
;
3253 printf_filtered (_("\
3254 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3255 b
->number
, print_thread_id (tp
));
3257 /* Hide it from the user. */
3263 /* Remove breakpoints of process PID. */
3266 remove_breakpoints_pid (int pid
)
3268 struct bp_location
*bl
, **blp_tmp
;
3270 struct inferior
*inf
= find_inferior_pid (pid
);
3272 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3274 if (bl
->pspace
!= inf
->pspace
)
3277 if (bl
->inserted
&& !bl
->target_info
.persist
)
3279 val
= remove_breakpoint (bl
, mark_uninserted
);
3288 reattach_breakpoints (int pid
)
3290 struct cleanup
*old_chain
;
3291 struct bp_location
*bl
, **blp_tmp
;
3293 struct ui_file
*tmp_error_stream
;
3294 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3295 struct inferior
*inf
;
3296 struct thread_info
*tp
;
3298 tp
= any_live_thread_of_process (pid
);
3302 inf
= find_inferior_pid (pid
);
3303 old_chain
= save_inferior_ptid ();
3305 inferior_ptid
= tp
->ptid
;
3307 tmp_error_stream
= mem_fileopen ();
3308 make_cleanup_ui_file_delete (tmp_error_stream
);
3310 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3312 if (bl
->pspace
!= inf
->pspace
)
3318 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3321 do_cleanups (old_chain
);
3326 do_cleanups (old_chain
);
3330 static int internal_breakpoint_number
= -1;
3332 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3333 If INTERNAL is non-zero, the breakpoint number will be populated
3334 from internal_breakpoint_number and that variable decremented.
3335 Otherwise the breakpoint number will be populated from
3336 breakpoint_count and that value incremented. Internal breakpoints
3337 do not set the internal var bpnum. */
3339 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3342 b
->number
= internal_breakpoint_number
--;
3345 set_breakpoint_count (breakpoint_count
+ 1);
3346 b
->number
= breakpoint_count
;
3350 static struct breakpoint
*
3351 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3352 CORE_ADDR address
, enum bptype type
,
3353 const struct breakpoint_ops
*ops
)
3355 struct symtab_and_line sal
;
3356 struct breakpoint
*b
;
3358 init_sal (&sal
); /* Initialize to zeroes. */
3361 sal
.section
= find_pc_overlay (sal
.pc
);
3362 sal
.pspace
= current_program_space
;
3364 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3365 b
->number
= internal_breakpoint_number
--;
3366 b
->disposition
= disp_donttouch
;
3371 static const char *const longjmp_names
[] =
3373 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3375 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3377 /* Per-objfile data private to breakpoint.c. */
3378 struct breakpoint_objfile_data
3380 /* Minimal symbol for "_ovly_debug_event" (if any). */
3381 struct bound_minimal_symbol overlay_msym
;
3383 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3384 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3386 /* True if we have looked for longjmp probes. */
3387 int longjmp_searched
;
3389 /* SystemTap probe points for longjmp (if any). */
3390 VEC (probe_p
) *longjmp_probes
;
3392 /* Minimal symbol for "std::terminate()" (if any). */
3393 struct bound_minimal_symbol terminate_msym
;
3395 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3396 struct bound_minimal_symbol exception_msym
;
3398 /* True if we have looked for exception probes. */
3399 int exception_searched
;
3401 /* SystemTap probe points for unwinding (if any). */
3402 VEC (probe_p
) *exception_probes
;
3405 static const struct objfile_data
*breakpoint_objfile_key
;
3407 /* Minimal symbol not found sentinel. */
3408 static struct minimal_symbol msym_not_found
;
3410 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3413 msym_not_found_p (const struct minimal_symbol
*msym
)
3415 return msym
== &msym_not_found
;
3418 /* Return per-objfile data needed by breakpoint.c.
3419 Allocate the data if necessary. */
3421 static struct breakpoint_objfile_data
*
3422 get_breakpoint_objfile_data (struct objfile
*objfile
)
3424 struct breakpoint_objfile_data
*bp_objfile_data
;
3426 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3427 objfile_data (objfile
, breakpoint_objfile_key
));
3428 if (bp_objfile_data
== NULL
)
3431 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3433 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3434 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3436 return bp_objfile_data
;
3440 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3442 struct breakpoint_objfile_data
*bp_objfile_data
3443 = (struct breakpoint_objfile_data
*) data
;
3445 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3446 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3450 create_overlay_event_breakpoint (void)
3452 struct objfile
*objfile
;
3453 const char *const func_name
= "_ovly_debug_event";
3455 ALL_OBJFILES (objfile
)
3457 struct breakpoint
*b
;
3458 struct breakpoint_objfile_data
*bp_objfile_data
;
3460 struct explicit_location explicit_loc
;
3462 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3464 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3467 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3469 struct bound_minimal_symbol m
;
3471 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3472 if (m
.minsym
== NULL
)
3474 /* Avoid future lookups in this objfile. */
3475 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3478 bp_objfile_data
->overlay_msym
= m
;
3481 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3482 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3484 &internal_breakpoint_ops
);
3485 initialize_explicit_location (&explicit_loc
);
3486 explicit_loc
.function_name
= ASTRDUP (func_name
);
3487 b
->location
= new_explicit_location (&explicit_loc
);
3489 if (overlay_debugging
== ovly_auto
)
3491 b
->enable_state
= bp_enabled
;
3492 overlay_events_enabled
= 1;
3496 b
->enable_state
= bp_disabled
;
3497 overlay_events_enabled
= 0;
3500 update_global_location_list (UGLL_MAY_INSERT
);
3504 create_longjmp_master_breakpoint (void)
3506 struct program_space
*pspace
;
3507 struct cleanup
*old_chain
;
3509 old_chain
= save_current_program_space ();
3511 ALL_PSPACES (pspace
)
3513 struct objfile
*objfile
;
3515 set_current_program_space (pspace
);
3517 ALL_OBJFILES (objfile
)
3520 struct gdbarch
*gdbarch
;
3521 struct breakpoint_objfile_data
*bp_objfile_data
;
3523 gdbarch
= get_objfile_arch (objfile
);
3525 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3527 if (!bp_objfile_data
->longjmp_searched
)
3531 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3534 /* We are only interested in checking one element. */
3535 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3537 if (!can_evaluate_probe_arguments (p
))
3539 /* We cannot use the probe interface here, because it does
3540 not know how to evaluate arguments. */
3541 VEC_free (probe_p
, ret
);
3545 bp_objfile_data
->longjmp_probes
= ret
;
3546 bp_objfile_data
->longjmp_searched
= 1;
3549 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3552 struct probe
*probe
;
3553 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3556 VEC_iterate (probe_p
,
3557 bp_objfile_data
->longjmp_probes
,
3561 struct breakpoint
*b
;
3563 b
= create_internal_breakpoint (gdbarch
,
3564 get_probe_address (probe
,
3567 &internal_breakpoint_ops
);
3569 = new_probe_location ("-probe-stap libc:longjmp");
3570 b
->enable_state
= bp_disabled
;
3576 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3579 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3581 struct breakpoint
*b
;
3582 const char *func_name
;
3584 struct explicit_location explicit_loc
;
3586 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3589 func_name
= longjmp_names
[i
];
3590 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3592 struct bound_minimal_symbol m
;
3594 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3595 if (m
.minsym
== NULL
)
3597 /* Prevent future lookups in this objfile. */
3598 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3601 bp_objfile_data
->longjmp_msym
[i
] = m
;
3604 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3605 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3606 &internal_breakpoint_ops
);
3607 initialize_explicit_location (&explicit_loc
);
3608 explicit_loc
.function_name
= ASTRDUP (func_name
);
3609 b
->location
= new_explicit_location (&explicit_loc
);
3610 b
->enable_state
= bp_disabled
;
3614 update_global_location_list (UGLL_MAY_INSERT
);
3616 do_cleanups (old_chain
);
3619 /* Create a master std::terminate breakpoint. */
3621 create_std_terminate_master_breakpoint (void)
3623 struct program_space
*pspace
;
3624 struct cleanup
*old_chain
;
3625 const char *const func_name
= "std::terminate()";
3627 old_chain
= save_current_program_space ();
3629 ALL_PSPACES (pspace
)
3631 struct objfile
*objfile
;
3634 set_current_program_space (pspace
);
3636 ALL_OBJFILES (objfile
)
3638 struct breakpoint
*b
;
3639 struct breakpoint_objfile_data
*bp_objfile_data
;
3640 struct explicit_location explicit_loc
;
3642 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3644 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3647 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3649 struct bound_minimal_symbol m
;
3651 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3652 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3653 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3655 /* Prevent future lookups in this objfile. */
3656 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3659 bp_objfile_data
->terminate_msym
= m
;
3662 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3663 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3664 bp_std_terminate_master
,
3665 &internal_breakpoint_ops
);
3666 initialize_explicit_location (&explicit_loc
);
3667 explicit_loc
.function_name
= ASTRDUP (func_name
);
3668 b
->location
= new_explicit_location (&explicit_loc
);
3669 b
->enable_state
= bp_disabled
;
3673 update_global_location_list (UGLL_MAY_INSERT
);
3675 do_cleanups (old_chain
);
3678 /* Install a master breakpoint on the unwinder's debug hook. */
3681 create_exception_master_breakpoint (void)
3683 struct objfile
*objfile
;
3684 const char *const func_name
= "_Unwind_DebugHook";
3686 ALL_OBJFILES (objfile
)
3688 struct breakpoint
*b
;
3689 struct gdbarch
*gdbarch
;
3690 struct breakpoint_objfile_data
*bp_objfile_data
;
3692 struct explicit_location explicit_loc
;
3694 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3696 /* We prefer the SystemTap probe point if it exists. */
3697 if (!bp_objfile_data
->exception_searched
)
3701 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3705 /* We are only interested in checking one element. */
3706 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3708 if (!can_evaluate_probe_arguments (p
))
3710 /* We cannot use the probe interface here, because it does
3711 not know how to evaluate arguments. */
3712 VEC_free (probe_p
, ret
);
3716 bp_objfile_data
->exception_probes
= ret
;
3717 bp_objfile_data
->exception_searched
= 1;
3720 if (bp_objfile_data
->exception_probes
!= NULL
)
3722 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3724 struct probe
*probe
;
3727 VEC_iterate (probe_p
,
3728 bp_objfile_data
->exception_probes
,
3732 struct breakpoint
*b
;
3734 b
= create_internal_breakpoint (gdbarch
,
3735 get_probe_address (probe
,
3737 bp_exception_master
,
3738 &internal_breakpoint_ops
);
3740 = new_probe_location ("-probe-stap libgcc:unwind");
3741 b
->enable_state
= bp_disabled
;
3747 /* Otherwise, try the hook function. */
3749 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3752 gdbarch
= get_objfile_arch (objfile
);
3754 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3756 struct bound_minimal_symbol debug_hook
;
3758 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3759 if (debug_hook
.minsym
== NULL
)
3761 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3765 bp_objfile_data
->exception_msym
= debug_hook
;
3768 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3769 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3771 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3772 &internal_breakpoint_ops
);
3773 initialize_explicit_location (&explicit_loc
);
3774 explicit_loc
.function_name
= ASTRDUP (func_name
);
3775 b
->location
= new_explicit_location (&explicit_loc
);
3776 b
->enable_state
= bp_disabled
;
3779 update_global_location_list (UGLL_MAY_INSERT
);
3783 update_breakpoints_after_exec (void)
3785 struct breakpoint
*b
, *b_tmp
;
3786 struct bp_location
*bploc
, **bplocp_tmp
;
3788 /* We're about to delete breakpoints from GDB's lists. If the
3789 INSERTED flag is true, GDB will try to lift the breakpoints by
3790 writing the breakpoints' "shadow contents" back into memory. The
3791 "shadow contents" are NOT valid after an exec, so GDB should not
3792 do that. Instead, the target is responsible from marking
3793 breakpoints out as soon as it detects an exec. We don't do that
3794 here instead, because there may be other attempts to delete
3795 breakpoints after detecting an exec and before reaching here. */
3796 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3797 if (bploc
->pspace
== current_program_space
)
3798 gdb_assert (!bploc
->inserted
);
3800 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3802 if (b
->pspace
!= current_program_space
)
3805 /* Solib breakpoints must be explicitly reset after an exec(). */
3806 if (b
->type
== bp_shlib_event
)
3808 delete_breakpoint (b
);
3812 /* JIT breakpoints must be explicitly reset after an exec(). */
3813 if (b
->type
== bp_jit_event
)
3815 delete_breakpoint (b
);
3819 /* Thread event breakpoints must be set anew after an exec(),
3820 as must overlay event and longjmp master breakpoints. */
3821 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3822 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3823 || b
->type
== bp_exception_master
)
3825 delete_breakpoint (b
);
3829 /* Step-resume breakpoints are meaningless after an exec(). */
3830 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3832 delete_breakpoint (b
);
3836 /* Just like single-step breakpoints. */
3837 if (b
->type
== bp_single_step
)
3839 delete_breakpoint (b
);
3843 /* Longjmp and longjmp-resume breakpoints are also meaningless
3845 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3846 || b
->type
== bp_longjmp_call_dummy
3847 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3849 delete_breakpoint (b
);
3853 if (b
->type
== bp_catchpoint
)
3855 /* For now, none of the bp_catchpoint breakpoints need to
3856 do anything at this point. In the future, if some of
3857 the catchpoints need to something, we will need to add
3858 a new method, and call this method from here. */
3862 /* bp_finish is a special case. The only way we ought to be able
3863 to see one of these when an exec() has happened, is if the user
3864 caught a vfork, and then said "finish". Ordinarily a finish just
3865 carries them to the call-site of the current callee, by setting
3866 a temporary bp there and resuming. But in this case, the finish
3867 will carry them entirely through the vfork & exec.
3869 We don't want to allow a bp_finish to remain inserted now. But
3870 we can't safely delete it, 'cause finish_command has a handle to
3871 the bp on a bpstat, and will later want to delete it. There's a
3872 chance (and I've seen it happen) that if we delete the bp_finish
3873 here, that its storage will get reused by the time finish_command
3874 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3875 We really must allow finish_command to delete a bp_finish.
3877 In the absence of a general solution for the "how do we know
3878 it's safe to delete something others may have handles to?"
3879 problem, what we'll do here is just uninsert the bp_finish, and
3880 let finish_command delete it.
3882 (We know the bp_finish is "doomed" in the sense that it's
3883 momentary, and will be deleted as soon as finish_command sees
3884 the inferior stopped. So it doesn't matter that the bp's
3885 address is probably bogus in the new a.out, unlike e.g., the
3886 solib breakpoints.) */
3888 if (b
->type
== bp_finish
)
3893 /* Without a symbolic address, we have little hope of the
3894 pre-exec() address meaning the same thing in the post-exec()
3896 if (event_location_empty_p (b
->location
))
3898 delete_breakpoint (b
);
3905 detach_breakpoints (ptid_t ptid
)
3907 struct bp_location
*bl
, **blp_tmp
;
3909 struct cleanup
*old_chain
= save_inferior_ptid ();
3910 struct inferior
*inf
= current_inferior ();
3912 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3913 error (_("Cannot detach breakpoints of inferior_ptid"));
3915 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3916 inferior_ptid
= ptid
;
3917 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3919 if (bl
->pspace
!= inf
->pspace
)
3922 /* This function must physically remove breakpoints locations
3923 from the specified ptid, without modifying the breakpoint
3924 package's state. Locations of type bp_loc_other are only
3925 maintained at GDB side. So, there is no need to remove
3926 these bp_loc_other locations. Moreover, removing these
3927 would modify the breakpoint package's state. */
3928 if (bl
->loc_type
== bp_loc_other
)
3932 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3935 do_cleanups (old_chain
);
3939 /* Remove the breakpoint location BL from the current address space.
3940 Note that this is used to detach breakpoints from a child fork.
3941 When we get here, the child isn't in the inferior list, and neither
3942 do we have objects to represent its address space --- we should
3943 *not* look at bl->pspace->aspace here. */
3946 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3950 /* BL is never in moribund_locations by our callers. */
3951 gdb_assert (bl
->owner
!= NULL
);
3953 /* The type of none suggests that owner is actually deleted.
3954 This should not ever happen. */
3955 gdb_assert (bl
->owner
->type
!= bp_none
);
3957 if (bl
->loc_type
== bp_loc_software_breakpoint
3958 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3960 /* "Normal" instruction breakpoint: either the standard
3961 trap-instruction bp (bp_breakpoint), or a
3962 bp_hardware_breakpoint. */
3964 /* First check to see if we have to handle an overlay. */
3965 if (overlay_debugging
== ovly_off
3966 || bl
->section
== NULL
3967 || !(section_is_overlay (bl
->section
)))
3969 /* No overlay handling: just remove the breakpoint. */
3971 /* If we're trying to uninsert a memory breakpoint that we
3972 know is set in a dynamic object that is marked
3973 shlib_disabled, then either the dynamic object was
3974 removed with "remove-symbol-file" or with
3975 "nosharedlibrary". In the former case, we don't know
3976 whether another dynamic object might have loaded over the
3977 breakpoint's address -- the user might well let us know
3978 about it next with add-symbol-file (the whole point of
3979 add-symbol-file is letting the user manually maintain a
3980 list of dynamically loaded objects). If we have the
3981 breakpoint's shadow memory, that is, this is a software
3982 breakpoint managed by GDB, check whether the breakpoint
3983 is still inserted in memory, to avoid overwriting wrong
3984 code with stale saved shadow contents. Note that HW
3985 breakpoints don't have shadow memory, as they're
3986 implemented using a mechanism that is not dependent on
3987 being able to modify the target's memory, and as such
3988 they should always be removed. */
3989 if (bl
->shlib_disabled
3990 && bl
->target_info
.shadow_len
!= 0
3991 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3994 val
= bl
->owner
->ops
->remove_location (bl
);
3998 /* This breakpoint is in an overlay section.
3999 Did we set a breakpoint at the LMA? */
4000 if (!overlay_events_enabled
)
4002 /* Yes -- overlay event support is not active, so we
4003 should have set a breakpoint at the LMA. Remove it.
4005 /* Ignore any failures: if the LMA is in ROM, we will
4006 have already warned when we failed to insert it. */
4007 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4008 target_remove_hw_breakpoint (bl
->gdbarch
,
4009 &bl
->overlay_target_info
);
4011 target_remove_breakpoint (bl
->gdbarch
,
4012 &bl
->overlay_target_info
);
4014 /* Did we set a breakpoint at the VMA?
4015 If so, we will have marked the breakpoint 'inserted'. */
4018 /* Yes -- remove it. Previously we did not bother to
4019 remove the breakpoint if the section had been
4020 unmapped, but let's not rely on that being safe. We
4021 don't know what the overlay manager might do. */
4023 /* However, we should remove *software* breakpoints only
4024 if the section is still mapped, or else we overwrite
4025 wrong code with the saved shadow contents. */
4026 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4027 || section_is_mapped (bl
->section
))
4028 val
= bl
->owner
->ops
->remove_location (bl
);
4034 /* No -- not inserted, so no need to remove. No error. */
4039 /* In some cases, we might not be able to remove a breakpoint in
4040 a shared library that has already been removed, but we have
4041 not yet processed the shlib unload event. Similarly for an
4042 unloaded add-symbol-file object - the user might not yet have
4043 had the chance to remove-symbol-file it. shlib_disabled will
4044 be set if the library/object has already been removed, but
4045 the breakpoint hasn't been uninserted yet, e.g., after
4046 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4047 always-inserted mode. */
4049 && (bl
->loc_type
== bp_loc_software_breakpoint
4050 && (bl
->shlib_disabled
4051 || solib_name_from_address (bl
->pspace
, bl
->address
)
4052 || shared_objfile_contains_address_p (bl
->pspace
,
4058 bl
->inserted
= (is
== mark_inserted
);
4060 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4062 gdb_assert (bl
->owner
->ops
!= NULL
4063 && bl
->owner
->ops
->remove_location
!= NULL
);
4065 bl
->inserted
= (is
== mark_inserted
);
4066 bl
->owner
->ops
->remove_location (bl
);
4068 /* Failure to remove any of the hardware watchpoints comes here. */
4069 if ((is
== mark_uninserted
) && (bl
->inserted
))
4070 warning (_("Could not remove hardware watchpoint %d."),
4073 else if (bl
->owner
->type
== bp_catchpoint
4074 && breakpoint_enabled (bl
->owner
)
4077 gdb_assert (bl
->owner
->ops
!= NULL
4078 && bl
->owner
->ops
->remove_location
!= NULL
);
4080 val
= bl
->owner
->ops
->remove_location (bl
);
4084 bl
->inserted
= (is
== mark_inserted
);
4091 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4094 struct cleanup
*old_chain
;
4096 /* BL is never in moribund_locations by our callers. */
4097 gdb_assert (bl
->owner
!= NULL
);
4099 /* The type of none suggests that owner is actually deleted.
4100 This should not ever happen. */
4101 gdb_assert (bl
->owner
->type
!= bp_none
);
4103 old_chain
= save_current_space_and_thread ();
4105 switch_to_program_space_and_thread (bl
->pspace
);
4107 ret
= remove_breakpoint_1 (bl
, is
);
4109 do_cleanups (old_chain
);
4113 /* Clear the "inserted" flag in all breakpoints. */
4116 mark_breakpoints_out (void)
4118 struct bp_location
*bl
, **blp_tmp
;
4120 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4121 if (bl
->pspace
== current_program_space
)
4125 /* Clear the "inserted" flag in all breakpoints and delete any
4126 breakpoints which should go away between runs of the program.
4128 Plus other such housekeeping that has to be done for breakpoints
4131 Note: this function gets called at the end of a run (by
4132 generic_mourn_inferior) and when a run begins (by
4133 init_wait_for_inferior). */
4138 breakpoint_init_inferior (enum inf_context context
)
4140 struct breakpoint
*b
, *b_tmp
;
4141 struct bp_location
*bl
, **blp_tmp
;
4143 struct program_space
*pspace
= current_program_space
;
4145 /* If breakpoint locations are shared across processes, then there's
4147 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4150 mark_breakpoints_out ();
4152 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4154 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4160 case bp_longjmp_call_dummy
:
4162 /* If the call dummy breakpoint is at the entry point it will
4163 cause problems when the inferior is rerun, so we better get
4166 case bp_watchpoint_scope
:
4168 /* Also get rid of scope breakpoints. */
4170 case bp_shlib_event
:
4172 /* Also remove solib event breakpoints. Their addresses may
4173 have changed since the last time we ran the program.
4174 Actually we may now be debugging against different target;
4175 and so the solib backend that installed this breakpoint may
4176 not be used in by the target. E.g.,
4178 (gdb) file prog-linux
4179 (gdb) run # native linux target
4182 (gdb) file prog-win.exe
4183 (gdb) tar rem :9999 # remote Windows gdbserver.
4186 case bp_step_resume
:
4188 /* Also remove step-resume breakpoints. */
4190 case bp_single_step
:
4192 /* Also remove single-step breakpoints. */
4194 delete_breakpoint (b
);
4198 case bp_hardware_watchpoint
:
4199 case bp_read_watchpoint
:
4200 case bp_access_watchpoint
:
4202 struct watchpoint
*w
= (struct watchpoint
*) b
;
4204 /* Likewise for watchpoints on local expressions. */
4205 if (w
->exp_valid_block
!= NULL
)
4206 delete_breakpoint (b
);
4207 else if (context
== inf_starting
)
4209 /* Reset val field to force reread of starting value in
4210 insert_breakpoints. */
4212 value_free (w
->val
);
4223 /* Get rid of the moribund locations. */
4224 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4225 decref_bp_location (&bl
);
4226 VEC_free (bp_location_p
, moribund_locations
);
4229 /* These functions concern about actual breakpoints inserted in the
4230 target --- to e.g. check if we need to do decr_pc adjustment or if
4231 we need to hop over the bkpt --- so we check for address space
4232 match, not program space. */
4234 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4235 exists at PC. It returns ordinary_breakpoint_here if it's an
4236 ordinary breakpoint, or permanent_breakpoint_here if it's a
4237 permanent breakpoint.
4238 - When continuing from a location with an ordinary breakpoint, we
4239 actually single step once before calling insert_breakpoints.
4240 - When continuing from a location with a permanent breakpoint, we
4241 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4242 the target, to advance the PC past the breakpoint. */
4244 enum breakpoint_here
4245 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4247 struct bp_location
*bl
, **blp_tmp
;
4248 int any_breakpoint_here
= 0;
4250 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4252 if (bl
->loc_type
!= bp_loc_software_breakpoint
4253 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4256 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4257 if ((breakpoint_enabled (bl
->owner
)
4259 && breakpoint_location_address_match (bl
, aspace
, pc
))
4261 if (overlay_debugging
4262 && section_is_overlay (bl
->section
)
4263 && !section_is_mapped (bl
->section
))
4264 continue; /* unmapped overlay -- can't be a match */
4265 else if (bl
->permanent
)
4266 return permanent_breakpoint_here
;
4268 any_breakpoint_here
= 1;
4272 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4275 /* See breakpoint.h. */
4278 breakpoint_in_range_p (struct address_space
*aspace
,
4279 CORE_ADDR addr
, ULONGEST len
)
4281 struct bp_location
*bl
, **blp_tmp
;
4283 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4285 if (bl
->loc_type
!= bp_loc_software_breakpoint
4286 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4289 if ((breakpoint_enabled (bl
->owner
)
4291 && breakpoint_location_address_range_overlap (bl
, aspace
,
4294 if (overlay_debugging
4295 && section_is_overlay (bl
->section
)
4296 && !section_is_mapped (bl
->section
))
4298 /* Unmapped overlay -- can't be a match. */
4309 /* Return true if there's a moribund breakpoint at PC. */
4312 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4314 struct bp_location
*loc
;
4317 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4318 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4324 /* Returns non-zero iff BL is inserted at PC, in address space
4328 bp_location_inserted_here_p (struct bp_location
*bl
,
4329 struct address_space
*aspace
, CORE_ADDR pc
)
4332 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4335 if (overlay_debugging
4336 && section_is_overlay (bl
->section
)
4337 && !section_is_mapped (bl
->section
))
4338 return 0; /* unmapped overlay -- can't be a match */
4345 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4348 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4350 struct bp_location
**blp
, **blp_tmp
= NULL
;
4351 struct bp_location
*bl
;
4353 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4355 struct bp_location
*bl
= *blp
;
4357 if (bl
->loc_type
!= bp_loc_software_breakpoint
4358 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4361 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4367 /* This function returns non-zero iff there is a software breakpoint
4371 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4374 struct bp_location
**blp
, **blp_tmp
= NULL
;
4375 struct bp_location
*bl
;
4377 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4379 struct bp_location
*bl
= *blp
;
4381 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4384 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4391 /* See breakpoint.h. */
4394 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4397 struct bp_location
**blp
, **blp_tmp
= NULL
;
4398 struct bp_location
*bl
;
4400 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4402 struct bp_location
*bl
= *blp
;
4404 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4407 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4415 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4416 CORE_ADDR addr
, ULONGEST len
)
4418 struct breakpoint
*bpt
;
4420 ALL_BREAKPOINTS (bpt
)
4422 struct bp_location
*loc
;
4424 if (bpt
->type
!= bp_hardware_watchpoint
4425 && bpt
->type
!= bp_access_watchpoint
)
4428 if (!breakpoint_enabled (bpt
))
4431 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4432 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4436 /* Check for intersection. */
4437 l
= max (loc
->address
, addr
);
4438 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4447 /* bpstat stuff. External routines' interfaces are documented
4451 is_catchpoint (struct breakpoint
*ep
)
4453 return (ep
->type
== bp_catchpoint
);
4456 /* Frees any storage that is part of a bpstat. Does not walk the
4460 bpstat_free (bpstat bs
)
4462 if (bs
->old_val
!= NULL
)
4463 value_free (bs
->old_val
);
4464 decref_counted_command_line (&bs
->commands
);
4465 decref_bp_location (&bs
->bp_location_at
);
4469 /* Clear a bpstat so that it says we are not at any breakpoint.
4470 Also free any storage that is part of a bpstat. */
4473 bpstat_clear (bpstat
*bsp
)
4490 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4491 is part of the bpstat is copied as well. */
4494 bpstat_copy (bpstat bs
)
4498 bpstat retval
= NULL
;
4503 for (; bs
!= NULL
; bs
= bs
->next
)
4505 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4506 memcpy (tmp
, bs
, sizeof (*tmp
));
4507 incref_counted_command_line (tmp
->commands
);
4508 incref_bp_location (tmp
->bp_location_at
);
4509 if (bs
->old_val
!= NULL
)
4511 tmp
->old_val
= value_copy (bs
->old_val
);
4512 release_value (tmp
->old_val
);
4516 /* This is the first thing in the chain. */
4526 /* Find the bpstat associated with this breakpoint. */
4529 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4534 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4536 if (bsp
->breakpoint_at
== breakpoint
)
4542 /* See breakpoint.h. */
4545 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4547 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4549 if (bsp
->breakpoint_at
== NULL
)
4551 /* A moribund location can never explain a signal other than
4553 if (sig
== GDB_SIGNAL_TRAP
)
4558 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4567 /* Put in *NUM the breakpoint number of the first breakpoint we are
4568 stopped at. *BSP upon return is a bpstat which points to the
4569 remaining breakpoints stopped at (but which is not guaranteed to be
4570 good for anything but further calls to bpstat_num).
4572 Return 0 if passed a bpstat which does not indicate any breakpoints.
4573 Return -1 if stopped at a breakpoint that has been deleted since
4575 Return 1 otherwise. */
4578 bpstat_num (bpstat
*bsp
, int *num
)
4580 struct breakpoint
*b
;
4583 return 0; /* No more breakpoint values */
4585 /* We assume we'll never have several bpstats that correspond to a
4586 single breakpoint -- otherwise, this function might return the
4587 same number more than once and this will look ugly. */
4588 b
= (*bsp
)->breakpoint_at
;
4589 *bsp
= (*bsp
)->next
;
4591 return -1; /* breakpoint that's been deleted since */
4593 *num
= b
->number
; /* We have its number */
4597 /* See breakpoint.h. */
4600 bpstat_clear_actions (void)
4602 struct thread_info
*tp
;
4605 if (ptid_equal (inferior_ptid
, null_ptid
))
4608 tp
= find_thread_ptid (inferior_ptid
);
4612 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4614 decref_counted_command_line (&bs
->commands
);
4616 if (bs
->old_val
!= NULL
)
4618 value_free (bs
->old_val
);
4624 /* Called when a command is about to proceed the inferior. */
4627 breakpoint_about_to_proceed (void)
4629 if (!ptid_equal (inferior_ptid
, null_ptid
))
4631 struct thread_info
*tp
= inferior_thread ();
4633 /* Allow inferior function calls in breakpoint commands to not
4634 interrupt the command list. When the call finishes
4635 successfully, the inferior will be standing at the same
4636 breakpoint as if nothing happened. */
4637 if (tp
->control
.in_infcall
)
4641 breakpoint_proceeded
= 1;
4644 /* Stub for cleaning up our state if we error-out of a breakpoint
4647 cleanup_executing_breakpoints (void *ignore
)
4649 executing_breakpoint_commands
= 0;
4652 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4653 or its equivalent. */
4656 command_line_is_silent (struct command_line
*cmd
)
4658 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4661 /* Execute all the commands associated with all the breakpoints at
4662 this location. Any of these commands could cause the process to
4663 proceed beyond this point, etc. We look out for such changes by
4664 checking the global "breakpoint_proceeded" after each command.
4666 Returns true if a breakpoint command resumed the inferior. In that
4667 case, it is the caller's responsibility to recall it again with the
4668 bpstat of the current thread. */
4671 bpstat_do_actions_1 (bpstat
*bsp
)
4674 struct cleanup
*old_chain
;
4677 /* Avoid endless recursion if a `source' command is contained
4679 if (executing_breakpoint_commands
)
4682 executing_breakpoint_commands
= 1;
4683 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4685 prevent_dont_repeat ();
4687 /* This pointer will iterate over the list of bpstat's. */
4690 breakpoint_proceeded
= 0;
4691 for (; bs
!= NULL
; bs
= bs
->next
)
4693 struct counted_command_line
*ccmd
;
4694 struct command_line
*cmd
;
4695 struct cleanup
*this_cmd_tree_chain
;
4697 /* Take ownership of the BSP's command tree, if it has one.
4699 The command tree could legitimately contain commands like
4700 'step' and 'next', which call clear_proceed_status, which
4701 frees stop_bpstat's command tree. To make sure this doesn't
4702 free the tree we're executing out from under us, we need to
4703 take ownership of the tree ourselves. Since a given bpstat's
4704 commands are only executed once, we don't need to copy it; we
4705 can clear the pointer in the bpstat, and make sure we free
4706 the tree when we're done. */
4707 ccmd
= bs
->commands
;
4708 bs
->commands
= NULL
;
4709 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4710 cmd
= ccmd
? ccmd
->commands
: NULL
;
4711 if (command_line_is_silent (cmd
))
4713 /* The action has been already done by bpstat_stop_status. */
4719 execute_control_command (cmd
);
4721 if (breakpoint_proceeded
)
4727 /* We can free this command tree now. */
4728 do_cleanups (this_cmd_tree_chain
);
4730 if (breakpoint_proceeded
)
4732 if (interpreter_async
)
4733 /* If we are in async mode, then the target might be still
4734 running, not stopped at any breakpoint, so nothing for
4735 us to do here -- just return to the event loop. */
4738 /* In sync mode, when execute_control_command returns
4739 we're already standing on the next breakpoint.
4740 Breakpoint commands for that stop were not run, since
4741 execute_command does not run breakpoint commands --
4742 only command_line_handler does, but that one is not
4743 involved in execution of breakpoint commands. So, we
4744 can now execute breakpoint commands. It should be
4745 noted that making execute_command do bpstat actions is
4746 not an option -- in this case we'll have recursive
4747 invocation of bpstat for each breakpoint with a
4748 command, and can easily blow up GDB stack. Instead, we
4749 return true, which will trigger the caller to recall us
4750 with the new stop_bpstat. */
4755 do_cleanups (old_chain
);
4760 bpstat_do_actions (void)
4762 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4764 /* Do any commands attached to breakpoint we are stopped at. */
4765 while (!ptid_equal (inferior_ptid
, null_ptid
)
4766 && target_has_execution
4767 && !is_exited (inferior_ptid
)
4768 && !is_executing (inferior_ptid
))
4769 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4770 and only return when it is stopped at the next breakpoint, we
4771 keep doing breakpoint actions until it returns false to
4772 indicate the inferior was not resumed. */
4773 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4776 discard_cleanups (cleanup_if_error
);
4779 /* Print out the (old or new) value associated with a watchpoint. */
4782 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4785 fprintf_unfiltered (stream
, _("<unreadable>"));
4788 struct value_print_options opts
;
4789 get_user_print_options (&opts
);
4790 value_print (val
, stream
, &opts
);
4794 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4795 debugging multiple threads. */
4798 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4800 if (ui_out_is_mi_like_p (uiout
))
4803 ui_out_text (uiout
, "\n");
4805 if (show_thread_that_caused_stop ())
4808 struct thread_info
*thr
= inferior_thread ();
4810 ui_out_text (uiout
, "Thread ");
4811 ui_out_field_fmt (uiout
, "thread-id", "%s", print_thread_id (thr
));
4813 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4816 ui_out_text (uiout
, " \"");
4817 ui_out_field_fmt (uiout
, "name", "%s", name
);
4818 ui_out_text (uiout
, "\"");
4821 ui_out_text (uiout
, " hit ");
4825 /* Generic routine for printing messages indicating why we
4826 stopped. The behavior of this function depends on the value
4827 'print_it' in the bpstat structure. Under some circumstances we
4828 may decide not to print anything here and delegate the task to
4831 static enum print_stop_action
4832 print_bp_stop_message (bpstat bs
)
4834 switch (bs
->print_it
)
4837 /* Nothing should be printed for this bpstat entry. */
4838 return PRINT_UNKNOWN
;
4842 /* We still want to print the frame, but we already printed the
4843 relevant messages. */
4844 return PRINT_SRC_AND_LOC
;
4847 case print_it_normal
:
4849 struct breakpoint
*b
= bs
->breakpoint_at
;
4851 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4852 which has since been deleted. */
4854 return PRINT_UNKNOWN
;
4856 /* Normal case. Call the breakpoint's print_it method. */
4857 return b
->ops
->print_it (bs
);
4862 internal_error (__FILE__
, __LINE__
,
4863 _("print_bp_stop_message: unrecognized enum value"));
4868 /* A helper function that prints a shared library stopped event. */
4871 print_solib_event (int is_catchpoint
)
4874 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4876 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4880 if (any_added
|| any_deleted
)
4881 ui_out_text (current_uiout
,
4882 _("Stopped due to shared library event:\n"));
4884 ui_out_text (current_uiout
,
4885 _("Stopped due to shared library event (no "
4886 "libraries added or removed)\n"));
4889 if (ui_out_is_mi_like_p (current_uiout
))
4890 ui_out_field_string (current_uiout
, "reason",
4891 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4895 struct cleanup
*cleanup
;
4899 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4900 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4903 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4908 ui_out_text (current_uiout
, " ");
4909 ui_out_field_string (current_uiout
, "library", name
);
4910 ui_out_text (current_uiout
, "\n");
4913 do_cleanups (cleanup
);
4918 struct so_list
*iter
;
4920 struct cleanup
*cleanup
;
4922 ui_out_text (current_uiout
, _(" Inferior loaded "));
4923 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4926 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4931 ui_out_text (current_uiout
, " ");
4932 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4933 ui_out_text (current_uiout
, "\n");
4936 do_cleanups (cleanup
);
4940 /* Print a message indicating what happened. This is called from
4941 normal_stop(). The input to this routine is the head of the bpstat
4942 list - a list of the eventpoints that caused this stop. KIND is
4943 the target_waitkind for the stopping event. This
4944 routine calls the generic print routine for printing a message
4945 about reasons for stopping. This will print (for example) the
4946 "Breakpoint n," part of the output. The return value of this
4949 PRINT_UNKNOWN: Means we printed nothing.
4950 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4951 code to print the location. An example is
4952 "Breakpoint 1, " which should be followed by
4954 PRINT_SRC_ONLY: Means we printed something, but there is no need
4955 to also print the location part of the message.
4956 An example is the catch/throw messages, which
4957 don't require a location appended to the end.
4958 PRINT_NOTHING: We have done some printing and we don't need any
4959 further info to be printed. */
4961 enum print_stop_action
4962 bpstat_print (bpstat bs
, int kind
)
4964 enum print_stop_action val
;
4966 /* Maybe another breakpoint in the chain caused us to stop.
4967 (Currently all watchpoints go on the bpstat whether hit or not.
4968 That probably could (should) be changed, provided care is taken
4969 with respect to bpstat_explains_signal). */
4970 for (; bs
; bs
= bs
->next
)
4972 val
= print_bp_stop_message (bs
);
4973 if (val
== PRINT_SRC_ONLY
4974 || val
== PRINT_SRC_AND_LOC
4975 || val
== PRINT_NOTHING
)
4979 /* If we had hit a shared library event breakpoint,
4980 print_bp_stop_message would print out this message. If we hit an
4981 OS-level shared library event, do the same thing. */
4982 if (kind
== TARGET_WAITKIND_LOADED
)
4984 print_solib_event (0);
4985 return PRINT_NOTHING
;
4988 /* We reached the end of the chain, or we got a null BS to start
4989 with and nothing was printed. */
4990 return PRINT_UNKNOWN
;
4993 /* Evaluate the expression EXP and return 1 if value is zero.
4994 This returns the inverse of the condition because it is called
4995 from catch_errors which returns 0 if an exception happened, and if an
4996 exception happens we want execution to stop.
4997 The argument is a "struct expression *" that has been cast to a
4998 "void *" to make it pass through catch_errors. */
5001 breakpoint_cond_eval (void *exp
)
5003 struct value
*mark
= value_mark ();
5004 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
5006 value_free_to_mark (mark
);
5010 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5013 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5017 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5019 **bs_link_pointer
= bs
;
5020 *bs_link_pointer
= &bs
->next
;
5021 bs
->breakpoint_at
= bl
->owner
;
5022 bs
->bp_location_at
= bl
;
5023 incref_bp_location (bl
);
5024 /* If the condition is false, etc., don't do the commands. */
5025 bs
->commands
= NULL
;
5027 bs
->print_it
= print_it_normal
;
5031 /* The target has stopped with waitstatus WS. Check if any hardware
5032 watchpoints have triggered, according to the target. */
5035 watchpoints_triggered (struct target_waitstatus
*ws
)
5037 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5039 struct breakpoint
*b
;
5041 if (!stopped_by_watchpoint
)
5043 /* We were not stopped by a watchpoint. Mark all watchpoints
5044 as not triggered. */
5046 if (is_hardware_watchpoint (b
))
5048 struct watchpoint
*w
= (struct watchpoint
*) b
;
5050 w
->watchpoint_triggered
= watch_triggered_no
;
5056 if (!target_stopped_data_address (¤t_target
, &addr
))
5058 /* We were stopped by a watchpoint, but we don't know where.
5059 Mark all watchpoints as unknown. */
5061 if (is_hardware_watchpoint (b
))
5063 struct watchpoint
*w
= (struct watchpoint
*) b
;
5065 w
->watchpoint_triggered
= watch_triggered_unknown
;
5071 /* The target could report the data address. Mark watchpoints
5072 affected by this data address as triggered, and all others as not
5076 if (is_hardware_watchpoint (b
))
5078 struct watchpoint
*w
= (struct watchpoint
*) b
;
5079 struct bp_location
*loc
;
5081 w
->watchpoint_triggered
= watch_triggered_no
;
5082 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5084 if (is_masked_watchpoint (b
))
5086 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5087 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5089 if (newaddr
== start
)
5091 w
->watchpoint_triggered
= watch_triggered_yes
;
5095 /* Exact match not required. Within range is sufficient. */
5096 else if (target_watchpoint_addr_within_range (¤t_target
,
5100 w
->watchpoint_triggered
= watch_triggered_yes
;
5109 /* Possible return values for watchpoint_check (this can't be an enum
5110 because of check_errors). */
5111 /* The watchpoint has been deleted. */
5112 #define WP_DELETED 1
5113 /* The value has changed. */
5114 #define WP_VALUE_CHANGED 2
5115 /* The value has not changed. */
5116 #define WP_VALUE_NOT_CHANGED 3
5117 /* Ignore this watchpoint, no matter if the value changed or not. */
5120 #define BP_TEMPFLAG 1
5121 #define BP_HARDWAREFLAG 2
5123 /* Evaluate watchpoint condition expression and check if its value
5126 P should be a pointer to struct bpstat, but is defined as a void *
5127 in order for this function to be usable with catch_errors. */
5130 watchpoint_check (void *p
)
5132 bpstat bs
= (bpstat
) p
;
5133 struct watchpoint
*b
;
5134 struct frame_info
*fr
;
5135 int within_current_scope
;
5137 /* BS is built from an existing struct breakpoint. */
5138 gdb_assert (bs
->breakpoint_at
!= NULL
);
5139 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5141 /* If this is a local watchpoint, we only want to check if the
5142 watchpoint frame is in scope if the current thread is the thread
5143 that was used to create the watchpoint. */
5144 if (!watchpoint_in_thread_scope (b
))
5147 if (b
->exp_valid_block
== NULL
)
5148 within_current_scope
= 1;
5151 struct frame_info
*frame
= get_current_frame ();
5152 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5153 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5155 /* stack_frame_destroyed_p() returns a non-zero value if we're
5156 still in the function but the stack frame has already been
5157 invalidated. Since we can't rely on the values of local
5158 variables after the stack has been destroyed, we are treating
5159 the watchpoint in that state as `not changed' without further
5160 checking. Don't mark watchpoints as changed if the current
5161 frame is in an epilogue - even if they are in some other
5162 frame, our view of the stack is likely to be wrong and
5163 frame_find_by_id could error out. */
5164 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5167 fr
= frame_find_by_id (b
->watchpoint_frame
);
5168 within_current_scope
= (fr
!= NULL
);
5170 /* If we've gotten confused in the unwinder, we might have
5171 returned a frame that can't describe this variable. */
5172 if (within_current_scope
)
5174 struct symbol
*function
;
5176 function
= get_frame_function (fr
);
5177 if (function
== NULL
5178 || !contained_in (b
->exp_valid_block
,
5179 SYMBOL_BLOCK_VALUE (function
)))
5180 within_current_scope
= 0;
5183 if (within_current_scope
)
5184 /* If we end up stopping, the current frame will get selected
5185 in normal_stop. So this call to select_frame won't affect
5190 if (within_current_scope
)
5192 /* We use value_{,free_to_}mark because it could be a *long*
5193 time before we return to the command level and call
5194 free_all_values. We can't call free_all_values because we
5195 might be in the middle of evaluating a function call. */
5199 struct value
*new_val
;
5201 if (is_masked_watchpoint (&b
->base
))
5202 /* Since we don't know the exact trigger address (from
5203 stopped_data_address), just tell the user we've triggered
5204 a mask watchpoint. */
5205 return WP_VALUE_CHANGED
;
5207 mark
= value_mark ();
5208 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5210 if (b
->val_bitsize
!= 0)
5211 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5213 /* We use value_equal_contents instead of value_equal because
5214 the latter coerces an array to a pointer, thus comparing just
5215 the address of the array instead of its contents. This is
5216 not what we want. */
5217 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5218 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5220 if (new_val
!= NULL
)
5222 release_value (new_val
);
5223 value_free_to_mark (mark
);
5225 bs
->old_val
= b
->val
;
5228 return WP_VALUE_CHANGED
;
5232 /* Nothing changed. */
5233 value_free_to_mark (mark
);
5234 return WP_VALUE_NOT_CHANGED
;
5239 struct ui_out
*uiout
= current_uiout
;
5241 /* This seems like the only logical thing to do because
5242 if we temporarily ignored the watchpoint, then when
5243 we reenter the block in which it is valid it contains
5244 garbage (in the case of a function, it may have two
5245 garbage values, one before and one after the prologue).
5246 So we can't even detect the first assignment to it and
5247 watch after that (since the garbage may or may not equal
5248 the first value assigned). */
5249 /* We print all the stop information in
5250 breakpoint_ops->print_it, but in this case, by the time we
5251 call breakpoint_ops->print_it this bp will be deleted
5252 already. So we have no choice but print the information
5254 if (ui_out_is_mi_like_p (uiout
))
5256 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5257 ui_out_text (uiout
, "\nWatchpoint ");
5258 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5260 " deleted because the program has left the block in\n\
5261 which its expression is valid.\n");
5263 /* Make sure the watchpoint's commands aren't executed. */
5264 decref_counted_command_line (&b
->base
.commands
);
5265 watchpoint_del_at_next_stop (b
);
5271 /* Return true if it looks like target has stopped due to hitting
5272 breakpoint location BL. This function does not check if we should
5273 stop, only if BL explains the stop. */
5276 bpstat_check_location (const struct bp_location
*bl
,
5277 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5278 const struct target_waitstatus
*ws
)
5280 struct breakpoint
*b
= bl
->owner
;
5282 /* BL is from an existing breakpoint. */
5283 gdb_assert (b
!= NULL
);
5285 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5288 /* Determine if the watched values have actually changed, and we
5289 should stop. If not, set BS->stop to 0. */
5292 bpstat_check_watchpoint (bpstat bs
)
5294 const struct bp_location
*bl
;
5295 struct watchpoint
*b
;
5297 /* BS is built for existing struct breakpoint. */
5298 bl
= bs
->bp_location_at
;
5299 gdb_assert (bl
!= NULL
);
5300 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5301 gdb_assert (b
!= NULL
);
5304 int must_check_value
= 0;
5306 if (b
->base
.type
== bp_watchpoint
)
5307 /* For a software watchpoint, we must always check the
5309 must_check_value
= 1;
5310 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5311 /* We have a hardware watchpoint (read, write, or access)
5312 and the target earlier reported an address watched by
5314 must_check_value
= 1;
5315 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5316 && b
->base
.type
== bp_hardware_watchpoint
)
5317 /* We were stopped by a hardware watchpoint, but the target could
5318 not report the data address. We must check the watchpoint's
5319 value. Access and read watchpoints are out of luck; without
5320 a data address, we can't figure it out. */
5321 must_check_value
= 1;
5323 if (must_check_value
)
5326 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5328 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5329 int e
= catch_errors (watchpoint_check
, bs
, message
,
5331 do_cleanups (cleanups
);
5335 /* We've already printed what needs to be printed. */
5336 bs
->print_it
= print_it_done
;
5340 bs
->print_it
= print_it_noop
;
5343 case WP_VALUE_CHANGED
:
5344 if (b
->base
.type
== bp_read_watchpoint
)
5346 /* There are two cases to consider here:
5348 1. We're watching the triggered memory for reads.
5349 In that case, trust the target, and always report
5350 the watchpoint hit to the user. Even though
5351 reads don't cause value changes, the value may
5352 have changed since the last time it was read, and
5353 since we're not trapping writes, we will not see
5354 those, and as such we should ignore our notion of
5357 2. We're watching the triggered memory for both
5358 reads and writes. There are two ways this may
5361 2.1. This is a target that can't break on data
5362 reads only, but can break on accesses (reads or
5363 writes), such as e.g., x86. We detect this case
5364 at the time we try to insert read watchpoints.
5366 2.2. Otherwise, the target supports read
5367 watchpoints, but, the user set an access or write
5368 watchpoint watching the same memory as this read
5371 If we're watching memory writes as well as reads,
5372 ignore watchpoint hits when we find that the
5373 value hasn't changed, as reads don't cause
5374 changes. This still gives false positives when
5375 the program writes the same value to memory as
5376 what there was already in memory (we will confuse
5377 it for a read), but it's much better than
5380 int other_write_watchpoint
= 0;
5382 if (bl
->watchpoint_type
== hw_read
)
5384 struct breakpoint
*other_b
;
5386 ALL_BREAKPOINTS (other_b
)
5387 if (other_b
->type
== bp_hardware_watchpoint
5388 || other_b
->type
== bp_access_watchpoint
)
5390 struct watchpoint
*other_w
=
5391 (struct watchpoint
*) other_b
;
5393 if (other_w
->watchpoint_triggered
5394 == watch_triggered_yes
)
5396 other_write_watchpoint
= 1;
5402 if (other_write_watchpoint
5403 || bl
->watchpoint_type
== hw_access
)
5405 /* We're watching the same memory for writes,
5406 and the value changed since the last time we
5407 updated it, so this trap must be for a write.
5409 bs
->print_it
= print_it_noop
;
5414 case WP_VALUE_NOT_CHANGED
:
5415 if (b
->base
.type
== bp_hardware_watchpoint
5416 || b
->base
.type
== bp_watchpoint
)
5418 /* Don't stop: write watchpoints shouldn't fire if
5419 the value hasn't changed. */
5420 bs
->print_it
= print_it_noop
;
5428 /* Error from catch_errors. */
5429 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5430 watchpoint_del_at_next_stop (b
);
5431 /* We've already printed what needs to be printed. */
5432 bs
->print_it
= print_it_done
;
5436 else /* must_check_value == 0 */
5438 /* This is a case where some watchpoint(s) triggered, but
5439 not at the address of this watchpoint, or else no
5440 watchpoint triggered after all. So don't print
5441 anything for this watchpoint. */
5442 bs
->print_it
= print_it_noop
;
5448 /* For breakpoints that are currently marked as telling gdb to stop,
5449 check conditions (condition proper, frame, thread and ignore count)
5450 of breakpoint referred to by BS. If we should not stop for this
5451 breakpoint, set BS->stop to 0. */
5454 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5456 const struct bp_location
*bl
;
5457 struct breakpoint
*b
;
5458 int value_is_zero
= 0;
5459 struct expression
*cond
;
5461 gdb_assert (bs
->stop
);
5463 /* BS is built for existing struct breakpoint. */
5464 bl
= bs
->bp_location_at
;
5465 gdb_assert (bl
!= NULL
);
5466 b
= bs
->breakpoint_at
;
5467 gdb_assert (b
!= NULL
);
5469 /* Even if the target evaluated the condition on its end and notified GDB, we
5470 need to do so again since GDB does not know if we stopped due to a
5471 breakpoint or a single step breakpoint. */
5473 if (frame_id_p (b
->frame_id
)
5474 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5480 /* If this is a thread/task-specific breakpoint, don't waste cpu
5481 evaluating the condition if this isn't the specified
5483 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5484 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5491 /* Evaluate extension language breakpoints that have a "stop" method
5493 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5495 if (is_watchpoint (b
))
5497 struct watchpoint
*w
= (struct watchpoint
*) b
;
5504 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5506 int within_current_scope
= 1;
5507 struct watchpoint
* w
;
5509 /* We use value_mark and value_free_to_mark because it could
5510 be a long time before we return to the command level and
5511 call free_all_values. We can't call free_all_values
5512 because we might be in the middle of evaluating a
5514 struct value
*mark
= value_mark ();
5516 if (is_watchpoint (b
))
5517 w
= (struct watchpoint
*) b
;
5521 /* Need to select the frame, with all that implies so that
5522 the conditions will have the right context. Because we
5523 use the frame, we will not see an inlined function's
5524 variables when we arrive at a breakpoint at the start
5525 of the inlined function; the current frame will be the
5527 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5528 select_frame (get_current_frame ());
5531 struct frame_info
*frame
;
5533 /* For local watchpoint expressions, which particular
5534 instance of a local is being watched matters, so we
5535 keep track of the frame to evaluate the expression
5536 in. To evaluate the condition however, it doesn't
5537 really matter which instantiation of the function
5538 where the condition makes sense triggers the
5539 watchpoint. This allows an expression like "watch
5540 global if q > 10" set in `func', catch writes to
5541 global on all threads that call `func', or catch
5542 writes on all recursive calls of `func' by a single
5543 thread. We simply always evaluate the condition in
5544 the innermost frame that's executing where it makes
5545 sense to evaluate the condition. It seems
5547 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5549 select_frame (frame
);
5551 within_current_scope
= 0;
5553 if (within_current_scope
)
5555 = catch_errors (breakpoint_cond_eval
, cond
,
5556 "Error in testing breakpoint condition:\n",
5560 warning (_("Watchpoint condition cannot be tested "
5561 "in the current scope"));
5562 /* If we failed to set the right context for this
5563 watchpoint, unconditionally report it. */
5566 /* FIXME-someday, should give breakpoint #. */
5567 value_free_to_mark (mark
);
5570 if (cond
&& value_is_zero
)
5574 else if (b
->ignore_count
> 0)
5578 /* Increase the hit count even though we don't stop. */
5580 observer_notify_breakpoint_modified (b
);
5584 /* Returns true if we need to track moribund locations of LOC's type
5585 on the current target. */
5588 need_moribund_for_location_type (struct bp_location
*loc
)
5590 return ((loc
->loc_type
== bp_loc_software_breakpoint
5591 && !target_supports_stopped_by_sw_breakpoint ())
5592 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5593 && !target_supports_stopped_by_hw_breakpoint ()));
5597 /* Get a bpstat associated with having just stopped at address
5598 BP_ADDR in thread PTID.
5600 Determine whether we stopped at a breakpoint, etc, or whether we
5601 don't understand this stop. Result is a chain of bpstat's such
5604 if we don't understand the stop, the result is a null pointer.
5606 if we understand why we stopped, the result is not null.
5608 Each element of the chain refers to a particular breakpoint or
5609 watchpoint at which we have stopped. (We may have stopped for
5610 several reasons concurrently.)
5612 Each element of the chain has valid next, breakpoint_at,
5613 commands, FIXME??? fields. */
5616 bpstat_stop_status (struct address_space
*aspace
,
5617 CORE_ADDR bp_addr
, ptid_t ptid
,
5618 const struct target_waitstatus
*ws
)
5620 struct breakpoint
*b
= NULL
;
5621 struct bp_location
*bl
;
5622 struct bp_location
*loc
;
5623 /* First item of allocated bpstat's. */
5624 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5625 /* Pointer to the last thing in the chain currently. */
5628 int need_remove_insert
;
5631 /* First, build the bpstat chain with locations that explain a
5632 target stop, while being careful to not set the target running,
5633 as that may invalidate locations (in particular watchpoint
5634 locations are recreated). Resuming will happen here with
5635 breakpoint conditions or watchpoint expressions that include
5636 inferior function calls. */
5640 if (!breakpoint_enabled (b
))
5643 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5645 /* For hardware watchpoints, we look only at the first
5646 location. The watchpoint_check function will work on the
5647 entire expression, not the individual locations. For
5648 read watchpoints, the watchpoints_triggered function has
5649 checked all locations already. */
5650 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5653 if (!bl
->enabled
|| bl
->shlib_disabled
)
5656 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5659 /* Come here if it's a watchpoint, or if the break address
5662 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5665 /* Assume we stop. Should we find a watchpoint that is not
5666 actually triggered, or if the condition of the breakpoint
5667 evaluates as false, we'll reset 'stop' to 0. */
5671 /* If this is a scope breakpoint, mark the associated
5672 watchpoint as triggered so that we will handle the
5673 out-of-scope event. We'll get to the watchpoint next
5675 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5677 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5679 w
->watchpoint_triggered
= watch_triggered_yes
;
5684 /* Check if a moribund breakpoint explains the stop. */
5685 if (!target_supports_stopped_by_sw_breakpoint ()
5686 || !target_supports_stopped_by_hw_breakpoint ())
5688 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5690 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5691 && need_moribund_for_location_type (loc
))
5693 bs
= bpstat_alloc (loc
, &bs_link
);
5694 /* For hits of moribund locations, we should just proceed. */
5697 bs
->print_it
= print_it_noop
;
5702 /* A bit of special processing for shlib breakpoints. We need to
5703 process solib loading here, so that the lists of loaded and
5704 unloaded libraries are correct before we handle "catch load" and
5706 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5708 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5710 handle_solib_event ();
5715 /* Now go through the locations that caused the target to stop, and
5716 check whether we're interested in reporting this stop to higher
5717 layers, or whether we should resume the target transparently. */
5721 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5726 b
= bs
->breakpoint_at
;
5727 b
->ops
->check_status (bs
);
5730 bpstat_check_breakpoint_conditions (bs
, ptid
);
5735 observer_notify_breakpoint_modified (b
);
5737 /* We will stop here. */
5738 if (b
->disposition
== disp_disable
)
5740 --(b
->enable_count
);
5741 if (b
->enable_count
<= 0)
5742 b
->enable_state
= bp_disabled
;
5747 bs
->commands
= b
->commands
;
5748 incref_counted_command_line (bs
->commands
);
5749 if (command_line_is_silent (bs
->commands
5750 ? bs
->commands
->commands
: NULL
))
5753 b
->ops
->after_condition_true (bs
);
5758 /* Print nothing for this entry if we don't stop or don't
5760 if (!bs
->stop
|| !bs
->print
)
5761 bs
->print_it
= print_it_noop
;
5764 /* If we aren't stopping, the value of some hardware watchpoint may
5765 not have changed, but the intermediate memory locations we are
5766 watching may have. Don't bother if we're stopping; this will get
5768 need_remove_insert
= 0;
5769 if (! bpstat_causes_stop (bs_head
))
5770 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5772 && bs
->breakpoint_at
5773 && is_hardware_watchpoint (bs
->breakpoint_at
))
5775 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5777 update_watchpoint (w
, 0 /* don't reparse. */);
5778 need_remove_insert
= 1;
5781 if (need_remove_insert
)
5782 update_global_location_list (UGLL_MAY_INSERT
);
5783 else if (removed_any
)
5784 update_global_location_list (UGLL_DONT_INSERT
);
5790 handle_jit_event (void)
5792 struct frame_info
*frame
;
5793 struct gdbarch
*gdbarch
;
5796 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5798 /* Switch terminal for any messages produced by
5799 breakpoint_re_set. */
5800 target_terminal_ours_for_output ();
5802 frame
= get_current_frame ();
5803 gdbarch
= get_frame_arch (frame
);
5805 jit_event_handler (gdbarch
);
5807 target_terminal_inferior ();
5810 /* Prepare WHAT final decision for infrun. */
5812 /* Decide what infrun needs to do with this bpstat. */
5815 bpstat_what (bpstat bs_head
)
5817 struct bpstat_what retval
;
5821 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5822 retval
.call_dummy
= STOP_NONE
;
5823 retval
.is_longjmp
= 0;
5825 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5827 /* Extract this BS's action. After processing each BS, we check
5828 if its action overrides all we've seem so far. */
5829 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5832 if (bs
->breakpoint_at
== NULL
)
5834 /* I suspect this can happen if it was a momentary
5835 breakpoint which has since been deleted. */
5839 bptype
= bs
->breakpoint_at
->type
;
5846 case bp_hardware_breakpoint
:
5847 case bp_single_step
:
5850 case bp_shlib_event
:
5854 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5856 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5859 this_action
= BPSTAT_WHAT_SINGLE
;
5862 case bp_hardware_watchpoint
:
5863 case bp_read_watchpoint
:
5864 case bp_access_watchpoint
:
5868 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5870 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5874 /* There was a watchpoint, but we're not stopping.
5875 This requires no further action. */
5879 case bp_longjmp_call_dummy
:
5883 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5884 retval
.is_longjmp
= bptype
!= bp_exception
;
5887 this_action
= BPSTAT_WHAT_SINGLE
;
5889 case bp_longjmp_resume
:
5890 case bp_exception_resume
:
5893 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5894 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5897 this_action
= BPSTAT_WHAT_SINGLE
;
5899 case bp_step_resume
:
5901 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5904 /* It is for the wrong frame. */
5905 this_action
= BPSTAT_WHAT_SINGLE
;
5908 case bp_hp_step_resume
:
5910 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5913 /* It is for the wrong frame. */
5914 this_action
= BPSTAT_WHAT_SINGLE
;
5917 case bp_watchpoint_scope
:
5918 case bp_thread_event
:
5919 case bp_overlay_event
:
5920 case bp_longjmp_master
:
5921 case bp_std_terminate_master
:
5922 case bp_exception_master
:
5923 this_action
= BPSTAT_WHAT_SINGLE
;
5929 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5931 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5935 /* There was a catchpoint, but we're not stopping.
5936 This requires no further action. */
5941 this_action
= BPSTAT_WHAT_SINGLE
;
5944 /* Make sure the action is stop (silent or noisy),
5945 so infrun.c pops the dummy frame. */
5946 retval
.call_dummy
= STOP_STACK_DUMMY
;
5947 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5949 case bp_std_terminate
:
5950 /* Make sure the action is stop (silent or noisy),
5951 so infrun.c pops the dummy frame. */
5952 retval
.call_dummy
= STOP_STD_TERMINATE
;
5953 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5956 case bp_fast_tracepoint
:
5957 case bp_static_tracepoint
:
5958 /* Tracepoint hits should not be reported back to GDB, and
5959 if one got through somehow, it should have been filtered
5961 internal_error (__FILE__
, __LINE__
,
5962 _("bpstat_what: tracepoint encountered"));
5964 case bp_gnu_ifunc_resolver
:
5965 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5966 this_action
= BPSTAT_WHAT_SINGLE
;
5968 case bp_gnu_ifunc_resolver_return
:
5969 /* The breakpoint will be removed, execution will restart from the
5970 PC of the former breakpoint. */
5971 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5976 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5978 this_action
= BPSTAT_WHAT_SINGLE
;
5982 internal_error (__FILE__
, __LINE__
,
5983 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5986 retval
.main_action
= max (retval
.main_action
, this_action
);
5993 bpstat_run_callbacks (bpstat bs_head
)
5997 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5999 struct breakpoint
*b
= bs
->breakpoint_at
;
6006 handle_jit_event ();
6008 case bp_gnu_ifunc_resolver
:
6009 gnu_ifunc_resolver_stop (b
);
6011 case bp_gnu_ifunc_resolver_return
:
6012 gnu_ifunc_resolver_return_stop (b
);
6018 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6019 without hardware support). This isn't related to a specific bpstat,
6020 just to things like whether watchpoints are set. */
6023 bpstat_should_step (void)
6025 struct breakpoint
*b
;
6028 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6034 bpstat_causes_stop (bpstat bs
)
6036 for (; bs
!= NULL
; bs
= bs
->next
)
6045 /* Compute a string of spaces suitable to indent the next line
6046 so it starts at the position corresponding to the table column
6047 named COL_NAME in the currently active table of UIOUT. */
6050 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6052 static char wrap_indent
[80];
6053 int i
, total_width
, width
, align
;
6057 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
6059 if (strcmp (text
, col_name
) == 0)
6061 gdb_assert (total_width
< sizeof wrap_indent
);
6062 memset (wrap_indent
, ' ', total_width
);
6063 wrap_indent
[total_width
] = 0;
6068 total_width
+= width
+ 1;
6074 /* Determine if the locations of this breakpoint will have their conditions
6075 evaluated by the target, host or a mix of both. Returns the following:
6077 "host": Host evals condition.
6078 "host or target": Host or Target evals condition.
6079 "target": Target evals condition.
6083 bp_condition_evaluator (struct breakpoint
*b
)
6085 struct bp_location
*bl
;
6086 char host_evals
= 0;
6087 char target_evals
= 0;
6092 if (!is_breakpoint (b
))
6095 if (gdb_evaluates_breakpoint_condition_p ()
6096 || !target_supports_evaluation_of_breakpoint_conditions ())
6097 return condition_evaluation_host
;
6099 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6101 if (bl
->cond_bytecode
)
6107 if (host_evals
&& target_evals
)
6108 return condition_evaluation_both
;
6109 else if (target_evals
)
6110 return condition_evaluation_target
;
6112 return condition_evaluation_host
;
6115 /* Determine the breakpoint location's condition evaluator. This is
6116 similar to bp_condition_evaluator, but for locations. */
6119 bp_location_condition_evaluator (struct bp_location
*bl
)
6121 if (bl
&& !is_breakpoint (bl
->owner
))
6124 if (gdb_evaluates_breakpoint_condition_p ()
6125 || !target_supports_evaluation_of_breakpoint_conditions ())
6126 return condition_evaluation_host
;
6128 if (bl
&& bl
->cond_bytecode
)
6129 return condition_evaluation_target
;
6131 return condition_evaluation_host
;
6134 /* Print the LOC location out of the list of B->LOC locations. */
6137 print_breakpoint_location (struct breakpoint
*b
,
6138 struct bp_location
*loc
)
6140 struct ui_out
*uiout
= current_uiout
;
6141 struct cleanup
*old_chain
= save_current_program_space ();
6143 if (loc
!= NULL
&& loc
->shlib_disabled
)
6147 set_current_program_space (loc
->pspace
);
6149 if (b
->display_canonical
)
6150 ui_out_field_string (uiout
, "what",
6151 event_location_to_string (b
->location
));
6152 else if (loc
&& loc
->symtab
)
6155 = find_pc_sect_function (loc
->address
, loc
->section
);
6158 ui_out_text (uiout
, "in ");
6159 ui_out_field_string (uiout
, "func",
6160 SYMBOL_PRINT_NAME (sym
));
6161 ui_out_text (uiout
, " ");
6162 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6163 ui_out_text (uiout
, "at ");
6165 ui_out_field_string (uiout
, "file",
6166 symtab_to_filename_for_display (loc
->symtab
));
6167 ui_out_text (uiout
, ":");
6169 if (ui_out_is_mi_like_p (uiout
))
6170 ui_out_field_string (uiout
, "fullname",
6171 symtab_to_fullname (loc
->symtab
));
6173 ui_out_field_int (uiout
, "line", loc
->line_number
);
6177 struct ui_file
*stb
= mem_fileopen ();
6178 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6180 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6182 ui_out_field_stream (uiout
, "at", stb
);
6184 do_cleanups (stb_chain
);
6188 ui_out_field_string (uiout
, "pending",
6189 event_location_to_string (b
->location
));
6190 /* If extra_string is available, it could be holding a condition
6191 or dprintf arguments. In either case, make sure it is printed,
6192 too, but only for non-MI streams. */
6193 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6195 if (b
->type
== bp_dprintf
)
6196 ui_out_text (uiout
, ",");
6198 ui_out_text (uiout
, " ");
6199 ui_out_text (uiout
, b
->extra_string
);
6203 if (loc
&& is_breakpoint (b
)
6204 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6205 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6207 ui_out_text (uiout
, " (");
6208 ui_out_field_string (uiout
, "evaluated-by",
6209 bp_location_condition_evaluator (loc
));
6210 ui_out_text (uiout
, ")");
6213 do_cleanups (old_chain
);
6217 bptype_string (enum bptype type
)
6219 struct ep_type_description
6224 static struct ep_type_description bptypes
[] =
6226 {bp_none
, "?deleted?"},
6227 {bp_breakpoint
, "breakpoint"},
6228 {bp_hardware_breakpoint
, "hw breakpoint"},
6229 {bp_single_step
, "sw single-step"},
6230 {bp_until
, "until"},
6231 {bp_finish
, "finish"},
6232 {bp_watchpoint
, "watchpoint"},
6233 {bp_hardware_watchpoint
, "hw watchpoint"},
6234 {bp_read_watchpoint
, "read watchpoint"},
6235 {bp_access_watchpoint
, "acc watchpoint"},
6236 {bp_longjmp
, "longjmp"},
6237 {bp_longjmp_resume
, "longjmp resume"},
6238 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6239 {bp_exception
, "exception"},
6240 {bp_exception_resume
, "exception resume"},
6241 {bp_step_resume
, "step resume"},
6242 {bp_hp_step_resume
, "high-priority step resume"},
6243 {bp_watchpoint_scope
, "watchpoint scope"},
6244 {bp_call_dummy
, "call dummy"},
6245 {bp_std_terminate
, "std::terminate"},
6246 {bp_shlib_event
, "shlib events"},
6247 {bp_thread_event
, "thread events"},
6248 {bp_overlay_event
, "overlay events"},
6249 {bp_longjmp_master
, "longjmp master"},
6250 {bp_std_terminate_master
, "std::terminate master"},
6251 {bp_exception_master
, "exception master"},
6252 {bp_catchpoint
, "catchpoint"},
6253 {bp_tracepoint
, "tracepoint"},
6254 {bp_fast_tracepoint
, "fast tracepoint"},
6255 {bp_static_tracepoint
, "static tracepoint"},
6256 {bp_dprintf
, "dprintf"},
6257 {bp_jit_event
, "jit events"},
6258 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6259 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6262 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6263 || ((int) type
!= bptypes
[(int) type
].type
))
6264 internal_error (__FILE__
, __LINE__
,
6265 _("bptypes table does not describe type #%d."),
6268 return bptypes
[(int) type
].description
;
6271 /* For MI, output a field named 'thread-groups' with a list as the value.
6272 For CLI, prefix the list with the string 'inf'. */
6275 output_thread_groups (struct ui_out
*uiout
,
6276 const char *field_name
,
6280 struct cleanup
*back_to
;
6281 int is_mi
= ui_out_is_mi_like_p (uiout
);
6285 /* For backward compatibility, don't display inferiors in CLI unless
6286 there are several. Always display them for MI. */
6287 if (!is_mi
&& mi_only
)
6290 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6292 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6298 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6299 ui_out_field_string (uiout
, NULL
, mi_group
);
6304 ui_out_text (uiout
, " inf ");
6306 ui_out_text (uiout
, ", ");
6308 ui_out_text (uiout
, plongest (inf
));
6312 do_cleanups (back_to
);
6315 /* Print B to gdb_stdout. */
6318 print_one_breakpoint_location (struct breakpoint
*b
,
6319 struct bp_location
*loc
,
6321 struct bp_location
**last_loc
,
6324 struct command_line
*l
;
6325 static char bpenables
[] = "nynny";
6327 struct ui_out
*uiout
= current_uiout
;
6328 int header_of_multiple
= 0;
6329 int part_of_multiple
= (loc
!= NULL
);
6330 struct value_print_options opts
;
6332 get_user_print_options (&opts
);
6334 gdb_assert (!loc
|| loc_number
!= 0);
6335 /* See comment in print_one_breakpoint concerning treatment of
6336 breakpoints with single disabled location. */
6339 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6340 header_of_multiple
= 1;
6348 if (part_of_multiple
)
6351 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6352 ui_out_field_string (uiout
, "number", formatted
);
6357 ui_out_field_int (uiout
, "number", b
->number
);
6362 if (part_of_multiple
)
6363 ui_out_field_skip (uiout
, "type");
6365 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6369 if (part_of_multiple
)
6370 ui_out_field_skip (uiout
, "disp");
6372 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6377 if (part_of_multiple
)
6378 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6380 ui_out_field_fmt (uiout
, "enabled", "%c",
6381 bpenables
[(int) b
->enable_state
]);
6382 ui_out_spaces (uiout
, 2);
6386 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6388 /* Although the print_one can possibly print all locations,
6389 calling it here is not likely to get any nice result. So,
6390 make sure there's just one location. */
6391 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6392 b
->ops
->print_one (b
, last_loc
);
6398 internal_error (__FILE__
, __LINE__
,
6399 _("print_one_breakpoint: bp_none encountered\n"));
6403 case bp_hardware_watchpoint
:
6404 case bp_read_watchpoint
:
6405 case bp_access_watchpoint
:
6407 struct watchpoint
*w
= (struct watchpoint
*) b
;
6409 /* Field 4, the address, is omitted (which makes the columns
6410 not line up too nicely with the headers, but the effect
6411 is relatively readable). */
6412 if (opts
.addressprint
)
6413 ui_out_field_skip (uiout
, "addr");
6415 ui_out_field_string (uiout
, "what", w
->exp_string
);
6420 case bp_hardware_breakpoint
:
6421 case bp_single_step
:
6425 case bp_longjmp_resume
:
6426 case bp_longjmp_call_dummy
:
6428 case bp_exception_resume
:
6429 case bp_step_resume
:
6430 case bp_hp_step_resume
:
6431 case bp_watchpoint_scope
:
6433 case bp_std_terminate
:
6434 case bp_shlib_event
:
6435 case bp_thread_event
:
6436 case bp_overlay_event
:
6437 case bp_longjmp_master
:
6438 case bp_std_terminate_master
:
6439 case bp_exception_master
:
6441 case bp_fast_tracepoint
:
6442 case bp_static_tracepoint
:
6445 case bp_gnu_ifunc_resolver
:
6446 case bp_gnu_ifunc_resolver_return
:
6447 if (opts
.addressprint
)
6450 if (header_of_multiple
)
6451 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6452 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6453 ui_out_field_string (uiout
, "addr", "<PENDING>");
6455 ui_out_field_core_addr (uiout
, "addr",
6456 loc
->gdbarch
, loc
->address
);
6459 if (!header_of_multiple
)
6460 print_breakpoint_location (b
, loc
);
6467 if (loc
!= NULL
&& !header_of_multiple
)
6469 struct inferior
*inf
;
6470 VEC(int) *inf_num
= NULL
;
6475 if (inf
->pspace
== loc
->pspace
)
6476 VEC_safe_push (int, inf_num
, inf
->num
);
6479 /* For backward compatibility, don't display inferiors in CLI unless
6480 there are several. Always display for MI. */
6482 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6483 && (number_of_program_spaces () > 1
6484 || number_of_inferiors () > 1)
6485 /* LOC is for existing B, it cannot be in
6486 moribund_locations and thus having NULL OWNER. */
6487 && loc
->owner
->type
!= bp_catchpoint
))
6489 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6490 VEC_free (int, inf_num
);
6493 if (!part_of_multiple
)
6495 if (b
->thread
!= -1)
6497 /* FIXME: This seems to be redundant and lost here; see the
6498 "stop only in" line a little further down. */
6499 ui_out_text (uiout
, " thread ");
6500 ui_out_field_int (uiout
, "thread", b
->thread
);
6502 else if (b
->task
!= 0)
6504 ui_out_text (uiout
, " task ");
6505 ui_out_field_int (uiout
, "task", b
->task
);
6509 ui_out_text (uiout
, "\n");
6511 if (!part_of_multiple
)
6512 b
->ops
->print_one_detail (b
, uiout
);
6514 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6517 ui_out_text (uiout
, "\tstop only in stack frame at ");
6518 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6520 ui_out_field_core_addr (uiout
, "frame",
6521 b
->gdbarch
, b
->frame_id
.stack_addr
);
6522 ui_out_text (uiout
, "\n");
6525 if (!part_of_multiple
&& b
->cond_string
)
6528 if (is_tracepoint (b
))
6529 ui_out_text (uiout
, "\ttrace only if ");
6531 ui_out_text (uiout
, "\tstop only if ");
6532 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6534 /* Print whether the target is doing the breakpoint's condition
6535 evaluation. If GDB is doing the evaluation, don't print anything. */
6536 if (is_breakpoint (b
)
6537 && breakpoint_condition_evaluation_mode ()
6538 == condition_evaluation_target
)
6540 ui_out_text (uiout
, " (");
6541 ui_out_field_string (uiout
, "evaluated-by",
6542 bp_condition_evaluator (b
));
6543 ui_out_text (uiout
, " evals)");
6545 ui_out_text (uiout
, "\n");
6548 if (!part_of_multiple
&& b
->thread
!= -1)
6550 /* FIXME should make an annotation for this. */
6551 ui_out_text (uiout
, "\tstop only in thread ");
6552 if (ui_out_is_mi_like_p (uiout
))
6553 ui_out_field_int (uiout
, "thread", b
->thread
);
6556 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6558 ui_out_field_string (uiout
, "thread", print_thread_id (thr
));
6560 ui_out_text (uiout
, "\n");
6563 if (!part_of_multiple
)
6567 /* FIXME should make an annotation for this. */
6568 if (is_catchpoint (b
))
6569 ui_out_text (uiout
, "\tcatchpoint");
6570 else if (is_tracepoint (b
))
6571 ui_out_text (uiout
, "\ttracepoint");
6573 ui_out_text (uiout
, "\tbreakpoint");
6574 ui_out_text (uiout
, " already hit ");
6575 ui_out_field_int (uiout
, "times", b
->hit_count
);
6576 if (b
->hit_count
== 1)
6577 ui_out_text (uiout
, " time\n");
6579 ui_out_text (uiout
, " times\n");
6583 /* Output the count also if it is zero, but only if this is mi. */
6584 if (ui_out_is_mi_like_p (uiout
))
6585 ui_out_field_int (uiout
, "times", b
->hit_count
);
6589 if (!part_of_multiple
&& b
->ignore_count
)
6592 ui_out_text (uiout
, "\tignore next ");
6593 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6594 ui_out_text (uiout
, " hits\n");
6597 /* Note that an enable count of 1 corresponds to "enable once"
6598 behavior, which is reported by the combination of enablement and
6599 disposition, so we don't need to mention it here. */
6600 if (!part_of_multiple
&& b
->enable_count
> 1)
6603 ui_out_text (uiout
, "\tdisable after ");
6604 /* Tweak the wording to clarify that ignore and enable counts
6605 are distinct, and have additive effect. */
6606 if (b
->ignore_count
)
6607 ui_out_text (uiout
, "additional ");
6609 ui_out_text (uiout
, "next ");
6610 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6611 ui_out_text (uiout
, " hits\n");
6614 if (!part_of_multiple
&& is_tracepoint (b
))
6616 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6618 if (tp
->traceframe_usage
)
6620 ui_out_text (uiout
, "\ttrace buffer usage ");
6621 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6622 ui_out_text (uiout
, " bytes\n");
6626 l
= b
->commands
? b
->commands
->commands
: NULL
;
6627 if (!part_of_multiple
&& l
)
6629 struct cleanup
*script_chain
;
6632 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6633 print_command_lines (uiout
, l
, 4);
6634 do_cleanups (script_chain
);
6637 if (is_tracepoint (b
))
6639 struct tracepoint
*t
= (struct tracepoint
*) b
;
6641 if (!part_of_multiple
&& t
->pass_count
)
6643 annotate_field (10);
6644 ui_out_text (uiout
, "\tpass count ");
6645 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6646 ui_out_text (uiout
, " \n");
6649 /* Don't display it when tracepoint or tracepoint location is
6651 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6653 annotate_field (11);
6655 if (ui_out_is_mi_like_p (uiout
))
6656 ui_out_field_string (uiout
, "installed",
6657 loc
->inserted
? "y" : "n");
6661 ui_out_text (uiout
, "\t");
6663 ui_out_text (uiout
, "\tnot ");
6664 ui_out_text (uiout
, "installed on target\n");
6669 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6671 if (is_watchpoint (b
))
6673 struct watchpoint
*w
= (struct watchpoint
*) b
;
6675 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6677 else if (b
->location
!= NULL
6678 && event_location_to_string (b
->location
) != NULL
)
6679 ui_out_field_string (uiout
, "original-location",
6680 event_location_to_string (b
->location
));
6685 print_one_breakpoint (struct breakpoint
*b
,
6686 struct bp_location
**last_loc
,
6689 struct cleanup
*bkpt_chain
;
6690 struct ui_out
*uiout
= current_uiout
;
6692 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6694 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6695 do_cleanups (bkpt_chain
);
6697 /* If this breakpoint has custom print function,
6698 it's already printed. Otherwise, print individual
6699 locations, if any. */
6700 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6702 /* If breakpoint has a single location that is disabled, we
6703 print it as if it had several locations, since otherwise it's
6704 hard to represent "breakpoint enabled, location disabled"
6707 Note that while hardware watchpoints have several locations
6708 internally, that's not a property exposed to user. */
6710 && !is_hardware_watchpoint (b
)
6711 && (b
->loc
->next
|| !b
->loc
->enabled
))
6713 struct bp_location
*loc
;
6716 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6718 struct cleanup
*inner2
=
6719 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6720 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6721 do_cleanups (inner2
);
6728 breakpoint_address_bits (struct breakpoint
*b
)
6730 int print_address_bits
= 0;
6731 struct bp_location
*loc
;
6733 /* Software watchpoints that aren't watching memory don't have an
6734 address to print. */
6735 if (is_no_memory_software_watchpoint (b
))
6738 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6742 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6743 if (addr_bit
> print_address_bits
)
6744 print_address_bits
= addr_bit
;
6747 return print_address_bits
;
6750 struct captured_breakpoint_query_args
6756 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6758 struct captured_breakpoint_query_args
*args
6759 = (struct captured_breakpoint_query_args
*) data
;
6760 struct breakpoint
*b
;
6761 struct bp_location
*dummy_loc
= NULL
;
6765 if (args
->bnum
== b
->number
)
6767 print_one_breakpoint (b
, &dummy_loc
, 0);
6775 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6776 char **error_message
)
6778 struct captured_breakpoint_query_args args
;
6781 /* For the moment we don't trust print_one_breakpoint() to not throw
6783 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6784 error_message
, RETURN_MASK_ALL
) < 0)
6790 /* Return true if this breakpoint was set by the user, false if it is
6791 internal or momentary. */
6794 user_breakpoint_p (struct breakpoint
*b
)
6796 return b
->number
> 0;
6799 /* Print information on user settable breakpoint (watchpoint, etc)
6800 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6801 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6802 FILTER is non-NULL, call it on each breakpoint and only include the
6803 ones for which it returns non-zero. Return the total number of
6804 breakpoints listed. */
6807 breakpoint_1 (char *args
, int allflag
,
6808 int (*filter
) (const struct breakpoint
*))
6810 struct breakpoint
*b
;
6811 struct bp_location
*last_loc
= NULL
;
6812 int nr_printable_breakpoints
;
6813 struct cleanup
*bkpttbl_chain
;
6814 struct value_print_options opts
;
6815 int print_address_bits
= 0;
6816 int print_type_col_width
= 14;
6817 struct ui_out
*uiout
= current_uiout
;
6819 get_user_print_options (&opts
);
6821 /* Compute the number of rows in the table, as well as the size
6822 required for address fields. */
6823 nr_printable_breakpoints
= 0;
6826 /* If we have a filter, only list the breakpoints it accepts. */
6827 if (filter
&& !filter (b
))
6830 /* If we have an "args" string, it is a list of breakpoints to
6831 accept. Skip the others. */
6832 if (args
!= NULL
&& *args
!= '\0')
6834 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6836 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6840 if (allflag
|| user_breakpoint_p (b
))
6842 int addr_bit
, type_len
;
6844 addr_bit
= breakpoint_address_bits (b
);
6845 if (addr_bit
> print_address_bits
)
6846 print_address_bits
= addr_bit
;
6848 type_len
= strlen (bptype_string (b
->type
));
6849 if (type_len
> print_type_col_width
)
6850 print_type_col_width
= type_len
;
6852 nr_printable_breakpoints
++;
6856 if (opts
.addressprint
)
6858 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6859 nr_printable_breakpoints
,
6863 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6864 nr_printable_breakpoints
,
6867 if (nr_printable_breakpoints
> 0)
6868 annotate_breakpoints_headers ();
6869 if (nr_printable_breakpoints
> 0)
6871 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6872 if (nr_printable_breakpoints
> 0)
6874 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6875 "type", "Type"); /* 2 */
6876 if (nr_printable_breakpoints
> 0)
6878 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6879 if (nr_printable_breakpoints
> 0)
6881 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6882 if (opts
.addressprint
)
6884 if (nr_printable_breakpoints
> 0)
6886 if (print_address_bits
<= 32)
6887 ui_out_table_header (uiout
, 10, ui_left
,
6888 "addr", "Address"); /* 5 */
6890 ui_out_table_header (uiout
, 18, ui_left
,
6891 "addr", "Address"); /* 5 */
6893 if (nr_printable_breakpoints
> 0)
6895 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6896 ui_out_table_body (uiout
);
6897 if (nr_printable_breakpoints
> 0)
6898 annotate_breakpoints_table ();
6903 /* If we have a filter, only list the breakpoints it accepts. */
6904 if (filter
&& !filter (b
))
6907 /* If we have an "args" string, it is a list of breakpoints to
6908 accept. Skip the others. */
6910 if (args
!= NULL
&& *args
!= '\0')
6912 if (allflag
) /* maintenance info breakpoint */
6914 if (parse_and_eval_long (args
) != b
->number
)
6917 else /* all others */
6919 if (!number_is_in_list (args
, b
->number
))
6923 /* We only print out user settable breakpoints unless the
6925 if (allflag
|| user_breakpoint_p (b
))
6926 print_one_breakpoint (b
, &last_loc
, allflag
);
6929 do_cleanups (bkpttbl_chain
);
6931 if (nr_printable_breakpoints
== 0)
6933 /* If there's a filter, let the caller decide how to report
6937 if (args
== NULL
|| *args
== '\0')
6938 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6940 ui_out_message (uiout
, 0,
6941 "No breakpoint or watchpoint matching '%s'.\n",
6947 if (last_loc
&& !server_command
)
6948 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6951 /* FIXME? Should this be moved up so that it is only called when
6952 there have been breakpoints? */
6953 annotate_breakpoints_table_end ();
6955 return nr_printable_breakpoints
;
6958 /* Display the value of default-collect in a way that is generally
6959 compatible with the breakpoint list. */
6962 default_collect_info (void)
6964 struct ui_out
*uiout
= current_uiout
;
6966 /* If it has no value (which is frequently the case), say nothing; a
6967 message like "No default-collect." gets in user's face when it's
6969 if (!*default_collect
)
6972 /* The following phrase lines up nicely with per-tracepoint collect
6974 ui_out_text (uiout
, "default collect ");
6975 ui_out_field_string (uiout
, "default-collect", default_collect
);
6976 ui_out_text (uiout
, " \n");
6980 breakpoints_info (char *args
, int from_tty
)
6982 breakpoint_1 (args
, 0, NULL
);
6984 default_collect_info ();
6988 watchpoints_info (char *args
, int from_tty
)
6990 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6991 struct ui_out
*uiout
= current_uiout
;
6993 if (num_printed
== 0)
6995 if (args
== NULL
|| *args
== '\0')
6996 ui_out_message (uiout
, 0, "No watchpoints.\n");
6998 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
7003 maintenance_info_breakpoints (char *args
, int from_tty
)
7005 breakpoint_1 (args
, 1, NULL
);
7007 default_collect_info ();
7011 breakpoint_has_pc (struct breakpoint
*b
,
7012 struct program_space
*pspace
,
7013 CORE_ADDR pc
, struct obj_section
*section
)
7015 struct bp_location
*bl
= b
->loc
;
7017 for (; bl
; bl
= bl
->next
)
7019 if (bl
->pspace
== pspace
7020 && bl
->address
== pc
7021 && (!overlay_debugging
|| bl
->section
== section
))
7027 /* Print a message describing any user-breakpoints set at PC. This
7028 concerns with logical breakpoints, so we match program spaces, not
7032 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7033 struct program_space
*pspace
, CORE_ADDR pc
,
7034 struct obj_section
*section
, int thread
)
7037 struct breakpoint
*b
;
7040 others
+= (user_breakpoint_p (b
)
7041 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7045 printf_filtered (_("Note: breakpoint "));
7046 else /* if (others == ???) */
7047 printf_filtered (_("Note: breakpoints "));
7049 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7052 printf_filtered ("%d", b
->number
);
7053 if (b
->thread
== -1 && thread
!= -1)
7054 printf_filtered (" (all threads)");
7055 else if (b
->thread
!= -1)
7056 printf_filtered (" (thread %d)", b
->thread
);
7057 printf_filtered ("%s%s ",
7058 ((b
->enable_state
== bp_disabled
7059 || b
->enable_state
== bp_call_disabled
)
7063 : ((others
== 1) ? " and" : ""));
7065 printf_filtered (_("also set at pc "));
7066 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7067 printf_filtered (".\n");
7072 /* Return true iff it is meaningful to use the address member of
7073 BPT locations. For some breakpoint types, the locations' address members
7074 are irrelevant and it makes no sense to attempt to compare them to other
7075 addresses (or use them for any other purpose either).
7077 More specifically, each of the following breakpoint types will
7078 always have a zero valued location address and we don't want to mark
7079 breakpoints of any of these types to be a duplicate of an actual
7080 breakpoint location at address zero:
7088 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7090 enum bptype type
= bpt
->type
;
7092 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7095 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7096 true if LOC1 and LOC2 represent the same watchpoint location. */
7099 watchpoint_locations_match (struct bp_location
*loc1
,
7100 struct bp_location
*loc2
)
7102 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7103 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7105 /* Both of them must exist. */
7106 gdb_assert (w1
!= NULL
);
7107 gdb_assert (w2
!= NULL
);
7109 /* If the target can evaluate the condition expression in hardware,
7110 then we we need to insert both watchpoints even if they are at
7111 the same place. Otherwise the watchpoint will only trigger when
7112 the condition of whichever watchpoint was inserted evaluates to
7113 true, not giving a chance for GDB to check the condition of the
7114 other watchpoint. */
7116 && target_can_accel_watchpoint_condition (loc1
->address
,
7118 loc1
->watchpoint_type
,
7121 && target_can_accel_watchpoint_condition (loc2
->address
,
7123 loc2
->watchpoint_type
,
7127 /* Note that this checks the owner's type, not the location's. In
7128 case the target does not support read watchpoints, but does
7129 support access watchpoints, we'll have bp_read_watchpoint
7130 watchpoints with hw_access locations. Those should be considered
7131 duplicates of hw_read locations. The hw_read locations will
7132 become hw_access locations later. */
7133 return (loc1
->owner
->type
== loc2
->owner
->type
7134 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7135 && loc1
->address
== loc2
->address
7136 && loc1
->length
== loc2
->length
);
7139 /* See breakpoint.h. */
7142 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7143 struct address_space
*aspace2
, CORE_ADDR addr2
)
7145 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7146 || aspace1
== aspace2
)
7150 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7151 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7152 matches ASPACE2. On targets that have global breakpoints, the address
7153 space doesn't really matter. */
7156 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7157 int len1
, struct address_space
*aspace2
,
7160 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7161 || aspace1
== aspace2
)
7162 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7165 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7166 a ranged breakpoint. In most targets, a match happens only if ASPACE
7167 matches the breakpoint's address space. On targets that have global
7168 breakpoints, the address space doesn't really matter. */
7171 breakpoint_location_address_match (struct bp_location
*bl
,
7172 struct address_space
*aspace
,
7175 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7178 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7179 bl
->address
, bl
->length
,
7183 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7184 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7185 match happens only if ASPACE matches the breakpoint's address
7186 space. On targets that have global breakpoints, the address space
7187 doesn't really matter. */
7190 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7191 struct address_space
*aspace
,
7192 CORE_ADDR addr
, int len
)
7194 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7195 || bl
->pspace
->aspace
== aspace
)
7197 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7199 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7205 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7206 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7207 true, otherwise returns false. */
7210 tracepoint_locations_match (struct bp_location
*loc1
,
7211 struct bp_location
*loc2
)
7213 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7214 /* Since tracepoint locations are never duplicated with others', tracepoint
7215 locations at the same address of different tracepoints are regarded as
7216 different locations. */
7217 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7222 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7223 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7224 represent the same location. */
7227 breakpoint_locations_match (struct bp_location
*loc1
,
7228 struct bp_location
*loc2
)
7230 int hw_point1
, hw_point2
;
7232 /* Both of them must not be in moribund_locations. */
7233 gdb_assert (loc1
->owner
!= NULL
);
7234 gdb_assert (loc2
->owner
!= NULL
);
7236 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7237 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7239 if (hw_point1
!= hw_point2
)
7242 return watchpoint_locations_match (loc1
, loc2
);
7243 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7244 return tracepoint_locations_match (loc1
, loc2
);
7246 /* We compare bp_location.length in order to cover ranged breakpoints. */
7247 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7248 loc2
->pspace
->aspace
, loc2
->address
)
7249 && loc1
->length
== loc2
->length
);
7253 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7254 int bnum
, int have_bnum
)
7256 /* The longest string possibly returned by hex_string_custom
7257 is 50 chars. These must be at least that big for safety. */
7261 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7262 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7264 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7265 bnum
, astr1
, astr2
);
7267 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7270 /* Adjust a breakpoint's address to account for architectural
7271 constraints on breakpoint placement. Return the adjusted address.
7272 Note: Very few targets require this kind of adjustment. For most
7273 targets, this function is simply the identity function. */
7276 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7277 CORE_ADDR bpaddr
, enum bptype bptype
)
7279 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7281 /* Very few targets need any kind of breakpoint adjustment. */
7284 else if (bptype
== bp_watchpoint
7285 || bptype
== bp_hardware_watchpoint
7286 || bptype
== bp_read_watchpoint
7287 || bptype
== bp_access_watchpoint
7288 || bptype
== bp_catchpoint
)
7290 /* Watchpoints and the various bp_catch_* eventpoints should not
7291 have their addresses modified. */
7294 else if (bptype
== bp_single_step
)
7296 /* Single-step breakpoints should not have their addresses
7297 modified. If there's any architectural constrain that
7298 applies to this address, then it should have already been
7299 taken into account when the breakpoint was created in the
7300 first place. If we didn't do this, stepping through e.g.,
7301 Thumb-2 IT blocks would break. */
7306 CORE_ADDR adjusted_bpaddr
;
7308 /* Some targets have architectural constraints on the placement
7309 of breakpoint instructions. Obtain the adjusted address. */
7310 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7312 /* An adjusted breakpoint address can significantly alter
7313 a user's expectations. Print a warning if an adjustment
7315 if (adjusted_bpaddr
!= bpaddr
)
7316 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7318 return adjusted_bpaddr
;
7323 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7324 struct breakpoint
*owner
)
7326 memset (loc
, 0, sizeof (*loc
));
7328 gdb_assert (ops
!= NULL
);
7333 loc
->cond_bytecode
= NULL
;
7334 loc
->shlib_disabled
= 0;
7337 switch (owner
->type
)
7340 case bp_single_step
:
7344 case bp_longjmp_resume
:
7345 case bp_longjmp_call_dummy
:
7347 case bp_exception_resume
:
7348 case bp_step_resume
:
7349 case bp_hp_step_resume
:
7350 case bp_watchpoint_scope
:
7352 case bp_std_terminate
:
7353 case bp_shlib_event
:
7354 case bp_thread_event
:
7355 case bp_overlay_event
:
7357 case bp_longjmp_master
:
7358 case bp_std_terminate_master
:
7359 case bp_exception_master
:
7360 case bp_gnu_ifunc_resolver
:
7361 case bp_gnu_ifunc_resolver_return
:
7363 loc
->loc_type
= bp_loc_software_breakpoint
;
7364 mark_breakpoint_location_modified (loc
);
7366 case bp_hardware_breakpoint
:
7367 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7368 mark_breakpoint_location_modified (loc
);
7370 case bp_hardware_watchpoint
:
7371 case bp_read_watchpoint
:
7372 case bp_access_watchpoint
:
7373 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7378 case bp_fast_tracepoint
:
7379 case bp_static_tracepoint
:
7380 loc
->loc_type
= bp_loc_other
;
7383 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7389 /* Allocate a struct bp_location. */
7391 static struct bp_location
*
7392 allocate_bp_location (struct breakpoint
*bpt
)
7394 return bpt
->ops
->allocate_location (bpt
);
7398 free_bp_location (struct bp_location
*loc
)
7400 loc
->ops
->dtor (loc
);
7404 /* Increment reference count. */
7407 incref_bp_location (struct bp_location
*bl
)
7412 /* Decrement reference count. If the reference count reaches 0,
7413 destroy the bp_location. Sets *BLP to NULL. */
7416 decref_bp_location (struct bp_location
**blp
)
7418 gdb_assert ((*blp
)->refc
> 0);
7420 if (--(*blp
)->refc
== 0)
7421 free_bp_location (*blp
);
7425 /* Add breakpoint B at the end of the global breakpoint chain. */
7428 add_to_breakpoint_chain (struct breakpoint
*b
)
7430 struct breakpoint
*b1
;
7432 /* Add this breakpoint to the end of the chain so that a list of
7433 breakpoints will come out in order of increasing numbers. */
7435 b1
= breakpoint_chain
;
7437 breakpoint_chain
= b
;
7446 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7449 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7450 struct gdbarch
*gdbarch
,
7452 const struct breakpoint_ops
*ops
)
7454 memset (b
, 0, sizeof (*b
));
7456 gdb_assert (ops
!= NULL
);
7460 b
->gdbarch
= gdbarch
;
7461 b
->language
= current_language
->la_language
;
7462 b
->input_radix
= input_radix
;
7464 b
->enable_state
= bp_enabled
;
7467 b
->ignore_count
= 0;
7469 b
->frame_id
= null_frame_id
;
7470 b
->condition_not_parsed
= 0;
7471 b
->py_bp_object
= NULL
;
7472 b
->related_breakpoint
= b
;
7476 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7477 that has type BPTYPE and has no locations as yet. */
7479 static struct breakpoint
*
7480 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7482 const struct breakpoint_ops
*ops
)
7484 struct breakpoint
*b
= XNEW (struct breakpoint
);
7486 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7487 add_to_breakpoint_chain (b
);
7491 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7492 resolutions should be made as the user specified the location explicitly
7496 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7498 gdb_assert (loc
->owner
!= NULL
);
7500 if (loc
->owner
->type
== bp_breakpoint
7501 || loc
->owner
->type
== bp_hardware_breakpoint
7502 || is_tracepoint (loc
->owner
))
7505 const char *function_name
;
7506 CORE_ADDR func_addr
;
7508 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7509 &func_addr
, NULL
, &is_gnu_ifunc
);
7511 if (is_gnu_ifunc
&& !explicit_loc
)
7513 struct breakpoint
*b
= loc
->owner
;
7515 gdb_assert (loc
->pspace
== current_program_space
);
7516 if (gnu_ifunc_resolve_name (function_name
,
7517 &loc
->requested_address
))
7519 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7520 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7521 loc
->requested_address
,
7524 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7525 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7527 /* Create only the whole new breakpoint of this type but do not
7528 mess more complicated breakpoints with multiple locations. */
7529 b
->type
= bp_gnu_ifunc_resolver
;
7530 /* Remember the resolver's address for use by the return
7532 loc
->related_address
= func_addr
;
7537 loc
->function_name
= xstrdup (function_name
);
7541 /* Attempt to determine architecture of location identified by SAL. */
7543 get_sal_arch (struct symtab_and_line sal
)
7546 return get_objfile_arch (sal
.section
->objfile
);
7548 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7553 /* Low level routine for partially initializing a breakpoint of type
7554 BPTYPE. The newly created breakpoint's address, section, source
7555 file name, and line number are provided by SAL.
7557 It is expected that the caller will complete the initialization of
7558 the newly created breakpoint struct as well as output any status
7559 information regarding the creation of a new breakpoint. */
7562 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7563 struct symtab_and_line sal
, enum bptype bptype
,
7564 const struct breakpoint_ops
*ops
)
7566 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7568 add_location_to_breakpoint (b
, &sal
);
7570 if (bptype
!= bp_catchpoint
)
7571 gdb_assert (sal
.pspace
!= NULL
);
7573 /* Store the program space that was used to set the breakpoint,
7574 except for ordinary breakpoints, which are independent of the
7576 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7577 b
->pspace
= sal
.pspace
;
7580 /* set_raw_breakpoint is a low level routine for allocating and
7581 partially initializing a breakpoint of type BPTYPE. The newly
7582 created breakpoint's address, section, source file name, and line
7583 number are provided by SAL. The newly created and partially
7584 initialized breakpoint is added to the breakpoint chain and
7585 is also returned as the value of this function.
7587 It is expected that the caller will complete the initialization of
7588 the newly created breakpoint struct as well as output any status
7589 information regarding the creation of a new breakpoint. In
7590 particular, set_raw_breakpoint does NOT set the breakpoint
7591 number! Care should be taken to not allow an error to occur
7592 prior to completing the initialization of the breakpoint. If this
7593 should happen, a bogus breakpoint will be left on the chain. */
7596 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7597 struct symtab_and_line sal
, enum bptype bptype
,
7598 const struct breakpoint_ops
*ops
)
7600 struct breakpoint
*b
= XNEW (struct breakpoint
);
7602 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7603 add_to_breakpoint_chain (b
);
7607 /* Call this routine when stepping and nexting to enable a breakpoint
7608 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7609 initiated the operation. */
7612 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7614 struct breakpoint
*b
, *b_tmp
;
7615 int thread
= tp
->global_num
;
7617 /* To avoid having to rescan all objfile symbols at every step,
7618 we maintain a list of continually-inserted but always disabled
7619 longjmp "master" breakpoints. Here, we simply create momentary
7620 clones of those and enable them for the requested thread. */
7621 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7622 if (b
->pspace
== current_program_space
7623 && (b
->type
== bp_longjmp_master
7624 || b
->type
== bp_exception_master
))
7626 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7627 struct breakpoint
*clone
;
7629 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7630 after their removal. */
7631 clone
= momentary_breakpoint_from_master (b
, type
,
7632 &longjmp_breakpoint_ops
, 1);
7633 clone
->thread
= thread
;
7636 tp
->initiating_frame
= frame
;
7639 /* Delete all longjmp breakpoints from THREAD. */
7641 delete_longjmp_breakpoint (int thread
)
7643 struct breakpoint
*b
, *b_tmp
;
7645 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7646 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7648 if (b
->thread
== thread
)
7649 delete_breakpoint (b
);
7654 delete_longjmp_breakpoint_at_next_stop (int thread
)
7656 struct breakpoint
*b
, *b_tmp
;
7658 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7659 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7661 if (b
->thread
== thread
)
7662 b
->disposition
= disp_del_at_next_stop
;
7666 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7667 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7668 pointer to any of them. Return NULL if this system cannot place longjmp
7672 set_longjmp_breakpoint_for_call_dummy (void)
7674 struct breakpoint
*b
, *retval
= NULL
;
7677 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7679 struct breakpoint
*new_b
;
7681 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7682 &momentary_breakpoint_ops
,
7684 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7686 /* Link NEW_B into the chain of RETVAL breakpoints. */
7688 gdb_assert (new_b
->related_breakpoint
== new_b
);
7691 new_b
->related_breakpoint
= retval
;
7692 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7693 retval
= retval
->related_breakpoint
;
7694 retval
->related_breakpoint
= new_b
;
7700 /* Verify all existing dummy frames and their associated breakpoints for
7701 TP. Remove those which can no longer be found in the current frame
7704 You should call this function only at places where it is safe to currently
7705 unwind the whole stack. Failed stack unwind would discard live dummy
7709 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7711 struct breakpoint
*b
, *b_tmp
;
7713 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7714 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7716 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7718 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7719 dummy_b
= dummy_b
->related_breakpoint
;
7720 if (dummy_b
->type
!= bp_call_dummy
7721 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7724 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7726 while (b
->related_breakpoint
!= b
)
7728 if (b_tmp
== b
->related_breakpoint
)
7729 b_tmp
= b
->related_breakpoint
->next
;
7730 delete_breakpoint (b
->related_breakpoint
);
7732 delete_breakpoint (b
);
7737 enable_overlay_breakpoints (void)
7739 struct breakpoint
*b
;
7742 if (b
->type
== bp_overlay_event
)
7744 b
->enable_state
= bp_enabled
;
7745 update_global_location_list (UGLL_MAY_INSERT
);
7746 overlay_events_enabled
= 1;
7751 disable_overlay_breakpoints (void)
7753 struct breakpoint
*b
;
7756 if (b
->type
== bp_overlay_event
)
7758 b
->enable_state
= bp_disabled
;
7759 update_global_location_list (UGLL_DONT_INSERT
);
7760 overlay_events_enabled
= 0;
7764 /* Set an active std::terminate breakpoint for each std::terminate
7765 master breakpoint. */
7767 set_std_terminate_breakpoint (void)
7769 struct breakpoint
*b
, *b_tmp
;
7771 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7772 if (b
->pspace
== current_program_space
7773 && b
->type
== bp_std_terminate_master
)
7775 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7776 &momentary_breakpoint_ops
, 1);
7780 /* Delete all the std::terminate breakpoints. */
7782 delete_std_terminate_breakpoint (void)
7784 struct breakpoint
*b
, *b_tmp
;
7786 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7787 if (b
->type
== bp_std_terminate
)
7788 delete_breakpoint (b
);
7792 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7794 struct breakpoint
*b
;
7796 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7797 &internal_breakpoint_ops
);
7799 b
->enable_state
= bp_enabled
;
7800 /* location has to be used or breakpoint_re_set will delete me. */
7801 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7803 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7808 struct lang_and_radix
7814 /* Create a breakpoint for JIT code registration and unregistration. */
7817 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7819 struct breakpoint
*b
;
7821 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7822 &internal_breakpoint_ops
);
7823 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7827 /* Remove JIT code registration and unregistration breakpoint(s). */
7830 remove_jit_event_breakpoints (void)
7832 struct breakpoint
*b
, *b_tmp
;
7834 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7835 if (b
->type
== bp_jit_event
7836 && b
->loc
->pspace
== current_program_space
)
7837 delete_breakpoint (b
);
7841 remove_solib_event_breakpoints (void)
7843 struct breakpoint
*b
, *b_tmp
;
7845 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7846 if (b
->type
== bp_shlib_event
7847 && b
->loc
->pspace
== current_program_space
)
7848 delete_breakpoint (b
);
7851 /* See breakpoint.h. */
7854 remove_solib_event_breakpoints_at_next_stop (void)
7856 struct breakpoint
*b
, *b_tmp
;
7858 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7859 if (b
->type
== bp_shlib_event
7860 && b
->loc
->pspace
== current_program_space
)
7861 b
->disposition
= disp_del_at_next_stop
;
7864 /* Helper for create_solib_event_breakpoint /
7865 create_and_insert_solib_event_breakpoint. Allows specifying which
7866 INSERT_MODE to pass through to update_global_location_list. */
7868 static struct breakpoint
*
7869 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7870 enum ugll_insert_mode insert_mode
)
7872 struct breakpoint
*b
;
7874 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7875 &internal_breakpoint_ops
);
7876 update_global_location_list_nothrow (insert_mode
);
7881 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7883 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7886 /* See breakpoint.h. */
7889 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7891 struct breakpoint
*b
;
7893 /* Explicitly tell update_global_location_list to insert
7895 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7896 if (!b
->loc
->inserted
)
7898 delete_breakpoint (b
);
7904 /* Disable any breakpoints that are on code in shared libraries. Only
7905 apply to enabled breakpoints, disabled ones can just stay disabled. */
7908 disable_breakpoints_in_shlibs (void)
7910 struct bp_location
*loc
, **locp_tmp
;
7912 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7914 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7915 struct breakpoint
*b
= loc
->owner
;
7917 /* We apply the check to all breakpoints, including disabled for
7918 those with loc->duplicate set. This is so that when breakpoint
7919 becomes enabled, or the duplicate is removed, gdb will try to
7920 insert all breakpoints. If we don't set shlib_disabled here,
7921 we'll try to insert those breakpoints and fail. */
7922 if (((b
->type
== bp_breakpoint
)
7923 || (b
->type
== bp_jit_event
)
7924 || (b
->type
== bp_hardware_breakpoint
)
7925 || (is_tracepoint (b
)))
7926 && loc
->pspace
== current_program_space
7927 && !loc
->shlib_disabled
7928 && solib_name_from_address (loc
->pspace
, loc
->address
)
7931 loc
->shlib_disabled
= 1;
7936 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7937 notification of unloaded_shlib. Only apply to enabled breakpoints,
7938 disabled ones can just stay disabled. */
7941 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7943 struct bp_location
*loc
, **locp_tmp
;
7944 int disabled_shlib_breaks
= 0;
7946 /* SunOS a.out shared libraries are always mapped, so do not
7947 disable breakpoints; they will only be reported as unloaded
7948 through clear_solib when GDB discards its shared library
7949 list. See clear_solib for more information. */
7950 if (exec_bfd
!= NULL
7951 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7954 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7956 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7957 struct breakpoint
*b
= loc
->owner
;
7959 if (solib
->pspace
== loc
->pspace
7960 && !loc
->shlib_disabled
7961 && (((b
->type
== bp_breakpoint
7962 || b
->type
== bp_jit_event
7963 || b
->type
== bp_hardware_breakpoint
)
7964 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7965 || loc
->loc_type
== bp_loc_software_breakpoint
))
7966 || is_tracepoint (b
))
7967 && solib_contains_address_p (solib
, loc
->address
))
7969 loc
->shlib_disabled
= 1;
7970 /* At this point, we cannot rely on remove_breakpoint
7971 succeeding so we must mark the breakpoint as not inserted
7972 to prevent future errors occurring in remove_breakpoints. */
7975 /* This may cause duplicate notifications for the same breakpoint. */
7976 observer_notify_breakpoint_modified (b
);
7978 if (!disabled_shlib_breaks
)
7980 target_terminal_ours_for_output ();
7981 warning (_("Temporarily disabling breakpoints "
7982 "for unloaded shared library \"%s\""),
7985 disabled_shlib_breaks
= 1;
7990 /* Disable any breakpoints and tracepoints in OBJFILE upon
7991 notification of free_objfile. Only apply to enabled breakpoints,
7992 disabled ones can just stay disabled. */
7995 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7997 struct breakpoint
*b
;
7999 if (objfile
== NULL
)
8002 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8003 managed by the user with add-symbol-file/remove-symbol-file.
8004 Similarly to how breakpoints in shared libraries are handled in
8005 response to "nosharedlibrary", mark breakpoints in such modules
8006 shlib_disabled so they end up uninserted on the next global
8007 location list update. Shared libraries not loaded by the user
8008 aren't handled here -- they're already handled in
8009 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8010 solib_unloaded observer. We skip objfiles that are not
8011 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8013 if ((objfile
->flags
& OBJF_SHARED
) == 0
8014 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8019 struct bp_location
*loc
;
8020 int bp_modified
= 0;
8022 if (!is_breakpoint (b
) && !is_tracepoint (b
))
8025 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
8027 CORE_ADDR loc_addr
= loc
->address
;
8029 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8030 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8033 if (loc
->shlib_disabled
!= 0)
8036 if (objfile
->pspace
!= loc
->pspace
)
8039 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8040 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8043 if (is_addr_in_objfile (loc_addr
, objfile
))
8045 loc
->shlib_disabled
= 1;
8046 /* At this point, we don't know whether the object was
8047 unmapped from the inferior or not, so leave the
8048 inserted flag alone. We'll handle failure to
8049 uninsert quietly, in case the object was indeed
8052 mark_breakpoint_location_modified (loc
);
8059 observer_notify_breakpoint_modified (b
);
8063 /* FORK & VFORK catchpoints. */
8065 /* An instance of this type is used to represent a fork or vfork
8066 catchpoint. It includes a "struct breakpoint" as a kind of base
8067 class; users downcast to "struct breakpoint *" when needed. A
8068 breakpoint is really of this type iff its ops pointer points to
8069 CATCH_FORK_BREAKPOINT_OPS. */
8071 struct fork_catchpoint
8073 /* The base class. */
8074 struct breakpoint base
;
8076 /* Process id of a child process whose forking triggered this
8077 catchpoint. This field is only valid immediately after this
8078 catchpoint has triggered. */
8079 ptid_t forked_inferior_pid
;
8082 /* Implement the "insert" breakpoint_ops method for fork
8086 insert_catch_fork (struct bp_location
*bl
)
8088 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8091 /* Implement the "remove" breakpoint_ops method for fork
8095 remove_catch_fork (struct bp_location
*bl
)
8097 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8100 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8104 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8105 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8106 const struct target_waitstatus
*ws
)
8108 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8110 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8113 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8117 /* Implement the "print_it" breakpoint_ops method for fork
8120 static enum print_stop_action
8121 print_it_catch_fork (bpstat bs
)
8123 struct ui_out
*uiout
= current_uiout
;
8124 struct breakpoint
*b
= bs
->breakpoint_at
;
8125 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8127 annotate_catchpoint (b
->number
);
8128 maybe_print_thread_hit_breakpoint (uiout
);
8129 if (b
->disposition
== disp_del
)
8130 ui_out_text (uiout
, "Temporary catchpoint ");
8132 ui_out_text (uiout
, "Catchpoint ");
8133 if (ui_out_is_mi_like_p (uiout
))
8135 ui_out_field_string (uiout
, "reason",
8136 async_reason_lookup (EXEC_ASYNC_FORK
));
8137 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8139 ui_out_field_int (uiout
, "bkptno", b
->number
);
8140 ui_out_text (uiout
, " (forked process ");
8141 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8142 ui_out_text (uiout
, "), ");
8143 return PRINT_SRC_AND_LOC
;
8146 /* Implement the "print_one" breakpoint_ops method for fork
8150 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8152 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8153 struct value_print_options opts
;
8154 struct ui_out
*uiout
= current_uiout
;
8156 get_user_print_options (&opts
);
8158 /* Field 4, the address, is omitted (which makes the columns not
8159 line up too nicely with the headers, but the effect is relatively
8161 if (opts
.addressprint
)
8162 ui_out_field_skip (uiout
, "addr");
8164 ui_out_text (uiout
, "fork");
8165 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8167 ui_out_text (uiout
, ", process ");
8168 ui_out_field_int (uiout
, "what",
8169 ptid_get_pid (c
->forked_inferior_pid
));
8170 ui_out_spaces (uiout
, 1);
8173 if (ui_out_is_mi_like_p (uiout
))
8174 ui_out_field_string (uiout
, "catch-type", "fork");
8177 /* Implement the "print_mention" breakpoint_ops method for fork
8181 print_mention_catch_fork (struct breakpoint
*b
)
8183 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8186 /* Implement the "print_recreate" breakpoint_ops method for fork
8190 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8192 fprintf_unfiltered (fp
, "catch fork");
8193 print_recreate_thread (b
, fp
);
8196 /* The breakpoint_ops structure to be used in fork catchpoints. */
8198 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8200 /* Implement the "insert" breakpoint_ops method for vfork
8204 insert_catch_vfork (struct bp_location
*bl
)
8206 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8209 /* Implement the "remove" breakpoint_ops method for vfork
8213 remove_catch_vfork (struct bp_location
*bl
)
8215 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8218 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8222 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8223 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8224 const struct target_waitstatus
*ws
)
8226 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8228 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8231 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8235 /* Implement the "print_it" breakpoint_ops method for vfork
8238 static enum print_stop_action
8239 print_it_catch_vfork (bpstat bs
)
8241 struct ui_out
*uiout
= current_uiout
;
8242 struct breakpoint
*b
= bs
->breakpoint_at
;
8243 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8245 annotate_catchpoint (b
->number
);
8246 maybe_print_thread_hit_breakpoint (uiout
);
8247 if (b
->disposition
== disp_del
)
8248 ui_out_text (uiout
, "Temporary catchpoint ");
8250 ui_out_text (uiout
, "Catchpoint ");
8251 if (ui_out_is_mi_like_p (uiout
))
8253 ui_out_field_string (uiout
, "reason",
8254 async_reason_lookup (EXEC_ASYNC_VFORK
));
8255 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8257 ui_out_field_int (uiout
, "bkptno", b
->number
);
8258 ui_out_text (uiout
, " (vforked process ");
8259 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8260 ui_out_text (uiout
, "), ");
8261 return PRINT_SRC_AND_LOC
;
8264 /* Implement the "print_one" breakpoint_ops method for vfork
8268 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8270 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8271 struct value_print_options opts
;
8272 struct ui_out
*uiout
= current_uiout
;
8274 get_user_print_options (&opts
);
8275 /* Field 4, the address, is omitted (which makes the columns not
8276 line up too nicely with the headers, but the effect is relatively
8278 if (opts
.addressprint
)
8279 ui_out_field_skip (uiout
, "addr");
8281 ui_out_text (uiout
, "vfork");
8282 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8284 ui_out_text (uiout
, ", process ");
8285 ui_out_field_int (uiout
, "what",
8286 ptid_get_pid (c
->forked_inferior_pid
));
8287 ui_out_spaces (uiout
, 1);
8290 if (ui_out_is_mi_like_p (uiout
))
8291 ui_out_field_string (uiout
, "catch-type", "vfork");
8294 /* Implement the "print_mention" breakpoint_ops method for vfork
8298 print_mention_catch_vfork (struct breakpoint
*b
)
8300 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8303 /* Implement the "print_recreate" breakpoint_ops method for vfork
8307 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8309 fprintf_unfiltered (fp
, "catch vfork");
8310 print_recreate_thread (b
, fp
);
8313 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8315 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8317 /* An instance of this type is used to represent an solib catchpoint.
8318 It includes a "struct breakpoint" as a kind of base class; users
8319 downcast to "struct breakpoint *" when needed. A breakpoint is
8320 really of this type iff its ops pointer points to
8321 CATCH_SOLIB_BREAKPOINT_OPS. */
8323 struct solib_catchpoint
8325 /* The base class. */
8326 struct breakpoint base
;
8328 /* True for "catch load", false for "catch unload". */
8329 unsigned char is_load
;
8331 /* Regular expression to match, if any. COMPILED is only valid when
8332 REGEX is non-NULL. */
8338 dtor_catch_solib (struct breakpoint
*b
)
8340 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8343 regfree (&self
->compiled
);
8344 xfree (self
->regex
);
8346 base_breakpoint_ops
.dtor (b
);
8350 insert_catch_solib (struct bp_location
*ignore
)
8356 remove_catch_solib (struct bp_location
*ignore
)
8362 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8363 struct address_space
*aspace
,
8365 const struct target_waitstatus
*ws
)
8367 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8368 struct breakpoint
*other
;
8370 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8373 ALL_BREAKPOINTS (other
)
8375 struct bp_location
*other_bl
;
8377 if (other
== bl
->owner
)
8380 if (other
->type
!= bp_shlib_event
)
8383 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8386 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8388 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8397 check_status_catch_solib (struct bpstats
*bs
)
8399 struct solib_catchpoint
*self
8400 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8405 struct so_list
*iter
;
8408 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8413 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8422 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8427 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8433 bs
->print_it
= print_it_noop
;
8436 static enum print_stop_action
8437 print_it_catch_solib (bpstat bs
)
8439 struct breakpoint
*b
= bs
->breakpoint_at
;
8440 struct ui_out
*uiout
= current_uiout
;
8442 annotate_catchpoint (b
->number
);
8443 maybe_print_thread_hit_breakpoint (uiout
);
8444 if (b
->disposition
== disp_del
)
8445 ui_out_text (uiout
, "Temporary catchpoint ");
8447 ui_out_text (uiout
, "Catchpoint ");
8448 ui_out_field_int (uiout
, "bkptno", b
->number
);
8449 ui_out_text (uiout
, "\n");
8450 if (ui_out_is_mi_like_p (uiout
))
8451 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8452 print_solib_event (1);
8453 return PRINT_SRC_AND_LOC
;
8457 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8459 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8460 struct value_print_options opts
;
8461 struct ui_out
*uiout
= current_uiout
;
8464 get_user_print_options (&opts
);
8465 /* Field 4, the address, is omitted (which makes the columns not
8466 line up too nicely with the headers, but the effect is relatively
8468 if (opts
.addressprint
)
8471 ui_out_field_skip (uiout
, "addr");
8478 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8480 msg
= xstrdup (_("load of library"));
8485 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8487 msg
= xstrdup (_("unload of library"));
8489 ui_out_field_string (uiout
, "what", msg
);
8492 if (ui_out_is_mi_like_p (uiout
))
8493 ui_out_field_string (uiout
, "catch-type",
8494 self
->is_load
? "load" : "unload");
8498 print_mention_catch_solib (struct breakpoint
*b
)
8500 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8502 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8503 self
->is_load
? "load" : "unload");
8507 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8509 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8511 fprintf_unfiltered (fp
, "%s %s",
8512 b
->disposition
== disp_del
? "tcatch" : "catch",
8513 self
->is_load
? "load" : "unload");
8515 fprintf_unfiltered (fp
, " %s", self
->regex
);
8516 fprintf_unfiltered (fp
, "\n");
8519 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8521 /* Shared helper function (MI and CLI) for creating and installing
8522 a shared object event catchpoint. If IS_LOAD is non-zero then
8523 the events to be caught are load events, otherwise they are
8524 unload events. If IS_TEMP is non-zero the catchpoint is a
8525 temporary one. If ENABLED is non-zero the catchpoint is
8526 created in an enabled state. */
8529 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8531 struct solib_catchpoint
*c
;
8532 struct gdbarch
*gdbarch
= get_current_arch ();
8533 struct cleanup
*cleanup
;
8537 arg
= skip_spaces (arg
);
8539 c
= XCNEW (struct solib_catchpoint
);
8540 cleanup
= make_cleanup (xfree
, c
);
8546 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8549 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8551 make_cleanup (xfree
, err
);
8552 error (_("Invalid regexp (%s): %s"), err
, arg
);
8554 c
->regex
= xstrdup (arg
);
8557 c
->is_load
= is_load
;
8558 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8559 &catch_solib_breakpoint_ops
);
8561 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8563 discard_cleanups (cleanup
);
8564 install_breakpoint (0, &c
->base
, 1);
8567 /* A helper function that does all the work for "catch load" and
8571 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8572 struct cmd_list_element
*command
)
8575 const int enabled
= 1;
8577 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8579 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8583 catch_load_command_1 (char *arg
, int from_tty
,
8584 struct cmd_list_element
*command
)
8586 catch_load_or_unload (arg
, from_tty
, 1, command
);
8590 catch_unload_command_1 (char *arg
, int from_tty
,
8591 struct cmd_list_element
*command
)
8593 catch_load_or_unload (arg
, from_tty
, 0, command
);
8596 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8597 is non-zero, then make the breakpoint temporary. If COND_STRING is
8598 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8599 the breakpoint_ops structure associated to the catchpoint. */
8602 init_catchpoint (struct breakpoint
*b
,
8603 struct gdbarch
*gdbarch
, int tempflag
,
8605 const struct breakpoint_ops
*ops
)
8607 struct symtab_and_line sal
;
8610 sal
.pspace
= current_program_space
;
8612 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8614 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8615 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8619 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8621 add_to_breakpoint_chain (b
);
8622 set_breakpoint_number (internal
, b
);
8623 if (is_tracepoint (b
))
8624 set_tracepoint_count (breakpoint_count
);
8627 observer_notify_breakpoint_created (b
);
8630 update_global_location_list (UGLL_MAY_INSERT
);
8634 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8635 int tempflag
, char *cond_string
,
8636 const struct breakpoint_ops
*ops
)
8638 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8640 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8642 c
->forked_inferior_pid
= null_ptid
;
8644 install_breakpoint (0, &c
->base
, 1);
8647 /* Exec catchpoints. */
8649 /* An instance of this type is used to represent an exec catchpoint.
8650 It includes a "struct breakpoint" as a kind of base class; users
8651 downcast to "struct breakpoint *" when needed. A breakpoint is
8652 really of this type iff its ops pointer points to
8653 CATCH_EXEC_BREAKPOINT_OPS. */
8655 struct exec_catchpoint
8657 /* The base class. */
8658 struct breakpoint base
;
8660 /* Filename of a program whose exec triggered this catchpoint.
8661 This field is only valid immediately after this catchpoint has
8663 char *exec_pathname
;
8666 /* Implement the "dtor" breakpoint_ops method for exec
8670 dtor_catch_exec (struct breakpoint
*b
)
8672 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8674 xfree (c
->exec_pathname
);
8676 base_breakpoint_ops
.dtor (b
);
8680 insert_catch_exec (struct bp_location
*bl
)
8682 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8686 remove_catch_exec (struct bp_location
*bl
)
8688 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8692 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8693 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8694 const struct target_waitstatus
*ws
)
8696 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8698 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8701 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8705 static enum print_stop_action
8706 print_it_catch_exec (bpstat bs
)
8708 struct ui_out
*uiout
= current_uiout
;
8709 struct breakpoint
*b
= bs
->breakpoint_at
;
8710 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8712 annotate_catchpoint (b
->number
);
8713 maybe_print_thread_hit_breakpoint (uiout
);
8714 if (b
->disposition
== disp_del
)
8715 ui_out_text (uiout
, "Temporary catchpoint ");
8717 ui_out_text (uiout
, "Catchpoint ");
8718 if (ui_out_is_mi_like_p (uiout
))
8720 ui_out_field_string (uiout
, "reason",
8721 async_reason_lookup (EXEC_ASYNC_EXEC
));
8722 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8724 ui_out_field_int (uiout
, "bkptno", b
->number
);
8725 ui_out_text (uiout
, " (exec'd ");
8726 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8727 ui_out_text (uiout
, "), ");
8729 return PRINT_SRC_AND_LOC
;
8733 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8735 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8736 struct value_print_options opts
;
8737 struct ui_out
*uiout
= current_uiout
;
8739 get_user_print_options (&opts
);
8741 /* Field 4, the address, is omitted (which makes the columns
8742 not line up too nicely with the headers, but the effect
8743 is relatively readable). */
8744 if (opts
.addressprint
)
8745 ui_out_field_skip (uiout
, "addr");
8747 ui_out_text (uiout
, "exec");
8748 if (c
->exec_pathname
!= NULL
)
8750 ui_out_text (uiout
, ", program \"");
8751 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8752 ui_out_text (uiout
, "\" ");
8755 if (ui_out_is_mi_like_p (uiout
))
8756 ui_out_field_string (uiout
, "catch-type", "exec");
8760 print_mention_catch_exec (struct breakpoint
*b
)
8762 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8765 /* Implement the "print_recreate" breakpoint_ops method for exec
8769 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8771 fprintf_unfiltered (fp
, "catch exec");
8772 print_recreate_thread (b
, fp
);
8775 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8778 hw_breakpoint_used_count (void)
8781 struct breakpoint
*b
;
8782 struct bp_location
*bl
;
8786 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8787 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8789 /* Special types of hardware breakpoints may use more than
8791 i
+= b
->ops
->resources_needed (bl
);
8798 /* Returns the resources B would use if it were a hardware
8802 hw_watchpoint_use_count (struct breakpoint
*b
)
8805 struct bp_location
*bl
;
8807 if (!breakpoint_enabled (b
))
8810 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8812 /* Special types of hardware watchpoints may use more than
8814 i
+= b
->ops
->resources_needed (bl
);
8820 /* Returns the sum the used resources of all hardware watchpoints of
8821 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8822 the sum of the used resources of all hardware watchpoints of other
8823 types _not_ TYPE. */
8826 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8827 enum bptype type
, int *other_type_used
)
8830 struct breakpoint
*b
;
8832 *other_type_used
= 0;
8837 if (!breakpoint_enabled (b
))
8840 if (b
->type
== type
)
8841 i
+= hw_watchpoint_use_count (b
);
8842 else if (is_hardware_watchpoint (b
))
8843 *other_type_used
= 1;
8850 disable_watchpoints_before_interactive_call_start (void)
8852 struct breakpoint
*b
;
8856 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8858 b
->enable_state
= bp_call_disabled
;
8859 update_global_location_list (UGLL_DONT_INSERT
);
8865 enable_watchpoints_after_interactive_call_stop (void)
8867 struct breakpoint
*b
;
8871 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8873 b
->enable_state
= bp_enabled
;
8874 update_global_location_list (UGLL_MAY_INSERT
);
8880 disable_breakpoints_before_startup (void)
8882 current_program_space
->executing_startup
= 1;
8883 update_global_location_list (UGLL_DONT_INSERT
);
8887 enable_breakpoints_after_startup (void)
8889 current_program_space
->executing_startup
= 0;
8890 breakpoint_re_set ();
8893 /* Create a new single-step breakpoint for thread THREAD, with no
8896 static struct breakpoint
*
8897 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8899 struct breakpoint
*b
= XNEW (struct breakpoint
);
8901 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8902 &momentary_breakpoint_ops
);
8904 b
->disposition
= disp_donttouch
;
8905 b
->frame_id
= null_frame_id
;
8908 gdb_assert (b
->thread
!= 0);
8910 add_to_breakpoint_chain (b
);
8915 /* Set a momentary breakpoint of type TYPE at address specified by
8916 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8920 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8921 struct frame_id frame_id
, enum bptype type
)
8923 struct breakpoint
*b
;
8925 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8927 gdb_assert (!frame_id_artificial_p (frame_id
));
8929 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8930 b
->enable_state
= bp_enabled
;
8931 b
->disposition
= disp_donttouch
;
8932 b
->frame_id
= frame_id
;
8934 /* If we're debugging a multi-threaded program, then we want
8935 momentary breakpoints to be active in only a single thread of
8937 if (in_thread_list (inferior_ptid
))
8938 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8940 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8945 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8946 The new breakpoint will have type TYPE, use OPS as its
8947 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8949 static struct breakpoint
*
8950 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8952 const struct breakpoint_ops
*ops
,
8955 struct breakpoint
*copy
;
8957 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8958 copy
->loc
= allocate_bp_location (copy
);
8959 set_breakpoint_location_function (copy
->loc
, 1);
8961 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8962 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8963 copy
->loc
->address
= orig
->loc
->address
;
8964 copy
->loc
->section
= orig
->loc
->section
;
8965 copy
->loc
->pspace
= orig
->loc
->pspace
;
8966 copy
->loc
->probe
= orig
->loc
->probe
;
8967 copy
->loc
->line_number
= orig
->loc
->line_number
;
8968 copy
->loc
->symtab
= orig
->loc
->symtab
;
8969 copy
->loc
->enabled
= loc_enabled
;
8970 copy
->frame_id
= orig
->frame_id
;
8971 copy
->thread
= orig
->thread
;
8972 copy
->pspace
= orig
->pspace
;
8974 copy
->enable_state
= bp_enabled
;
8975 copy
->disposition
= disp_donttouch
;
8976 copy
->number
= internal_breakpoint_number
--;
8978 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8982 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8986 clone_momentary_breakpoint (struct breakpoint
*orig
)
8988 /* If there's nothing to clone, then return nothing. */
8992 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8996 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8999 struct symtab_and_line sal
;
9001 sal
= find_pc_line (pc
, 0);
9003 sal
.section
= find_pc_overlay (pc
);
9004 sal
.explicit_pc
= 1;
9006 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9010 /* Tell the user we have just set a breakpoint B. */
9013 mention (struct breakpoint
*b
)
9015 b
->ops
->print_mention (b
);
9016 if (ui_out_is_mi_like_p (current_uiout
))
9018 printf_filtered ("\n");
9022 static int bp_loc_is_permanent (struct bp_location
*loc
);
9024 static struct bp_location
*
9025 add_location_to_breakpoint (struct breakpoint
*b
,
9026 const struct symtab_and_line
*sal
)
9028 struct bp_location
*loc
, **tmp
;
9029 CORE_ADDR adjusted_address
;
9030 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9032 if (loc_gdbarch
== NULL
)
9033 loc_gdbarch
= b
->gdbarch
;
9035 /* Adjust the breakpoint's address prior to allocating a location.
9036 Once we call allocate_bp_location(), that mostly uninitialized
9037 location will be placed on the location chain. Adjustment of the
9038 breakpoint may cause target_read_memory() to be called and we do
9039 not want its scan of the location chain to find a breakpoint and
9040 location that's only been partially initialized. */
9041 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9044 /* Sort the locations by their ADDRESS. */
9045 loc
= allocate_bp_location (b
);
9046 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9047 tmp
= &((*tmp
)->next
))
9052 loc
->requested_address
= sal
->pc
;
9053 loc
->address
= adjusted_address
;
9054 loc
->pspace
= sal
->pspace
;
9055 loc
->probe
.probe
= sal
->probe
;
9056 loc
->probe
.objfile
= sal
->objfile
;
9057 gdb_assert (loc
->pspace
!= NULL
);
9058 loc
->section
= sal
->section
;
9059 loc
->gdbarch
= loc_gdbarch
;
9060 loc
->line_number
= sal
->line
;
9061 loc
->symtab
= sal
->symtab
;
9063 set_breakpoint_location_function (loc
,
9064 sal
->explicit_pc
|| sal
->explicit_line
);
9066 /* While by definition, permanent breakpoints are already present in the
9067 code, we don't mark the location as inserted. Normally one would expect
9068 that GDB could rely on that breakpoint instruction to stop the program,
9069 thus removing the need to insert its own breakpoint, except that executing
9070 the breakpoint instruction can kill the target instead of reporting a
9071 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9072 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9073 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9074 breakpoint be inserted normally results in QEMU knowing about the GDB
9075 breakpoint, and thus trap before the breakpoint instruction is executed.
9076 (If GDB later needs to continue execution past the permanent breakpoint,
9077 it manually increments the PC, thus avoiding executing the breakpoint
9079 if (bp_loc_is_permanent (loc
))
9086 /* See breakpoint.h. */
9089 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9093 const gdb_byte
*bpoint
;
9094 gdb_byte
*target_mem
;
9095 struct cleanup
*cleanup
;
9099 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9101 /* Software breakpoints unsupported? */
9105 target_mem
= (gdb_byte
*) alloca (len
);
9107 /* Enable the automatic memory restoration from breakpoints while
9108 we read the memory. Otherwise we could say about our temporary
9109 breakpoints they are permanent. */
9110 cleanup
= make_show_memory_breakpoints_cleanup (0);
9112 if (target_read_memory (address
, target_mem
, len
) == 0
9113 && memcmp (target_mem
, bpoint
, len
) == 0)
9116 do_cleanups (cleanup
);
9121 /* Return 1 if LOC is pointing to a permanent breakpoint,
9122 return 0 otherwise. */
9125 bp_loc_is_permanent (struct bp_location
*loc
)
9127 struct cleanup
*cleanup
;
9130 gdb_assert (loc
!= NULL
);
9132 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9133 attempt to read from the addresses the locations of these breakpoint types
9134 point to. program_breakpoint_here_p, below, will attempt to read
9136 if (!breakpoint_address_is_meaningful (loc
->owner
))
9139 cleanup
= save_current_space_and_thread ();
9140 switch_to_program_space_and_thread (loc
->pspace
);
9142 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9144 do_cleanups (cleanup
);
9149 /* Build a command list for the dprintf corresponding to the current
9150 settings of the dprintf style options. */
9153 update_dprintf_command_list (struct breakpoint
*b
)
9155 char *dprintf_args
= b
->extra_string
;
9156 char *printf_line
= NULL
;
9161 dprintf_args
= skip_spaces (dprintf_args
);
9163 /* Allow a comma, as it may have terminated a location, but don't
9165 if (*dprintf_args
== ',')
9167 dprintf_args
= skip_spaces (dprintf_args
);
9169 if (*dprintf_args
!= '"')
9170 error (_("Bad format string, missing '\"'."));
9172 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9173 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9174 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9176 if (!dprintf_function
)
9177 error (_("No function supplied for dprintf call"));
9179 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9180 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9185 printf_line
= xstrprintf ("call (void) %s (%s)",
9189 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9191 if (target_can_run_breakpoint_commands ())
9192 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9195 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9196 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9200 internal_error (__FILE__
, __LINE__
,
9201 _("Invalid dprintf style."));
9203 gdb_assert (printf_line
!= NULL
);
9204 /* Manufacture a printf sequence. */
9206 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9208 printf_cmd_line
->control_type
= simple_control
;
9209 printf_cmd_line
->body_count
= 0;
9210 printf_cmd_line
->body_list
= NULL
;
9211 printf_cmd_line
->next
= NULL
;
9212 printf_cmd_line
->line
= printf_line
;
9214 breakpoint_set_commands (b
, printf_cmd_line
);
9218 /* Update all dprintf commands, making their command lists reflect
9219 current style settings. */
9222 update_dprintf_commands (char *args
, int from_tty
,
9223 struct cmd_list_element
*c
)
9225 struct breakpoint
*b
;
9229 if (b
->type
== bp_dprintf
)
9230 update_dprintf_command_list (b
);
9234 /* Create a breakpoint with SAL as location. Use LOCATION
9235 as a description of the location, and COND_STRING
9236 as condition expression. */
9239 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9240 struct symtabs_and_lines sals
,
9241 struct event_location
*location
,
9242 char *filter
, char *cond_string
,
9244 enum bptype type
, enum bpdisp disposition
,
9245 int thread
, int task
, int ignore_count
,
9246 const struct breakpoint_ops
*ops
, int from_tty
,
9247 int enabled
, int internal
, unsigned flags
,
9248 int display_canonical
)
9252 if (type
== bp_hardware_breakpoint
)
9254 int target_resources_ok
;
9256 i
= hw_breakpoint_used_count ();
9257 target_resources_ok
=
9258 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9260 if (target_resources_ok
== 0)
9261 error (_("No hardware breakpoint support in the target."));
9262 else if (target_resources_ok
< 0)
9263 error (_("Hardware breakpoints used exceeds limit."));
9266 gdb_assert (sals
.nelts
> 0);
9268 for (i
= 0; i
< sals
.nelts
; ++i
)
9270 struct symtab_and_line sal
= sals
.sals
[i
];
9271 struct bp_location
*loc
;
9275 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9277 loc_gdbarch
= gdbarch
;
9279 describe_other_breakpoints (loc_gdbarch
,
9280 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9285 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9289 b
->cond_string
= cond_string
;
9290 b
->extra_string
= extra_string
;
9291 b
->ignore_count
= ignore_count
;
9292 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9293 b
->disposition
= disposition
;
9295 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9296 b
->loc
->inserted
= 1;
9298 if (type
== bp_static_tracepoint
)
9300 struct tracepoint
*t
= (struct tracepoint
*) b
;
9301 struct static_tracepoint_marker marker
;
9303 if (strace_marker_p (b
))
9305 /* We already know the marker exists, otherwise, we
9306 wouldn't see a sal for it. */
9307 const char *p
= &event_location_to_string (b
->location
)[3];
9311 p
= skip_spaces_const (p
);
9313 endp
= skip_to_space_const (p
);
9315 marker_str
= savestring (p
, endp
- p
);
9316 t
->static_trace_marker_id
= marker_str
;
9318 printf_filtered (_("Probed static tracepoint "
9320 t
->static_trace_marker_id
);
9322 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9324 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9325 release_static_tracepoint_marker (&marker
);
9327 printf_filtered (_("Probed static tracepoint "
9329 t
->static_trace_marker_id
);
9332 warning (_("Couldn't determine the static "
9333 "tracepoint marker to probe"));
9340 loc
= add_location_to_breakpoint (b
, &sal
);
9341 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9347 const char *arg
= b
->cond_string
;
9349 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9350 block_for_pc (loc
->address
), 0);
9352 error (_("Garbage '%s' follows condition"), arg
);
9355 /* Dynamic printf requires and uses additional arguments on the
9356 command line, otherwise it's an error. */
9357 if (type
== bp_dprintf
)
9359 if (b
->extra_string
)
9360 update_dprintf_command_list (b
);
9362 error (_("Format string required"));
9364 else if (b
->extra_string
)
9365 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9368 b
->display_canonical
= display_canonical
;
9369 if (location
!= NULL
)
9370 b
->location
= location
;
9373 const char *addr_string
= NULL
;
9374 int addr_string_len
= 0;
9376 if (location
!= NULL
)
9377 addr_string
= event_location_to_string (location
);
9378 if (addr_string
!= NULL
)
9379 addr_string_len
= strlen (addr_string
);
9381 b
->location
= new_address_location (b
->loc
->address
,
9382 addr_string
, addr_string_len
);
9388 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9389 struct symtabs_and_lines sals
,
9390 struct event_location
*location
,
9391 char *filter
, char *cond_string
,
9393 enum bptype type
, enum bpdisp disposition
,
9394 int thread
, int task
, int ignore_count
,
9395 const struct breakpoint_ops
*ops
, int from_tty
,
9396 int enabled
, int internal
, unsigned flags
,
9397 int display_canonical
)
9399 struct breakpoint
*b
;
9400 struct cleanup
*old_chain
;
9402 if (is_tracepoint_type (type
))
9404 struct tracepoint
*t
;
9406 t
= XCNEW (struct tracepoint
);
9410 b
= XNEW (struct breakpoint
);
9412 old_chain
= make_cleanup (xfree
, b
);
9414 init_breakpoint_sal (b
, gdbarch
,
9416 filter
, cond_string
, extra_string
,
9418 thread
, task
, ignore_count
,
9420 enabled
, internal
, flags
,
9422 discard_cleanups (old_chain
);
9424 install_breakpoint (internal
, b
, 0);
9427 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9428 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9429 value. COND_STRING, if not NULL, specified the condition to be
9430 used for all breakpoints. Essentially the only case where
9431 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9432 function. In that case, it's still not possible to specify
9433 separate conditions for different overloaded functions, so
9434 we take just a single condition string.
9436 NOTE: If the function succeeds, the caller is expected to cleanup
9437 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9438 array contents). If the function fails (error() is called), the
9439 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9440 COND and SALS arrays and each of those arrays contents. */
9443 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9444 struct linespec_result
*canonical
,
9445 char *cond_string
, char *extra_string
,
9446 enum bptype type
, enum bpdisp disposition
,
9447 int thread
, int task
, int ignore_count
,
9448 const struct breakpoint_ops
*ops
, int from_tty
,
9449 int enabled
, int internal
, unsigned flags
)
9452 struct linespec_sals
*lsal
;
9454 if (canonical
->pre_expanded
)
9455 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9457 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9459 /* Note that 'location' can be NULL in the case of a plain
9460 'break', without arguments. */
9461 struct event_location
*location
9462 = (canonical
->location
!= NULL
9463 ? copy_event_location (canonical
->location
) : NULL
);
9464 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9465 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9467 make_cleanup (xfree
, filter_string
);
9468 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9471 cond_string
, extra_string
,
9473 thread
, task
, ignore_count
, ops
,
9474 from_tty
, enabled
, internal
, flags
,
9475 canonical
->special_display
);
9476 discard_cleanups (inner
);
9480 /* Parse LOCATION which is assumed to be a SAL specification possibly
9481 followed by conditionals. On return, SALS contains an array of SAL
9482 addresses found. LOCATION points to the end of the SAL (for
9483 linespec locations).
9485 The array and the line spec strings are allocated on the heap, it is
9486 the caller's responsibility to free them. */
9489 parse_breakpoint_sals (const struct event_location
*location
,
9490 struct linespec_result
*canonical
)
9492 struct symtab_and_line cursal
;
9494 if (event_location_type (location
) == LINESPEC_LOCATION
)
9496 const char *address
= get_linespec_location (location
);
9498 if (address
== NULL
)
9500 /* The last displayed codepoint, if it's valid, is our default
9501 breakpoint address. */
9502 if (last_displayed_sal_is_valid ())
9504 struct linespec_sals lsal
;
9505 struct symtab_and_line sal
;
9508 init_sal (&sal
); /* Initialize to zeroes. */
9509 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9511 /* Set sal's pspace, pc, symtab, and line to the values
9512 corresponding to the last call to print_frame_info.
9513 Be sure to reinitialize LINE with NOTCURRENT == 0
9514 as the breakpoint line number is inappropriate otherwise.
9515 find_pc_line would adjust PC, re-set it back. */
9516 get_last_displayed_sal (&sal
);
9518 sal
= find_pc_line (pc
, 0);
9520 /* "break" without arguments is equivalent to "break *PC"
9521 where PC is the last displayed codepoint's address. So
9522 make sure to set sal.explicit_pc to prevent GDB from
9523 trying to expand the list of sals to include all other
9524 instances with the same symtab and line. */
9526 sal
.explicit_pc
= 1;
9528 lsal
.sals
.sals
[0] = sal
;
9529 lsal
.sals
.nelts
= 1;
9530 lsal
.canonical
= NULL
;
9532 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9536 error (_("No default breakpoint address now."));
9540 /* Force almost all breakpoints to be in terms of the
9541 current_source_symtab (which is decode_line_1's default).
9542 This should produce the results we want almost all of the
9543 time while leaving default_breakpoint_* alone.
9545 ObjC: However, don't match an Objective-C method name which
9546 may have a '+' or '-' succeeded by a '['. */
9547 cursal
= get_current_source_symtab_and_line ();
9548 if (last_displayed_sal_is_valid ())
9550 const char *address
= NULL
;
9552 if (event_location_type (location
) == LINESPEC_LOCATION
)
9553 address
= get_linespec_location (location
);
9557 && strchr ("+-", address
[0]) != NULL
9558 && address
[1] != '['))
9560 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9561 get_last_displayed_symtab (),
9562 get_last_displayed_line (),
9563 canonical
, NULL
, NULL
);
9568 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9569 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9573 /* Convert each SAL into a real PC. Verify that the PC can be
9574 inserted as a breakpoint. If it can't throw an error. */
9577 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9581 for (i
= 0; i
< sals
->nelts
; i
++)
9582 resolve_sal_pc (&sals
->sals
[i
]);
9585 /* Fast tracepoints may have restrictions on valid locations. For
9586 instance, a fast tracepoint using a jump instead of a trap will
9587 likely have to overwrite more bytes than a trap would, and so can
9588 only be placed where the instruction is longer than the jump, or a
9589 multi-instruction sequence does not have a jump into the middle of
9593 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9594 struct symtabs_and_lines
*sals
)
9597 struct symtab_and_line
*sal
;
9599 struct cleanup
*old_chain
;
9601 for (i
= 0; i
< sals
->nelts
; i
++)
9603 struct gdbarch
*sarch
;
9605 sal
= &sals
->sals
[i
];
9607 sarch
= get_sal_arch (*sal
);
9608 /* We fall back to GDBARCH if there is no architecture
9609 associated with SAL. */
9612 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9613 old_chain
= make_cleanup (xfree
, msg
);
9616 error (_("May not have a fast tracepoint at 0x%s%s"),
9617 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9619 do_cleanups (old_chain
);
9623 /* Given TOK, a string specification of condition and thread, as
9624 accepted by the 'break' command, extract the condition
9625 string and thread number and set *COND_STRING and *THREAD.
9626 PC identifies the context at which the condition should be parsed.
9627 If no condition is found, *COND_STRING is set to NULL.
9628 If no thread is found, *THREAD is set to -1. */
9631 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9632 char **cond_string
, int *thread
, int *task
,
9635 *cond_string
= NULL
;
9642 const char *end_tok
;
9644 const char *cond_start
= NULL
;
9645 const char *cond_end
= NULL
;
9647 tok
= skip_spaces_const (tok
);
9649 if ((*tok
== '"' || *tok
== ',') && rest
)
9651 *rest
= savestring (tok
, strlen (tok
));
9655 end_tok
= skip_to_space_const (tok
);
9657 toklen
= end_tok
- tok
;
9659 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9661 struct expression
*expr
;
9663 tok
= cond_start
= end_tok
+ 1;
9664 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9667 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9669 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9672 struct thread_info
*thr
;
9675 thr
= parse_thread_id (tok
, &tmptok
);
9677 error (_("Junk after thread keyword."));
9678 *thread
= thr
->global_num
;
9681 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9686 *task
= strtol (tok
, &tmptok
, 0);
9688 error (_("Junk after task keyword."));
9689 if (!valid_task_id (*task
))
9690 error (_("Unknown task %d."), *task
);
9695 *rest
= savestring (tok
, strlen (tok
));
9699 error (_("Junk at end of arguments."));
9703 /* Decode a static tracepoint marker spec. */
9705 static struct symtabs_and_lines
9706 decode_static_tracepoint_spec (const char **arg_p
)
9708 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9709 struct symtabs_and_lines sals
;
9710 struct cleanup
*old_chain
;
9711 const char *p
= &(*arg_p
)[3];
9716 p
= skip_spaces_const (p
);
9718 endp
= skip_to_space_const (p
);
9720 marker_str
= savestring (p
, endp
- p
);
9721 old_chain
= make_cleanup (xfree
, marker_str
);
9723 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9724 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9725 error (_("No known static tracepoint marker named %s"), marker_str
);
9727 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9728 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9730 for (i
= 0; i
< sals
.nelts
; i
++)
9732 struct static_tracepoint_marker
*marker
;
9734 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9736 init_sal (&sals
.sals
[i
]);
9738 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9739 sals
.sals
[i
].pc
= marker
->address
;
9741 release_static_tracepoint_marker (marker
);
9744 do_cleanups (old_chain
);
9750 /* See breakpoint.h. */
9753 create_breakpoint (struct gdbarch
*gdbarch
,
9754 const struct event_location
*location
, char *cond_string
,
9755 int thread
, char *extra_string
,
9757 int tempflag
, enum bptype type_wanted
,
9759 enum auto_boolean pending_break_support
,
9760 const struct breakpoint_ops
*ops
,
9761 int from_tty
, int enabled
, int internal
,
9764 struct linespec_result canonical
;
9765 struct cleanup
*old_chain
;
9766 struct cleanup
*bkpt_chain
= NULL
;
9769 int prev_bkpt_count
= breakpoint_count
;
9771 gdb_assert (ops
!= NULL
);
9773 /* If extra_string isn't useful, set it to NULL. */
9774 if (extra_string
!= NULL
&& *extra_string
== '\0')
9775 extra_string
= NULL
;
9777 init_linespec_result (&canonical
);
9781 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9783 CATCH (e
, RETURN_MASK_ERROR
)
9785 /* If caller is interested in rc value from parse, set
9787 if (e
.error
== NOT_FOUND_ERROR
)
9789 /* If pending breakpoint support is turned off, throw
9792 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9793 throw_exception (e
);
9795 exception_print (gdb_stderr
, e
);
9797 /* If pending breakpoint support is auto query and the user
9798 selects no, then simply return the error code. */
9799 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9800 && !nquery (_("Make %s pending on future shared library load? "),
9801 bptype_string (type_wanted
)))
9804 /* At this point, either the user was queried about setting
9805 a pending breakpoint and selected yes, or pending
9806 breakpoint behavior is on and thus a pending breakpoint
9807 is defaulted on behalf of the user. */
9811 throw_exception (e
);
9815 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9818 /* Create a chain of things that always need to be cleaned up. */
9819 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9821 /* ----------------------------- SNIP -----------------------------
9822 Anything added to the cleanup chain beyond this point is assumed
9823 to be part of a breakpoint. If the breakpoint create succeeds
9824 then the memory is not reclaimed. */
9825 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9827 /* Resolve all line numbers to PC's and verify that the addresses
9828 are ok for the target. */
9832 struct linespec_sals
*iter
;
9834 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9835 breakpoint_sals_to_pc (&iter
->sals
);
9838 /* Fast tracepoints may have additional restrictions on location. */
9839 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9842 struct linespec_sals
*iter
;
9844 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9845 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9848 /* Verify that condition can be parsed, before setting any
9849 breakpoints. Allocate a separate condition expression for each
9856 struct linespec_sals
*lsal
;
9858 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9860 /* Here we only parse 'arg' to separate condition
9861 from thread number, so parsing in context of first
9862 sal is OK. When setting the breakpoint we'll
9863 re-parse it in context of each sal. */
9865 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9866 &cond_string
, &thread
, &task
, &rest
);
9868 make_cleanup (xfree
, cond_string
);
9870 make_cleanup (xfree
, rest
);
9872 extra_string
= rest
;
9874 extra_string
= NULL
;
9878 if (type_wanted
!= bp_dprintf
9879 && extra_string
!= NULL
&& *extra_string
!= '\0')
9880 error (_("Garbage '%s' at end of location"), extra_string
);
9882 /* Create a private copy of condition string. */
9885 cond_string
= xstrdup (cond_string
);
9886 make_cleanup (xfree
, cond_string
);
9888 /* Create a private copy of any extra string. */
9891 extra_string
= xstrdup (extra_string
);
9892 make_cleanup (xfree
, extra_string
);
9896 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9897 cond_string
, extra_string
, type_wanted
,
9898 tempflag
? disp_del
: disp_donttouch
,
9899 thread
, task
, ignore_count
, ops
,
9900 from_tty
, enabled
, internal
, flags
);
9904 struct breakpoint
*b
;
9906 if (is_tracepoint_type (type_wanted
))
9908 struct tracepoint
*t
;
9910 t
= XCNEW (struct tracepoint
);
9914 b
= XNEW (struct breakpoint
);
9916 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9917 b
->location
= copy_event_location (location
);
9920 b
->cond_string
= NULL
;
9923 /* Create a private copy of condition string. */
9926 cond_string
= xstrdup (cond_string
);
9927 make_cleanup (xfree
, cond_string
);
9929 b
->cond_string
= cond_string
;
9933 /* Create a private copy of any extra string. */
9934 if (extra_string
!= NULL
)
9936 extra_string
= xstrdup (extra_string
);
9937 make_cleanup (xfree
, extra_string
);
9939 b
->extra_string
= extra_string
;
9940 b
->ignore_count
= ignore_count
;
9941 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9942 b
->condition_not_parsed
= 1;
9943 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9944 if ((type_wanted
!= bp_breakpoint
9945 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9946 b
->pspace
= current_program_space
;
9948 install_breakpoint (internal
, b
, 0);
9951 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9953 warning (_("Multiple breakpoints were set.\nUse the "
9954 "\"delete\" command to delete unwanted breakpoints."));
9955 prev_breakpoint_count
= prev_bkpt_count
;
9958 /* That's it. Discard the cleanups for data inserted into the
9960 discard_cleanups (bkpt_chain
);
9961 /* But cleanup everything else. */
9962 do_cleanups (old_chain
);
9964 /* error call may happen here - have BKPT_CHAIN already discarded. */
9965 update_global_location_list (UGLL_MAY_INSERT
);
9970 /* Set a breakpoint.
9971 ARG is a string describing breakpoint address,
9972 condition, and thread.
9973 FLAG specifies if a breakpoint is hardware on,
9974 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9978 break_command_1 (char *arg
, int flag
, int from_tty
)
9980 int tempflag
= flag
& BP_TEMPFLAG
;
9981 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9982 ? bp_hardware_breakpoint
9984 struct breakpoint_ops
*ops
;
9985 struct event_location
*location
;
9986 struct cleanup
*cleanup
;
9988 location
= string_to_event_location (&arg
, current_language
);
9989 cleanup
= make_cleanup_delete_event_location (location
);
9991 /* Matching breakpoints on probes. */
9992 if (location
!= NULL
9993 && event_location_type (location
) == PROBE_LOCATION
)
9994 ops
= &bkpt_probe_breakpoint_ops
;
9996 ops
= &bkpt_breakpoint_ops
;
9998 create_breakpoint (get_current_arch (),
10000 NULL
, 0, arg
, 1 /* parse arg */,
10001 tempflag
, type_wanted
,
10002 0 /* Ignore count */,
10003 pending_break_support
,
10009 do_cleanups (cleanup
);
10012 /* Helper function for break_command_1 and disassemble_command. */
10015 resolve_sal_pc (struct symtab_and_line
*sal
)
10019 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10021 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10022 error (_("No line %d in file \"%s\"."),
10023 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10026 /* If this SAL corresponds to a breakpoint inserted using a line
10027 number, then skip the function prologue if necessary. */
10028 if (sal
->explicit_line
)
10029 skip_prologue_sal (sal
);
10032 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10034 const struct blockvector
*bv
;
10035 const struct block
*b
;
10036 struct symbol
*sym
;
10038 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10039 SYMTAB_COMPUNIT (sal
->symtab
));
10042 sym
= block_linkage_function (b
);
10045 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10046 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10051 /* It really is worthwhile to have the section, so we'll
10052 just have to look harder. This case can be executed
10053 if we have line numbers but no functions (as can
10054 happen in assembly source). */
10056 struct bound_minimal_symbol msym
;
10057 struct cleanup
*old_chain
= save_current_space_and_thread ();
10059 switch_to_program_space_and_thread (sal
->pspace
);
10061 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10063 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10065 do_cleanups (old_chain
);
10072 break_command (char *arg
, int from_tty
)
10074 break_command_1 (arg
, 0, from_tty
);
10078 tbreak_command (char *arg
, int from_tty
)
10080 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10084 hbreak_command (char *arg
, int from_tty
)
10086 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10090 thbreak_command (char *arg
, int from_tty
)
10092 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10096 stop_command (char *arg
, int from_tty
)
10098 printf_filtered (_("Specify the type of breakpoint to set.\n\
10099 Usage: stop in <function | address>\n\
10100 stop at <line>\n"));
10104 stopin_command (char *arg
, int from_tty
)
10108 if (arg
== (char *) NULL
)
10110 else if (*arg
!= '*')
10112 char *argptr
= arg
;
10115 /* Look for a ':'. If this is a line number specification, then
10116 say it is bad, otherwise, it should be an address or
10117 function/method name. */
10118 while (*argptr
&& !hasColon
)
10120 hasColon
= (*argptr
== ':');
10125 badInput
= (*argptr
!= ':'); /* Not a class::method */
10127 badInput
= isdigit (*arg
); /* a simple line number */
10131 printf_filtered (_("Usage: stop in <function | address>\n"));
10133 break_command_1 (arg
, 0, from_tty
);
10137 stopat_command (char *arg
, int from_tty
)
10141 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10145 char *argptr
= arg
;
10148 /* Look for a ':'. If there is a '::' then get out, otherwise
10149 it is probably a line number. */
10150 while (*argptr
&& !hasColon
)
10152 hasColon
= (*argptr
== ':');
10157 badInput
= (*argptr
== ':'); /* we have class::method */
10159 badInput
= !isdigit (*arg
); /* not a line number */
10163 printf_filtered (_("Usage: stop at <line>\n"));
10165 break_command_1 (arg
, 0, from_tty
);
10168 /* The dynamic printf command is mostly like a regular breakpoint, but
10169 with a prewired command list consisting of a single output command,
10170 built from extra arguments supplied on the dprintf command
10174 dprintf_command (char *arg
, int from_tty
)
10176 struct event_location
*location
;
10177 struct cleanup
*cleanup
;
10179 location
= string_to_event_location (&arg
, current_language
);
10180 cleanup
= make_cleanup_delete_event_location (location
);
10182 /* If non-NULL, ARG should have been advanced past the location;
10183 the next character must be ','. */
10186 if (arg
[0] != ',' || arg
[1] == '\0')
10187 error (_("Format string required"));
10190 /* Skip the comma. */
10195 create_breakpoint (get_current_arch (),
10197 NULL
, 0, arg
, 1 /* parse arg */,
10199 0 /* Ignore count */,
10200 pending_break_support
,
10201 &dprintf_breakpoint_ops
,
10206 do_cleanups (cleanup
);
10210 agent_printf_command (char *arg
, int from_tty
)
10212 error (_("May only run agent-printf on the target"));
10215 /* Implement the "breakpoint_hit" breakpoint_ops method for
10216 ranged breakpoints. */
10219 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10220 struct address_space
*aspace
,
10222 const struct target_waitstatus
*ws
)
10224 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10225 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10228 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10229 bl
->length
, aspace
, bp_addr
);
10232 /* Implement the "resources_needed" breakpoint_ops method for
10233 ranged breakpoints. */
10236 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10238 return target_ranged_break_num_registers ();
10241 /* Implement the "print_it" breakpoint_ops method for
10242 ranged breakpoints. */
10244 static enum print_stop_action
10245 print_it_ranged_breakpoint (bpstat bs
)
10247 struct breakpoint
*b
= bs
->breakpoint_at
;
10248 struct bp_location
*bl
= b
->loc
;
10249 struct ui_out
*uiout
= current_uiout
;
10251 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10253 /* Ranged breakpoints have only one location. */
10254 gdb_assert (bl
&& bl
->next
== NULL
);
10256 annotate_breakpoint (b
->number
);
10258 maybe_print_thread_hit_breakpoint (uiout
);
10260 if (b
->disposition
== disp_del
)
10261 ui_out_text (uiout
, "Temporary ranged breakpoint ");
10263 ui_out_text (uiout
, "Ranged breakpoint ");
10264 if (ui_out_is_mi_like_p (uiout
))
10266 ui_out_field_string (uiout
, "reason",
10267 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10268 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10270 ui_out_field_int (uiout
, "bkptno", b
->number
);
10271 ui_out_text (uiout
, ", ");
10273 return PRINT_SRC_AND_LOC
;
10276 /* Implement the "print_one" breakpoint_ops method for
10277 ranged breakpoints. */
10280 print_one_ranged_breakpoint (struct breakpoint
*b
,
10281 struct bp_location
**last_loc
)
10283 struct bp_location
*bl
= b
->loc
;
10284 struct value_print_options opts
;
10285 struct ui_out
*uiout
= current_uiout
;
10287 /* Ranged breakpoints have only one location. */
10288 gdb_assert (bl
&& bl
->next
== NULL
);
10290 get_user_print_options (&opts
);
10292 if (opts
.addressprint
)
10293 /* We don't print the address range here, it will be printed later
10294 by print_one_detail_ranged_breakpoint. */
10295 ui_out_field_skip (uiout
, "addr");
10296 annotate_field (5);
10297 print_breakpoint_location (b
, bl
);
10301 /* Implement the "print_one_detail" breakpoint_ops method for
10302 ranged breakpoints. */
10305 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10306 struct ui_out
*uiout
)
10308 CORE_ADDR address_start
, address_end
;
10309 struct bp_location
*bl
= b
->loc
;
10310 struct ui_file
*stb
= mem_fileopen ();
10311 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10315 address_start
= bl
->address
;
10316 address_end
= address_start
+ bl
->length
- 1;
10318 ui_out_text (uiout
, "\taddress range: ");
10319 fprintf_unfiltered (stb
, "[%s, %s]",
10320 print_core_address (bl
->gdbarch
, address_start
),
10321 print_core_address (bl
->gdbarch
, address_end
));
10322 ui_out_field_stream (uiout
, "addr", stb
);
10323 ui_out_text (uiout
, "\n");
10325 do_cleanups (cleanup
);
10328 /* Implement the "print_mention" breakpoint_ops method for
10329 ranged breakpoints. */
10332 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10334 struct bp_location
*bl
= b
->loc
;
10335 struct ui_out
*uiout
= current_uiout
;
10338 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10340 if (ui_out_is_mi_like_p (uiout
))
10343 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10344 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10345 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10348 /* Implement the "print_recreate" breakpoint_ops method for
10349 ranged breakpoints. */
10352 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10354 fprintf_unfiltered (fp
, "break-range %s, %s",
10355 event_location_to_string (b
->location
),
10356 event_location_to_string (b
->location_range_end
));
10357 print_recreate_thread (b
, fp
);
10360 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10362 static struct breakpoint_ops ranged_breakpoint_ops
;
10364 /* Find the address where the end of the breakpoint range should be
10365 placed, given the SAL of the end of the range. This is so that if
10366 the user provides a line number, the end of the range is set to the
10367 last instruction of the given line. */
10370 find_breakpoint_range_end (struct symtab_and_line sal
)
10374 /* If the user provided a PC value, use it. Otherwise,
10375 find the address of the end of the given location. */
10376 if (sal
.explicit_pc
)
10383 ret
= find_line_pc_range (sal
, &start
, &end
);
10385 error (_("Could not find location of the end of the range."));
10387 /* find_line_pc_range returns the start of the next line. */
10394 /* Implement the "break-range" CLI command. */
10397 break_range_command (char *arg
, int from_tty
)
10399 char *arg_start
, *addr_string_start
, *addr_string_end
;
10400 struct linespec_result canonical_start
, canonical_end
;
10401 int bp_count
, can_use_bp
, length
;
10403 struct breakpoint
*b
;
10404 struct symtab_and_line sal_start
, sal_end
;
10405 struct cleanup
*cleanup_bkpt
;
10406 struct linespec_sals
*lsal_start
, *lsal_end
;
10407 struct event_location
*start_location
, *end_location
;
10409 /* We don't support software ranged breakpoints. */
10410 if (target_ranged_break_num_registers () < 0)
10411 error (_("This target does not support hardware ranged breakpoints."));
10413 bp_count
= hw_breakpoint_used_count ();
10414 bp_count
+= target_ranged_break_num_registers ();
10415 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10417 if (can_use_bp
< 0)
10418 error (_("Hardware breakpoints used exceeds limit."));
10420 arg
= skip_spaces (arg
);
10421 if (arg
== NULL
|| arg
[0] == '\0')
10422 error(_("No address range specified."));
10424 init_linespec_result (&canonical_start
);
10427 start_location
= string_to_event_location (&arg
, current_language
);
10428 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10429 parse_breakpoint_sals (start_location
, &canonical_start
);
10430 make_cleanup_destroy_linespec_result (&canonical_start
);
10433 error (_("Too few arguments."));
10434 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10435 error (_("Could not find location of the beginning of the range."));
10437 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10439 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10440 || lsal_start
->sals
.nelts
!= 1)
10441 error (_("Cannot create a ranged breakpoint with multiple locations."));
10443 sal_start
= lsal_start
->sals
.sals
[0];
10444 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10445 make_cleanup (xfree
, addr_string_start
);
10447 arg
++; /* Skip the comma. */
10448 arg
= skip_spaces (arg
);
10450 /* Parse the end location. */
10452 init_linespec_result (&canonical_end
);
10455 /* We call decode_line_full directly here instead of using
10456 parse_breakpoint_sals because we need to specify the start location's
10457 symtab and line as the default symtab and line for the end of the
10458 range. This makes it possible to have ranges like "foo.c:27, +14",
10459 where +14 means 14 lines from the start location. */
10460 end_location
= string_to_event_location (&arg
, current_language
);
10461 make_cleanup_delete_event_location (end_location
);
10462 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
10463 sal_start
.symtab
, sal_start
.line
,
10464 &canonical_end
, NULL
, NULL
);
10466 make_cleanup_destroy_linespec_result (&canonical_end
);
10468 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10469 error (_("Could not find location of the end of the range."));
10471 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10472 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10473 || lsal_end
->sals
.nelts
!= 1)
10474 error (_("Cannot create a ranged breakpoint with multiple locations."));
10476 sal_end
= lsal_end
->sals
.sals
[0];
10478 end
= find_breakpoint_range_end (sal_end
);
10479 if (sal_start
.pc
> end
)
10480 error (_("Invalid address range, end precedes start."));
10482 length
= end
- sal_start
.pc
+ 1;
10484 /* Length overflowed. */
10485 error (_("Address range too large."));
10486 else if (length
== 1)
10488 /* This range is simple enough to be handled by
10489 the `hbreak' command. */
10490 hbreak_command (addr_string_start
, 1);
10492 do_cleanups (cleanup_bkpt
);
10497 /* Now set up the breakpoint. */
10498 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10499 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10500 set_breakpoint_count (breakpoint_count
+ 1);
10501 b
->number
= breakpoint_count
;
10502 b
->disposition
= disp_donttouch
;
10503 b
->location
= copy_event_location (start_location
);
10504 b
->location_range_end
= copy_event_location (end_location
);
10505 b
->loc
->length
= length
;
10507 do_cleanups (cleanup_bkpt
);
10510 observer_notify_breakpoint_created (b
);
10511 update_global_location_list (UGLL_MAY_INSERT
);
10514 /* Return non-zero if EXP is verified as constant. Returned zero
10515 means EXP is variable. Also the constant detection may fail for
10516 some constant expressions and in such case still falsely return
10520 watchpoint_exp_is_const (const struct expression
*exp
)
10522 int i
= exp
->nelts
;
10528 /* We are only interested in the descriptor of each element. */
10529 operator_length (exp
, i
, &oplenp
, &argsp
);
10532 switch (exp
->elts
[i
].opcode
)
10542 case BINOP_LOGICAL_AND
:
10543 case BINOP_LOGICAL_OR
:
10544 case BINOP_BITWISE_AND
:
10545 case BINOP_BITWISE_IOR
:
10546 case BINOP_BITWISE_XOR
:
10548 case BINOP_NOTEQUAL
:
10575 case OP_OBJC_NSSTRING
:
10578 case UNOP_LOGICAL_NOT
:
10579 case UNOP_COMPLEMENT
:
10584 case UNOP_CAST_TYPE
:
10585 case UNOP_REINTERPRET_CAST
:
10586 case UNOP_DYNAMIC_CAST
:
10587 /* Unary, binary and ternary operators: We have to check
10588 their operands. If they are constant, then so is the
10589 result of that operation. For instance, if A and B are
10590 determined to be constants, then so is "A + B".
10592 UNOP_IND is one exception to the rule above, because the
10593 value of *ADDR is not necessarily a constant, even when
10598 /* Check whether the associated symbol is a constant.
10600 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10601 possible that a buggy compiler could mark a variable as
10602 constant even when it is not, and TYPE_CONST would return
10603 true in this case, while SYMBOL_CLASS wouldn't.
10605 We also have to check for function symbols because they
10606 are always constant. */
10608 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10610 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10611 && SYMBOL_CLASS (s
) != LOC_CONST
10612 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10617 /* The default action is to return 0 because we are using
10618 the optimistic approach here: If we don't know something,
10619 then it is not a constant. */
10628 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10631 dtor_watchpoint (struct breakpoint
*self
)
10633 struct watchpoint
*w
= (struct watchpoint
*) self
;
10635 xfree (w
->cond_exp
);
10637 xfree (w
->exp_string
);
10638 xfree (w
->exp_string_reparse
);
10639 value_free (w
->val
);
10641 base_breakpoint_ops
.dtor (self
);
10644 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10647 re_set_watchpoint (struct breakpoint
*b
)
10649 struct watchpoint
*w
= (struct watchpoint
*) b
;
10651 /* Watchpoint can be either on expression using entirely global
10652 variables, or it can be on local variables.
10654 Watchpoints of the first kind are never auto-deleted, and even
10655 persist across program restarts. Since they can use variables
10656 from shared libraries, we need to reparse expression as libraries
10657 are loaded and unloaded.
10659 Watchpoints on local variables can also change meaning as result
10660 of solib event. For example, if a watchpoint uses both a local
10661 and a global variables in expression, it's a local watchpoint,
10662 but unloading of a shared library will make the expression
10663 invalid. This is not a very common use case, but we still
10664 re-evaluate expression, to avoid surprises to the user.
10666 Note that for local watchpoints, we re-evaluate it only if
10667 watchpoints frame id is still valid. If it's not, it means the
10668 watchpoint is out of scope and will be deleted soon. In fact,
10669 I'm not sure we'll ever be called in this case.
10671 If a local watchpoint's frame id is still valid, then
10672 w->exp_valid_block is likewise valid, and we can safely use it.
10674 Don't do anything about disabled watchpoints, since they will be
10675 reevaluated again when enabled. */
10676 update_watchpoint (w
, 1 /* reparse */);
10679 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10682 insert_watchpoint (struct bp_location
*bl
)
10684 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10685 int length
= w
->exact
? 1 : bl
->length
;
10687 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10691 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10694 remove_watchpoint (struct bp_location
*bl
)
10696 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10697 int length
= w
->exact
? 1 : bl
->length
;
10699 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10704 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10705 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10706 const struct target_waitstatus
*ws
)
10708 struct breakpoint
*b
= bl
->owner
;
10709 struct watchpoint
*w
= (struct watchpoint
*) b
;
10711 /* Continuable hardware watchpoints are treated as non-existent if the
10712 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10713 some data address). Otherwise gdb won't stop on a break instruction
10714 in the code (not from a breakpoint) when a hardware watchpoint has
10715 been defined. Also skip watchpoints which we know did not trigger
10716 (did not match the data address). */
10717 if (is_hardware_watchpoint (b
)
10718 && w
->watchpoint_triggered
== watch_triggered_no
)
10725 check_status_watchpoint (bpstat bs
)
10727 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10729 bpstat_check_watchpoint (bs
);
10732 /* Implement the "resources_needed" breakpoint_ops method for
10733 hardware watchpoints. */
10736 resources_needed_watchpoint (const struct bp_location
*bl
)
10738 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10739 int length
= w
->exact
? 1 : bl
->length
;
10741 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10744 /* Implement the "works_in_software_mode" breakpoint_ops method for
10745 hardware watchpoints. */
10748 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10750 /* Read and access watchpoints only work with hardware support. */
10751 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10754 static enum print_stop_action
10755 print_it_watchpoint (bpstat bs
)
10757 struct cleanup
*old_chain
;
10758 struct breakpoint
*b
;
10759 struct ui_file
*stb
;
10760 enum print_stop_action result
;
10761 struct watchpoint
*w
;
10762 struct ui_out
*uiout
= current_uiout
;
10764 gdb_assert (bs
->bp_location_at
!= NULL
);
10766 b
= bs
->breakpoint_at
;
10767 w
= (struct watchpoint
*) b
;
10769 stb
= mem_fileopen ();
10770 old_chain
= make_cleanup_ui_file_delete (stb
);
10772 annotate_watchpoint (b
->number
);
10773 maybe_print_thread_hit_breakpoint (uiout
);
10777 case bp_watchpoint
:
10778 case bp_hardware_watchpoint
:
10779 if (ui_out_is_mi_like_p (uiout
))
10780 ui_out_field_string
10782 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10784 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10785 ui_out_text (uiout
, "\nOld value = ");
10786 watchpoint_value_print (bs
->old_val
, stb
);
10787 ui_out_field_stream (uiout
, "old", stb
);
10788 ui_out_text (uiout
, "\nNew value = ");
10789 watchpoint_value_print (w
->val
, stb
);
10790 ui_out_field_stream (uiout
, "new", stb
);
10791 ui_out_text (uiout
, "\n");
10792 /* More than one watchpoint may have been triggered. */
10793 result
= PRINT_UNKNOWN
;
10796 case bp_read_watchpoint
:
10797 if (ui_out_is_mi_like_p (uiout
))
10798 ui_out_field_string
10800 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10802 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10803 ui_out_text (uiout
, "\nValue = ");
10804 watchpoint_value_print (w
->val
, stb
);
10805 ui_out_field_stream (uiout
, "value", stb
);
10806 ui_out_text (uiout
, "\n");
10807 result
= PRINT_UNKNOWN
;
10810 case bp_access_watchpoint
:
10811 if (bs
->old_val
!= NULL
)
10813 if (ui_out_is_mi_like_p (uiout
))
10814 ui_out_field_string
10816 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10818 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10819 ui_out_text (uiout
, "\nOld value = ");
10820 watchpoint_value_print (bs
->old_val
, stb
);
10821 ui_out_field_stream (uiout
, "old", stb
);
10822 ui_out_text (uiout
, "\nNew value = ");
10827 if (ui_out_is_mi_like_p (uiout
))
10828 ui_out_field_string
10830 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10831 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10832 ui_out_text (uiout
, "\nValue = ");
10834 watchpoint_value_print (w
->val
, stb
);
10835 ui_out_field_stream (uiout
, "new", stb
);
10836 ui_out_text (uiout
, "\n");
10837 result
= PRINT_UNKNOWN
;
10840 result
= PRINT_UNKNOWN
;
10843 do_cleanups (old_chain
);
10847 /* Implement the "print_mention" breakpoint_ops method for hardware
10851 print_mention_watchpoint (struct breakpoint
*b
)
10853 struct cleanup
*ui_out_chain
;
10854 struct watchpoint
*w
= (struct watchpoint
*) b
;
10855 struct ui_out
*uiout
= current_uiout
;
10859 case bp_watchpoint
:
10860 ui_out_text (uiout
, "Watchpoint ");
10861 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10863 case bp_hardware_watchpoint
:
10864 ui_out_text (uiout
, "Hardware watchpoint ");
10865 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10867 case bp_read_watchpoint
:
10868 ui_out_text (uiout
, "Hardware read watchpoint ");
10869 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10871 case bp_access_watchpoint
:
10872 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10873 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10876 internal_error (__FILE__
, __LINE__
,
10877 _("Invalid hardware watchpoint type."));
10880 ui_out_field_int (uiout
, "number", b
->number
);
10881 ui_out_text (uiout
, ": ");
10882 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10883 do_cleanups (ui_out_chain
);
10886 /* Implement the "print_recreate" breakpoint_ops method for
10890 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10892 struct watchpoint
*w
= (struct watchpoint
*) b
;
10896 case bp_watchpoint
:
10897 case bp_hardware_watchpoint
:
10898 fprintf_unfiltered (fp
, "watch");
10900 case bp_read_watchpoint
:
10901 fprintf_unfiltered (fp
, "rwatch");
10903 case bp_access_watchpoint
:
10904 fprintf_unfiltered (fp
, "awatch");
10907 internal_error (__FILE__
, __LINE__
,
10908 _("Invalid watchpoint type."));
10911 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10912 print_recreate_thread (b
, fp
);
10915 /* Implement the "explains_signal" breakpoint_ops method for
10919 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10921 /* A software watchpoint cannot cause a signal other than
10922 GDB_SIGNAL_TRAP. */
10923 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10929 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10931 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10933 /* Implement the "insert" breakpoint_ops method for
10934 masked hardware watchpoints. */
10937 insert_masked_watchpoint (struct bp_location
*bl
)
10939 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10941 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10942 bl
->watchpoint_type
);
10945 /* Implement the "remove" breakpoint_ops method for
10946 masked hardware watchpoints. */
10949 remove_masked_watchpoint (struct bp_location
*bl
)
10951 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10953 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10954 bl
->watchpoint_type
);
10957 /* Implement the "resources_needed" breakpoint_ops method for
10958 masked hardware watchpoints. */
10961 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10963 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10965 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10968 /* Implement the "works_in_software_mode" breakpoint_ops method for
10969 masked hardware watchpoints. */
10972 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10977 /* Implement the "print_it" breakpoint_ops method for
10978 masked hardware watchpoints. */
10980 static enum print_stop_action
10981 print_it_masked_watchpoint (bpstat bs
)
10983 struct breakpoint
*b
= bs
->breakpoint_at
;
10984 struct ui_out
*uiout
= current_uiout
;
10986 /* Masked watchpoints have only one location. */
10987 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10989 annotate_watchpoint (b
->number
);
10990 maybe_print_thread_hit_breakpoint (uiout
);
10994 case bp_hardware_watchpoint
:
10995 if (ui_out_is_mi_like_p (uiout
))
10996 ui_out_field_string
10998 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11001 case bp_read_watchpoint
:
11002 if (ui_out_is_mi_like_p (uiout
))
11003 ui_out_field_string
11005 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11008 case bp_access_watchpoint
:
11009 if (ui_out_is_mi_like_p (uiout
))
11010 ui_out_field_string
11012 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11015 internal_error (__FILE__
, __LINE__
,
11016 _("Invalid hardware watchpoint type."));
11020 ui_out_text (uiout
, _("\n\
11021 Check the underlying instruction at PC for the memory\n\
11022 address and value which triggered this watchpoint.\n"));
11023 ui_out_text (uiout
, "\n");
11025 /* More than one watchpoint may have been triggered. */
11026 return PRINT_UNKNOWN
;
11029 /* Implement the "print_one_detail" breakpoint_ops method for
11030 masked hardware watchpoints. */
11033 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11034 struct ui_out
*uiout
)
11036 struct watchpoint
*w
= (struct watchpoint
*) b
;
11038 /* Masked watchpoints have only one location. */
11039 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11041 ui_out_text (uiout
, "\tmask ");
11042 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11043 ui_out_text (uiout
, "\n");
11046 /* Implement the "print_mention" breakpoint_ops method for
11047 masked hardware watchpoints. */
11050 print_mention_masked_watchpoint (struct breakpoint
*b
)
11052 struct watchpoint
*w
= (struct watchpoint
*) b
;
11053 struct ui_out
*uiout
= current_uiout
;
11054 struct cleanup
*ui_out_chain
;
11058 case bp_hardware_watchpoint
:
11059 ui_out_text (uiout
, "Masked hardware watchpoint ");
11060 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11062 case bp_read_watchpoint
:
11063 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11064 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11066 case bp_access_watchpoint
:
11067 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11068 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11071 internal_error (__FILE__
, __LINE__
,
11072 _("Invalid hardware watchpoint type."));
11075 ui_out_field_int (uiout
, "number", b
->number
);
11076 ui_out_text (uiout
, ": ");
11077 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11078 do_cleanups (ui_out_chain
);
11081 /* Implement the "print_recreate" breakpoint_ops method for
11082 masked hardware watchpoints. */
11085 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11087 struct watchpoint
*w
= (struct watchpoint
*) b
;
11092 case bp_hardware_watchpoint
:
11093 fprintf_unfiltered (fp
, "watch");
11095 case bp_read_watchpoint
:
11096 fprintf_unfiltered (fp
, "rwatch");
11098 case bp_access_watchpoint
:
11099 fprintf_unfiltered (fp
, "awatch");
11102 internal_error (__FILE__
, __LINE__
,
11103 _("Invalid hardware watchpoint type."));
11106 sprintf_vma (tmp
, w
->hw_wp_mask
);
11107 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11108 print_recreate_thread (b
, fp
);
11111 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11113 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11115 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11118 is_masked_watchpoint (const struct breakpoint
*b
)
11120 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11123 /* accessflag: hw_write: watch write,
11124 hw_read: watch read,
11125 hw_access: watch access (read or write) */
11127 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11128 int just_location
, int internal
)
11130 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11131 struct expression
*exp
;
11132 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11133 struct value
*val
, *mark
, *result
;
11134 int saved_bitpos
= 0, saved_bitsize
= 0;
11135 struct frame_info
*frame
;
11136 const char *exp_start
= NULL
;
11137 const char *exp_end
= NULL
;
11138 const char *tok
, *end_tok
;
11140 const char *cond_start
= NULL
;
11141 const char *cond_end
= NULL
;
11142 enum bptype bp_type
;
11145 /* Flag to indicate whether we are going to use masks for
11146 the hardware watchpoint. */
11148 CORE_ADDR mask
= 0;
11149 struct watchpoint
*w
;
11151 struct cleanup
*back_to
;
11153 /* Make sure that we actually have parameters to parse. */
11154 if (arg
!= NULL
&& arg
[0] != '\0')
11156 const char *value_start
;
11158 exp_end
= arg
+ strlen (arg
);
11160 /* Look for "parameter value" pairs at the end
11161 of the arguments string. */
11162 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11164 /* Skip whitespace at the end of the argument list. */
11165 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11168 /* Find the beginning of the last token.
11169 This is the value of the parameter. */
11170 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11172 value_start
= tok
+ 1;
11174 /* Skip whitespace. */
11175 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11180 /* Find the beginning of the second to last token.
11181 This is the parameter itself. */
11182 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11185 toklen
= end_tok
- tok
+ 1;
11187 if (toklen
== 6 && startswith (tok
, "thread"))
11189 struct thread_info
*thr
;
11190 /* At this point we've found a "thread" token, which means
11191 the user is trying to set a watchpoint that triggers
11192 only in a specific thread. */
11196 error(_("You can specify only one thread."));
11198 /* Extract the thread ID from the next token. */
11199 thr
= parse_thread_id (value_start
, &endp
);
11201 /* Check if the user provided a valid thread ID. */
11202 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11203 invalid_thread_id_error (value_start
);
11205 thread
= thr
->global_num
;
11207 else if (toklen
== 4 && startswith (tok
, "mask"))
11209 /* We've found a "mask" token, which means the user wants to
11210 create a hardware watchpoint that is going to have the mask
11212 struct value
*mask_value
, *mark
;
11215 error(_("You can specify only one mask."));
11217 use_mask
= just_location
= 1;
11219 mark
= value_mark ();
11220 mask_value
= parse_to_comma_and_eval (&value_start
);
11221 mask
= value_as_address (mask_value
);
11222 value_free_to_mark (mark
);
11225 /* We didn't recognize what we found. We should stop here. */
11228 /* Truncate the string and get rid of the "parameter value" pair before
11229 the arguments string is parsed by the parse_exp_1 function. */
11236 /* Parse the rest of the arguments. From here on out, everything
11237 is in terms of a newly allocated string instead of the original
11239 innermost_block
= NULL
;
11240 expression
= savestring (arg
, exp_end
- arg
);
11241 back_to
= make_cleanup (xfree
, expression
);
11242 exp_start
= arg
= expression
;
11243 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11245 /* Remove trailing whitespace from the expression before saving it.
11246 This makes the eventual display of the expression string a bit
11248 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11251 /* Checking if the expression is not constant. */
11252 if (watchpoint_exp_is_const (exp
))
11256 len
= exp_end
- exp_start
;
11257 while (len
> 0 && isspace (exp_start
[len
- 1]))
11259 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11262 exp_valid_block
= innermost_block
;
11263 mark
= value_mark ();
11264 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11266 if (val
!= NULL
&& just_location
)
11268 saved_bitpos
= value_bitpos (val
);
11269 saved_bitsize
= value_bitsize (val
);
11276 exp_valid_block
= NULL
;
11277 val
= value_addr (result
);
11278 release_value (val
);
11279 value_free_to_mark (mark
);
11283 ret
= target_masked_watch_num_registers (value_as_address (val
),
11286 error (_("This target does not support masked watchpoints."));
11287 else if (ret
== -2)
11288 error (_("Invalid mask or memory region."));
11291 else if (val
!= NULL
)
11292 release_value (val
);
11294 tok
= skip_spaces_const (arg
);
11295 end_tok
= skip_to_space_const (tok
);
11297 toklen
= end_tok
- tok
;
11298 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11300 struct expression
*cond
;
11302 innermost_block
= NULL
;
11303 tok
= cond_start
= end_tok
+ 1;
11304 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11306 /* The watchpoint expression may not be local, but the condition
11307 may still be. E.g.: `watch global if local > 0'. */
11308 cond_exp_valid_block
= innermost_block
;
11314 error (_("Junk at end of command."));
11316 frame
= block_innermost_frame (exp_valid_block
);
11318 /* If the expression is "local", then set up a "watchpoint scope"
11319 breakpoint at the point where we've left the scope of the watchpoint
11320 expression. Create the scope breakpoint before the watchpoint, so
11321 that we will encounter it first in bpstat_stop_status. */
11322 if (exp_valid_block
&& frame
)
11324 if (frame_id_p (frame_unwind_caller_id (frame
)))
11327 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11328 frame_unwind_caller_pc (frame
),
11329 bp_watchpoint_scope
,
11330 &momentary_breakpoint_ops
);
11332 scope_breakpoint
->enable_state
= bp_enabled
;
11334 /* Automatically delete the breakpoint when it hits. */
11335 scope_breakpoint
->disposition
= disp_del
;
11337 /* Only break in the proper frame (help with recursion). */
11338 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11340 /* Set the address at which we will stop. */
11341 scope_breakpoint
->loc
->gdbarch
11342 = frame_unwind_caller_arch (frame
);
11343 scope_breakpoint
->loc
->requested_address
11344 = frame_unwind_caller_pc (frame
);
11345 scope_breakpoint
->loc
->address
11346 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11347 scope_breakpoint
->loc
->requested_address
,
11348 scope_breakpoint
->type
);
11352 /* Now set up the breakpoint. We create all watchpoints as hardware
11353 watchpoints here even if hardware watchpoints are turned off, a call
11354 to update_watchpoint later in this function will cause the type to
11355 drop back to bp_watchpoint (software watchpoint) if required. */
11357 if (accessflag
== hw_read
)
11358 bp_type
= bp_read_watchpoint
;
11359 else if (accessflag
== hw_access
)
11360 bp_type
= bp_access_watchpoint
;
11362 bp_type
= bp_hardware_watchpoint
;
11364 w
= XCNEW (struct watchpoint
);
11367 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11368 &masked_watchpoint_breakpoint_ops
);
11370 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11371 &watchpoint_breakpoint_ops
);
11372 b
->thread
= thread
;
11373 b
->disposition
= disp_donttouch
;
11374 b
->pspace
= current_program_space
;
11376 w
->exp_valid_block
= exp_valid_block
;
11377 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11380 struct type
*t
= value_type (val
);
11381 CORE_ADDR addr
= value_as_address (val
);
11384 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11385 name
= type_to_string (t
);
11387 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11388 core_addr_to_string (addr
));
11391 w
->exp_string
= xstrprintf ("-location %.*s",
11392 (int) (exp_end
- exp_start
), exp_start
);
11394 /* The above expression is in C. */
11395 b
->language
= language_c
;
11398 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11402 w
->hw_wp_mask
= mask
;
11407 w
->val_bitpos
= saved_bitpos
;
11408 w
->val_bitsize
= saved_bitsize
;
11413 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11415 b
->cond_string
= 0;
11419 w
->watchpoint_frame
= get_frame_id (frame
);
11420 w
->watchpoint_thread
= inferior_ptid
;
11424 w
->watchpoint_frame
= null_frame_id
;
11425 w
->watchpoint_thread
= null_ptid
;
11428 if (scope_breakpoint
!= NULL
)
11430 /* The scope breakpoint is related to the watchpoint. We will
11431 need to act on them together. */
11432 b
->related_breakpoint
= scope_breakpoint
;
11433 scope_breakpoint
->related_breakpoint
= b
;
11436 if (!just_location
)
11437 value_free_to_mark (mark
);
11441 /* Finally update the new watchpoint. This creates the locations
11442 that should be inserted. */
11443 update_watchpoint (w
, 1);
11445 CATCH (e
, RETURN_MASK_ALL
)
11447 delete_breakpoint (b
);
11448 throw_exception (e
);
11452 install_breakpoint (internal
, b
, 1);
11453 do_cleanups (back_to
);
11456 /* Return count of debug registers needed to watch the given expression.
11457 If the watchpoint cannot be handled in hardware return zero. */
11460 can_use_hardware_watchpoint (struct value
*v
)
11462 int found_memory_cnt
= 0;
11463 struct value
*head
= v
;
11465 /* Did the user specifically forbid us to use hardware watchpoints? */
11466 if (!can_use_hw_watchpoints
)
11469 /* Make sure that the value of the expression depends only upon
11470 memory contents, and values computed from them within GDB. If we
11471 find any register references or function calls, we can't use a
11472 hardware watchpoint.
11474 The idea here is that evaluating an expression generates a series
11475 of values, one holding the value of every subexpression. (The
11476 expression a*b+c has five subexpressions: a, b, a*b, c, and
11477 a*b+c.) GDB's values hold almost enough information to establish
11478 the criteria given above --- they identify memory lvalues,
11479 register lvalues, computed values, etcetera. So we can evaluate
11480 the expression, and then scan the chain of values that leaves
11481 behind to decide whether we can detect any possible change to the
11482 expression's final value using only hardware watchpoints.
11484 However, I don't think that the values returned by inferior
11485 function calls are special in any way. So this function may not
11486 notice that an expression involving an inferior function call
11487 can't be watched with hardware watchpoints. FIXME. */
11488 for (; v
; v
= value_next (v
))
11490 if (VALUE_LVAL (v
) == lval_memory
)
11492 if (v
!= head
&& value_lazy (v
))
11493 /* A lazy memory lvalue in the chain is one that GDB never
11494 needed to fetch; we either just used its address (e.g.,
11495 `a' in `a.b') or we never needed it at all (e.g., `a'
11496 in `a,b'). This doesn't apply to HEAD; if that is
11497 lazy then it was not readable, but watch it anyway. */
11501 /* Ahh, memory we actually used! Check if we can cover
11502 it with hardware watchpoints. */
11503 struct type
*vtype
= check_typedef (value_type (v
));
11505 /* We only watch structs and arrays if user asked for it
11506 explicitly, never if they just happen to appear in a
11507 middle of some value chain. */
11509 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11510 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11512 CORE_ADDR vaddr
= value_address (v
);
11516 len
= (target_exact_watchpoints
11517 && is_scalar_type_recursive (vtype
))?
11518 1 : TYPE_LENGTH (value_type (v
));
11520 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11524 found_memory_cnt
+= num_regs
;
11528 else if (VALUE_LVAL (v
) != not_lval
11529 && deprecated_value_modifiable (v
) == 0)
11530 return 0; /* These are values from the history (e.g., $1). */
11531 else if (VALUE_LVAL (v
) == lval_register
)
11532 return 0; /* Cannot watch a register with a HW watchpoint. */
11535 /* The expression itself looks suitable for using a hardware
11536 watchpoint, but give the target machine a chance to reject it. */
11537 return found_memory_cnt
;
11541 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11543 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11546 /* A helper function that looks for the "-location" argument and then
11547 calls watch_command_1. */
11550 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11552 int just_location
= 0;
11555 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11556 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11558 arg
= skip_spaces (arg
);
11562 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11566 watch_command (char *arg
, int from_tty
)
11568 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11572 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11574 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11578 rwatch_command (char *arg
, int from_tty
)
11580 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11584 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11586 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11590 awatch_command (char *arg
, int from_tty
)
11592 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11596 /* Data for the FSM that manages the until(location)/advance commands
11597 in infcmd.c. Here because it uses the mechanisms of
11600 struct until_break_fsm
11602 /* The base class. */
11603 struct thread_fsm thread_fsm
;
11605 /* The thread that as current when the command was executed. */
11608 /* The breakpoint set at the destination location. */
11609 struct breakpoint
*location_breakpoint
;
11611 /* Breakpoint set at the return address in the caller frame. May be
11613 struct breakpoint
*caller_breakpoint
;
11616 static void until_break_fsm_clean_up (struct thread_fsm
*self
);
11617 static int until_break_fsm_should_stop (struct thread_fsm
*self
);
11618 static enum async_reply_reason
11619 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11621 /* until_break_fsm's vtable. */
11623 static struct thread_fsm_ops until_break_fsm_ops
=
11626 until_break_fsm_clean_up
,
11627 until_break_fsm_should_stop
,
11628 NULL
, /* return_value */
11629 until_break_fsm_async_reply_reason
,
11632 /* Allocate a new until_break_command_fsm. */
11634 static struct until_break_fsm
*
11635 new_until_break_fsm (int thread
,
11636 struct breakpoint
*location_breakpoint
,
11637 struct breakpoint
*caller_breakpoint
)
11639 struct until_break_fsm
*sm
;
11641 sm
= XCNEW (struct until_break_fsm
);
11642 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
);
11644 sm
->thread
= thread
;
11645 sm
->location_breakpoint
= location_breakpoint
;
11646 sm
->caller_breakpoint
= caller_breakpoint
;
11651 /* Implementation of the 'should_stop' FSM method for the
11652 until(location)/advance commands. */
11655 until_break_fsm_should_stop (struct thread_fsm
*self
)
11657 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11658 struct thread_info
*tp
= inferior_thread ();
11660 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11661 sm
->location_breakpoint
) != NULL
11662 || (sm
->caller_breakpoint
!= NULL
11663 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11664 sm
->caller_breakpoint
) != NULL
))
11665 thread_fsm_set_finished (self
);
11670 /* Implementation of the 'clean_up' FSM method for the
11671 until(location)/advance commands. */
11674 until_break_fsm_clean_up (struct thread_fsm
*self
)
11676 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11678 /* Clean up our temporary breakpoints. */
11679 if (sm
->location_breakpoint
!= NULL
)
11681 delete_breakpoint (sm
->location_breakpoint
);
11682 sm
->location_breakpoint
= NULL
;
11684 if (sm
->caller_breakpoint
!= NULL
)
11686 delete_breakpoint (sm
->caller_breakpoint
);
11687 sm
->caller_breakpoint
= NULL
;
11689 delete_longjmp_breakpoint (sm
->thread
);
11692 /* Implementation of the 'async_reply_reason' FSM method for the
11693 until(location)/advance commands. */
11695 static enum async_reply_reason
11696 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11698 return EXEC_ASYNC_LOCATION_REACHED
;
11702 until_break_command (char *arg
, int from_tty
, int anywhere
)
11704 struct symtabs_and_lines sals
;
11705 struct symtab_and_line sal
;
11706 struct frame_info
*frame
;
11707 struct gdbarch
*frame_gdbarch
;
11708 struct frame_id stack_frame_id
;
11709 struct frame_id caller_frame_id
;
11710 struct breakpoint
*location_breakpoint
;
11711 struct breakpoint
*caller_breakpoint
= NULL
;
11712 struct cleanup
*old_chain
, *cleanup
;
11714 struct thread_info
*tp
;
11715 struct event_location
*location
;
11716 struct until_break_fsm
*sm
;
11718 clear_proceed_status (0);
11720 /* Set a breakpoint where the user wants it and at return from
11723 location
= string_to_event_location (&arg
, current_language
);
11724 cleanup
= make_cleanup_delete_event_location (location
);
11726 if (last_displayed_sal_is_valid ())
11727 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
11728 get_last_displayed_symtab (),
11729 get_last_displayed_line ());
11731 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11732 NULL
, (struct symtab
*) NULL
, 0);
11734 if (sals
.nelts
!= 1)
11735 error (_("Couldn't get information on specified line."));
11737 sal
= sals
.sals
[0];
11738 xfree (sals
.sals
); /* malloc'd, so freed. */
11741 error (_("Junk at end of arguments."));
11743 resolve_sal_pc (&sal
);
11745 tp
= inferior_thread ();
11746 thread
= tp
->global_num
;
11748 old_chain
= make_cleanup (null_cleanup
, NULL
);
11750 /* Note linespec handling above invalidates the frame chain.
11751 Installing a breakpoint also invalidates the frame chain (as it
11752 may need to switch threads), so do any frame handling before
11755 frame
= get_selected_frame (NULL
);
11756 frame_gdbarch
= get_frame_arch (frame
);
11757 stack_frame_id
= get_stack_frame_id (frame
);
11758 caller_frame_id
= frame_unwind_caller_id (frame
);
11760 /* Keep within the current frame, or in frames called by the current
11763 if (frame_id_p (caller_frame_id
))
11765 struct symtab_and_line sal2
;
11766 struct gdbarch
*caller_gdbarch
;
11768 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11769 sal2
.pc
= frame_unwind_caller_pc (frame
);
11770 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11771 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11775 make_cleanup_delete_breakpoint (caller_breakpoint
);
11777 set_longjmp_breakpoint (tp
, caller_frame_id
);
11778 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11781 /* set_momentary_breakpoint could invalidate FRAME. */
11785 /* If the user told us to continue until a specified location,
11786 we don't specify a frame at which we need to stop. */
11787 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11788 null_frame_id
, bp_until
);
11790 /* Otherwise, specify the selected frame, because we want to stop
11791 only at the very same frame. */
11792 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11793 stack_frame_id
, bp_until
);
11794 make_cleanup_delete_breakpoint (location_breakpoint
);
11796 sm
= new_until_break_fsm (tp
->global_num
,
11797 location_breakpoint
, caller_breakpoint
);
11798 tp
->thread_fsm
= &sm
->thread_fsm
;
11800 discard_cleanups (old_chain
);
11802 proceed (-1, GDB_SIGNAL_DEFAULT
);
11804 do_cleanups (cleanup
);
11807 /* This function attempts to parse an optional "if <cond>" clause
11808 from the arg string. If one is not found, it returns NULL.
11810 Else, it returns a pointer to the condition string. (It does not
11811 attempt to evaluate the string against a particular block.) And,
11812 it updates arg to point to the first character following the parsed
11813 if clause in the arg string. */
11816 ep_parse_optional_if_clause (char **arg
)
11820 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11823 /* Skip the "if" keyword. */
11826 /* Skip any extra leading whitespace, and record the start of the
11827 condition string. */
11828 *arg
= skip_spaces (*arg
);
11829 cond_string
= *arg
;
11831 /* Assume that the condition occupies the remainder of the arg
11833 (*arg
) += strlen (cond_string
);
11835 return cond_string
;
11838 /* Commands to deal with catching events, such as signals, exceptions,
11839 process start/exit, etc. */
11843 catch_fork_temporary
, catch_vfork_temporary
,
11844 catch_fork_permanent
, catch_vfork_permanent
11849 catch_fork_command_1 (char *arg
, int from_tty
,
11850 struct cmd_list_element
*command
)
11852 struct gdbarch
*gdbarch
= get_current_arch ();
11853 char *cond_string
= NULL
;
11854 catch_fork_kind fork_kind
;
11857 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11858 tempflag
= (fork_kind
== catch_fork_temporary
11859 || fork_kind
== catch_vfork_temporary
);
11863 arg
= skip_spaces (arg
);
11865 /* The allowed syntax is:
11867 catch [v]fork if <cond>
11869 First, check if there's an if clause. */
11870 cond_string
= ep_parse_optional_if_clause (&arg
);
11872 if ((*arg
!= '\0') && !isspace (*arg
))
11873 error (_("Junk at end of arguments."));
11875 /* If this target supports it, create a fork or vfork catchpoint
11876 and enable reporting of such events. */
11879 case catch_fork_temporary
:
11880 case catch_fork_permanent
:
11881 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11882 &catch_fork_breakpoint_ops
);
11884 case catch_vfork_temporary
:
11885 case catch_vfork_permanent
:
11886 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11887 &catch_vfork_breakpoint_ops
);
11890 error (_("unsupported or unknown fork kind; cannot catch it"));
11896 catch_exec_command_1 (char *arg
, int from_tty
,
11897 struct cmd_list_element
*command
)
11899 struct exec_catchpoint
*c
;
11900 struct gdbarch
*gdbarch
= get_current_arch ();
11902 char *cond_string
= NULL
;
11904 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11908 arg
= skip_spaces (arg
);
11910 /* The allowed syntax is:
11912 catch exec if <cond>
11914 First, check if there's an if clause. */
11915 cond_string
= ep_parse_optional_if_clause (&arg
);
11917 if ((*arg
!= '\0') && !isspace (*arg
))
11918 error (_("Junk at end of arguments."));
11920 c
= XNEW (struct exec_catchpoint
);
11921 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11922 &catch_exec_breakpoint_ops
);
11923 c
->exec_pathname
= NULL
;
11925 install_breakpoint (0, &c
->base
, 1);
11929 init_ada_exception_breakpoint (struct breakpoint
*b
,
11930 struct gdbarch
*gdbarch
,
11931 struct symtab_and_line sal
,
11933 const struct breakpoint_ops
*ops
,
11940 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11942 loc_gdbarch
= gdbarch
;
11944 describe_other_breakpoints (loc_gdbarch
,
11945 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11946 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11947 version for exception catchpoints, because two catchpoints
11948 used for different exception names will use the same address.
11949 In this case, a "breakpoint ... also set at..." warning is
11950 unproductive. Besides, the warning phrasing is also a bit
11951 inappropriate, we should use the word catchpoint, and tell
11952 the user what type of catchpoint it is. The above is good
11953 enough for now, though. */
11956 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11958 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11959 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11960 b
->location
= string_to_event_location (&addr_string
,
11961 language_def (language_ada
));
11962 b
->language
= language_ada
;
11966 catch_command (char *arg
, int from_tty
)
11968 error (_("Catch requires an event name."));
11973 tcatch_command (char *arg
, int from_tty
)
11975 error (_("Catch requires an event name."));
11978 /* A qsort comparison function that sorts breakpoints in order. */
11981 compare_breakpoints (const void *a
, const void *b
)
11983 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11984 uintptr_t ua
= (uintptr_t) *ba
;
11985 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11986 uintptr_t ub
= (uintptr_t) *bb
;
11988 if ((*ba
)->number
< (*bb
)->number
)
11990 else if ((*ba
)->number
> (*bb
)->number
)
11993 /* Now sort by address, in case we see, e..g, two breakpoints with
11997 return ua
> ub
? 1 : 0;
12000 /* Delete breakpoints by address or line. */
12003 clear_command (char *arg
, int from_tty
)
12005 struct breakpoint
*b
, *prev
;
12006 VEC(breakpoint_p
) *found
= 0;
12009 struct symtabs_and_lines sals
;
12010 struct symtab_and_line sal
;
12012 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12016 sals
= decode_line_with_current_source (arg
,
12017 (DECODE_LINE_FUNFIRSTLINE
12018 | DECODE_LINE_LIST_MODE
));
12019 make_cleanup (xfree
, sals
.sals
);
12024 sals
.sals
= XNEW (struct symtab_and_line
);
12025 make_cleanup (xfree
, sals
.sals
);
12026 init_sal (&sal
); /* Initialize to zeroes. */
12028 /* Set sal's line, symtab, pc, and pspace to the values
12029 corresponding to the last call to print_frame_info. If the
12030 codepoint is not valid, this will set all the fields to 0. */
12031 get_last_displayed_sal (&sal
);
12032 if (sal
.symtab
== 0)
12033 error (_("No source file specified."));
12035 sals
.sals
[0] = sal
;
12041 /* We don't call resolve_sal_pc here. That's not as bad as it
12042 seems, because all existing breakpoints typically have both
12043 file/line and pc set. So, if clear is given file/line, we can
12044 match this to existing breakpoint without obtaining pc at all.
12046 We only support clearing given the address explicitly
12047 present in breakpoint table. Say, we've set breakpoint
12048 at file:line. There were several PC values for that file:line,
12049 due to optimization, all in one block.
12051 We've picked one PC value. If "clear" is issued with another
12052 PC corresponding to the same file:line, the breakpoint won't
12053 be cleared. We probably can still clear the breakpoint, but
12054 since the other PC value is never presented to user, user
12055 can only find it by guessing, and it does not seem important
12056 to support that. */
12058 /* For each line spec given, delete bps which correspond to it. Do
12059 it in two passes, solely to preserve the current behavior that
12060 from_tty is forced true if we delete more than one
12064 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12065 for (i
= 0; i
< sals
.nelts
; i
++)
12067 const char *sal_fullname
;
12069 /* If exact pc given, clear bpts at that pc.
12070 If line given (pc == 0), clear all bpts on specified line.
12071 If defaulting, clear all bpts on default line
12074 defaulting sal.pc != 0 tests to do
12079 1 0 <can't happen> */
12081 sal
= sals
.sals
[i
];
12082 sal_fullname
= (sal
.symtab
== NULL
12083 ? NULL
: symtab_to_fullname (sal
.symtab
));
12085 /* Find all matching breakpoints and add them to 'found'. */
12086 ALL_BREAKPOINTS (b
)
12089 /* Are we going to delete b? */
12090 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12092 struct bp_location
*loc
= b
->loc
;
12093 for (; loc
; loc
= loc
->next
)
12095 /* If the user specified file:line, don't allow a PC
12096 match. This matches historical gdb behavior. */
12097 int pc_match
= (!sal
.explicit_line
12099 && (loc
->pspace
== sal
.pspace
)
12100 && (loc
->address
== sal
.pc
)
12101 && (!section_is_overlay (loc
->section
)
12102 || loc
->section
== sal
.section
));
12103 int line_match
= 0;
12105 if ((default_match
|| sal
.explicit_line
)
12106 && loc
->symtab
!= NULL
12107 && sal_fullname
!= NULL
12108 && sal
.pspace
== loc
->pspace
12109 && loc
->line_number
== sal
.line
12110 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12111 sal_fullname
) == 0)
12114 if (pc_match
|| line_match
)
12123 VEC_safe_push(breakpoint_p
, found
, b
);
12127 /* Now go thru the 'found' chain and delete them. */
12128 if (VEC_empty(breakpoint_p
, found
))
12131 error (_("No breakpoint at %s."), arg
);
12133 error (_("No breakpoint at this line."));
12136 /* Remove duplicates from the vec. */
12137 qsort (VEC_address (breakpoint_p
, found
),
12138 VEC_length (breakpoint_p
, found
),
12139 sizeof (breakpoint_p
),
12140 compare_breakpoints
);
12141 prev
= VEC_index (breakpoint_p
, found
, 0);
12142 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12146 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12151 if (VEC_length(breakpoint_p
, found
) > 1)
12152 from_tty
= 1; /* Always report if deleted more than one. */
12155 if (VEC_length(breakpoint_p
, found
) == 1)
12156 printf_unfiltered (_("Deleted breakpoint "));
12158 printf_unfiltered (_("Deleted breakpoints "));
12161 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12164 printf_unfiltered ("%d ", b
->number
);
12165 delete_breakpoint (b
);
12168 putchar_unfiltered ('\n');
12170 do_cleanups (cleanups
);
12173 /* Delete breakpoint in BS if they are `delete' breakpoints and
12174 all breakpoints that are marked for deletion, whether hit or not.
12175 This is called after any breakpoint is hit, or after errors. */
12178 breakpoint_auto_delete (bpstat bs
)
12180 struct breakpoint
*b
, *b_tmp
;
12182 for (; bs
; bs
= bs
->next
)
12183 if (bs
->breakpoint_at
12184 && bs
->breakpoint_at
->disposition
== disp_del
12186 delete_breakpoint (bs
->breakpoint_at
);
12188 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12190 if (b
->disposition
== disp_del_at_next_stop
)
12191 delete_breakpoint (b
);
12195 /* A comparison function for bp_location AP and BP being interfaced to
12196 qsort. Sort elements primarily by their ADDRESS (no matter what
12197 does breakpoint_address_is_meaningful say for its OWNER),
12198 secondarily by ordering first permanent elements and
12199 terciarily just ensuring the array is sorted stable way despite
12200 qsort being an unstable algorithm. */
12203 bp_location_compare (const void *ap
, const void *bp
)
12205 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12206 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12208 if (a
->address
!= b
->address
)
12209 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12211 /* Sort locations at the same address by their pspace number, keeping
12212 locations of the same inferior (in a multi-inferior environment)
12215 if (a
->pspace
->num
!= b
->pspace
->num
)
12216 return ((a
->pspace
->num
> b
->pspace
->num
)
12217 - (a
->pspace
->num
< b
->pspace
->num
));
12219 /* Sort permanent breakpoints first. */
12220 if (a
->permanent
!= b
->permanent
)
12221 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12223 /* Make the internal GDB representation stable across GDB runs
12224 where A and B memory inside GDB can differ. Breakpoint locations of
12225 the same type at the same address can be sorted in arbitrary order. */
12227 if (a
->owner
->number
!= b
->owner
->number
)
12228 return ((a
->owner
->number
> b
->owner
->number
)
12229 - (a
->owner
->number
< b
->owner
->number
));
12231 return (a
> b
) - (a
< b
);
12234 /* Set bp_location_placed_address_before_address_max and
12235 bp_location_shadow_len_after_address_max according to the current
12236 content of the bp_location array. */
12239 bp_location_target_extensions_update (void)
12241 struct bp_location
*bl
, **blp_tmp
;
12243 bp_location_placed_address_before_address_max
= 0;
12244 bp_location_shadow_len_after_address_max
= 0;
12246 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12248 CORE_ADDR start
, end
, addr
;
12250 if (!bp_location_has_shadow (bl
))
12253 start
= bl
->target_info
.placed_address
;
12254 end
= start
+ bl
->target_info
.shadow_len
;
12256 gdb_assert (bl
->address
>= start
);
12257 addr
= bl
->address
- start
;
12258 if (addr
> bp_location_placed_address_before_address_max
)
12259 bp_location_placed_address_before_address_max
= addr
;
12261 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12263 gdb_assert (bl
->address
< end
);
12264 addr
= end
- bl
->address
;
12265 if (addr
> bp_location_shadow_len_after_address_max
)
12266 bp_location_shadow_len_after_address_max
= addr
;
12270 /* Download tracepoint locations if they haven't been. */
12273 download_tracepoint_locations (void)
12275 struct breakpoint
*b
;
12276 struct cleanup
*old_chain
;
12277 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12279 old_chain
= save_current_space_and_thread ();
12281 ALL_TRACEPOINTS (b
)
12283 struct bp_location
*bl
;
12284 struct tracepoint
*t
;
12285 int bp_location_downloaded
= 0;
12287 if ((b
->type
== bp_fast_tracepoint
12288 ? !may_insert_fast_tracepoints
12289 : !may_insert_tracepoints
))
12292 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12294 if (target_can_download_tracepoint ())
12295 can_download_tracepoint
= TRIBOOL_TRUE
;
12297 can_download_tracepoint
= TRIBOOL_FALSE
;
12300 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12303 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12305 /* In tracepoint, locations are _never_ duplicated, so
12306 should_be_inserted is equivalent to
12307 unduplicated_should_be_inserted. */
12308 if (!should_be_inserted (bl
) || bl
->inserted
)
12311 switch_to_program_space_and_thread (bl
->pspace
);
12313 target_download_tracepoint (bl
);
12316 bp_location_downloaded
= 1;
12318 t
= (struct tracepoint
*) b
;
12319 t
->number_on_target
= b
->number
;
12320 if (bp_location_downloaded
)
12321 observer_notify_breakpoint_modified (b
);
12324 do_cleanups (old_chain
);
12327 /* Swap the insertion/duplication state between two locations. */
12330 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12332 const int left_inserted
= left
->inserted
;
12333 const int left_duplicate
= left
->duplicate
;
12334 const int left_needs_update
= left
->needs_update
;
12335 const struct bp_target_info left_target_info
= left
->target_info
;
12337 /* Locations of tracepoints can never be duplicated. */
12338 if (is_tracepoint (left
->owner
))
12339 gdb_assert (!left
->duplicate
);
12340 if (is_tracepoint (right
->owner
))
12341 gdb_assert (!right
->duplicate
);
12343 left
->inserted
= right
->inserted
;
12344 left
->duplicate
= right
->duplicate
;
12345 left
->needs_update
= right
->needs_update
;
12346 left
->target_info
= right
->target_info
;
12347 right
->inserted
= left_inserted
;
12348 right
->duplicate
= left_duplicate
;
12349 right
->needs_update
= left_needs_update
;
12350 right
->target_info
= left_target_info
;
12353 /* Force the re-insertion of the locations at ADDRESS. This is called
12354 once a new/deleted/modified duplicate location is found and we are evaluating
12355 conditions on the target's side. Such conditions need to be updated on
12359 force_breakpoint_reinsertion (struct bp_location
*bl
)
12361 struct bp_location
**locp
= NULL
, **loc2p
;
12362 struct bp_location
*loc
;
12363 CORE_ADDR address
= 0;
12366 address
= bl
->address
;
12367 pspace_num
= bl
->pspace
->num
;
12369 /* This is only meaningful if the target is
12370 evaluating conditions and if the user has
12371 opted for condition evaluation on the target's
12373 if (gdb_evaluates_breakpoint_condition_p ()
12374 || !target_supports_evaluation_of_breakpoint_conditions ())
12377 /* Flag all breakpoint locations with this address and
12378 the same program space as the location
12379 as "its condition has changed". We need to
12380 update the conditions on the target's side. */
12381 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12385 if (!is_breakpoint (loc
->owner
)
12386 || pspace_num
!= loc
->pspace
->num
)
12389 /* Flag the location appropriately. We use a different state to
12390 let everyone know that we already updated the set of locations
12391 with addr bl->address and program space bl->pspace. This is so
12392 we don't have to keep calling these functions just to mark locations
12393 that have already been marked. */
12394 loc
->condition_changed
= condition_updated
;
12396 /* Free the agent expression bytecode as well. We will compute
12398 if (loc
->cond_bytecode
)
12400 free_agent_expr (loc
->cond_bytecode
);
12401 loc
->cond_bytecode
= NULL
;
12405 /* Called whether new breakpoints are created, or existing breakpoints
12406 deleted, to update the global location list and recompute which
12407 locations are duplicate of which.
12409 The INSERT_MODE flag determines whether locations may not, may, or
12410 shall be inserted now. See 'enum ugll_insert_mode' for more
12414 update_global_location_list (enum ugll_insert_mode insert_mode
)
12416 struct breakpoint
*b
;
12417 struct bp_location
**locp
, *loc
;
12418 struct cleanup
*cleanups
;
12419 /* Last breakpoint location address that was marked for update. */
12420 CORE_ADDR last_addr
= 0;
12421 /* Last breakpoint location program space that was marked for update. */
12422 int last_pspace_num
= -1;
12424 /* Used in the duplicates detection below. When iterating over all
12425 bp_locations, points to the first bp_location of a given address.
12426 Breakpoints and watchpoints of different types are never
12427 duplicates of each other. Keep one pointer for each type of
12428 breakpoint/watchpoint, so we only need to loop over all locations
12430 struct bp_location
*bp_loc_first
; /* breakpoint */
12431 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12432 struct bp_location
*awp_loc_first
; /* access watchpoint */
12433 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12435 /* Saved former bp_location array which we compare against the newly
12436 built bp_location from the current state of ALL_BREAKPOINTS. */
12437 struct bp_location
**old_location
, **old_locp
;
12438 unsigned old_location_count
;
12440 old_location
= bp_location
;
12441 old_location_count
= bp_location_count
;
12442 bp_location
= NULL
;
12443 bp_location_count
= 0;
12444 cleanups
= make_cleanup (xfree
, old_location
);
12446 ALL_BREAKPOINTS (b
)
12447 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12448 bp_location_count
++;
12450 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12451 locp
= bp_location
;
12452 ALL_BREAKPOINTS (b
)
12453 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12455 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12456 bp_location_compare
);
12458 bp_location_target_extensions_update ();
12460 /* Identify bp_location instances that are no longer present in the
12461 new list, and therefore should be freed. Note that it's not
12462 necessary that those locations should be removed from inferior --
12463 if there's another location at the same address (previously
12464 marked as duplicate), we don't need to remove/insert the
12467 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12468 and former bp_location array state respectively. */
12470 locp
= bp_location
;
12471 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12474 struct bp_location
*old_loc
= *old_locp
;
12475 struct bp_location
**loc2p
;
12477 /* Tells if 'old_loc' is found among the new locations. If
12478 not, we have to free it. */
12479 int found_object
= 0;
12480 /* Tells if the location should remain inserted in the target. */
12481 int keep_in_target
= 0;
12484 /* Skip LOCP entries which will definitely never be needed.
12485 Stop either at or being the one matching OLD_LOC. */
12486 while (locp
< bp_location
+ bp_location_count
12487 && (*locp
)->address
< old_loc
->address
)
12491 (loc2p
< bp_location
+ bp_location_count
12492 && (*loc2p
)->address
== old_loc
->address
);
12495 /* Check if this is a new/duplicated location or a duplicated
12496 location that had its condition modified. If so, we want to send
12497 its condition to the target if evaluation of conditions is taking
12499 if ((*loc2p
)->condition_changed
== condition_modified
12500 && (last_addr
!= old_loc
->address
12501 || last_pspace_num
!= old_loc
->pspace
->num
))
12503 force_breakpoint_reinsertion (*loc2p
);
12504 last_pspace_num
= old_loc
->pspace
->num
;
12507 if (*loc2p
== old_loc
)
12511 /* We have already handled this address, update it so that we don't
12512 have to go through updates again. */
12513 last_addr
= old_loc
->address
;
12515 /* Target-side condition evaluation: Handle deleted locations. */
12517 force_breakpoint_reinsertion (old_loc
);
12519 /* If this location is no longer present, and inserted, look if
12520 there's maybe a new location at the same address. If so,
12521 mark that one inserted, and don't remove this one. This is
12522 needed so that we don't have a time window where a breakpoint
12523 at certain location is not inserted. */
12525 if (old_loc
->inserted
)
12527 /* If the location is inserted now, we might have to remove
12530 if (found_object
&& should_be_inserted (old_loc
))
12532 /* The location is still present in the location list,
12533 and still should be inserted. Don't do anything. */
12534 keep_in_target
= 1;
12538 /* This location still exists, but it won't be kept in the
12539 target since it may have been disabled. We proceed to
12540 remove its target-side condition. */
12542 /* The location is either no longer present, or got
12543 disabled. See if there's another location at the
12544 same address, in which case we don't need to remove
12545 this one from the target. */
12547 /* OLD_LOC comes from existing struct breakpoint. */
12548 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12551 (loc2p
< bp_location
+ bp_location_count
12552 && (*loc2p
)->address
== old_loc
->address
);
12555 struct bp_location
*loc2
= *loc2p
;
12557 if (breakpoint_locations_match (loc2
, old_loc
))
12559 /* Read watchpoint locations are switched to
12560 access watchpoints, if the former are not
12561 supported, but the latter are. */
12562 if (is_hardware_watchpoint (old_loc
->owner
))
12564 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12565 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12568 /* loc2 is a duplicated location. We need to check
12569 if it should be inserted in case it will be
12571 if (loc2
!= old_loc
12572 && unduplicated_should_be_inserted (loc2
))
12574 swap_insertion (old_loc
, loc2
);
12575 keep_in_target
= 1;
12583 if (!keep_in_target
)
12585 if (remove_breakpoint (old_loc
, mark_uninserted
))
12587 /* This is just about all we can do. We could keep
12588 this location on the global list, and try to
12589 remove it next time, but there's no particular
12590 reason why we will succeed next time.
12592 Note that at this point, old_loc->owner is still
12593 valid, as delete_breakpoint frees the breakpoint
12594 only after calling us. */
12595 printf_filtered (_("warning: Error removing "
12596 "breakpoint %d\n"),
12597 old_loc
->owner
->number
);
12605 if (removed
&& target_is_non_stop_p ()
12606 && need_moribund_for_location_type (old_loc
))
12608 /* This location was removed from the target. In
12609 non-stop mode, a race condition is possible where
12610 we've removed a breakpoint, but stop events for that
12611 breakpoint are already queued and will arrive later.
12612 We apply an heuristic to be able to distinguish such
12613 SIGTRAPs from other random SIGTRAPs: we keep this
12614 breakpoint location for a bit, and will retire it
12615 after we see some number of events. The theory here
12616 is that reporting of events should, "on the average",
12617 be fair, so after a while we'll see events from all
12618 threads that have anything of interest, and no longer
12619 need to keep this breakpoint location around. We
12620 don't hold locations forever so to reduce chances of
12621 mistaking a non-breakpoint SIGTRAP for a breakpoint
12624 The heuristic failing can be disastrous on
12625 decr_pc_after_break targets.
12627 On decr_pc_after_break targets, like e.g., x86-linux,
12628 if we fail to recognize a late breakpoint SIGTRAP,
12629 because events_till_retirement has reached 0 too
12630 soon, we'll fail to do the PC adjustment, and report
12631 a random SIGTRAP to the user. When the user resumes
12632 the inferior, it will most likely immediately crash
12633 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12634 corrupted, because of being resumed e.g., in the
12635 middle of a multi-byte instruction, or skipped a
12636 one-byte instruction. This was actually seen happen
12637 on native x86-linux, and should be less rare on
12638 targets that do not support new thread events, like
12639 remote, due to the heuristic depending on
12642 Mistaking a random SIGTRAP for a breakpoint trap
12643 causes similar symptoms (PC adjustment applied when
12644 it shouldn't), but then again, playing with SIGTRAPs
12645 behind the debugger's back is asking for trouble.
12647 Since hardware watchpoint traps are always
12648 distinguishable from other traps, so we don't need to
12649 apply keep hardware watchpoint moribund locations
12650 around. We simply always ignore hardware watchpoint
12651 traps we can no longer explain. */
12653 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12654 old_loc
->owner
= NULL
;
12656 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12660 old_loc
->owner
= NULL
;
12661 decref_bp_location (&old_loc
);
12666 /* Rescan breakpoints at the same address and section, marking the
12667 first one as "first" and any others as "duplicates". This is so
12668 that the bpt instruction is only inserted once. If we have a
12669 permanent breakpoint at the same place as BPT, make that one the
12670 official one, and the rest as duplicates. Permanent breakpoints
12671 are sorted first for the same address.
12673 Do the same for hardware watchpoints, but also considering the
12674 watchpoint's type (regular/access/read) and length. */
12676 bp_loc_first
= NULL
;
12677 wp_loc_first
= NULL
;
12678 awp_loc_first
= NULL
;
12679 rwp_loc_first
= NULL
;
12680 ALL_BP_LOCATIONS (loc
, locp
)
12682 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12684 struct bp_location
**loc_first_p
;
12687 if (!unduplicated_should_be_inserted (loc
)
12688 || !breakpoint_address_is_meaningful (b
)
12689 /* Don't detect duplicate for tracepoint locations because they are
12690 never duplicated. See the comments in field `duplicate' of
12691 `struct bp_location'. */
12692 || is_tracepoint (b
))
12694 /* Clear the condition modification flag. */
12695 loc
->condition_changed
= condition_unchanged
;
12699 if (b
->type
== bp_hardware_watchpoint
)
12700 loc_first_p
= &wp_loc_first
;
12701 else if (b
->type
== bp_read_watchpoint
)
12702 loc_first_p
= &rwp_loc_first
;
12703 else if (b
->type
== bp_access_watchpoint
)
12704 loc_first_p
= &awp_loc_first
;
12706 loc_first_p
= &bp_loc_first
;
12708 if (*loc_first_p
== NULL
12709 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12710 || !breakpoint_locations_match (loc
, *loc_first_p
))
12712 *loc_first_p
= loc
;
12713 loc
->duplicate
= 0;
12715 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12717 loc
->needs_update
= 1;
12718 /* Clear the condition modification flag. */
12719 loc
->condition_changed
= condition_unchanged
;
12725 /* This and the above ensure the invariant that the first location
12726 is not duplicated, and is the inserted one.
12727 All following are marked as duplicated, and are not inserted. */
12729 swap_insertion (loc
, *loc_first_p
);
12730 loc
->duplicate
= 1;
12732 /* Clear the condition modification flag. */
12733 loc
->condition_changed
= condition_unchanged
;
12736 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12738 if (insert_mode
!= UGLL_DONT_INSERT
)
12739 insert_breakpoint_locations ();
12742 /* Even though the caller told us to not insert new
12743 locations, we may still need to update conditions on the
12744 target's side of breakpoints that were already inserted
12745 if the target is evaluating breakpoint conditions. We
12746 only update conditions for locations that are marked
12748 update_inserted_breakpoint_locations ();
12752 if (insert_mode
!= UGLL_DONT_INSERT
)
12753 download_tracepoint_locations ();
12755 do_cleanups (cleanups
);
12759 breakpoint_retire_moribund (void)
12761 struct bp_location
*loc
;
12764 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12765 if (--(loc
->events_till_retirement
) == 0)
12767 decref_bp_location (&loc
);
12768 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12774 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12779 update_global_location_list (insert_mode
);
12781 CATCH (e
, RETURN_MASK_ERROR
)
12787 /* Clear BKP from a BPS. */
12790 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12794 for (bs
= bps
; bs
; bs
= bs
->next
)
12795 if (bs
->breakpoint_at
== bpt
)
12797 bs
->breakpoint_at
= NULL
;
12798 bs
->old_val
= NULL
;
12799 /* bs->commands will be freed later. */
12803 /* Callback for iterate_over_threads. */
12805 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12807 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12809 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12813 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12817 say_where (struct breakpoint
*b
)
12819 struct value_print_options opts
;
12821 get_user_print_options (&opts
);
12823 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12825 if (b
->loc
== NULL
)
12827 /* For pending locations, the output differs slightly based
12828 on b->extra_string. If this is non-NULL, it contains either
12829 a condition or dprintf arguments. */
12830 if (b
->extra_string
== NULL
)
12832 printf_filtered (_(" (%s) pending."),
12833 event_location_to_string (b
->location
));
12835 else if (b
->type
== bp_dprintf
)
12837 printf_filtered (_(" (%s,%s) pending."),
12838 event_location_to_string (b
->location
),
12843 printf_filtered (_(" (%s %s) pending."),
12844 event_location_to_string (b
->location
),
12850 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12852 printf_filtered (" at ");
12853 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12856 if (b
->loc
->symtab
!= NULL
)
12858 /* If there is a single location, we can print the location
12860 if (b
->loc
->next
== NULL
)
12861 printf_filtered (": file %s, line %d.",
12862 symtab_to_filename_for_display (b
->loc
->symtab
),
12863 b
->loc
->line_number
);
12865 /* This is not ideal, but each location may have a
12866 different file name, and this at least reflects the
12867 real situation somewhat. */
12868 printf_filtered (": %s.",
12869 event_location_to_string (b
->location
));
12874 struct bp_location
*loc
= b
->loc
;
12876 for (; loc
; loc
= loc
->next
)
12878 printf_filtered (" (%d locations)", n
);
12883 /* Default bp_location_ops methods. */
12886 bp_location_dtor (struct bp_location
*self
)
12888 xfree (self
->cond
);
12889 if (self
->cond_bytecode
)
12890 free_agent_expr (self
->cond_bytecode
);
12891 xfree (self
->function_name
);
12893 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12894 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12897 static const struct bp_location_ops bp_location_ops
=
12902 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12906 base_breakpoint_dtor (struct breakpoint
*self
)
12908 decref_counted_command_line (&self
->commands
);
12909 xfree (self
->cond_string
);
12910 xfree (self
->extra_string
);
12911 xfree (self
->filter
);
12912 delete_event_location (self
->location
);
12913 delete_event_location (self
->location_range_end
);
12916 static struct bp_location
*
12917 base_breakpoint_allocate_location (struct breakpoint
*self
)
12919 struct bp_location
*loc
;
12921 loc
= XNEW (struct bp_location
);
12922 init_bp_location (loc
, &bp_location_ops
, self
);
12927 base_breakpoint_re_set (struct breakpoint
*b
)
12929 /* Nothing to re-set. */
12932 #define internal_error_pure_virtual_called() \
12933 gdb_assert_not_reached ("pure virtual function called")
12936 base_breakpoint_insert_location (struct bp_location
*bl
)
12938 internal_error_pure_virtual_called ();
12942 base_breakpoint_remove_location (struct bp_location
*bl
)
12944 internal_error_pure_virtual_called ();
12948 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12949 struct address_space
*aspace
,
12951 const struct target_waitstatus
*ws
)
12953 internal_error_pure_virtual_called ();
12957 base_breakpoint_check_status (bpstat bs
)
12962 /* A "works_in_software_mode" breakpoint_ops method that just internal
12966 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12968 internal_error_pure_virtual_called ();
12971 /* A "resources_needed" breakpoint_ops method that just internal
12975 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12977 internal_error_pure_virtual_called ();
12980 static enum print_stop_action
12981 base_breakpoint_print_it (bpstat bs
)
12983 internal_error_pure_virtual_called ();
12987 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12988 struct ui_out
*uiout
)
12994 base_breakpoint_print_mention (struct breakpoint
*b
)
12996 internal_error_pure_virtual_called ();
13000 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13002 internal_error_pure_virtual_called ();
13006 base_breakpoint_create_sals_from_location
13007 (const struct event_location
*location
,
13008 struct linespec_result
*canonical
,
13009 enum bptype type_wanted
)
13011 internal_error_pure_virtual_called ();
13015 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13016 struct linespec_result
*c
,
13018 char *extra_string
,
13019 enum bptype type_wanted
,
13020 enum bpdisp disposition
,
13022 int task
, int ignore_count
,
13023 const struct breakpoint_ops
*o
,
13024 int from_tty
, int enabled
,
13025 int internal
, unsigned flags
)
13027 internal_error_pure_virtual_called ();
13031 base_breakpoint_decode_location (struct breakpoint
*b
,
13032 const struct event_location
*location
,
13033 struct program_space
*search_pspace
,
13034 struct symtabs_and_lines
*sals
)
13036 internal_error_pure_virtual_called ();
13039 /* The default 'explains_signal' method. */
13042 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13047 /* The default "after_condition_true" method. */
13050 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13052 /* Nothing to do. */
13055 struct breakpoint_ops base_breakpoint_ops
=
13057 base_breakpoint_dtor
,
13058 base_breakpoint_allocate_location
,
13059 base_breakpoint_re_set
,
13060 base_breakpoint_insert_location
,
13061 base_breakpoint_remove_location
,
13062 base_breakpoint_breakpoint_hit
,
13063 base_breakpoint_check_status
,
13064 base_breakpoint_resources_needed
,
13065 base_breakpoint_works_in_software_mode
,
13066 base_breakpoint_print_it
,
13068 base_breakpoint_print_one_detail
,
13069 base_breakpoint_print_mention
,
13070 base_breakpoint_print_recreate
,
13071 base_breakpoint_create_sals_from_location
,
13072 base_breakpoint_create_breakpoints_sal
,
13073 base_breakpoint_decode_location
,
13074 base_breakpoint_explains_signal
,
13075 base_breakpoint_after_condition_true
,
13078 /* Default breakpoint_ops methods. */
13081 bkpt_re_set (struct breakpoint
*b
)
13083 /* FIXME: is this still reachable? */
13084 if (event_location_empty_p (b
->location
))
13086 /* Anything without a location can't be re-set. */
13087 delete_breakpoint (b
);
13091 breakpoint_re_set_default (b
);
13095 bkpt_insert_location (struct bp_location
*bl
)
13097 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13098 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13100 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13104 bkpt_remove_location (struct bp_location
*bl
)
13106 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13107 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13109 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13113 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13114 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13115 const struct target_waitstatus
*ws
)
13117 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13118 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13121 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13125 if (overlay_debugging
/* unmapped overlay section */
13126 && section_is_overlay (bl
->section
)
13127 && !section_is_mapped (bl
->section
))
13134 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13135 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13136 const struct target_waitstatus
*ws
)
13138 if (dprintf_style
== dprintf_style_agent
13139 && target_can_run_breakpoint_commands ())
13141 /* An agent-style dprintf never causes a stop. If we see a trap
13142 for this address it must be for a breakpoint that happens to
13143 be set at the same address. */
13147 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13151 bkpt_resources_needed (const struct bp_location
*bl
)
13153 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13158 static enum print_stop_action
13159 bkpt_print_it (bpstat bs
)
13161 struct breakpoint
*b
;
13162 const struct bp_location
*bl
;
13164 struct ui_out
*uiout
= current_uiout
;
13166 gdb_assert (bs
->bp_location_at
!= NULL
);
13168 bl
= bs
->bp_location_at
;
13169 b
= bs
->breakpoint_at
;
13171 bp_temp
= b
->disposition
== disp_del
;
13172 if (bl
->address
!= bl
->requested_address
)
13173 breakpoint_adjustment_warning (bl
->requested_address
,
13176 annotate_breakpoint (b
->number
);
13177 maybe_print_thread_hit_breakpoint (uiout
);
13180 ui_out_text (uiout
, "Temporary breakpoint ");
13182 ui_out_text (uiout
, "Breakpoint ");
13183 if (ui_out_is_mi_like_p (uiout
))
13185 ui_out_field_string (uiout
, "reason",
13186 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13187 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13189 ui_out_field_int (uiout
, "bkptno", b
->number
);
13190 ui_out_text (uiout
, ", ");
13192 return PRINT_SRC_AND_LOC
;
13196 bkpt_print_mention (struct breakpoint
*b
)
13198 if (ui_out_is_mi_like_p (current_uiout
))
13203 case bp_breakpoint
:
13204 case bp_gnu_ifunc_resolver
:
13205 if (b
->disposition
== disp_del
)
13206 printf_filtered (_("Temporary breakpoint"));
13208 printf_filtered (_("Breakpoint"));
13209 printf_filtered (_(" %d"), b
->number
);
13210 if (b
->type
== bp_gnu_ifunc_resolver
)
13211 printf_filtered (_(" at gnu-indirect-function resolver"));
13213 case bp_hardware_breakpoint
:
13214 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13217 printf_filtered (_("Dprintf %d"), b
->number
);
13225 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13227 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13228 fprintf_unfiltered (fp
, "tbreak");
13229 else if (tp
->type
== bp_breakpoint
)
13230 fprintf_unfiltered (fp
, "break");
13231 else if (tp
->type
== bp_hardware_breakpoint
13232 && tp
->disposition
== disp_del
)
13233 fprintf_unfiltered (fp
, "thbreak");
13234 else if (tp
->type
== bp_hardware_breakpoint
)
13235 fprintf_unfiltered (fp
, "hbreak");
13237 internal_error (__FILE__
, __LINE__
,
13238 _("unhandled breakpoint type %d"), (int) tp
->type
);
13240 fprintf_unfiltered (fp
, " %s",
13241 event_location_to_string (tp
->location
));
13243 /* Print out extra_string if this breakpoint is pending. It might
13244 contain, for example, conditions that were set by the user. */
13245 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13246 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13248 print_recreate_thread (tp
, fp
);
13252 bkpt_create_sals_from_location (const struct event_location
*location
,
13253 struct linespec_result
*canonical
,
13254 enum bptype type_wanted
)
13256 create_sals_from_location_default (location
, canonical
, type_wanted
);
13260 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13261 struct linespec_result
*canonical
,
13263 char *extra_string
,
13264 enum bptype type_wanted
,
13265 enum bpdisp disposition
,
13267 int task
, int ignore_count
,
13268 const struct breakpoint_ops
*ops
,
13269 int from_tty
, int enabled
,
13270 int internal
, unsigned flags
)
13272 create_breakpoints_sal_default (gdbarch
, canonical
,
13273 cond_string
, extra_string
,
13275 disposition
, thread
, task
,
13276 ignore_count
, ops
, from_tty
,
13277 enabled
, internal
, flags
);
13281 bkpt_decode_location (struct breakpoint
*b
,
13282 const struct event_location
*location
,
13283 struct program_space
*search_pspace
,
13284 struct symtabs_and_lines
*sals
)
13286 decode_location_default (b
, location
, search_pspace
, sals
);
13289 /* Virtual table for internal breakpoints. */
13292 internal_bkpt_re_set (struct breakpoint
*b
)
13296 /* Delete overlay event and longjmp master breakpoints; they
13297 will be reset later by breakpoint_re_set. */
13298 case bp_overlay_event
:
13299 case bp_longjmp_master
:
13300 case bp_std_terminate_master
:
13301 case bp_exception_master
:
13302 delete_breakpoint (b
);
13305 /* This breakpoint is special, it's set up when the inferior
13306 starts and we really don't want to touch it. */
13307 case bp_shlib_event
:
13309 /* Like bp_shlib_event, this breakpoint type is special. Once
13310 it is set up, we do not want to touch it. */
13311 case bp_thread_event
:
13317 internal_bkpt_check_status (bpstat bs
)
13319 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13321 /* If requested, stop when the dynamic linker notifies GDB of
13322 events. This allows the user to get control and place
13323 breakpoints in initializer routines for dynamically loaded
13324 objects (among other things). */
13325 bs
->stop
= stop_on_solib_events
;
13326 bs
->print
= stop_on_solib_events
;
13332 static enum print_stop_action
13333 internal_bkpt_print_it (bpstat bs
)
13335 struct breakpoint
*b
;
13337 b
= bs
->breakpoint_at
;
13341 case bp_shlib_event
:
13342 /* Did we stop because the user set the stop_on_solib_events
13343 variable? (If so, we report this as a generic, "Stopped due
13344 to shlib event" message.) */
13345 print_solib_event (0);
13348 case bp_thread_event
:
13349 /* Not sure how we will get here.
13350 GDB should not stop for these breakpoints. */
13351 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13354 case bp_overlay_event
:
13355 /* By analogy with the thread event, GDB should not stop for these. */
13356 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13359 case bp_longjmp_master
:
13360 /* These should never be enabled. */
13361 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13364 case bp_std_terminate_master
:
13365 /* These should never be enabled. */
13366 printf_filtered (_("std::terminate Master Breakpoint: "
13367 "gdb should not stop!\n"));
13370 case bp_exception_master
:
13371 /* These should never be enabled. */
13372 printf_filtered (_("Exception Master Breakpoint: "
13373 "gdb should not stop!\n"));
13377 return PRINT_NOTHING
;
13381 internal_bkpt_print_mention (struct breakpoint
*b
)
13383 /* Nothing to mention. These breakpoints are internal. */
13386 /* Virtual table for momentary breakpoints */
13389 momentary_bkpt_re_set (struct breakpoint
*b
)
13391 /* Keep temporary breakpoints, which can be encountered when we step
13392 over a dlopen call and solib_add is resetting the breakpoints.
13393 Otherwise these should have been blown away via the cleanup chain
13394 or by breakpoint_init_inferior when we rerun the executable. */
13398 momentary_bkpt_check_status (bpstat bs
)
13400 /* Nothing. The point of these breakpoints is causing a stop. */
13403 static enum print_stop_action
13404 momentary_bkpt_print_it (bpstat bs
)
13406 return PRINT_UNKNOWN
;
13410 momentary_bkpt_print_mention (struct breakpoint
*b
)
13412 /* Nothing to mention. These breakpoints are internal. */
13415 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13417 It gets cleared already on the removal of the first one of such placed
13418 breakpoints. This is OK as they get all removed altogether. */
13421 longjmp_bkpt_dtor (struct breakpoint
*self
)
13423 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13426 tp
->initiating_frame
= null_frame_id
;
13428 momentary_breakpoint_ops
.dtor (self
);
13431 /* Specific methods for probe breakpoints. */
13434 bkpt_probe_insert_location (struct bp_location
*bl
)
13436 int v
= bkpt_insert_location (bl
);
13440 /* The insertion was successful, now let's set the probe's semaphore
13442 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13443 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13452 bkpt_probe_remove_location (struct bp_location
*bl
)
13454 /* Let's clear the semaphore before removing the location. */
13455 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13456 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13460 return bkpt_remove_location (bl
);
13464 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13465 struct linespec_result
*canonical
,
13466 enum bptype type_wanted
)
13468 struct linespec_sals lsal
;
13470 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13471 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13472 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13476 bkpt_probe_decode_location (struct breakpoint
*b
,
13477 const struct event_location
*location
,
13478 struct program_space
*search_pspace
,
13479 struct symtabs_and_lines
*sals
)
13481 *sals
= parse_probes (location
, search_pspace
, NULL
);
13483 error (_("probe not found"));
13486 /* The breakpoint_ops structure to be used in tracepoints. */
13489 tracepoint_re_set (struct breakpoint
*b
)
13491 breakpoint_re_set_default (b
);
13495 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13496 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13497 const struct target_waitstatus
*ws
)
13499 /* By definition, the inferior does not report stops at
13505 tracepoint_print_one_detail (const struct breakpoint
*self
,
13506 struct ui_out
*uiout
)
13508 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13509 if (tp
->static_trace_marker_id
)
13511 gdb_assert (self
->type
== bp_static_tracepoint
);
13513 ui_out_text (uiout
, "\tmarker id is ");
13514 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13515 tp
->static_trace_marker_id
);
13516 ui_out_text (uiout
, "\n");
13521 tracepoint_print_mention (struct breakpoint
*b
)
13523 if (ui_out_is_mi_like_p (current_uiout
))
13528 case bp_tracepoint
:
13529 printf_filtered (_("Tracepoint"));
13530 printf_filtered (_(" %d"), b
->number
);
13532 case bp_fast_tracepoint
:
13533 printf_filtered (_("Fast tracepoint"));
13534 printf_filtered (_(" %d"), b
->number
);
13536 case bp_static_tracepoint
:
13537 printf_filtered (_("Static tracepoint"));
13538 printf_filtered (_(" %d"), b
->number
);
13541 internal_error (__FILE__
, __LINE__
,
13542 _("unhandled tracepoint type %d"), (int) b
->type
);
13549 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13551 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13553 if (self
->type
== bp_fast_tracepoint
)
13554 fprintf_unfiltered (fp
, "ftrace");
13555 else if (self
->type
== bp_static_tracepoint
)
13556 fprintf_unfiltered (fp
, "strace");
13557 else if (self
->type
== bp_tracepoint
)
13558 fprintf_unfiltered (fp
, "trace");
13560 internal_error (__FILE__
, __LINE__
,
13561 _("unhandled tracepoint type %d"), (int) self
->type
);
13563 fprintf_unfiltered (fp
, " %s",
13564 event_location_to_string (self
->location
));
13565 print_recreate_thread (self
, fp
);
13567 if (tp
->pass_count
)
13568 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13572 tracepoint_create_sals_from_location (const struct event_location
*location
,
13573 struct linespec_result
*canonical
,
13574 enum bptype type_wanted
)
13576 create_sals_from_location_default (location
, canonical
, type_wanted
);
13580 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13581 struct linespec_result
*canonical
,
13583 char *extra_string
,
13584 enum bptype type_wanted
,
13585 enum bpdisp disposition
,
13587 int task
, int ignore_count
,
13588 const struct breakpoint_ops
*ops
,
13589 int from_tty
, int enabled
,
13590 int internal
, unsigned flags
)
13592 create_breakpoints_sal_default (gdbarch
, canonical
,
13593 cond_string
, extra_string
,
13595 disposition
, thread
, task
,
13596 ignore_count
, ops
, from_tty
,
13597 enabled
, internal
, flags
);
13601 tracepoint_decode_location (struct breakpoint
*b
,
13602 const struct event_location
*location
,
13603 struct program_space
*search_pspace
,
13604 struct symtabs_and_lines
*sals
)
13606 decode_location_default (b
, location
, search_pspace
, sals
);
13609 struct breakpoint_ops tracepoint_breakpoint_ops
;
13611 /* The breakpoint_ops structure to be use on tracepoints placed in a
13615 tracepoint_probe_create_sals_from_location
13616 (const struct event_location
*location
,
13617 struct linespec_result
*canonical
,
13618 enum bptype type_wanted
)
13620 /* We use the same method for breakpoint on probes. */
13621 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13625 tracepoint_probe_decode_location (struct breakpoint
*b
,
13626 const struct event_location
*location
,
13627 struct program_space
*search_pspace
,
13628 struct symtabs_and_lines
*sals
)
13630 /* We use the same method for breakpoint on probes. */
13631 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13634 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13636 /* Dprintf breakpoint_ops methods. */
13639 dprintf_re_set (struct breakpoint
*b
)
13641 breakpoint_re_set_default (b
);
13643 /* extra_string should never be non-NULL for dprintf. */
13644 gdb_assert (b
->extra_string
!= NULL
);
13646 /* 1 - connect to target 1, that can run breakpoint commands.
13647 2 - create a dprintf, which resolves fine.
13648 3 - disconnect from target 1
13649 4 - connect to target 2, that can NOT run breakpoint commands.
13651 After steps #3/#4, you'll want the dprintf command list to
13652 be updated, because target 1 and 2 may well return different
13653 answers for target_can_run_breakpoint_commands().
13654 Given absence of finer grained resetting, we get to do
13655 it all the time. */
13656 if (b
->extra_string
!= NULL
)
13657 update_dprintf_command_list (b
);
13660 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13663 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13665 fprintf_unfiltered (fp
, "dprintf %s,%s",
13666 event_location_to_string (tp
->location
),
13668 print_recreate_thread (tp
, fp
);
13671 /* Implement the "after_condition_true" breakpoint_ops method for
13674 dprintf's are implemented with regular commands in their command
13675 list, but we run the commands here instead of before presenting the
13676 stop to the user, as dprintf's don't actually cause a stop. This
13677 also makes it so that the commands of multiple dprintfs at the same
13678 address are all handled. */
13681 dprintf_after_condition_true (struct bpstats
*bs
)
13683 struct cleanup
*old_chain
;
13684 struct bpstats tmp_bs
= { NULL
};
13685 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13687 /* dprintf's never cause a stop. This wasn't set in the
13688 check_status hook instead because that would make the dprintf's
13689 condition not be evaluated. */
13692 /* Run the command list here. Take ownership of it instead of
13693 copying. We never want these commands to run later in
13694 bpstat_do_actions, if a breakpoint that causes a stop happens to
13695 be set at same address as this dprintf, or even if running the
13696 commands here throws. */
13697 tmp_bs
.commands
= bs
->commands
;
13698 bs
->commands
= NULL
;
13699 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13701 bpstat_do_actions_1 (&tmp_bs_p
);
13703 /* 'tmp_bs.commands' will usually be NULL by now, but
13704 bpstat_do_actions_1 may return early without processing the whole
13706 do_cleanups (old_chain
);
13709 /* The breakpoint_ops structure to be used on static tracepoints with
13713 strace_marker_create_sals_from_location (const struct event_location
*location
,
13714 struct linespec_result
*canonical
,
13715 enum bptype type_wanted
)
13717 struct linespec_sals lsal
;
13718 const char *arg_start
, *arg
;
13720 struct cleanup
*cleanup
;
13722 arg
= arg_start
= get_linespec_location (location
);
13723 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13725 str
= savestring (arg_start
, arg
- arg_start
);
13726 cleanup
= make_cleanup (xfree
, str
);
13727 canonical
->location
= new_linespec_location (&str
);
13728 do_cleanups (cleanup
);
13730 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13731 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13735 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13736 struct linespec_result
*canonical
,
13738 char *extra_string
,
13739 enum bptype type_wanted
,
13740 enum bpdisp disposition
,
13742 int task
, int ignore_count
,
13743 const struct breakpoint_ops
*ops
,
13744 int from_tty
, int enabled
,
13745 int internal
, unsigned flags
)
13748 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13749 canonical
->sals
, 0);
13751 /* If the user is creating a static tracepoint by marker id
13752 (strace -m MARKER_ID), then store the sals index, so that
13753 breakpoint_re_set can try to match up which of the newly
13754 found markers corresponds to this one, and, don't try to
13755 expand multiple locations for each sal, given than SALS
13756 already should contain all sals for MARKER_ID. */
13758 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13760 struct symtabs_and_lines expanded
;
13761 struct tracepoint
*tp
;
13762 struct cleanup
*old_chain
;
13763 struct event_location
*location
;
13765 expanded
.nelts
= 1;
13766 expanded
.sals
= &lsal
->sals
.sals
[i
];
13768 location
= copy_event_location (canonical
->location
);
13769 old_chain
= make_cleanup_delete_event_location (location
);
13771 tp
= XCNEW (struct tracepoint
);
13772 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13774 cond_string
, extra_string
,
13775 type_wanted
, disposition
,
13776 thread
, task
, ignore_count
, ops
,
13777 from_tty
, enabled
, internal
, flags
,
13778 canonical
->special_display
);
13779 /* Given that its possible to have multiple markers with
13780 the same string id, if the user is creating a static
13781 tracepoint by marker id ("strace -m MARKER_ID"), then
13782 store the sals index, so that breakpoint_re_set can
13783 try to match up which of the newly found markers
13784 corresponds to this one */
13785 tp
->static_trace_marker_id_idx
= i
;
13787 install_breakpoint (internal
, &tp
->base
, 0);
13789 discard_cleanups (old_chain
);
13794 strace_marker_decode_location (struct breakpoint
*b
,
13795 const struct event_location
*location
,
13796 struct program_space
*search_pspace
,
13797 struct symtabs_and_lines
*sals
)
13799 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13800 const char *s
= get_linespec_location (location
);
13802 *sals
= decode_static_tracepoint_spec (&s
);
13803 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13805 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13809 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13812 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13815 strace_marker_p (struct breakpoint
*b
)
13817 return b
->ops
== &strace_marker_breakpoint_ops
;
13820 /* Delete a breakpoint and clean up all traces of it in the data
13824 delete_breakpoint (struct breakpoint
*bpt
)
13826 struct breakpoint
*b
;
13828 gdb_assert (bpt
!= NULL
);
13830 /* Has this bp already been deleted? This can happen because
13831 multiple lists can hold pointers to bp's. bpstat lists are
13834 One example of this happening is a watchpoint's scope bp. When
13835 the scope bp triggers, we notice that the watchpoint is out of
13836 scope, and delete it. We also delete its scope bp. But the
13837 scope bp is marked "auto-deleting", and is already on a bpstat.
13838 That bpstat is then checked for auto-deleting bp's, which are
13841 A real solution to this problem might involve reference counts in
13842 bp's, and/or giving them pointers back to their referencing
13843 bpstat's, and teaching delete_breakpoint to only free a bp's
13844 storage when no more references were extent. A cheaper bandaid
13846 if (bpt
->type
== bp_none
)
13849 /* At least avoid this stale reference until the reference counting
13850 of breakpoints gets resolved. */
13851 if (bpt
->related_breakpoint
!= bpt
)
13853 struct breakpoint
*related
;
13854 struct watchpoint
*w
;
13856 if (bpt
->type
== bp_watchpoint_scope
)
13857 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13858 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13859 w
= (struct watchpoint
*) bpt
;
13863 watchpoint_del_at_next_stop (w
);
13865 /* Unlink bpt from the bpt->related_breakpoint ring. */
13866 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13867 related
= related
->related_breakpoint
);
13868 related
->related_breakpoint
= bpt
->related_breakpoint
;
13869 bpt
->related_breakpoint
= bpt
;
13872 /* watch_command_1 creates a watchpoint but only sets its number if
13873 update_watchpoint succeeds in creating its bp_locations. If there's
13874 a problem in that process, we'll be asked to delete the half-created
13875 watchpoint. In that case, don't announce the deletion. */
13877 observer_notify_breakpoint_deleted (bpt
);
13879 if (breakpoint_chain
== bpt
)
13880 breakpoint_chain
= bpt
->next
;
13882 ALL_BREAKPOINTS (b
)
13883 if (b
->next
== bpt
)
13885 b
->next
= bpt
->next
;
13889 /* Be sure no bpstat's are pointing at the breakpoint after it's
13891 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13892 in all threads for now. Note that we cannot just remove bpstats
13893 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13894 commands are associated with the bpstat; if we remove it here,
13895 then the later call to bpstat_do_actions (&stop_bpstat); in
13896 event-top.c won't do anything, and temporary breakpoints with
13897 commands won't work. */
13899 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13901 /* Now that breakpoint is removed from breakpoint list, update the
13902 global location list. This will remove locations that used to
13903 belong to this breakpoint. Do this before freeing the breakpoint
13904 itself, since remove_breakpoint looks at location's owner. It
13905 might be better design to have location completely
13906 self-contained, but it's not the case now. */
13907 update_global_location_list (UGLL_DONT_INSERT
);
13909 bpt
->ops
->dtor (bpt
);
13910 /* On the chance that someone will soon try again to delete this
13911 same bp, we mark it as deleted before freeing its storage. */
13912 bpt
->type
= bp_none
;
13917 do_delete_breakpoint_cleanup (void *b
)
13919 delete_breakpoint ((struct breakpoint
*) b
);
13923 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13925 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13928 /* Iterator function to call a user-provided callback function once
13929 for each of B and its related breakpoints. */
13932 iterate_over_related_breakpoints (struct breakpoint
*b
,
13933 void (*function
) (struct breakpoint
*,
13937 struct breakpoint
*related
;
13942 struct breakpoint
*next
;
13944 /* FUNCTION may delete RELATED. */
13945 next
= related
->related_breakpoint
;
13947 if (next
== related
)
13949 /* RELATED is the last ring entry. */
13950 function (related
, data
);
13952 /* FUNCTION may have deleted it, so we'd never reach back to
13953 B. There's nothing left to do anyway, so just break
13958 function (related
, data
);
13962 while (related
!= b
);
13966 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13968 delete_breakpoint (b
);
13971 /* A callback for map_breakpoint_numbers that calls
13972 delete_breakpoint. */
13975 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13977 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13981 delete_command (char *arg
, int from_tty
)
13983 struct breakpoint
*b
, *b_tmp
;
13989 int breaks_to_delete
= 0;
13991 /* Delete all breakpoints if no argument. Do not delete
13992 internal breakpoints, these have to be deleted with an
13993 explicit breakpoint number argument. */
13994 ALL_BREAKPOINTS (b
)
13995 if (user_breakpoint_p (b
))
13997 breaks_to_delete
= 1;
14001 /* Ask user only if there are some breakpoints to delete. */
14003 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14005 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14006 if (user_breakpoint_p (b
))
14007 delete_breakpoint (b
);
14011 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14014 /* Return true if all locations of B bound to PSPACE are pending. If
14015 PSPACE is NULL, all locations of all program spaces are
14019 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
14021 struct bp_location
*loc
;
14023 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14024 if ((pspace
== NULL
14025 || loc
->pspace
== pspace
)
14026 && !loc
->shlib_disabled
14027 && !loc
->pspace
->executing_startup
)
14032 /* Subroutine of update_breakpoint_locations to simplify it.
14033 Return non-zero if multiple fns in list LOC have the same name.
14034 Null names are ignored. */
14037 ambiguous_names_p (struct bp_location
*loc
)
14039 struct bp_location
*l
;
14040 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14041 (int (*) (const void *,
14042 const void *)) streq
,
14043 NULL
, xcalloc
, xfree
);
14045 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14048 const char *name
= l
->function_name
;
14050 /* Allow for some names to be NULL, ignore them. */
14054 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14056 /* NOTE: We can assume slot != NULL here because xcalloc never
14060 htab_delete (htab
);
14066 htab_delete (htab
);
14070 /* When symbols change, it probably means the sources changed as well,
14071 and it might mean the static tracepoint markers are no longer at
14072 the same address or line numbers they used to be at last we
14073 checked. Losing your static tracepoints whenever you rebuild is
14074 undesirable. This function tries to resync/rematch gdb static
14075 tracepoints with the markers on the target, for static tracepoints
14076 that have not been set by marker id. Static tracepoint that have
14077 been set by marker id are reset by marker id in breakpoint_re_set.
14080 1) For a tracepoint set at a specific address, look for a marker at
14081 the old PC. If one is found there, assume to be the same marker.
14082 If the name / string id of the marker found is different from the
14083 previous known name, assume that means the user renamed the marker
14084 in the sources, and output a warning.
14086 2) For a tracepoint set at a given line number, look for a marker
14087 at the new address of the old line number. If one is found there,
14088 assume to be the same marker. If the name / string id of the
14089 marker found is different from the previous known name, assume that
14090 means the user renamed the marker in the sources, and output a
14093 3) If a marker is no longer found at the same address or line, it
14094 may mean the marker no longer exists. But it may also just mean
14095 the code changed a bit. Maybe the user added a few lines of code
14096 that made the marker move up or down (in line number terms). Ask
14097 the target for info about the marker with the string id as we knew
14098 it. If found, update line number and address in the matching
14099 static tracepoint. This will get confused if there's more than one
14100 marker with the same ID (possible in UST, although unadvised
14101 precisely because it confuses tools). */
14103 static struct symtab_and_line
14104 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14106 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14107 struct static_tracepoint_marker marker
;
14112 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14114 if (target_static_tracepoint_marker_at (pc
, &marker
))
14116 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14117 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14119 tp
->static_trace_marker_id
, marker
.str_id
);
14121 xfree (tp
->static_trace_marker_id
);
14122 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14123 release_static_tracepoint_marker (&marker
);
14128 /* Old marker wasn't found on target at lineno. Try looking it up
14130 if (!sal
.explicit_pc
14132 && sal
.symtab
!= NULL
14133 && tp
->static_trace_marker_id
!= NULL
)
14135 VEC(static_tracepoint_marker_p
) *markers
;
14138 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14140 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14142 struct symtab_and_line sal2
;
14143 struct symbol
*sym
;
14144 struct static_tracepoint_marker
*tpmarker
;
14145 struct ui_out
*uiout
= current_uiout
;
14146 struct explicit_location explicit_loc
;
14148 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14150 xfree (tp
->static_trace_marker_id
);
14151 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14153 warning (_("marker for static tracepoint %d (%s) not "
14154 "found at previous line number"),
14155 b
->number
, tp
->static_trace_marker_id
);
14159 sal2
.pc
= tpmarker
->address
;
14161 sal2
= find_pc_line (tpmarker
->address
, 0);
14162 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14163 ui_out_text (uiout
, "Now in ");
14166 ui_out_field_string (uiout
, "func",
14167 SYMBOL_PRINT_NAME (sym
));
14168 ui_out_text (uiout
, " at ");
14170 ui_out_field_string (uiout
, "file",
14171 symtab_to_filename_for_display (sal2
.symtab
));
14172 ui_out_text (uiout
, ":");
14174 if (ui_out_is_mi_like_p (uiout
))
14176 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14178 ui_out_field_string (uiout
, "fullname", fullname
);
14181 ui_out_field_int (uiout
, "line", sal2
.line
);
14182 ui_out_text (uiout
, "\n");
14184 b
->loc
->line_number
= sal2
.line
;
14185 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14187 delete_event_location (b
->location
);
14188 initialize_explicit_location (&explicit_loc
);
14189 explicit_loc
.source_filename
14190 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14191 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14192 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14193 b
->location
= new_explicit_location (&explicit_loc
);
14195 /* Might be nice to check if function changed, and warn if
14198 release_static_tracepoint_marker (tpmarker
);
14204 /* Returns 1 iff locations A and B are sufficiently same that
14205 we don't need to report breakpoint as changed. */
14208 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14212 if (a
->address
!= b
->address
)
14215 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14218 if (a
->enabled
!= b
->enabled
)
14225 if ((a
== NULL
) != (b
== NULL
))
14231 /* Split all locations of B that are bound to PSPACE out of B's
14232 location list to a separate list and return that list's head. If
14233 PSPACE is NULL, hoist out all locations of B. */
14235 static struct bp_location
*
14236 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14238 struct bp_location head
;
14239 struct bp_location
*i
= b
->loc
;
14240 struct bp_location
**i_link
= &b
->loc
;
14241 struct bp_location
*hoisted
= &head
;
14243 if (pspace
== NULL
)
14254 if (i
->pspace
== pspace
)
14269 /* Create new breakpoint locations for B (a hardware or software
14270 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14271 zero, then B is a ranged breakpoint. Only recreates locations for
14272 FILTER_PSPACE. Locations of other program spaces are left
14276 update_breakpoint_locations (struct breakpoint
*b
,
14277 struct program_space
*filter_pspace
,
14278 struct symtabs_and_lines sals
,
14279 struct symtabs_and_lines sals_end
)
14282 struct bp_location
*existing_locations
;
14284 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14286 /* Ranged breakpoints have only one start location and one end
14288 b
->enable_state
= bp_disabled
;
14289 update_global_location_list (UGLL_MAY_INSERT
);
14290 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14291 "multiple locations found\n"),
14296 /* If there's no new locations, and all existing locations are
14297 pending, don't do anything. This optimizes the common case where
14298 all locations are in the same shared library, that was unloaded.
14299 We'd like to retain the location, so that when the library is
14300 loaded again, we don't loose the enabled/disabled status of the
14301 individual locations. */
14302 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14305 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14307 for (i
= 0; i
< sals
.nelts
; ++i
)
14309 struct bp_location
*new_loc
;
14311 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14313 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14315 /* Reparse conditions, they might contain references to the
14317 if (b
->cond_string
!= NULL
)
14321 s
= b
->cond_string
;
14324 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14325 block_for_pc (sals
.sals
[i
].pc
),
14328 CATCH (e
, RETURN_MASK_ERROR
)
14330 warning (_("failed to reevaluate condition "
14331 "for breakpoint %d: %s"),
14332 b
->number
, e
.message
);
14333 new_loc
->enabled
= 0;
14338 if (sals_end
.nelts
)
14340 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14342 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14346 /* If possible, carry over 'disable' status from existing
14349 struct bp_location
*e
= existing_locations
;
14350 /* If there are multiple breakpoints with the same function name,
14351 e.g. for inline functions, comparing function names won't work.
14352 Instead compare pc addresses; this is just a heuristic as things
14353 may have moved, but in practice it gives the correct answer
14354 often enough until a better solution is found. */
14355 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14357 for (; e
; e
= e
->next
)
14359 if (!e
->enabled
&& e
->function_name
)
14361 struct bp_location
*l
= b
->loc
;
14362 if (have_ambiguous_names
)
14364 for (; l
; l
= l
->next
)
14365 if (breakpoint_locations_match (e
, l
))
14373 for (; l
; l
= l
->next
)
14374 if (l
->function_name
14375 && strcmp (e
->function_name
, l
->function_name
) == 0)
14385 if (!locations_are_equal (existing_locations
, b
->loc
))
14386 observer_notify_breakpoint_modified (b
);
14388 update_global_location_list (UGLL_MAY_INSERT
);
14391 /* Find the SaL locations corresponding to the given LOCATION.
14392 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14394 static struct symtabs_and_lines
14395 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14396 struct program_space
*search_pspace
, int *found
)
14398 struct symtabs_and_lines sals
= {0};
14399 struct gdb_exception exception
= exception_none
;
14401 gdb_assert (b
->ops
!= NULL
);
14405 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14407 CATCH (e
, RETURN_MASK_ERROR
)
14409 int not_found_and_ok
= 0;
14413 /* For pending breakpoints, it's expected that parsing will
14414 fail until the right shared library is loaded. User has
14415 already told to create pending breakpoints and don't need
14416 extra messages. If breakpoint is in bp_shlib_disabled
14417 state, then user already saw the message about that
14418 breakpoint being disabled, and don't want to see more
14420 if (e
.error
== NOT_FOUND_ERROR
14421 && (b
->condition_not_parsed
14423 && search_pspace
!= NULL
14424 && b
->loc
->pspace
!= search_pspace
)
14425 || (b
->loc
&& b
->loc
->shlib_disabled
)
14426 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14427 || b
->enable_state
== bp_disabled
))
14428 not_found_and_ok
= 1;
14430 if (!not_found_and_ok
)
14432 /* We surely don't want to warn about the same breakpoint
14433 10 times. One solution, implemented here, is disable
14434 the breakpoint on error. Another solution would be to
14435 have separate 'warning emitted' flag. Since this
14436 happens only when a binary has changed, I don't know
14437 which approach is better. */
14438 b
->enable_state
= bp_disabled
;
14439 throw_exception (e
);
14444 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14448 for (i
= 0; i
< sals
.nelts
; ++i
)
14449 resolve_sal_pc (&sals
.sals
[i
]);
14450 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14452 char *cond_string
, *extra_string
;
14455 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14456 &cond_string
, &thread
, &task
,
14458 gdb_assert (b
->cond_string
== NULL
);
14460 b
->cond_string
= cond_string
;
14461 b
->thread
= thread
;
14465 xfree (b
->extra_string
);
14466 b
->extra_string
= extra_string
;
14468 b
->condition_not_parsed
= 0;
14471 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14472 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14482 /* The default re_set method, for typical hardware or software
14483 breakpoints. Reevaluate the breakpoint and recreate its
14487 breakpoint_re_set_default (struct breakpoint
*b
)
14490 struct symtabs_and_lines sals
, sals_end
;
14491 struct symtabs_and_lines expanded
= {0};
14492 struct symtabs_and_lines expanded_end
= {0};
14493 struct program_space
*filter_pspace
= current_program_space
;
14495 sals
= location_to_sals (b
, b
->location
, filter_pspace
, &found
);
14498 make_cleanup (xfree
, sals
.sals
);
14502 if (b
->location_range_end
!= NULL
)
14504 sals_end
= location_to_sals (b
, b
->location_range_end
,
14505 filter_pspace
, &found
);
14508 make_cleanup (xfree
, sals_end
.sals
);
14509 expanded_end
= sals_end
;
14513 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14516 /* Default method for creating SALs from an address string. It basically
14517 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14520 create_sals_from_location_default (const struct event_location
*location
,
14521 struct linespec_result
*canonical
,
14522 enum bptype type_wanted
)
14524 parse_breakpoint_sals (location
, canonical
);
14527 /* Call create_breakpoints_sal for the given arguments. This is the default
14528 function for the `create_breakpoints_sal' method of
14532 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14533 struct linespec_result
*canonical
,
14535 char *extra_string
,
14536 enum bptype type_wanted
,
14537 enum bpdisp disposition
,
14539 int task
, int ignore_count
,
14540 const struct breakpoint_ops
*ops
,
14541 int from_tty
, int enabled
,
14542 int internal
, unsigned flags
)
14544 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14546 type_wanted
, disposition
,
14547 thread
, task
, ignore_count
, ops
, from_tty
,
14548 enabled
, internal
, flags
);
14551 /* Decode the line represented by S by calling decode_line_full. This is the
14552 default function for the `decode_location' method of breakpoint_ops. */
14555 decode_location_default (struct breakpoint
*b
,
14556 const struct event_location
*location
,
14557 struct program_space
*search_pspace
,
14558 struct symtabs_and_lines
*sals
)
14560 struct linespec_result canonical
;
14562 init_linespec_result (&canonical
);
14563 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14564 (struct symtab
*) NULL
, 0,
14565 &canonical
, multiple_symbols_all
,
14568 /* We should get 0 or 1 resulting SALs. */
14569 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14571 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14573 struct linespec_sals
*lsal
;
14575 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14576 *sals
= lsal
->sals
;
14577 /* Arrange it so the destructor does not free the
14579 lsal
->sals
.sals
= NULL
;
14582 destroy_linespec_result (&canonical
);
14585 /* Prepare the global context for a re-set of breakpoint B. */
14587 static struct cleanup
*
14588 prepare_re_set_context (struct breakpoint
*b
)
14590 input_radix
= b
->input_radix
;
14591 set_language (b
->language
);
14593 return make_cleanup (null_cleanup
, NULL
);
14596 /* Reset a breakpoint given it's struct breakpoint * BINT.
14597 The value we return ends up being the return value from catch_errors.
14598 Unused in this case. */
14601 breakpoint_re_set_one (void *bint
)
14603 /* Get past catch_errs. */
14604 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14605 struct cleanup
*cleanups
;
14607 cleanups
= prepare_re_set_context (b
);
14608 b
->ops
->re_set (b
);
14609 do_cleanups (cleanups
);
14613 /* Re-set breakpoint locations for the current program space.
14614 Locations bound to other program spaces are left untouched. */
14617 breakpoint_re_set (void)
14619 struct breakpoint
*b
, *b_tmp
;
14620 enum language save_language
;
14621 int save_input_radix
;
14622 struct cleanup
*old_chain
;
14624 save_language
= current_language
->la_language
;
14625 save_input_radix
= input_radix
;
14626 old_chain
= save_current_space_and_thread ();
14628 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14630 /* Format possible error msg. */
14631 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14633 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14634 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14635 do_cleanups (cleanups
);
14637 set_language (save_language
);
14638 input_radix
= save_input_radix
;
14640 jit_breakpoint_re_set ();
14642 do_cleanups (old_chain
);
14644 create_overlay_event_breakpoint ();
14645 create_longjmp_master_breakpoint ();
14646 create_std_terminate_master_breakpoint ();
14647 create_exception_master_breakpoint ();
14650 /* Reset the thread number of this breakpoint:
14652 - If the breakpoint is for all threads, leave it as-is.
14653 - Else, reset it to the current thread for inferior_ptid. */
14655 breakpoint_re_set_thread (struct breakpoint
*b
)
14657 if (b
->thread
!= -1)
14659 if (in_thread_list (inferior_ptid
))
14660 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14662 /* We're being called after following a fork. The new fork is
14663 selected as current, and unless this was a vfork will have a
14664 different program space from the original thread. Reset that
14666 b
->loc
->pspace
= current_program_space
;
14670 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14671 If from_tty is nonzero, it prints a message to that effect,
14672 which ends with a period (no newline). */
14675 set_ignore_count (int bptnum
, int count
, int from_tty
)
14677 struct breakpoint
*b
;
14682 ALL_BREAKPOINTS (b
)
14683 if (b
->number
== bptnum
)
14685 if (is_tracepoint (b
))
14687 if (from_tty
&& count
!= 0)
14688 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14693 b
->ignore_count
= count
;
14697 printf_filtered (_("Will stop next time "
14698 "breakpoint %d is reached."),
14700 else if (count
== 1)
14701 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14704 printf_filtered (_("Will ignore next %d "
14705 "crossings of breakpoint %d."),
14708 observer_notify_breakpoint_modified (b
);
14712 error (_("No breakpoint number %d."), bptnum
);
14715 /* Command to set ignore-count of breakpoint N to COUNT. */
14718 ignore_command (char *args
, int from_tty
)
14724 error_no_arg (_("a breakpoint number"));
14726 num
= get_number (&p
);
14728 error (_("bad breakpoint number: '%s'"), args
);
14730 error (_("Second argument (specified ignore-count) is missing."));
14732 set_ignore_count (num
,
14733 longest_to_int (value_as_long (parse_and_eval (p
))),
14736 printf_filtered ("\n");
14739 /* Call FUNCTION on each of the breakpoints
14740 whose numbers are given in ARGS. */
14743 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14748 struct breakpoint
*b
, *tmp
;
14750 struct get_number_or_range_state state
;
14752 if (args
== 0 || *args
== '\0')
14753 error_no_arg (_("one or more breakpoint numbers"));
14755 init_number_or_range (&state
, args
);
14757 while (!state
.finished
)
14759 const char *p
= state
.string
;
14763 num
= get_number_or_range (&state
);
14766 warning (_("bad breakpoint number at or near '%s'"), p
);
14770 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14771 if (b
->number
== num
)
14774 function (b
, data
);
14778 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14783 static struct bp_location
*
14784 find_location_by_number (char *number
)
14786 char *dot
= strchr (number
, '.');
14790 struct breakpoint
*b
;
14791 struct bp_location
*loc
;
14796 bp_num
= get_number (&p1
);
14798 error (_("Bad breakpoint number '%s'"), number
);
14800 ALL_BREAKPOINTS (b
)
14801 if (b
->number
== bp_num
)
14806 if (!b
|| b
->number
!= bp_num
)
14807 error (_("Bad breakpoint number '%s'"), number
);
14810 loc_num
= get_number (&p1
);
14812 error (_("Bad breakpoint location number '%s'"), number
);
14816 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14819 error (_("Bad breakpoint location number '%s'"), dot
+1);
14825 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14826 If from_tty is nonzero, it prints a message to that effect,
14827 which ends with a period (no newline). */
14830 disable_breakpoint (struct breakpoint
*bpt
)
14832 /* Never disable a watchpoint scope breakpoint; we want to
14833 hit them when we leave scope so we can delete both the
14834 watchpoint and its scope breakpoint at that time. */
14835 if (bpt
->type
== bp_watchpoint_scope
)
14838 bpt
->enable_state
= bp_disabled
;
14840 /* Mark breakpoint locations modified. */
14841 mark_breakpoint_modified (bpt
);
14843 if (target_supports_enable_disable_tracepoint ()
14844 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14846 struct bp_location
*location
;
14848 for (location
= bpt
->loc
; location
; location
= location
->next
)
14849 target_disable_tracepoint (location
);
14852 update_global_location_list (UGLL_DONT_INSERT
);
14854 observer_notify_breakpoint_modified (bpt
);
14857 /* A callback for iterate_over_related_breakpoints. */
14860 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14862 disable_breakpoint (b
);
14865 /* A callback for map_breakpoint_numbers that calls
14866 disable_breakpoint. */
14869 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14871 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14875 disable_command (char *args
, int from_tty
)
14879 struct breakpoint
*bpt
;
14881 ALL_BREAKPOINTS (bpt
)
14882 if (user_breakpoint_p (bpt
))
14883 disable_breakpoint (bpt
);
14887 char *num
= extract_arg (&args
);
14891 if (strchr (num
, '.'))
14893 struct bp_location
*loc
= find_location_by_number (num
);
14900 mark_breakpoint_location_modified (loc
);
14902 if (target_supports_enable_disable_tracepoint ()
14903 && current_trace_status ()->running
&& loc
->owner
14904 && is_tracepoint (loc
->owner
))
14905 target_disable_tracepoint (loc
);
14907 update_global_location_list (UGLL_DONT_INSERT
);
14910 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14911 num
= extract_arg (&args
);
14917 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14920 int target_resources_ok
;
14922 if (bpt
->type
== bp_hardware_breakpoint
)
14925 i
= hw_breakpoint_used_count ();
14926 target_resources_ok
=
14927 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14929 if (target_resources_ok
== 0)
14930 error (_("No hardware breakpoint support in the target."));
14931 else if (target_resources_ok
< 0)
14932 error (_("Hardware breakpoints used exceeds limit."));
14935 if (is_watchpoint (bpt
))
14937 /* Initialize it just to avoid a GCC false warning. */
14938 enum enable_state orig_enable_state
= bp_disabled
;
14942 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14944 orig_enable_state
= bpt
->enable_state
;
14945 bpt
->enable_state
= bp_enabled
;
14946 update_watchpoint (w
, 1 /* reparse */);
14948 CATCH (e
, RETURN_MASK_ALL
)
14950 bpt
->enable_state
= orig_enable_state
;
14951 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14958 bpt
->enable_state
= bp_enabled
;
14960 /* Mark breakpoint locations modified. */
14961 mark_breakpoint_modified (bpt
);
14963 if (target_supports_enable_disable_tracepoint ()
14964 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14966 struct bp_location
*location
;
14968 for (location
= bpt
->loc
; location
; location
= location
->next
)
14969 target_enable_tracepoint (location
);
14972 bpt
->disposition
= disposition
;
14973 bpt
->enable_count
= count
;
14974 update_global_location_list (UGLL_MAY_INSERT
);
14976 observer_notify_breakpoint_modified (bpt
);
14981 enable_breakpoint (struct breakpoint
*bpt
)
14983 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14987 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14989 enable_breakpoint (bpt
);
14992 /* A callback for map_breakpoint_numbers that calls
14993 enable_breakpoint. */
14996 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14998 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15001 /* The enable command enables the specified breakpoints (or all defined
15002 breakpoints) so they once again become (or continue to be) effective
15003 in stopping the inferior. */
15006 enable_command (char *args
, int from_tty
)
15010 struct breakpoint
*bpt
;
15012 ALL_BREAKPOINTS (bpt
)
15013 if (user_breakpoint_p (bpt
))
15014 enable_breakpoint (bpt
);
15018 char *num
= extract_arg (&args
);
15022 if (strchr (num
, '.'))
15024 struct bp_location
*loc
= find_location_by_number (num
);
15031 mark_breakpoint_location_modified (loc
);
15033 if (target_supports_enable_disable_tracepoint ()
15034 && current_trace_status ()->running
&& loc
->owner
15035 && is_tracepoint (loc
->owner
))
15036 target_enable_tracepoint (loc
);
15038 update_global_location_list (UGLL_MAY_INSERT
);
15041 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15042 num
= extract_arg (&args
);
15047 /* This struct packages up disposition data for application to multiple
15057 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15059 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15061 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15065 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15067 struct disp_data disp
= { disp_disable
, 1 };
15069 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15073 enable_once_command (char *args
, int from_tty
)
15075 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15079 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15081 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15083 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15087 enable_count_command (char *args
, int from_tty
)
15092 error_no_arg (_("hit count"));
15094 count
= get_number (&args
);
15096 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15100 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15102 struct disp_data disp
= { disp_del
, 1 };
15104 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15108 enable_delete_command (char *args
, int from_tty
)
15110 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15114 set_breakpoint_cmd (char *args
, int from_tty
)
15119 show_breakpoint_cmd (char *args
, int from_tty
)
15123 /* Invalidate last known value of any hardware watchpoint if
15124 the memory which that value represents has been written to by
15128 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15129 CORE_ADDR addr
, ssize_t len
,
15130 const bfd_byte
*data
)
15132 struct breakpoint
*bp
;
15134 ALL_BREAKPOINTS (bp
)
15135 if (bp
->enable_state
== bp_enabled
15136 && bp
->type
== bp_hardware_watchpoint
)
15138 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15140 if (wp
->val_valid
&& wp
->val
)
15142 struct bp_location
*loc
;
15144 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15145 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15146 && loc
->address
+ loc
->length
> addr
15147 && addr
+ len
> loc
->address
)
15149 value_free (wp
->val
);
15157 /* Create and insert a breakpoint for software single step. */
15160 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15161 struct address_space
*aspace
,
15164 struct thread_info
*tp
= inferior_thread ();
15165 struct symtab_and_line sal
;
15166 CORE_ADDR pc
= next_pc
;
15168 if (tp
->control
.single_step_breakpoints
== NULL
)
15170 tp
->control
.single_step_breakpoints
15171 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15174 sal
= find_pc_line (pc
, 0);
15176 sal
.section
= find_pc_overlay (pc
);
15177 sal
.explicit_pc
= 1;
15178 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15180 update_global_location_list (UGLL_INSERT
);
15183 /* See breakpoint.h. */
15186 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15187 struct address_space
*aspace
,
15190 struct bp_location
*loc
;
15192 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15194 && breakpoint_location_address_match (loc
, aspace
, pc
))
15200 /* Check whether a software single-step breakpoint is inserted at
15204 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15207 struct breakpoint
*bpt
;
15209 ALL_BREAKPOINTS (bpt
)
15211 if (bpt
->type
== bp_single_step
15212 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15218 /* Tracepoint-specific operations. */
15220 /* Set tracepoint count to NUM. */
15222 set_tracepoint_count (int num
)
15224 tracepoint_count
= num
;
15225 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15229 trace_command (char *arg
, int from_tty
)
15231 struct breakpoint_ops
*ops
;
15232 struct event_location
*location
;
15233 struct cleanup
*back_to
;
15235 location
= string_to_event_location (&arg
, current_language
);
15236 back_to
= make_cleanup_delete_event_location (location
);
15237 if (location
!= NULL
15238 && event_location_type (location
) == PROBE_LOCATION
)
15239 ops
= &tracepoint_probe_breakpoint_ops
;
15241 ops
= &tracepoint_breakpoint_ops
;
15243 create_breakpoint (get_current_arch (),
15245 NULL
, 0, arg
, 1 /* parse arg */,
15247 bp_tracepoint
/* type_wanted */,
15248 0 /* Ignore count */,
15249 pending_break_support
,
15253 0 /* internal */, 0);
15254 do_cleanups (back_to
);
15258 ftrace_command (char *arg
, int from_tty
)
15260 struct event_location
*location
;
15261 struct cleanup
*back_to
;
15263 location
= string_to_event_location (&arg
, current_language
);
15264 back_to
= make_cleanup_delete_event_location (location
);
15265 create_breakpoint (get_current_arch (),
15267 NULL
, 0, arg
, 1 /* parse arg */,
15269 bp_fast_tracepoint
/* type_wanted */,
15270 0 /* Ignore count */,
15271 pending_break_support
,
15272 &tracepoint_breakpoint_ops
,
15275 0 /* internal */, 0);
15276 do_cleanups (back_to
);
15279 /* strace command implementation. Creates a static tracepoint. */
15282 strace_command (char *arg
, int from_tty
)
15284 struct breakpoint_ops
*ops
;
15285 struct event_location
*location
;
15286 struct cleanup
*back_to
;
15288 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15289 or with a normal static tracepoint. */
15290 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15292 ops
= &strace_marker_breakpoint_ops
;
15293 location
= new_linespec_location (&arg
);
15297 ops
= &tracepoint_breakpoint_ops
;
15298 location
= string_to_event_location (&arg
, current_language
);
15301 back_to
= make_cleanup_delete_event_location (location
);
15302 create_breakpoint (get_current_arch (),
15304 NULL
, 0, arg
, 1 /* parse arg */,
15306 bp_static_tracepoint
/* type_wanted */,
15307 0 /* Ignore count */,
15308 pending_break_support
,
15312 0 /* internal */, 0);
15313 do_cleanups (back_to
);
15316 /* Set up a fake reader function that gets command lines from a linked
15317 list that was acquired during tracepoint uploading. */
15319 static struct uploaded_tp
*this_utp
;
15320 static int next_cmd
;
15323 read_uploaded_action (void)
15327 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15334 /* Given information about a tracepoint as recorded on a target (which
15335 can be either a live system or a trace file), attempt to create an
15336 equivalent GDB tracepoint. This is not a reliable process, since
15337 the target does not necessarily have all the information used when
15338 the tracepoint was originally defined. */
15340 struct tracepoint
*
15341 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15343 char *addr_str
, small_buf
[100];
15344 struct tracepoint
*tp
;
15345 struct event_location
*location
;
15346 struct cleanup
*cleanup
;
15348 if (utp
->at_string
)
15349 addr_str
= utp
->at_string
;
15352 /* In the absence of a source location, fall back to raw
15353 address. Since there is no way to confirm that the address
15354 means the same thing as when the trace was started, warn the
15356 warning (_("Uploaded tracepoint %d has no "
15357 "source location, using raw address"),
15359 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15360 addr_str
= small_buf
;
15363 /* There's not much we can do with a sequence of bytecodes. */
15364 if (utp
->cond
&& !utp
->cond_string
)
15365 warning (_("Uploaded tracepoint %d condition "
15366 "has no source form, ignoring it"),
15369 location
= string_to_event_location (&addr_str
, current_language
);
15370 cleanup
= make_cleanup_delete_event_location (location
);
15371 if (!create_breakpoint (get_current_arch (),
15373 utp
->cond_string
, -1, addr_str
,
15374 0 /* parse cond/thread */,
15376 utp
->type
/* type_wanted */,
15377 0 /* Ignore count */,
15378 pending_break_support
,
15379 &tracepoint_breakpoint_ops
,
15381 utp
->enabled
/* enabled */,
15383 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15385 do_cleanups (cleanup
);
15389 do_cleanups (cleanup
);
15391 /* Get the tracepoint we just created. */
15392 tp
= get_tracepoint (tracepoint_count
);
15393 gdb_assert (tp
!= NULL
);
15397 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15400 trace_pass_command (small_buf
, 0);
15403 /* If we have uploaded versions of the original commands, set up a
15404 special-purpose "reader" function and call the usual command line
15405 reader, then pass the result to the breakpoint command-setting
15407 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15409 struct command_line
*cmd_list
;
15414 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15416 breakpoint_set_commands (&tp
->base
, cmd_list
);
15418 else if (!VEC_empty (char_ptr
, utp
->actions
)
15419 || !VEC_empty (char_ptr
, utp
->step_actions
))
15420 warning (_("Uploaded tracepoint %d actions "
15421 "have no source form, ignoring them"),
15424 /* Copy any status information that might be available. */
15425 tp
->base
.hit_count
= utp
->hit_count
;
15426 tp
->traceframe_usage
= utp
->traceframe_usage
;
15431 /* Print information on tracepoint number TPNUM_EXP, or all if
15435 tracepoints_info (char *args
, int from_tty
)
15437 struct ui_out
*uiout
= current_uiout
;
15440 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15442 if (num_printed
== 0)
15444 if (args
== NULL
|| *args
== '\0')
15445 ui_out_message (uiout
, 0, "No tracepoints.\n");
15447 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15450 default_collect_info ();
15453 /* The 'enable trace' command enables tracepoints.
15454 Not supported by all targets. */
15456 enable_trace_command (char *args
, int from_tty
)
15458 enable_command (args
, from_tty
);
15461 /* The 'disable trace' command disables tracepoints.
15462 Not supported by all targets. */
15464 disable_trace_command (char *args
, int from_tty
)
15466 disable_command (args
, from_tty
);
15469 /* Remove a tracepoint (or all if no argument). */
15471 delete_trace_command (char *arg
, int from_tty
)
15473 struct breakpoint
*b
, *b_tmp
;
15479 int breaks_to_delete
= 0;
15481 /* Delete all breakpoints if no argument.
15482 Do not delete internal or call-dummy breakpoints, these
15483 have to be deleted with an explicit breakpoint number
15485 ALL_TRACEPOINTS (b
)
15486 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15488 breaks_to_delete
= 1;
15492 /* Ask user only if there are some breakpoints to delete. */
15494 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15496 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15497 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15498 delete_breakpoint (b
);
15502 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15505 /* Helper function for trace_pass_command. */
15508 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15510 tp
->pass_count
= count
;
15511 observer_notify_breakpoint_modified (&tp
->base
);
15513 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15514 tp
->base
.number
, count
);
15517 /* Set passcount for tracepoint.
15519 First command argument is passcount, second is tracepoint number.
15520 If tracepoint number omitted, apply to most recently defined.
15521 Also accepts special argument "all". */
15524 trace_pass_command (char *args
, int from_tty
)
15526 struct tracepoint
*t1
;
15527 unsigned int count
;
15529 if (args
== 0 || *args
== 0)
15530 error (_("passcount command requires an "
15531 "argument (count + optional TP num)"));
15533 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15535 args
= skip_spaces (args
);
15536 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15538 struct breakpoint
*b
;
15540 args
+= 3; /* Skip special argument "all". */
15542 error (_("Junk at end of arguments."));
15544 ALL_TRACEPOINTS (b
)
15546 t1
= (struct tracepoint
*) b
;
15547 trace_pass_set_count (t1
, count
, from_tty
);
15550 else if (*args
== '\0')
15552 t1
= get_tracepoint_by_number (&args
, NULL
);
15554 trace_pass_set_count (t1
, count
, from_tty
);
15558 struct get_number_or_range_state state
;
15560 init_number_or_range (&state
, args
);
15561 while (!state
.finished
)
15563 t1
= get_tracepoint_by_number (&args
, &state
);
15565 trace_pass_set_count (t1
, count
, from_tty
);
15570 struct tracepoint
*
15571 get_tracepoint (int num
)
15573 struct breakpoint
*t
;
15575 ALL_TRACEPOINTS (t
)
15576 if (t
->number
== num
)
15577 return (struct tracepoint
*) t
;
15582 /* Find the tracepoint with the given target-side number (which may be
15583 different from the tracepoint number after disconnecting and
15586 struct tracepoint
*
15587 get_tracepoint_by_number_on_target (int num
)
15589 struct breakpoint
*b
;
15591 ALL_TRACEPOINTS (b
)
15593 struct tracepoint
*t
= (struct tracepoint
*) b
;
15595 if (t
->number_on_target
== num
)
15602 /* Utility: parse a tracepoint number and look it up in the list.
15603 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15604 If the argument is missing, the most recent tracepoint
15605 (tracepoint_count) is returned. */
15607 struct tracepoint
*
15608 get_tracepoint_by_number (char **arg
,
15609 struct get_number_or_range_state
*state
)
15611 struct breakpoint
*t
;
15613 char *instring
= arg
== NULL
? NULL
: *arg
;
15617 gdb_assert (!state
->finished
);
15618 tpnum
= get_number_or_range (state
);
15620 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15621 tpnum
= tracepoint_count
;
15623 tpnum
= get_number (arg
);
15627 if (instring
&& *instring
)
15628 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15631 printf_filtered (_("No previous tracepoint\n"));
15635 ALL_TRACEPOINTS (t
)
15636 if (t
->number
== tpnum
)
15638 return (struct tracepoint
*) t
;
15641 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15646 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15648 if (b
->thread
!= -1)
15649 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15652 fprintf_unfiltered (fp
, " task %d", b
->task
);
15654 fprintf_unfiltered (fp
, "\n");
15657 /* Save information on user settable breakpoints (watchpoints, etc) to
15658 a new script file named FILENAME. If FILTER is non-NULL, call it
15659 on each breakpoint and only include the ones for which it returns
15663 save_breakpoints (char *filename
, int from_tty
,
15664 int (*filter
) (const struct breakpoint
*))
15666 struct breakpoint
*tp
;
15668 struct cleanup
*cleanup
;
15669 struct ui_file
*fp
;
15670 int extra_trace_bits
= 0;
15672 if (filename
== 0 || *filename
== 0)
15673 error (_("Argument required (file name in which to save)"));
15675 /* See if we have anything to save. */
15676 ALL_BREAKPOINTS (tp
)
15678 /* Skip internal and momentary breakpoints. */
15679 if (!user_breakpoint_p (tp
))
15682 /* If we have a filter, only save the breakpoints it accepts. */
15683 if (filter
&& !filter (tp
))
15688 if (is_tracepoint (tp
))
15690 extra_trace_bits
= 1;
15692 /* We can stop searching. */
15699 warning (_("Nothing to save."));
15703 filename
= tilde_expand (filename
);
15704 cleanup
= make_cleanup (xfree
, filename
);
15705 fp
= gdb_fopen (filename
, "w");
15707 error (_("Unable to open file '%s' for saving (%s)"),
15708 filename
, safe_strerror (errno
));
15709 make_cleanup_ui_file_delete (fp
);
15711 if (extra_trace_bits
)
15712 save_trace_state_variables (fp
);
15714 ALL_BREAKPOINTS (tp
)
15716 /* Skip internal and momentary breakpoints. */
15717 if (!user_breakpoint_p (tp
))
15720 /* If we have a filter, only save the breakpoints it accepts. */
15721 if (filter
&& !filter (tp
))
15724 tp
->ops
->print_recreate (tp
, fp
);
15726 /* Note, we can't rely on tp->number for anything, as we can't
15727 assume the recreated breakpoint numbers will match. Use $bpnum
15730 if (tp
->cond_string
)
15731 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15733 if (tp
->ignore_count
)
15734 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15736 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15738 struct gdb_exception exception
;
15740 fprintf_unfiltered (fp
, " commands\n");
15742 ui_out_redirect (current_uiout
, fp
);
15745 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15747 CATCH (ex
, RETURN_MASK_ALL
)
15749 ui_out_redirect (current_uiout
, NULL
);
15750 throw_exception (ex
);
15754 ui_out_redirect (current_uiout
, NULL
);
15755 fprintf_unfiltered (fp
, " end\n");
15758 if (tp
->enable_state
== bp_disabled
)
15759 fprintf_unfiltered (fp
, "disable $bpnum\n");
15761 /* If this is a multi-location breakpoint, check if the locations
15762 should be individually disabled. Watchpoint locations are
15763 special, and not user visible. */
15764 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15766 struct bp_location
*loc
;
15769 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15771 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15775 if (extra_trace_bits
&& *default_collect
)
15776 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15779 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15780 do_cleanups (cleanup
);
15783 /* The `save breakpoints' command. */
15786 save_breakpoints_command (char *args
, int from_tty
)
15788 save_breakpoints (args
, from_tty
, NULL
);
15791 /* The `save tracepoints' command. */
15794 save_tracepoints_command (char *args
, int from_tty
)
15796 save_breakpoints (args
, from_tty
, is_tracepoint
);
15799 /* Create a vector of all tracepoints. */
15801 VEC(breakpoint_p
) *
15802 all_tracepoints (void)
15804 VEC(breakpoint_p
) *tp_vec
= 0;
15805 struct breakpoint
*tp
;
15807 ALL_TRACEPOINTS (tp
)
15809 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15816 /* This help string is used to consolidate all the help string for specifying
15817 locations used by several commands. */
15819 #define LOCATION_HELP_STRING \
15820 "Linespecs are colon-separated lists of location parameters, such as\n\
15821 source filename, function name, label name, and line number.\n\
15822 Example: To specify the start of a label named \"the_top\" in the\n\
15823 function \"fact\" in the file \"factorial.c\", use\n\
15824 \"factorial.c:fact:the_top\".\n\
15826 Address locations begin with \"*\" and specify an exact address in the\n\
15827 program. Example: To specify the fourth byte past the start function\n\
15828 \"main\", use \"*main + 4\".\n\
15830 Explicit locations are similar to linespecs but use an option/argument\n\
15831 syntax to specify location parameters.\n\
15832 Example: To specify the start of the label named \"the_top\" in the\n\
15833 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15834 -function fact -label the_top\".\n"
15836 /* This help string is used for the break, hbreak, tbreak and thbreak
15837 commands. It is defined as a macro to prevent duplication.
15838 COMMAND should be a string constant containing the name of the
15841 #define BREAK_ARGS_HELP(command) \
15842 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15843 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15844 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15845 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15846 `-probe-dtrace' (for a DTrace probe).\n\
15847 LOCATION may be a linespec, address, or explicit location as described\n\
15850 With no LOCATION, uses current execution address of the selected\n\
15851 stack frame. This is useful for breaking on return to a stack frame.\n\
15853 THREADNUM is the number from \"info threads\".\n\
15854 CONDITION is a boolean expression.\n\
15855 \n" LOCATION_HELP_STRING "\n\
15856 Multiple breakpoints at one place are permitted, and useful if their\n\
15857 conditions are different.\n\
15859 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15861 /* List of subcommands for "catch". */
15862 static struct cmd_list_element
*catch_cmdlist
;
15864 /* List of subcommands for "tcatch". */
15865 static struct cmd_list_element
*tcatch_cmdlist
;
15868 add_catch_command (char *name
, char *docstring
,
15869 cmd_sfunc_ftype
*sfunc
,
15870 completer_ftype
*completer
,
15871 void *user_data_catch
,
15872 void *user_data_tcatch
)
15874 struct cmd_list_element
*command
;
15876 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15878 set_cmd_sfunc (command
, sfunc
);
15879 set_cmd_context (command
, user_data_catch
);
15880 set_cmd_completer (command
, completer
);
15882 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15884 set_cmd_sfunc (command
, sfunc
);
15885 set_cmd_context (command
, user_data_tcatch
);
15886 set_cmd_completer (command
, completer
);
15890 save_command (char *arg
, int from_tty
)
15892 printf_unfiltered (_("\"save\" must be followed by "
15893 "the name of a save subcommand.\n"));
15894 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15897 struct breakpoint
*
15898 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15901 struct breakpoint
*b
, *b_tmp
;
15903 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15905 if ((*callback
) (b
, data
))
15912 /* Zero if any of the breakpoint's locations could be a location where
15913 functions have been inlined, nonzero otherwise. */
15916 is_non_inline_function (struct breakpoint
*b
)
15918 /* The shared library event breakpoint is set on the address of a
15919 non-inline function. */
15920 if (b
->type
== bp_shlib_event
)
15926 /* Nonzero if the specified PC cannot be a location where functions
15927 have been inlined. */
15930 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15931 const struct target_waitstatus
*ws
)
15933 struct breakpoint
*b
;
15934 struct bp_location
*bl
;
15936 ALL_BREAKPOINTS (b
)
15938 if (!is_non_inline_function (b
))
15941 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15943 if (!bl
->shlib_disabled
15944 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15952 /* Remove any references to OBJFILE which is going to be freed. */
15955 breakpoint_free_objfile (struct objfile
*objfile
)
15957 struct bp_location
**locp
, *loc
;
15959 ALL_BP_LOCATIONS (loc
, locp
)
15960 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15961 loc
->symtab
= NULL
;
15965 initialize_breakpoint_ops (void)
15967 static int initialized
= 0;
15969 struct breakpoint_ops
*ops
;
15975 /* The breakpoint_ops structure to be inherit by all kinds of
15976 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15977 internal and momentary breakpoints, etc.). */
15978 ops
= &bkpt_base_breakpoint_ops
;
15979 *ops
= base_breakpoint_ops
;
15980 ops
->re_set
= bkpt_re_set
;
15981 ops
->insert_location
= bkpt_insert_location
;
15982 ops
->remove_location
= bkpt_remove_location
;
15983 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15984 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15985 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15986 ops
->decode_location
= bkpt_decode_location
;
15988 /* The breakpoint_ops structure to be used in regular breakpoints. */
15989 ops
= &bkpt_breakpoint_ops
;
15990 *ops
= bkpt_base_breakpoint_ops
;
15991 ops
->re_set
= bkpt_re_set
;
15992 ops
->resources_needed
= bkpt_resources_needed
;
15993 ops
->print_it
= bkpt_print_it
;
15994 ops
->print_mention
= bkpt_print_mention
;
15995 ops
->print_recreate
= bkpt_print_recreate
;
15997 /* Ranged breakpoints. */
15998 ops
= &ranged_breakpoint_ops
;
15999 *ops
= bkpt_breakpoint_ops
;
16000 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16001 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16002 ops
->print_it
= print_it_ranged_breakpoint
;
16003 ops
->print_one
= print_one_ranged_breakpoint
;
16004 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16005 ops
->print_mention
= print_mention_ranged_breakpoint
;
16006 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16008 /* Internal breakpoints. */
16009 ops
= &internal_breakpoint_ops
;
16010 *ops
= bkpt_base_breakpoint_ops
;
16011 ops
->re_set
= internal_bkpt_re_set
;
16012 ops
->check_status
= internal_bkpt_check_status
;
16013 ops
->print_it
= internal_bkpt_print_it
;
16014 ops
->print_mention
= internal_bkpt_print_mention
;
16016 /* Momentary breakpoints. */
16017 ops
= &momentary_breakpoint_ops
;
16018 *ops
= bkpt_base_breakpoint_ops
;
16019 ops
->re_set
= momentary_bkpt_re_set
;
16020 ops
->check_status
= momentary_bkpt_check_status
;
16021 ops
->print_it
= momentary_bkpt_print_it
;
16022 ops
->print_mention
= momentary_bkpt_print_mention
;
16024 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16025 ops
= &longjmp_breakpoint_ops
;
16026 *ops
= momentary_breakpoint_ops
;
16027 ops
->dtor
= longjmp_bkpt_dtor
;
16029 /* Probe breakpoints. */
16030 ops
= &bkpt_probe_breakpoint_ops
;
16031 *ops
= bkpt_breakpoint_ops
;
16032 ops
->insert_location
= bkpt_probe_insert_location
;
16033 ops
->remove_location
= bkpt_probe_remove_location
;
16034 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
16035 ops
->decode_location
= bkpt_probe_decode_location
;
16038 ops
= &watchpoint_breakpoint_ops
;
16039 *ops
= base_breakpoint_ops
;
16040 ops
->dtor
= dtor_watchpoint
;
16041 ops
->re_set
= re_set_watchpoint
;
16042 ops
->insert_location
= insert_watchpoint
;
16043 ops
->remove_location
= remove_watchpoint
;
16044 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16045 ops
->check_status
= check_status_watchpoint
;
16046 ops
->resources_needed
= resources_needed_watchpoint
;
16047 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16048 ops
->print_it
= print_it_watchpoint
;
16049 ops
->print_mention
= print_mention_watchpoint
;
16050 ops
->print_recreate
= print_recreate_watchpoint
;
16051 ops
->explains_signal
= explains_signal_watchpoint
;
16053 /* Masked watchpoints. */
16054 ops
= &masked_watchpoint_breakpoint_ops
;
16055 *ops
= watchpoint_breakpoint_ops
;
16056 ops
->insert_location
= insert_masked_watchpoint
;
16057 ops
->remove_location
= remove_masked_watchpoint
;
16058 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16059 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16060 ops
->print_it
= print_it_masked_watchpoint
;
16061 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16062 ops
->print_mention
= print_mention_masked_watchpoint
;
16063 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16066 ops
= &tracepoint_breakpoint_ops
;
16067 *ops
= base_breakpoint_ops
;
16068 ops
->re_set
= tracepoint_re_set
;
16069 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16070 ops
->print_one_detail
= tracepoint_print_one_detail
;
16071 ops
->print_mention
= tracepoint_print_mention
;
16072 ops
->print_recreate
= tracepoint_print_recreate
;
16073 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
16074 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16075 ops
->decode_location
= tracepoint_decode_location
;
16077 /* Probe tracepoints. */
16078 ops
= &tracepoint_probe_breakpoint_ops
;
16079 *ops
= tracepoint_breakpoint_ops
;
16080 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
16081 ops
->decode_location
= tracepoint_probe_decode_location
;
16083 /* Static tracepoints with marker (`-m'). */
16084 ops
= &strace_marker_breakpoint_ops
;
16085 *ops
= tracepoint_breakpoint_ops
;
16086 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16087 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16088 ops
->decode_location
= strace_marker_decode_location
;
16090 /* Fork catchpoints. */
16091 ops
= &catch_fork_breakpoint_ops
;
16092 *ops
= base_breakpoint_ops
;
16093 ops
->insert_location
= insert_catch_fork
;
16094 ops
->remove_location
= remove_catch_fork
;
16095 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16096 ops
->print_it
= print_it_catch_fork
;
16097 ops
->print_one
= print_one_catch_fork
;
16098 ops
->print_mention
= print_mention_catch_fork
;
16099 ops
->print_recreate
= print_recreate_catch_fork
;
16101 /* Vfork catchpoints. */
16102 ops
= &catch_vfork_breakpoint_ops
;
16103 *ops
= base_breakpoint_ops
;
16104 ops
->insert_location
= insert_catch_vfork
;
16105 ops
->remove_location
= remove_catch_vfork
;
16106 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16107 ops
->print_it
= print_it_catch_vfork
;
16108 ops
->print_one
= print_one_catch_vfork
;
16109 ops
->print_mention
= print_mention_catch_vfork
;
16110 ops
->print_recreate
= print_recreate_catch_vfork
;
16112 /* Exec catchpoints. */
16113 ops
= &catch_exec_breakpoint_ops
;
16114 *ops
= base_breakpoint_ops
;
16115 ops
->dtor
= dtor_catch_exec
;
16116 ops
->insert_location
= insert_catch_exec
;
16117 ops
->remove_location
= remove_catch_exec
;
16118 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16119 ops
->print_it
= print_it_catch_exec
;
16120 ops
->print_one
= print_one_catch_exec
;
16121 ops
->print_mention
= print_mention_catch_exec
;
16122 ops
->print_recreate
= print_recreate_catch_exec
;
16124 /* Solib-related catchpoints. */
16125 ops
= &catch_solib_breakpoint_ops
;
16126 *ops
= base_breakpoint_ops
;
16127 ops
->dtor
= dtor_catch_solib
;
16128 ops
->insert_location
= insert_catch_solib
;
16129 ops
->remove_location
= remove_catch_solib
;
16130 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16131 ops
->check_status
= check_status_catch_solib
;
16132 ops
->print_it
= print_it_catch_solib
;
16133 ops
->print_one
= print_one_catch_solib
;
16134 ops
->print_mention
= print_mention_catch_solib
;
16135 ops
->print_recreate
= print_recreate_catch_solib
;
16137 ops
= &dprintf_breakpoint_ops
;
16138 *ops
= bkpt_base_breakpoint_ops
;
16139 ops
->re_set
= dprintf_re_set
;
16140 ops
->resources_needed
= bkpt_resources_needed
;
16141 ops
->print_it
= bkpt_print_it
;
16142 ops
->print_mention
= bkpt_print_mention
;
16143 ops
->print_recreate
= dprintf_print_recreate
;
16144 ops
->after_condition_true
= dprintf_after_condition_true
;
16145 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16148 /* Chain containing all defined "enable breakpoint" subcommands. */
16150 static struct cmd_list_element
*enablebreaklist
= NULL
;
16153 _initialize_breakpoint (void)
16155 struct cmd_list_element
*c
;
16157 initialize_breakpoint_ops ();
16159 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16160 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16161 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16163 breakpoint_objfile_key
16164 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16166 breakpoint_chain
= 0;
16167 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16168 before a breakpoint is set. */
16169 breakpoint_count
= 0;
16171 tracepoint_count
= 0;
16173 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16174 Set ignore-count of breakpoint number N to COUNT.\n\
16175 Usage is `ignore N COUNT'."));
16177 add_com ("commands", class_breakpoint
, commands_command
, _("\
16178 Set commands to be executed when a breakpoint is hit.\n\
16179 Give breakpoint number as argument after \"commands\".\n\
16180 With no argument, the targeted breakpoint is the last one set.\n\
16181 The commands themselves follow starting on the next line.\n\
16182 Type a line containing \"end\" to indicate the end of them.\n\
16183 Give \"silent\" as the first line to make the breakpoint silent;\n\
16184 then no output is printed when it is hit, except what the commands print."));
16186 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16187 Specify breakpoint number N to break only if COND is true.\n\
16188 Usage is `condition N COND', where N is an integer and COND is an\n\
16189 expression to be evaluated whenever breakpoint N is reached."));
16190 set_cmd_completer (c
, condition_completer
);
16192 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16193 Set a temporary breakpoint.\n\
16194 Like \"break\" except the breakpoint is only temporary,\n\
16195 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16196 by using \"enable delete\" on the breakpoint number.\n\
16198 BREAK_ARGS_HELP ("tbreak")));
16199 set_cmd_completer (c
, location_completer
);
16201 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16202 Set a hardware assisted breakpoint.\n\
16203 Like \"break\" except the breakpoint requires hardware support,\n\
16204 some target hardware may not have this support.\n\
16206 BREAK_ARGS_HELP ("hbreak")));
16207 set_cmd_completer (c
, location_completer
);
16209 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16210 Set a temporary hardware assisted breakpoint.\n\
16211 Like \"hbreak\" except the breakpoint is only temporary,\n\
16212 so it will be deleted when hit.\n\
16214 BREAK_ARGS_HELP ("thbreak")));
16215 set_cmd_completer (c
, location_completer
);
16217 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16218 Enable some breakpoints.\n\
16219 Give breakpoint numbers (separated by spaces) as arguments.\n\
16220 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16221 This is used to cancel the effect of the \"disable\" command.\n\
16222 With a subcommand you can enable temporarily."),
16223 &enablelist
, "enable ", 1, &cmdlist
);
16225 add_com_alias ("en", "enable", class_breakpoint
, 1);
16227 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16228 Enable some breakpoints.\n\
16229 Give breakpoint numbers (separated by spaces) as arguments.\n\
16230 This is used to cancel the effect of the \"disable\" command.\n\
16231 May be abbreviated to simply \"enable\".\n"),
16232 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16234 add_cmd ("once", no_class
, enable_once_command
, _("\
16235 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16236 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16239 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16240 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16241 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16244 add_cmd ("count", no_class
, enable_count_command
, _("\
16245 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16246 If a breakpoint is hit while enabled in this fashion,\n\
16247 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16250 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16251 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16252 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16255 add_cmd ("once", no_class
, enable_once_command
, _("\
16256 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16257 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16260 add_cmd ("count", no_class
, enable_count_command
, _("\
16261 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16262 If a breakpoint is hit while enabled in this fashion,\n\
16263 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16266 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16267 Disable some breakpoints.\n\
16268 Arguments are breakpoint numbers with spaces in between.\n\
16269 To disable all breakpoints, give no argument.\n\
16270 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16271 &disablelist
, "disable ", 1, &cmdlist
);
16272 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16273 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16275 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16276 Disable some breakpoints.\n\
16277 Arguments are breakpoint numbers with spaces in between.\n\
16278 To disable all breakpoints, give no argument.\n\
16279 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16280 This command may be abbreviated \"disable\"."),
16283 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16284 Delete some breakpoints or auto-display expressions.\n\
16285 Arguments are breakpoint numbers with spaces in between.\n\
16286 To delete all breakpoints, give no argument.\n\
16288 Also a prefix command for deletion of other GDB objects.\n\
16289 The \"unset\" command is also an alias for \"delete\"."),
16290 &deletelist
, "delete ", 1, &cmdlist
);
16291 add_com_alias ("d", "delete", class_breakpoint
, 1);
16292 add_com_alias ("del", "delete", class_breakpoint
, 1);
16294 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16295 Delete some breakpoints or auto-display expressions.\n\
16296 Arguments are breakpoint numbers with spaces in between.\n\
16297 To delete all breakpoints, give no argument.\n\
16298 This command may be abbreviated \"delete\"."),
16301 add_com ("clear", class_breakpoint
, clear_command
, _("\
16302 Clear breakpoint at specified location.\n\
16303 Argument may be a linespec, explicit, or address location as described below.\n\
16305 With no argument, clears all breakpoints in the line that the selected frame\n\
16306 is executing in.\n"
16307 "\n" LOCATION_HELP_STRING
"\n\
16308 See also the \"delete\" command which clears breakpoints by number."));
16309 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16311 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16312 Set breakpoint at specified location.\n"
16313 BREAK_ARGS_HELP ("break")));
16314 set_cmd_completer (c
, location_completer
);
16316 add_com_alias ("b", "break", class_run
, 1);
16317 add_com_alias ("br", "break", class_run
, 1);
16318 add_com_alias ("bre", "break", class_run
, 1);
16319 add_com_alias ("brea", "break", class_run
, 1);
16323 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16324 Break in function/address or break at a line in the current file."),
16325 &stoplist
, "stop ", 1, &cmdlist
);
16326 add_cmd ("in", class_breakpoint
, stopin_command
,
16327 _("Break in function or address."), &stoplist
);
16328 add_cmd ("at", class_breakpoint
, stopat_command
,
16329 _("Break at a line in the current file."), &stoplist
);
16330 add_com ("status", class_info
, breakpoints_info
, _("\
16331 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16332 The \"Type\" column indicates one of:\n\
16333 \tbreakpoint - normal breakpoint\n\
16334 \twatchpoint - watchpoint\n\
16335 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16336 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16337 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16338 address and file/line number respectively.\n\
16340 Convenience variable \"$_\" and default examine address for \"x\"\n\
16341 are set to the address of the last breakpoint listed unless the command\n\
16342 is prefixed with \"server \".\n\n\
16343 Convenience variable \"$bpnum\" contains the number of the last\n\
16344 breakpoint set."));
16347 add_info ("breakpoints", breakpoints_info
, _("\
16348 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16349 The \"Type\" column indicates one of:\n\
16350 \tbreakpoint - normal breakpoint\n\
16351 \twatchpoint - watchpoint\n\
16352 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16353 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16354 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16355 address and file/line number respectively.\n\
16357 Convenience variable \"$_\" and default examine address for \"x\"\n\
16358 are set to the address of the last breakpoint listed unless the command\n\
16359 is prefixed with \"server \".\n\n\
16360 Convenience variable \"$bpnum\" contains the number of the last\n\
16361 breakpoint set."));
16363 add_info_alias ("b", "breakpoints", 1);
16365 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16366 Status of all breakpoints, or breakpoint number NUMBER.\n\
16367 The \"Type\" column indicates one of:\n\
16368 \tbreakpoint - normal breakpoint\n\
16369 \twatchpoint - watchpoint\n\
16370 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16371 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16372 \tuntil - internal breakpoint used by the \"until\" command\n\
16373 \tfinish - internal breakpoint used by the \"finish\" command\n\
16374 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16375 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16376 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16377 address and file/line number respectively.\n\
16379 Convenience variable \"$_\" and default examine address for \"x\"\n\
16380 are set to the address of the last breakpoint listed unless the command\n\
16381 is prefixed with \"server \".\n\n\
16382 Convenience variable \"$bpnum\" contains the number of the last\n\
16384 &maintenanceinfolist
);
16386 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16387 Set catchpoints to catch events."),
16388 &catch_cmdlist
, "catch ",
16389 0/*allow-unknown*/, &cmdlist
);
16391 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16392 Set temporary catchpoints to catch events."),
16393 &tcatch_cmdlist
, "tcatch ",
16394 0/*allow-unknown*/, &cmdlist
);
16396 add_catch_command ("fork", _("Catch calls to fork."),
16397 catch_fork_command_1
,
16399 (void *) (uintptr_t) catch_fork_permanent
,
16400 (void *) (uintptr_t) catch_fork_temporary
);
16401 add_catch_command ("vfork", _("Catch calls to vfork."),
16402 catch_fork_command_1
,
16404 (void *) (uintptr_t) catch_vfork_permanent
,
16405 (void *) (uintptr_t) catch_vfork_temporary
);
16406 add_catch_command ("exec", _("Catch calls to exec."),
16407 catch_exec_command_1
,
16411 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16412 Usage: catch load [REGEX]\n\
16413 If REGEX is given, only stop for libraries matching the regular expression."),
16414 catch_load_command_1
,
16418 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16419 Usage: catch unload [REGEX]\n\
16420 If REGEX is given, only stop for libraries matching the regular expression."),
16421 catch_unload_command_1
,
16426 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16427 Set a watchpoint for an expression.\n\
16428 Usage: watch [-l|-location] EXPRESSION\n\
16429 A watchpoint stops execution of your program whenever the value of\n\
16430 an expression changes.\n\
16431 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16432 the memory to which it refers."));
16433 set_cmd_completer (c
, expression_completer
);
16435 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16436 Set a read watchpoint for an expression.\n\
16437 Usage: rwatch [-l|-location] EXPRESSION\n\
16438 A watchpoint stops execution of your program whenever the value of\n\
16439 an expression is read.\n\
16440 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16441 the memory to which it refers."));
16442 set_cmd_completer (c
, expression_completer
);
16444 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16445 Set a watchpoint for an expression.\n\
16446 Usage: awatch [-l|-location] EXPRESSION\n\
16447 A watchpoint stops execution of your program whenever the value of\n\
16448 an expression is either read or written.\n\
16449 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16450 the memory to which it refers."));
16451 set_cmd_completer (c
, expression_completer
);
16453 add_info ("watchpoints", watchpoints_info
, _("\
16454 Status of specified watchpoints (all watchpoints if no argument)."));
16456 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16457 respond to changes - contrary to the description. */
16458 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16459 &can_use_hw_watchpoints
, _("\
16460 Set debugger's willingness to use watchpoint hardware."), _("\
16461 Show debugger's willingness to use watchpoint hardware."), _("\
16462 If zero, gdb will not use hardware for new watchpoints, even if\n\
16463 such is available. (However, any hardware watchpoints that were\n\
16464 created before setting this to nonzero, will continue to use watchpoint\n\
16467 show_can_use_hw_watchpoints
,
16468 &setlist
, &showlist
);
16470 can_use_hw_watchpoints
= 1;
16472 /* Tracepoint manipulation commands. */
16474 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16475 Set a tracepoint at specified location.\n\
16477 BREAK_ARGS_HELP ("trace") "\n\
16478 Do \"help tracepoints\" for info on other tracepoint commands."));
16479 set_cmd_completer (c
, location_completer
);
16481 add_com_alias ("tp", "trace", class_alias
, 0);
16482 add_com_alias ("tr", "trace", class_alias
, 1);
16483 add_com_alias ("tra", "trace", class_alias
, 1);
16484 add_com_alias ("trac", "trace", class_alias
, 1);
16486 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16487 Set a fast tracepoint at specified location.\n\
16489 BREAK_ARGS_HELP ("ftrace") "\n\
16490 Do \"help tracepoints\" for info on other tracepoint commands."));
16491 set_cmd_completer (c
, location_completer
);
16493 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16494 Set a static tracepoint at location or marker.\n\
16496 strace [LOCATION] [if CONDITION]\n\
16497 LOCATION may be a linespec, explicit, or address location (described below) \n\
16498 or -m MARKER_ID.\n\n\
16499 If a marker id is specified, probe the marker with that name. With\n\
16500 no LOCATION, uses current execution address of the selected stack frame.\n\
16501 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16502 This collects arbitrary user data passed in the probe point call to the\n\
16503 tracing library. You can inspect it when analyzing the trace buffer,\n\
16504 by printing the $_sdata variable like any other convenience variable.\n\
16506 CONDITION is a boolean expression.\n\
16507 \n" LOCATION_HELP_STRING
"\n\
16508 Multiple tracepoints at one place are permitted, and useful if their\n\
16509 conditions are different.\n\
16511 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16512 Do \"help tracepoints\" for info on other tracepoint commands."));
16513 set_cmd_completer (c
, location_completer
);
16515 add_info ("tracepoints", tracepoints_info
, _("\
16516 Status of specified tracepoints (all tracepoints if no argument).\n\
16517 Convenience variable \"$tpnum\" contains the number of the\n\
16518 last tracepoint set."));
16520 add_info_alias ("tp", "tracepoints", 1);
16522 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16523 Delete specified tracepoints.\n\
16524 Arguments are tracepoint numbers, separated by spaces.\n\
16525 No argument means delete all tracepoints."),
16527 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16529 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16530 Disable specified tracepoints.\n\
16531 Arguments are tracepoint numbers, separated by spaces.\n\
16532 No argument means disable all tracepoints."),
16534 deprecate_cmd (c
, "disable");
16536 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16537 Enable specified tracepoints.\n\
16538 Arguments are tracepoint numbers, separated by spaces.\n\
16539 No argument means enable all tracepoints."),
16541 deprecate_cmd (c
, "enable");
16543 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16544 Set the passcount for a tracepoint.\n\
16545 The trace will end when the tracepoint has been passed 'count' times.\n\
16546 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16547 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16549 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16550 _("Save breakpoint definitions as a script."),
16551 &save_cmdlist
, "save ",
16552 0/*allow-unknown*/, &cmdlist
);
16554 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16555 Save current breakpoint definitions as a script.\n\
16556 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16557 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16558 session to restore them."),
16560 set_cmd_completer (c
, filename_completer
);
16562 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16563 Save current tracepoint definitions as a script.\n\
16564 Use the 'source' command in another debug session to restore them."),
16566 set_cmd_completer (c
, filename_completer
);
16568 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16569 deprecate_cmd (c
, "save tracepoints");
16571 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16572 Breakpoint specific settings\n\
16573 Configure various breakpoint-specific variables such as\n\
16574 pending breakpoint behavior"),
16575 &breakpoint_set_cmdlist
, "set breakpoint ",
16576 0/*allow-unknown*/, &setlist
);
16577 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16578 Breakpoint specific settings\n\
16579 Configure various breakpoint-specific variables such as\n\
16580 pending breakpoint behavior"),
16581 &breakpoint_show_cmdlist
, "show breakpoint ",
16582 0/*allow-unknown*/, &showlist
);
16584 add_setshow_auto_boolean_cmd ("pending", no_class
,
16585 &pending_break_support
, _("\
16586 Set debugger's behavior regarding pending breakpoints."), _("\
16587 Show debugger's behavior regarding pending breakpoints."), _("\
16588 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16589 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16590 an error. If auto, an unrecognized breakpoint location results in a\n\
16591 user-query to see if a pending breakpoint should be created."),
16593 show_pending_break_support
,
16594 &breakpoint_set_cmdlist
,
16595 &breakpoint_show_cmdlist
);
16597 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16599 add_setshow_boolean_cmd ("auto-hw", no_class
,
16600 &automatic_hardware_breakpoints
, _("\
16601 Set automatic usage of hardware breakpoints."), _("\
16602 Show automatic usage of hardware breakpoints."), _("\
16603 If set, the debugger will automatically use hardware breakpoints for\n\
16604 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16605 a warning will be emitted for such breakpoints."),
16607 show_automatic_hardware_breakpoints
,
16608 &breakpoint_set_cmdlist
,
16609 &breakpoint_show_cmdlist
);
16611 add_setshow_boolean_cmd ("always-inserted", class_support
,
16612 &always_inserted_mode
, _("\
16613 Set mode for inserting breakpoints."), _("\
16614 Show mode for inserting breakpoints."), _("\
16615 When this mode is on, breakpoints are inserted immediately as soon as\n\
16616 they're created, kept inserted even when execution stops, and removed\n\
16617 only when the user deletes them. When this mode is off (the default),\n\
16618 breakpoints are inserted only when execution continues, and removed\n\
16619 when execution stops."),
16621 &show_always_inserted_mode
,
16622 &breakpoint_set_cmdlist
,
16623 &breakpoint_show_cmdlist
);
16625 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16626 condition_evaluation_enums
,
16627 &condition_evaluation_mode_1
, _("\
16628 Set mode of breakpoint condition evaluation."), _("\
16629 Show mode of breakpoint condition evaluation."), _("\
16630 When this is set to \"host\", breakpoint conditions will be\n\
16631 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16632 breakpoint conditions will be downloaded to the target (if the target\n\
16633 supports such feature) and conditions will be evaluated on the target's side.\n\
16634 If this is set to \"auto\" (default), this will be automatically set to\n\
16635 \"target\" if it supports condition evaluation, otherwise it will\n\
16636 be set to \"gdb\""),
16637 &set_condition_evaluation_mode
,
16638 &show_condition_evaluation_mode
,
16639 &breakpoint_set_cmdlist
,
16640 &breakpoint_show_cmdlist
);
16642 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16643 Set a breakpoint for an address range.\n\
16644 break-range START-LOCATION, END-LOCATION\n\
16645 where START-LOCATION and END-LOCATION can be one of the following:\n\
16646 LINENUM, for that line in the current file,\n\
16647 FILE:LINENUM, for that line in that file,\n\
16648 +OFFSET, for that number of lines after the current line\n\
16649 or the start of the range\n\
16650 FUNCTION, for the first line in that function,\n\
16651 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16652 *ADDRESS, for the instruction at that address.\n\
16654 The breakpoint will stop execution of the inferior whenever it executes\n\
16655 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16656 range (including START-LOCATION and END-LOCATION)."));
16658 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16659 Set a dynamic printf at specified location.\n\
16660 dprintf location,format string,arg1,arg2,...\n\
16661 location may be a linespec, explicit, or address location.\n"
16662 "\n" LOCATION_HELP_STRING
));
16663 set_cmd_completer (c
, location_completer
);
16665 add_setshow_enum_cmd ("dprintf-style", class_support
,
16666 dprintf_style_enums
, &dprintf_style
, _("\
16667 Set the style of usage for dynamic printf."), _("\
16668 Show the style of usage for dynamic printf."), _("\
16669 This setting chooses how GDB will do a dynamic printf.\n\
16670 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16671 console, as with the \"printf\" command.\n\
16672 If the value is \"call\", the print is done by calling a function in your\n\
16673 program; by default printf(), but you can choose a different function or\n\
16674 output stream by setting dprintf-function and dprintf-channel."),
16675 update_dprintf_commands
, NULL
,
16676 &setlist
, &showlist
);
16678 dprintf_function
= xstrdup ("printf");
16679 add_setshow_string_cmd ("dprintf-function", class_support
,
16680 &dprintf_function
, _("\
16681 Set the function to use for dynamic printf"), _("\
16682 Show the function to use for dynamic printf"), NULL
,
16683 update_dprintf_commands
, NULL
,
16684 &setlist
, &showlist
);
16686 dprintf_channel
= xstrdup ("");
16687 add_setshow_string_cmd ("dprintf-channel", class_support
,
16688 &dprintf_channel
, _("\
16689 Set the channel to use for dynamic printf"), _("\
16690 Show the channel to use for dynamic printf"), NULL
,
16691 update_dprintf_commands
, NULL
,
16692 &setlist
, &showlist
);
16694 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16695 &disconnected_dprintf
, _("\
16696 Set whether dprintf continues after GDB disconnects."), _("\
16697 Show whether dprintf continues after GDB disconnects."), _("\
16698 Use this to let dprintf commands continue to hit and produce output\n\
16699 even if GDB disconnects or detaches from the target."),
16702 &setlist
, &showlist
);
16704 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16705 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16706 (target agent only) This is useful for formatted output in user-defined commands."));
16708 automatic_hardware_breakpoints
= 1;
16710 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16711 observer_attach_thread_exit (remove_threaded_breakpoints
);