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"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (const char *,
106 void (*) (struct breakpoint
*,
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint
*);
117 create_sals_from_location_default (const struct event_location
*location
,
118 struct linespec_result
*canonical
,
119 enum bptype type_wanted
);
121 static void create_breakpoints_sal_default (struct gdbarch
*,
122 struct linespec_result
*,
123 char *, char *, enum bptype
,
124 enum bpdisp
, int, int,
126 const struct breakpoint_ops
*,
127 int, int, int, unsigned);
129 static void decode_location_default (struct breakpoint
*b
,
130 const struct event_location
*location
,
131 struct program_space
*search_pspace
,
132 struct symtabs_and_lines
*sals
);
134 static void clear_command (char *, int);
136 static void catch_command (char *, int);
138 static int can_use_hardware_watchpoint (struct value
*);
140 static void break_command_1 (char *, int, int);
142 static void mention (struct breakpoint
*);
144 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
146 const struct breakpoint_ops
*);
147 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
148 const struct symtab_and_line
*);
150 /* This function is used in gdbtk sources and thus can not be made
152 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
153 struct symtab_and_line
,
155 const struct breakpoint_ops
*);
157 static struct breakpoint
*
158 momentary_breakpoint_from_master (struct breakpoint
*orig
,
160 const struct breakpoint_ops
*ops
,
163 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
165 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
169 static void describe_other_breakpoints (struct gdbarch
*,
170 struct program_space
*, CORE_ADDR
,
171 struct obj_section
*, int);
173 static int watchpoint_locations_match (struct bp_location
*loc1
,
174 struct bp_location
*loc2
);
176 static int breakpoint_location_address_match (struct bp_location
*bl
,
177 struct address_space
*aspace
,
180 static int breakpoint_location_address_range_overlap (struct bp_location
*,
181 struct address_space
*,
184 static void breakpoints_info (char *, int);
186 static void watchpoints_info (char *, int);
188 static int breakpoint_1 (char *, int,
189 int (*) (const struct breakpoint
*));
191 static int breakpoint_cond_eval (void *);
193 static void cleanup_executing_breakpoints (void *);
195 static void commands_command (char *, int);
197 static void condition_command (char *, int);
199 static int remove_breakpoint (struct bp_location
*);
200 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
202 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
204 static int watchpoint_check (void *);
206 static void maintenance_info_breakpoints (char *, int);
208 static int hw_breakpoint_used_count (void);
210 static int hw_watchpoint_use_count (struct breakpoint
*);
212 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
214 int *other_type_used
);
216 static void hbreak_command (char *, int);
218 static void thbreak_command (char *, int);
220 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
223 static void stop_command (char *arg
, int from_tty
);
225 static void stopin_command (char *arg
, int from_tty
);
227 static void stopat_command (char *arg
, int from_tty
);
229 static void tcatch_command (char *arg
, int from_tty
);
231 static void free_bp_location (struct bp_location
*loc
);
232 static void incref_bp_location (struct bp_location
*loc
);
233 static void decref_bp_location (struct bp_location
**loc
);
235 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
237 /* update_global_location_list's modes of operation wrt to whether to
238 insert locations now. */
239 enum ugll_insert_mode
241 /* Don't insert any breakpoint locations into the inferior, only
242 remove already-inserted locations that no longer should be
243 inserted. Functions that delete a breakpoint or breakpoints
244 should specify this mode, so that deleting a breakpoint doesn't
245 have the side effect of inserting the locations of other
246 breakpoints that are marked not-inserted, but should_be_inserted
247 returns true on them.
249 This behavior is useful is situations close to tear-down -- e.g.,
250 after an exec, while the target still has execution, but
251 breakpoint shadows of the previous executable image should *NOT*
252 be restored to the new image; or before detaching, where the
253 target still has execution and wants to delete breakpoints from
254 GDB's lists, and all breakpoints had already been removed from
258 /* May insert breakpoints iff breakpoints_should_be_inserted_now
259 claims breakpoints should be inserted now. */
262 /* Insert locations now, irrespective of
263 breakpoints_should_be_inserted_now. E.g., say all threads are
264 stopped right now, and the user did "continue". We need to
265 insert breakpoints _before_ resuming the target, but
266 UGLL_MAY_INSERT wouldn't insert them, because
267 breakpoints_should_be_inserted_now returns false at that point,
268 as no thread is running yet. */
272 static void update_global_location_list (enum ugll_insert_mode
);
274 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
276 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
278 static void insert_breakpoint_locations (void);
280 static void tracepoints_info (char *, int);
282 static void delete_trace_command (char *, int);
284 static void enable_trace_command (char *, int);
286 static void disable_trace_command (char *, int);
288 static void trace_pass_command (char *, int);
290 static void set_tracepoint_count (int num
);
292 static int is_masked_watchpoint (const struct breakpoint
*b
);
294 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
296 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
299 static int strace_marker_p (struct breakpoint
*b
);
301 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
302 that are implemented on top of software or hardware breakpoints
303 (user breakpoints, internal and momentary breakpoints, etc.). */
304 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
306 /* Internal breakpoints class type. */
307 static struct breakpoint_ops internal_breakpoint_ops
;
309 /* Momentary breakpoints class type. */
310 static struct breakpoint_ops momentary_breakpoint_ops
;
312 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
313 static struct breakpoint_ops longjmp_breakpoint_ops
;
315 /* The breakpoint_ops structure to be used in regular user created
317 struct breakpoint_ops bkpt_breakpoint_ops
;
319 /* Breakpoints set on probes. */
320 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
322 /* Dynamic printf class type. */
323 struct breakpoint_ops dprintf_breakpoint_ops
;
325 /* The style in which to perform a dynamic printf. This is a user
326 option because different output options have different tradeoffs;
327 if GDB does the printing, there is better error handling if there
328 is a problem with any of the arguments, but using an inferior
329 function lets you have special-purpose printers and sending of
330 output to the same place as compiled-in print functions. */
332 static const char dprintf_style_gdb
[] = "gdb";
333 static const char dprintf_style_call
[] = "call";
334 static const char dprintf_style_agent
[] = "agent";
335 static const char *const dprintf_style_enums
[] = {
341 static const char *dprintf_style
= dprintf_style_gdb
;
343 /* The function to use for dynamic printf if the preferred style is to
344 call into the inferior. The value is simply a string that is
345 copied into the command, so it can be anything that GDB can
346 evaluate to a callable address, not necessarily a function name. */
348 static char *dprintf_function
= "";
350 /* The channel to use for dynamic printf if the preferred style is to
351 call into the inferior; if a nonempty string, it will be passed to
352 the call as the first argument, with the format string as the
353 second. As with the dprintf function, this can be anything that
354 GDB knows how to evaluate, so in addition to common choices like
355 "stderr", this could be an app-specific expression like
356 "mystreams[curlogger]". */
358 static char *dprintf_channel
= "";
360 /* True if dprintf commands should continue to operate even if GDB
362 static int disconnected_dprintf
= 1;
364 /* A reference-counted struct command_line. This lets multiple
365 breakpoints share a single command list. */
366 struct counted_command_line
368 /* The reference count. */
371 /* The command list. */
372 struct command_line
*commands
;
375 struct command_line
*
376 breakpoint_commands (struct breakpoint
*b
)
378 return b
->commands
? b
->commands
->commands
: NULL
;
381 /* Flag indicating that a command has proceeded the inferior past the
382 current breakpoint. */
384 static int breakpoint_proceeded
;
387 bpdisp_text (enum bpdisp disp
)
389 /* NOTE: the following values are a part of MI protocol and
390 represent values of 'disp' field returned when inferior stops at
392 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
394 return bpdisps
[(int) disp
];
397 /* Prototypes for exported functions. */
398 /* If FALSE, gdb will not use hardware support for watchpoints, even
399 if such is available. */
400 static int can_use_hw_watchpoints
;
403 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
404 struct cmd_list_element
*c
,
407 fprintf_filtered (file
,
408 _("Debugger's willingness to use "
409 "watchpoint hardware is %s.\n"),
413 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
414 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
415 for unrecognized breakpoint locations.
416 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
417 static enum auto_boolean pending_break_support
;
419 show_pending_break_support (struct ui_file
*file
, int from_tty
,
420 struct cmd_list_element
*c
,
423 fprintf_filtered (file
,
424 _("Debugger's behavior regarding "
425 "pending breakpoints is %s.\n"),
429 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
430 set with "break" but falling in read-only memory.
431 If 0, gdb will warn about such breakpoints, but won't automatically
432 use hardware breakpoints. */
433 static int automatic_hardware_breakpoints
;
435 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
436 struct cmd_list_element
*c
,
439 fprintf_filtered (file
,
440 _("Automatic usage of hardware breakpoints is %s.\n"),
444 /* If on, GDB keeps breakpoints inserted even if the inferior is
445 stopped, and immediately inserts any new breakpoints as soon as
446 they're created. If off (default), GDB keeps breakpoints off of
447 the target as long as possible. That is, it delays inserting
448 breakpoints until the next resume, and removes them again when the
449 target fully stops. This is a bit safer in case GDB crashes while
450 processing user input. */
451 static int always_inserted_mode
= 0;
454 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
455 struct cmd_list_element
*c
, const char *value
)
457 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
461 /* See breakpoint.h. */
464 breakpoints_should_be_inserted_now (void)
466 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
468 /* If breakpoints are global, they should be inserted even if no
469 thread under gdb's control is running, or even if there are
470 no threads under GDB's control yet. */
473 else if (target_has_execution
)
475 struct thread_info
*tp
;
477 if (always_inserted_mode
)
479 /* The user wants breakpoints inserted even if all threads
484 if (threads_are_executing ())
487 /* Don't remove breakpoints yet if, even though all threads are
488 stopped, we still have events to process. */
489 ALL_NON_EXITED_THREADS (tp
)
491 && tp
->suspend
.waitstatus_pending_p
)
497 static const char condition_evaluation_both
[] = "host or target";
499 /* Modes for breakpoint condition evaluation. */
500 static const char condition_evaluation_auto
[] = "auto";
501 static const char condition_evaluation_host
[] = "host";
502 static const char condition_evaluation_target
[] = "target";
503 static const char *const condition_evaluation_enums
[] = {
504 condition_evaluation_auto
,
505 condition_evaluation_host
,
506 condition_evaluation_target
,
510 /* Global that holds the current mode for breakpoint condition evaluation. */
511 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
513 /* Global that we use to display information to the user (gets its value from
514 condition_evaluation_mode_1. */
515 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
517 /* Translate a condition evaluation mode MODE into either "host"
518 or "target". This is used mostly to translate from "auto" to the
519 real setting that is being used. It returns the translated
523 translate_condition_evaluation_mode (const char *mode
)
525 if (mode
== condition_evaluation_auto
)
527 if (target_supports_evaluation_of_breakpoint_conditions ())
528 return condition_evaluation_target
;
530 return condition_evaluation_host
;
536 /* Discovers what condition_evaluation_auto translates to. */
539 breakpoint_condition_evaluation_mode (void)
541 return translate_condition_evaluation_mode (condition_evaluation_mode
);
544 /* Return true if GDB should evaluate breakpoint conditions or false
548 gdb_evaluates_breakpoint_condition_p (void)
550 const char *mode
= breakpoint_condition_evaluation_mode ();
552 return (mode
== condition_evaluation_host
);
555 void _initialize_breakpoint (void);
557 /* Are we executing breakpoint commands? */
558 static int executing_breakpoint_commands
;
560 /* Are overlay event breakpoints enabled? */
561 static int overlay_events_enabled
;
563 /* See description in breakpoint.h. */
564 int target_exact_watchpoints
= 0;
566 /* Walk the following statement or block through all breakpoints.
567 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
568 current breakpoint. */
570 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
572 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
573 for (B = breakpoint_chain; \
574 B ? (TMP=B->next, 1): 0; \
577 /* Similar iterator for the low-level breakpoints. SAFE variant is
578 not provided so update_global_location_list must not be called
579 while executing the block of ALL_BP_LOCATIONS. */
581 #define ALL_BP_LOCATIONS(B,BP_TMP) \
582 for (BP_TMP = bp_location; \
583 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
586 /* Iterates through locations with address ADDRESS for the currently selected
587 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
588 to where the loop should start from.
589 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
590 appropriate location to start with. */
592 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
593 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
594 BP_LOCP_TMP = BP_LOCP_START; \
596 && (BP_LOCP_TMP < bp_location + bp_location_count \
597 && (*BP_LOCP_TMP)->address == ADDRESS); \
600 /* Iterator for tracepoints only. */
602 #define ALL_TRACEPOINTS(B) \
603 for (B = breakpoint_chain; B; B = B->next) \
604 if (is_tracepoint (B))
606 /* Chains of all breakpoints defined. */
608 struct breakpoint
*breakpoint_chain
;
610 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
612 static struct bp_location
**bp_location
;
614 /* Number of elements of BP_LOCATION. */
616 static unsigned bp_location_count
;
618 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
619 ADDRESS for the current elements of BP_LOCATION which get a valid
620 result from bp_location_has_shadow. You can use it for roughly
621 limiting the subrange of BP_LOCATION to scan for shadow bytes for
622 an address you need to read. */
624 static CORE_ADDR bp_location_placed_address_before_address_max
;
626 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
627 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
628 BP_LOCATION which get a valid result from bp_location_has_shadow.
629 You can use it for roughly limiting the subrange of BP_LOCATION to
630 scan for shadow bytes for an address you need to read. */
632 static CORE_ADDR bp_location_shadow_len_after_address_max
;
634 /* The locations that no longer correspond to any breakpoint, unlinked
635 from bp_location array, but for which a hit may still be reported
637 VEC(bp_location_p
) *moribund_locations
= NULL
;
639 /* Number of last breakpoint made. */
641 static int breakpoint_count
;
643 /* The value of `breakpoint_count' before the last command that
644 created breakpoints. If the last (break-like) command created more
645 than one breakpoint, then the difference between BREAKPOINT_COUNT
646 and PREV_BREAKPOINT_COUNT is more than one. */
647 static int prev_breakpoint_count
;
649 /* Number of last tracepoint made. */
651 static int tracepoint_count
;
653 static struct cmd_list_element
*breakpoint_set_cmdlist
;
654 static struct cmd_list_element
*breakpoint_show_cmdlist
;
655 struct cmd_list_element
*save_cmdlist
;
657 /* See declaration at breakpoint.h. */
660 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
663 struct breakpoint
*b
= NULL
;
667 if (func (b
, user_data
) != 0)
674 /* Return whether a breakpoint is an active enabled breakpoint. */
676 breakpoint_enabled (struct breakpoint
*b
)
678 return (b
->enable_state
== bp_enabled
);
681 /* Set breakpoint count to NUM. */
684 set_breakpoint_count (int num
)
686 prev_breakpoint_count
= breakpoint_count
;
687 breakpoint_count
= num
;
688 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
691 /* Used by `start_rbreak_breakpoints' below, to record the current
692 breakpoint count before "rbreak" creates any breakpoint. */
693 static int rbreak_start_breakpoint_count
;
695 /* Called at the start an "rbreak" command to record the first
699 start_rbreak_breakpoints (void)
701 rbreak_start_breakpoint_count
= breakpoint_count
;
704 /* Called at the end of an "rbreak" command to record the last
708 end_rbreak_breakpoints (void)
710 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
713 /* Used in run_command to zero the hit count when a new run starts. */
716 clear_breakpoint_hit_counts (void)
718 struct breakpoint
*b
;
724 /* Allocate a new counted_command_line with reference count of 1.
725 The new structure owns COMMANDS. */
727 static struct counted_command_line
*
728 alloc_counted_command_line (struct command_line
*commands
)
730 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
733 result
->commands
= commands
;
738 /* Increment reference count. This does nothing if CMD is NULL. */
741 incref_counted_command_line (struct counted_command_line
*cmd
)
747 /* Decrement reference count. If the reference count reaches 0,
748 destroy the counted_command_line. Sets *CMDP to NULL. This does
749 nothing if *CMDP is NULL. */
752 decref_counted_command_line (struct counted_command_line
**cmdp
)
756 if (--(*cmdp
)->refc
== 0)
758 free_command_lines (&(*cmdp
)->commands
);
765 /* A cleanup function that calls decref_counted_command_line. */
768 do_cleanup_counted_command_line (void *arg
)
770 decref_counted_command_line ((struct counted_command_line
**) arg
);
773 /* Create a cleanup that calls decref_counted_command_line on the
776 static struct cleanup
*
777 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
779 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
783 /* Return the breakpoint with the specified number, or NULL
784 if the number does not refer to an existing breakpoint. */
787 get_breakpoint (int num
)
789 struct breakpoint
*b
;
792 if (b
->number
== num
)
800 /* Mark locations as "conditions have changed" in case the target supports
801 evaluating conditions on its side. */
804 mark_breakpoint_modified (struct breakpoint
*b
)
806 struct bp_location
*loc
;
808 /* This is only meaningful if the target is
809 evaluating conditions and if the user has
810 opted for condition evaluation on the target's
812 if (gdb_evaluates_breakpoint_condition_p ()
813 || !target_supports_evaluation_of_breakpoint_conditions ())
816 if (!is_breakpoint (b
))
819 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
820 loc
->condition_changed
= condition_modified
;
823 /* Mark location as "conditions have changed" in case the target supports
824 evaluating conditions on its side. */
827 mark_breakpoint_location_modified (struct bp_location
*loc
)
829 /* This is only meaningful if the target is
830 evaluating conditions and if the user has
831 opted for condition evaluation on the target's
833 if (gdb_evaluates_breakpoint_condition_p ()
834 || !target_supports_evaluation_of_breakpoint_conditions ())
838 if (!is_breakpoint (loc
->owner
))
841 loc
->condition_changed
= condition_modified
;
844 /* Sets the condition-evaluation mode using the static global
845 condition_evaluation_mode. */
848 set_condition_evaluation_mode (char *args
, int from_tty
,
849 struct cmd_list_element
*c
)
851 const char *old_mode
, *new_mode
;
853 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
854 && !target_supports_evaluation_of_breakpoint_conditions ())
856 condition_evaluation_mode_1
= condition_evaluation_mode
;
857 warning (_("Target does not support breakpoint condition evaluation.\n"
858 "Using host evaluation mode instead."));
862 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
863 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
865 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
866 settings was "auto". */
867 condition_evaluation_mode
= condition_evaluation_mode_1
;
869 /* Only update the mode if the user picked a different one. */
870 if (new_mode
!= old_mode
)
872 struct bp_location
*loc
, **loc_tmp
;
873 /* If the user switched to a different evaluation mode, we
874 need to synch the changes with the target as follows:
876 "host" -> "target": Send all (valid) conditions to the target.
877 "target" -> "host": Remove all the conditions from the target.
880 if (new_mode
== condition_evaluation_target
)
882 /* Mark everything modified and synch conditions with the
884 ALL_BP_LOCATIONS (loc
, loc_tmp
)
885 mark_breakpoint_location_modified (loc
);
889 /* Manually mark non-duplicate locations to synch conditions
890 with the target. We do this to remove all the conditions the
891 target knows about. */
892 ALL_BP_LOCATIONS (loc
, loc_tmp
)
893 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
894 loc
->needs_update
= 1;
898 update_global_location_list (UGLL_MAY_INSERT
);
904 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
905 what "auto" is translating to. */
908 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
909 struct cmd_list_element
*c
, const char *value
)
911 if (condition_evaluation_mode
== condition_evaluation_auto
)
912 fprintf_filtered (file
,
913 _("Breakpoint condition evaluation "
914 "mode is %s (currently %s).\n"),
916 breakpoint_condition_evaluation_mode ());
918 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
922 /* A comparison function for bp_location AP and BP that is used by
923 bsearch. This comparison function only cares about addresses, unlike
924 the more general bp_location_compare function. */
927 bp_location_compare_addrs (const void *ap
, const void *bp
)
929 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
930 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
932 if (a
->address
== b
->address
)
935 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
938 /* Helper function to skip all bp_locations with addresses
939 less than ADDRESS. It returns the first bp_location that
940 is greater than or equal to ADDRESS. If none is found, just
943 static struct bp_location
**
944 get_first_locp_gte_addr (CORE_ADDR address
)
946 struct bp_location dummy_loc
;
947 struct bp_location
*dummy_locp
= &dummy_loc
;
948 struct bp_location
**locp_found
= NULL
;
950 /* Initialize the dummy location's address field. */
951 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
952 dummy_loc
.address
= address
;
954 /* Find a close match to the first location at ADDRESS. */
955 locp_found
= ((struct bp_location
**)
956 bsearch (&dummy_locp
, bp_location
, bp_location_count
,
957 sizeof (struct bp_location
**),
958 bp_location_compare_addrs
));
960 /* Nothing was found, nothing left to do. */
961 if (locp_found
== NULL
)
964 /* We may have found a location that is at ADDRESS but is not the first in the
965 location's list. Go backwards (if possible) and locate the first one. */
966 while ((locp_found
- 1) >= bp_location
967 && (*(locp_found
- 1))->address
== address
)
974 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
977 xfree (b
->cond_string
);
978 b
->cond_string
= NULL
;
980 if (is_watchpoint (b
))
982 struct watchpoint
*w
= (struct watchpoint
*) b
;
984 w
->cond_exp
.reset ();
988 struct bp_location
*loc
;
990 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
994 /* No need to free the condition agent expression
995 bytecode (if we have one). We will handle this
996 when we go through update_global_location_list. */
1003 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1007 const char *arg
= exp
;
1009 /* I don't know if it matters whether this is the string the user
1010 typed in or the decompiled expression. */
1011 b
->cond_string
= xstrdup (arg
);
1012 b
->condition_not_parsed
= 0;
1014 if (is_watchpoint (b
))
1016 struct watchpoint
*w
= (struct watchpoint
*) b
;
1018 innermost_block
= NULL
;
1020 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1022 error (_("Junk at end of expression"));
1023 w
->cond_exp_valid_block
= innermost_block
;
1027 struct bp_location
*loc
;
1029 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1033 parse_exp_1 (&arg
, loc
->address
,
1034 block_for_pc (loc
->address
), 0);
1036 error (_("Junk at end of expression"));
1040 mark_breakpoint_modified (b
);
1042 observer_notify_breakpoint_modified (b
);
1045 /* Completion for the "condition" command. */
1047 static VEC (char_ptr
) *
1048 condition_completer (struct cmd_list_element
*cmd
,
1049 const char *text
, const char *word
)
1053 text
= skip_spaces_const (text
);
1054 space
= skip_to_space_const (text
);
1058 struct breakpoint
*b
;
1059 VEC (char_ptr
) *result
= NULL
;
1063 /* We don't support completion of history indices. */
1064 if (isdigit (text
[1]))
1066 return complete_internalvar (&text
[1]);
1069 /* We're completing the breakpoint number. */
1070 len
= strlen (text
);
1076 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1078 if (strncmp (number
, text
, len
) == 0)
1079 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1085 /* We're completing the expression part. */
1086 text
= skip_spaces_const (space
);
1087 return expression_completer (cmd
, text
, word
);
1090 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1093 condition_command (char *arg
, int from_tty
)
1095 struct breakpoint
*b
;
1100 error_no_arg (_("breakpoint number"));
1103 bnum
= get_number (&p
);
1105 error (_("Bad breakpoint argument: '%s'"), arg
);
1108 if (b
->number
== bnum
)
1110 /* Check if this breakpoint has a "stop" method implemented in an
1111 extension language. This method and conditions entered into GDB
1112 from the CLI are mutually exclusive. */
1113 const struct extension_language_defn
*extlang
1114 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1116 if (extlang
!= NULL
)
1118 error (_("Only one stop condition allowed. There is currently"
1119 " a %s stop condition defined for this breakpoint."),
1120 ext_lang_capitalized_name (extlang
));
1122 set_breakpoint_condition (b
, p
, from_tty
);
1124 if (is_breakpoint (b
))
1125 update_global_location_list (UGLL_MAY_INSERT
);
1130 error (_("No breakpoint number %d."), bnum
);
1133 /* Check that COMMAND do not contain commands that are suitable
1134 only for tracepoints and not suitable for ordinary breakpoints.
1135 Throw if any such commands is found. */
1138 check_no_tracepoint_commands (struct command_line
*commands
)
1140 struct command_line
*c
;
1142 for (c
= commands
; c
; c
= c
->next
)
1146 if (c
->control_type
== while_stepping_control
)
1147 error (_("The 'while-stepping' command can "
1148 "only be used for tracepoints"));
1150 for (i
= 0; i
< c
->body_count
; ++i
)
1151 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1153 /* Not that command parsing removes leading whitespace and comment
1154 lines and also empty lines. So, we only need to check for
1155 command directly. */
1156 if (strstr (c
->line
, "collect ") == c
->line
)
1157 error (_("The 'collect' command can only be used for tracepoints"));
1159 if (strstr (c
->line
, "teval ") == c
->line
)
1160 error (_("The 'teval' command can only be used for tracepoints"));
1164 /* Encapsulate tests for different types of tracepoints. */
1167 is_tracepoint_type (enum bptype type
)
1169 return (type
== bp_tracepoint
1170 || type
== bp_fast_tracepoint
1171 || type
== bp_static_tracepoint
);
1175 is_tracepoint (const struct breakpoint
*b
)
1177 return is_tracepoint_type (b
->type
);
1180 /* A helper function that validates that COMMANDS are valid for a
1181 breakpoint. This function will throw an exception if a problem is
1185 validate_commands_for_breakpoint (struct breakpoint
*b
,
1186 struct command_line
*commands
)
1188 if (is_tracepoint (b
))
1190 struct tracepoint
*t
= (struct tracepoint
*) b
;
1191 struct command_line
*c
;
1192 struct command_line
*while_stepping
= 0;
1194 /* Reset the while-stepping step count. The previous commands
1195 might have included a while-stepping action, while the new
1199 /* We need to verify that each top-level element of commands is
1200 valid for tracepoints, that there's at most one
1201 while-stepping element, and that the while-stepping's body
1202 has valid tracing commands excluding nested while-stepping.
1203 We also need to validate the tracepoint action line in the
1204 context of the tracepoint --- validate_actionline actually
1205 has side effects, like setting the tracepoint's
1206 while-stepping STEP_COUNT, in addition to checking if the
1207 collect/teval actions parse and make sense in the
1208 tracepoint's context. */
1209 for (c
= commands
; c
; c
= c
->next
)
1211 if (c
->control_type
== while_stepping_control
)
1213 if (b
->type
== bp_fast_tracepoint
)
1214 error (_("The 'while-stepping' command "
1215 "cannot be used for fast tracepoint"));
1216 else if (b
->type
== bp_static_tracepoint
)
1217 error (_("The 'while-stepping' command "
1218 "cannot be used for static tracepoint"));
1221 error (_("The 'while-stepping' command "
1222 "can be used only once"));
1227 validate_actionline (c
->line
, b
);
1231 struct command_line
*c2
;
1233 gdb_assert (while_stepping
->body_count
== 1);
1234 c2
= while_stepping
->body_list
[0];
1235 for (; c2
; c2
= c2
->next
)
1237 if (c2
->control_type
== while_stepping_control
)
1238 error (_("The 'while-stepping' command cannot be nested"));
1244 check_no_tracepoint_commands (commands
);
1248 /* Return a vector of all the static tracepoints set at ADDR. The
1249 caller is responsible for releasing the vector. */
1252 static_tracepoints_here (CORE_ADDR addr
)
1254 struct breakpoint
*b
;
1255 VEC(breakpoint_p
) *found
= 0;
1256 struct bp_location
*loc
;
1259 if (b
->type
== bp_static_tracepoint
)
1261 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1262 if (loc
->address
== addr
)
1263 VEC_safe_push(breakpoint_p
, found
, b
);
1269 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1270 validate that only allowed commands are included. */
1273 breakpoint_set_commands (struct breakpoint
*b
,
1274 struct command_line
*commands
)
1276 validate_commands_for_breakpoint (b
, commands
);
1278 decref_counted_command_line (&b
->commands
);
1279 b
->commands
= alloc_counted_command_line (commands
);
1280 observer_notify_breakpoint_modified (b
);
1283 /* Set the internal `silent' flag on the breakpoint. Note that this
1284 is not the same as the "silent" that may appear in the breakpoint's
1288 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1290 int old_silent
= b
->silent
;
1293 if (old_silent
!= silent
)
1294 observer_notify_breakpoint_modified (b
);
1297 /* Set the thread for this breakpoint. If THREAD is -1, make the
1298 breakpoint work for any thread. */
1301 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1303 int old_thread
= b
->thread
;
1306 if (old_thread
!= thread
)
1307 observer_notify_breakpoint_modified (b
);
1310 /* Set the task for this breakpoint. If TASK is 0, make the
1311 breakpoint work for any task. */
1314 breakpoint_set_task (struct breakpoint
*b
, int task
)
1316 int old_task
= b
->task
;
1319 if (old_task
!= task
)
1320 observer_notify_breakpoint_modified (b
);
1324 check_tracepoint_command (char *line
, void *closure
)
1326 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1328 validate_actionline (line
, b
);
1331 /* A structure used to pass information through
1332 map_breakpoint_numbers. */
1334 struct commands_info
1336 /* True if the command was typed at a tty. */
1339 /* The breakpoint range spec. */
1342 /* Non-NULL if the body of the commands are being read from this
1343 already-parsed command. */
1344 struct command_line
*control
;
1346 /* The command lines read from the user, or NULL if they have not
1348 struct counted_command_line
*cmd
;
1351 /* A callback for map_breakpoint_numbers that sets the commands for
1352 commands_command. */
1355 do_map_commands_command (struct breakpoint
*b
, void *data
)
1357 struct commands_info
*info
= (struct commands_info
*) data
;
1359 if (info
->cmd
== NULL
)
1361 struct command_line
*l
;
1363 if (info
->control
!= NULL
)
1364 l
= copy_command_lines (info
->control
->body_list
[0]);
1367 struct cleanup
*old_chain
;
1370 str
= xstrprintf (_("Type commands for breakpoint(s) "
1371 "%s, one per line."),
1374 old_chain
= make_cleanup (xfree
, str
);
1376 l
= read_command_lines (str
,
1379 ? check_tracepoint_command
: 0),
1382 do_cleanups (old_chain
);
1385 info
->cmd
= alloc_counted_command_line (l
);
1388 /* If a breakpoint was on the list more than once, we don't need to
1390 if (b
->commands
!= info
->cmd
)
1392 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1393 incref_counted_command_line (info
->cmd
);
1394 decref_counted_command_line (&b
->commands
);
1395 b
->commands
= info
->cmd
;
1396 observer_notify_breakpoint_modified (b
);
1401 commands_command_1 (const char *arg
, int from_tty
,
1402 struct command_line
*control
)
1404 struct cleanup
*cleanups
;
1405 struct commands_info info
;
1407 info
.from_tty
= from_tty
;
1408 info
.control
= control
;
1410 /* If we read command lines from the user, then `info' will hold an
1411 extra reference to the commands that we must clean up. */
1412 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1414 std::string new_arg
;
1416 if (arg
== NULL
|| !*arg
)
1418 if (breakpoint_count
- prev_breakpoint_count
> 1)
1419 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1421 else if (breakpoint_count
> 0)
1422 new_arg
= string_printf ("%d", breakpoint_count
);
1427 info
.arg
= new_arg
.c_str ();
1429 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1431 if (info
.cmd
== NULL
)
1432 error (_("No breakpoints specified."));
1434 do_cleanups (cleanups
);
1438 commands_command (char *arg
, int from_tty
)
1440 commands_command_1 (arg
, from_tty
, NULL
);
1443 /* Like commands_command, but instead of reading the commands from
1444 input stream, takes them from an already parsed command structure.
1446 This is used by cli-script.c to DTRT with breakpoint commands
1447 that are part of if and while bodies. */
1448 enum command_control_type
1449 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1451 commands_command_1 (arg
, 0, cmd
);
1452 return simple_control
;
1455 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1458 bp_location_has_shadow (struct bp_location
*bl
)
1460 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1464 if (bl
->target_info
.shadow_len
== 0)
1465 /* BL isn't valid, or doesn't shadow memory. */
1470 /* Update BUF, which is LEN bytes read from the target address
1471 MEMADDR, by replacing a memory breakpoint with its shadowed
1474 If READBUF is not NULL, this buffer must not overlap with the of
1475 the breakpoint location's shadow_contents buffer. Otherwise, a
1476 failed assertion internal error will be raised. */
1479 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1480 const gdb_byte
*writebuf_org
,
1481 ULONGEST memaddr
, LONGEST len
,
1482 struct bp_target_info
*target_info
,
1483 struct gdbarch
*gdbarch
)
1485 /* Now do full processing of the found relevant range of elements. */
1486 CORE_ADDR bp_addr
= 0;
1490 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1491 current_program_space
->aspace
, 0))
1493 /* The breakpoint is inserted in a different address space. */
1497 /* Addresses and length of the part of the breakpoint that
1499 bp_addr
= target_info
->placed_address
;
1500 bp_size
= target_info
->shadow_len
;
1502 if (bp_addr
+ bp_size
<= memaddr
)
1504 /* The breakpoint is entirely before the chunk of memory we are
1509 if (bp_addr
>= memaddr
+ len
)
1511 /* The breakpoint is entirely after the chunk of memory we are
1516 /* Offset within shadow_contents. */
1517 if (bp_addr
< memaddr
)
1519 /* Only copy the second part of the breakpoint. */
1520 bp_size
-= memaddr
- bp_addr
;
1521 bptoffset
= memaddr
- bp_addr
;
1525 if (bp_addr
+ bp_size
> memaddr
+ len
)
1527 /* Only copy the first part of the breakpoint. */
1528 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1531 if (readbuf
!= NULL
)
1533 /* Verify that the readbuf buffer does not overlap with the
1534 shadow_contents buffer. */
1535 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1536 || readbuf
>= (target_info
->shadow_contents
1537 + target_info
->shadow_len
));
1539 /* Update the read buffer with this inserted breakpoint's
1541 memcpy (readbuf
+ bp_addr
- memaddr
,
1542 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1546 const unsigned char *bp
;
1547 CORE_ADDR addr
= target_info
->reqstd_address
;
1550 /* Update the shadow with what we want to write to memory. */
1551 memcpy (target_info
->shadow_contents
+ bptoffset
,
1552 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1554 /* Determine appropriate breakpoint contents and size for this
1556 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1558 /* Update the final write buffer with this inserted
1559 breakpoint's INSN. */
1560 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1564 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1565 by replacing any memory breakpoints with their shadowed contents.
1567 If READBUF is not NULL, this buffer must not overlap with any of
1568 the breakpoint location's shadow_contents buffers. Otherwise,
1569 a failed assertion internal error will be raised.
1571 The range of shadowed area by each bp_location is:
1572 bl->address - bp_location_placed_address_before_address_max
1573 up to bl->address + bp_location_shadow_len_after_address_max
1574 The range we were requested to resolve shadows for is:
1575 memaddr ... memaddr + len
1576 Thus the safe cutoff boundaries for performance optimization are
1577 memaddr + len <= (bl->address
1578 - bp_location_placed_address_before_address_max)
1580 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1583 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1584 const gdb_byte
*writebuf_org
,
1585 ULONGEST memaddr
, LONGEST len
)
1587 /* Left boundary, right boundary and median element of our binary
1589 unsigned bc_l
, bc_r
, bc
;
1591 /* Find BC_L which is a leftmost element which may affect BUF
1592 content. It is safe to report lower value but a failure to
1593 report higher one. */
1596 bc_r
= bp_location_count
;
1597 while (bc_l
+ 1 < bc_r
)
1599 struct bp_location
*bl
;
1601 bc
= (bc_l
+ bc_r
) / 2;
1602 bl
= bp_location
[bc
];
1604 /* Check first BL->ADDRESS will not overflow due to the added
1605 constant. Then advance the left boundary only if we are sure
1606 the BC element can in no way affect the BUF content (MEMADDR
1607 to MEMADDR + LEN range).
1609 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1610 offset so that we cannot miss a breakpoint with its shadow
1611 range tail still reaching MEMADDR. */
1613 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1615 && (bl
->address
+ bp_location_shadow_len_after_address_max
1622 /* Due to the binary search above, we need to make sure we pick the
1623 first location that's at BC_L's address. E.g., if there are
1624 multiple locations at the same address, BC_L may end up pointing
1625 at a duplicate location, and miss the "master"/"inserted"
1626 location. Say, given locations L1, L2 and L3 at addresses A and
1629 L1@A, L2@A, L3@B, ...
1631 BC_L could end up pointing at location L2, while the "master"
1632 location could be L1. Since the `loc->inserted' flag is only set
1633 on "master" locations, we'd forget to restore the shadow of L1
1636 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1639 /* Now do full processing of the found relevant range of elements. */
1641 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1643 struct bp_location
*bl
= bp_location
[bc
];
1645 /* bp_location array has BL->OWNER always non-NULL. */
1646 if (bl
->owner
->type
== bp_none
)
1647 warning (_("reading through apparently deleted breakpoint #%d?"),
1650 /* Performance optimization: any further element can no longer affect BUF
1653 if (bl
->address
>= bp_location_placed_address_before_address_max
1654 && memaddr
+ len
<= (bl
->address
1655 - bp_location_placed_address_before_address_max
))
1658 if (!bp_location_has_shadow (bl
))
1661 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1662 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1668 /* Return true if BPT is either a software breakpoint or a hardware
1672 is_breakpoint (const struct breakpoint
*bpt
)
1674 return (bpt
->type
== bp_breakpoint
1675 || bpt
->type
== bp_hardware_breakpoint
1676 || bpt
->type
== bp_dprintf
);
1679 /* Return true if BPT is of any hardware watchpoint kind. */
1682 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1684 return (bpt
->type
== bp_hardware_watchpoint
1685 || bpt
->type
== bp_read_watchpoint
1686 || bpt
->type
== bp_access_watchpoint
);
1689 /* Return true if BPT is of any watchpoint kind, hardware or
1693 is_watchpoint (const struct breakpoint
*bpt
)
1695 return (is_hardware_watchpoint (bpt
)
1696 || bpt
->type
== bp_watchpoint
);
1699 /* Returns true if the current thread and its running state are safe
1700 to evaluate or update watchpoint B. Watchpoints on local
1701 expressions need to be evaluated in the context of the thread that
1702 was current when the watchpoint was created, and, that thread needs
1703 to be stopped to be able to select the correct frame context.
1704 Watchpoints on global expressions can be evaluated on any thread,
1705 and in any state. It is presently left to the target allowing
1706 memory accesses when threads are running. */
1709 watchpoint_in_thread_scope (struct watchpoint
*b
)
1711 return (b
->base
.pspace
== current_program_space
1712 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1713 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1714 && !is_executing (inferior_ptid
))));
1717 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1718 associated bp_watchpoint_scope breakpoint. */
1721 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1723 struct breakpoint
*b
= &w
->base
;
1725 if (b
->related_breakpoint
!= b
)
1727 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1728 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1729 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1730 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1731 b
->related_breakpoint
= b
;
1733 b
->disposition
= disp_del_at_next_stop
;
1736 /* Extract a bitfield value from value VAL using the bit parameters contained in
1739 static struct value
*
1740 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1742 struct value
*bit_val
;
1747 bit_val
= allocate_value (value_type (val
));
1749 unpack_value_bitfield (bit_val
,
1752 value_contents_for_printing (val
),
1759 /* Allocate a dummy location and add it to B, which must be a software
1760 watchpoint. This is required because even if a software watchpoint
1761 is not watching any memory, bpstat_stop_status requires a location
1762 to be able to report stops. */
1765 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1766 struct program_space
*pspace
)
1768 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1770 b
->loc
= allocate_bp_location (b
);
1771 b
->loc
->pspace
= pspace
;
1772 b
->loc
->address
= -1;
1773 b
->loc
->length
= -1;
1776 /* Returns true if B is a software watchpoint that is not watching any
1777 memory (e.g., "watch $pc"). */
1780 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1782 return (b
->type
== bp_watchpoint
1784 && b
->loc
->next
== NULL
1785 && b
->loc
->address
== -1
1786 && b
->loc
->length
== -1);
1789 /* Assuming that B is a watchpoint:
1790 - Reparse watchpoint expression, if REPARSE is non-zero
1791 - Evaluate expression and store the result in B->val
1792 - Evaluate the condition if there is one, and store the result
1794 - Update the list of values that must be watched in B->loc.
1796 If the watchpoint disposition is disp_del_at_next_stop, then do
1797 nothing. If this is local watchpoint that is out of scope, delete
1800 Even with `set breakpoint always-inserted on' the watchpoints are
1801 removed + inserted on each stop here. Normal breakpoints must
1802 never be removed because they might be missed by a running thread
1803 when debugging in non-stop mode. On the other hand, hardware
1804 watchpoints (is_hardware_watchpoint; processed here) are specific
1805 to each LWP since they are stored in each LWP's hardware debug
1806 registers. Therefore, such LWP must be stopped first in order to
1807 be able to modify its hardware watchpoints.
1809 Hardware watchpoints must be reset exactly once after being
1810 presented to the user. It cannot be done sooner, because it would
1811 reset the data used to present the watchpoint hit to the user. And
1812 it must not be done later because it could display the same single
1813 watchpoint hit during multiple GDB stops. Note that the latter is
1814 relevant only to the hardware watchpoint types bp_read_watchpoint
1815 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1816 not user-visible - its hit is suppressed if the memory content has
1819 The following constraints influence the location where we can reset
1820 hardware watchpoints:
1822 * target_stopped_by_watchpoint and target_stopped_data_address are
1823 called several times when GDB stops.
1826 * Multiple hardware watchpoints can be hit at the same time,
1827 causing GDB to stop. GDB only presents one hardware watchpoint
1828 hit at a time as the reason for stopping, and all the other hits
1829 are presented later, one after the other, each time the user
1830 requests the execution to be resumed. Execution is not resumed
1831 for the threads still having pending hit event stored in
1832 LWP_INFO->STATUS. While the watchpoint is already removed from
1833 the inferior on the first stop the thread hit event is kept being
1834 reported from its cached value by linux_nat_stopped_data_address
1835 until the real thread resume happens after the watchpoint gets
1836 presented and thus its LWP_INFO->STATUS gets reset.
1838 Therefore the hardware watchpoint hit can get safely reset on the
1839 watchpoint removal from inferior. */
1842 update_watchpoint (struct watchpoint
*b
, int reparse
)
1844 int within_current_scope
;
1845 struct frame_id saved_frame_id
;
1848 /* If this is a local watchpoint, we only want to check if the
1849 watchpoint frame is in scope if the current thread is the thread
1850 that was used to create the watchpoint. */
1851 if (!watchpoint_in_thread_scope (b
))
1854 if (b
->base
.disposition
== disp_del_at_next_stop
)
1859 /* Determine if the watchpoint is within scope. */
1860 if (b
->exp_valid_block
== NULL
)
1861 within_current_scope
= 1;
1864 struct frame_info
*fi
= get_current_frame ();
1865 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1866 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1868 /* If we're at a point where the stack has been destroyed
1869 (e.g. in a function epilogue), unwinding may not work
1870 properly. Do not attempt to recreate locations at this
1871 point. See similar comments in watchpoint_check. */
1872 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1875 /* Save the current frame's ID so we can restore it after
1876 evaluating the watchpoint expression on its own frame. */
1877 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1878 took a frame parameter, so that we didn't have to change the
1881 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1883 fi
= frame_find_by_id (b
->watchpoint_frame
);
1884 within_current_scope
= (fi
!= NULL
);
1885 if (within_current_scope
)
1889 /* We don't free locations. They are stored in the bp_location array
1890 and update_global_location_list will eventually delete them and
1891 remove breakpoints if needed. */
1894 if (within_current_scope
&& reparse
)
1899 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1900 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1901 /* If the meaning of expression itself changed, the old value is
1902 no longer relevant. We don't want to report a watchpoint hit
1903 to the user when the old value and the new value may actually
1904 be completely different objects. */
1905 value_free (b
->val
);
1909 /* Note that unlike with breakpoints, the watchpoint's condition
1910 expression is stored in the breakpoint object, not in the
1911 locations (re)created below. */
1912 if (b
->base
.cond_string
!= NULL
)
1914 b
->cond_exp
.reset ();
1916 s
= b
->base
.cond_string
;
1917 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1921 /* If we failed to parse the expression, for example because
1922 it refers to a global variable in a not-yet-loaded shared library,
1923 don't try to insert watchpoint. We don't automatically delete
1924 such watchpoint, though, since failure to parse expression
1925 is different from out-of-scope watchpoint. */
1926 if (!target_has_execution
)
1928 /* Without execution, memory can't change. No use to try and
1929 set watchpoint locations. The watchpoint will be reset when
1930 the target gains execution, through breakpoint_re_set. */
1931 if (!can_use_hw_watchpoints
)
1933 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1934 b
->base
.type
= bp_watchpoint
;
1936 error (_("Can't set read/access watchpoint when "
1937 "hardware watchpoints are disabled."));
1940 else if (within_current_scope
&& b
->exp
)
1943 struct value
*val_chain
, *v
, *result
, *next
;
1944 struct program_space
*frame_pspace
;
1946 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1948 /* Avoid setting b->val if it's already set. The meaning of
1949 b->val is 'the last value' user saw, and we should update
1950 it only if we reported that last value to user. As it
1951 happens, the code that reports it updates b->val directly.
1952 We don't keep track of the memory value for masked
1954 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1956 if (b
->val_bitsize
!= 0)
1958 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1966 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1968 /* Look at each value on the value chain. */
1969 for (v
= val_chain
; v
; v
= value_next (v
))
1971 /* If it's a memory location, and GDB actually needed
1972 its contents to evaluate the expression, then we
1973 must watch it. If the first value returned is
1974 still lazy, that means an error occurred reading it;
1975 watch it anyway in case it becomes readable. */
1976 if (VALUE_LVAL (v
) == lval_memory
1977 && (v
== val_chain
|| ! value_lazy (v
)))
1979 struct type
*vtype
= check_typedef (value_type (v
));
1981 /* We only watch structs and arrays if user asked
1982 for it explicitly, never if they just happen to
1983 appear in the middle of some value chain. */
1985 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1986 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1989 enum target_hw_bp_type type
;
1990 struct bp_location
*loc
, **tmp
;
1991 int bitpos
= 0, bitsize
= 0;
1993 if (value_bitsize (v
) != 0)
1995 /* Extract the bit parameters out from the bitfield
1997 bitpos
= value_bitpos (v
);
1998 bitsize
= value_bitsize (v
);
2000 else if (v
== result
&& b
->val_bitsize
!= 0)
2002 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2003 lvalue whose bit parameters are saved in the fields
2004 VAL_BITPOS and VAL_BITSIZE. */
2005 bitpos
= b
->val_bitpos
;
2006 bitsize
= b
->val_bitsize
;
2009 addr
= value_address (v
);
2012 /* Skip the bytes that don't contain the bitfield. */
2017 if (b
->base
.type
== bp_read_watchpoint
)
2019 else if (b
->base
.type
== bp_access_watchpoint
)
2022 loc
= allocate_bp_location (&b
->base
);
2023 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2026 loc
->gdbarch
= get_type_arch (value_type (v
));
2028 loc
->pspace
= frame_pspace
;
2029 loc
->address
= addr
;
2033 /* Just cover the bytes that make up the bitfield. */
2034 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2037 loc
->length
= TYPE_LENGTH (value_type (v
));
2039 loc
->watchpoint_type
= type
;
2044 /* Change the type of breakpoint between hardware assisted or
2045 an ordinary watchpoint depending on the hardware support
2046 and free hardware slots. REPARSE is set when the inferior
2051 enum bp_loc_type loc_type
;
2052 struct bp_location
*bl
;
2054 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2058 int i
, target_resources_ok
, other_type_used
;
2061 /* Use an exact watchpoint when there's only one memory region to be
2062 watched, and only one debug register is needed to watch it. */
2063 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2065 /* We need to determine how many resources are already
2066 used for all other hardware watchpoints plus this one
2067 to see if we still have enough resources to also fit
2068 this watchpoint in as well. */
2070 /* If this is a software watchpoint, we try to turn it
2071 to a hardware one -- count resources as if B was of
2072 hardware watchpoint type. */
2073 type
= b
->base
.type
;
2074 if (type
== bp_watchpoint
)
2075 type
= bp_hardware_watchpoint
;
2077 /* This watchpoint may or may not have been placed on
2078 the list yet at this point (it won't be in the list
2079 if we're trying to create it for the first time,
2080 through watch_command), so always account for it
2083 /* Count resources used by all watchpoints except B. */
2084 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2086 /* Add in the resources needed for B. */
2087 i
+= hw_watchpoint_use_count (&b
->base
);
2090 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2091 if (target_resources_ok
<= 0)
2093 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2095 if (target_resources_ok
== 0 && !sw_mode
)
2096 error (_("Target does not support this type of "
2097 "hardware watchpoint."));
2098 else if (target_resources_ok
< 0 && !sw_mode
)
2099 error (_("There are not enough available hardware "
2100 "resources for this watchpoint."));
2102 /* Downgrade to software watchpoint. */
2103 b
->base
.type
= bp_watchpoint
;
2107 /* If this was a software watchpoint, we've just
2108 found we have enough resources to turn it to a
2109 hardware watchpoint. Otherwise, this is a
2111 b
->base
.type
= type
;
2114 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2116 if (!can_use_hw_watchpoints
)
2117 error (_("Can't set read/access watchpoint when "
2118 "hardware watchpoints are disabled."));
2120 error (_("Expression cannot be implemented with "
2121 "read/access watchpoint."));
2124 b
->base
.type
= bp_watchpoint
;
2126 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2127 : bp_loc_hardware_watchpoint
);
2128 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2129 bl
->loc_type
= loc_type
;
2132 for (v
= val_chain
; v
; v
= next
)
2134 next
= value_next (v
);
2139 /* If a software watchpoint is not watching any memory, then the
2140 above left it without any location set up. But,
2141 bpstat_stop_status requires a location to be able to report
2142 stops, so make sure there's at least a dummy one. */
2143 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2144 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2146 else if (!within_current_scope
)
2148 printf_filtered (_("\
2149 Watchpoint %d deleted because the program has left the block\n\
2150 in which its expression is valid.\n"),
2152 watchpoint_del_at_next_stop (b
);
2155 /* Restore the selected frame. */
2157 select_frame (frame_find_by_id (saved_frame_id
));
2161 /* Returns 1 iff breakpoint location should be
2162 inserted in the inferior. We don't differentiate the type of BL's owner
2163 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2164 breakpoint_ops is not defined, because in insert_bp_location,
2165 tracepoint's insert_location will not be called. */
2167 should_be_inserted (struct bp_location
*bl
)
2169 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2172 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2175 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2178 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2181 /* This is set for example, when we're attached to the parent of a
2182 vfork, and have detached from the child. The child is running
2183 free, and we expect it to do an exec or exit, at which point the
2184 OS makes the parent schedulable again (and the target reports
2185 that the vfork is done). Until the child is done with the shared
2186 memory region, do not insert breakpoints in the parent, otherwise
2187 the child could still trip on the parent's breakpoints. Since
2188 the parent is blocked anyway, it won't miss any breakpoint. */
2189 if (bl
->pspace
->breakpoints_not_allowed
)
2192 /* Don't insert a breakpoint if we're trying to step past its
2193 location, except if the breakpoint is a single-step breakpoint,
2194 and the breakpoint's thread is the thread which is stepping past
2196 if ((bl
->loc_type
== bp_loc_software_breakpoint
2197 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2198 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2200 /* The single-step breakpoint may be inserted at the location
2201 we're trying to step if the instruction branches to itself.
2202 However, the instruction won't be executed at all and it may
2203 break the semantics of the instruction, for example, the
2204 instruction is a conditional branch or updates some flags.
2205 We can't fix it unless GDB is able to emulate the instruction
2206 or switch to displaced stepping. */
2207 && !(bl
->owner
->type
== bp_single_step
2208 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2212 fprintf_unfiltered (gdb_stdlog
,
2213 "infrun: skipping breakpoint: "
2214 "stepping past insn at: %s\n",
2215 paddress (bl
->gdbarch
, bl
->address
));
2220 /* Don't insert watchpoints if we're trying to step past the
2221 instruction that triggered one. */
2222 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2223 && stepping_past_nonsteppable_watchpoint ())
2227 fprintf_unfiltered (gdb_stdlog
,
2228 "infrun: stepping past non-steppable watchpoint. "
2229 "skipping watchpoint at %s:%d\n",
2230 paddress (bl
->gdbarch
, bl
->address
),
2239 /* Same as should_be_inserted but does the check assuming
2240 that the location is not duplicated. */
2243 unduplicated_should_be_inserted (struct bp_location
*bl
)
2246 const int save_duplicate
= bl
->duplicate
;
2249 result
= should_be_inserted (bl
);
2250 bl
->duplicate
= save_duplicate
;
2254 /* Parses a conditional described by an expression COND into an
2255 agent expression bytecode suitable for evaluation
2256 by the bytecode interpreter. Return NULL if there was
2257 any error during parsing. */
2259 static struct agent_expr
*
2260 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2262 struct agent_expr
*aexpr
= NULL
;
2267 /* We don't want to stop processing, so catch any errors
2268 that may show up. */
2271 aexpr
= gen_eval_for_expr (scope
, cond
);
2274 CATCH (ex
, RETURN_MASK_ERROR
)
2276 /* If we got here, it means the condition could not be parsed to a valid
2277 bytecode expression and thus can't be evaluated on the target's side.
2278 It's no use iterating through the conditions. */
2283 /* We have a valid agent expression. */
2287 /* Based on location BL, create a list of breakpoint conditions to be
2288 passed on to the target. If we have duplicated locations with different
2289 conditions, we will add such conditions to the list. The idea is that the
2290 target will evaluate the list of conditions and will only notify GDB when
2291 one of them is true. */
2294 build_target_condition_list (struct bp_location
*bl
)
2296 struct bp_location
**locp
= NULL
, **loc2p
;
2297 int null_condition_or_parse_error
= 0;
2298 int modified
= bl
->needs_update
;
2299 struct bp_location
*loc
;
2301 /* Release conditions left over from a previous insert. */
2302 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2304 /* This is only meaningful if the target is
2305 evaluating conditions and if the user has
2306 opted for condition evaluation on the target's
2308 if (gdb_evaluates_breakpoint_condition_p ()
2309 || !target_supports_evaluation_of_breakpoint_conditions ())
2312 /* Do a first pass to check for locations with no assigned
2313 conditions or conditions that fail to parse to a valid agent expression
2314 bytecode. If any of these happen, then it's no use to send conditions
2315 to the target since this location will always trigger and generate a
2316 response back to GDB. */
2317 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2320 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2324 struct agent_expr
*aexpr
;
2326 /* Re-parse the conditions since something changed. In that
2327 case we already freed the condition bytecodes (see
2328 force_breakpoint_reinsertion). We just
2329 need to parse the condition to bytecodes again. */
2330 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
.get ());
2331 loc
->cond_bytecode
= aexpr
;
2334 /* If we have a NULL bytecode expression, it means something
2335 went wrong or we have a null condition expression. */
2336 if (!loc
->cond_bytecode
)
2338 null_condition_or_parse_error
= 1;
2344 /* If any of these happened, it means we will have to evaluate the conditions
2345 for the location's address on gdb's side. It is no use keeping bytecodes
2346 for all the other duplicate locations, thus we free all of them here.
2348 This is so we have a finer control over which locations' conditions are
2349 being evaluated by GDB or the remote stub. */
2350 if (null_condition_or_parse_error
)
2352 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2355 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2357 /* Only go as far as the first NULL bytecode is
2359 if (!loc
->cond_bytecode
)
2362 free_agent_expr (loc
->cond_bytecode
);
2363 loc
->cond_bytecode
= NULL
;
2368 /* No NULL conditions or failed bytecode generation. Build a condition list
2369 for this location's address. */
2370 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2374 && is_breakpoint (loc
->owner
)
2375 && loc
->pspace
->num
== bl
->pspace
->num
2376 && loc
->owner
->enable_state
== bp_enabled
2378 /* Add the condition to the vector. This will be used later to send the
2379 conditions to the target. */
2380 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2381 loc
->cond_bytecode
);
2387 /* Parses a command described by string CMD into an agent expression
2388 bytecode suitable for evaluation by the bytecode interpreter.
2389 Return NULL if there was any error during parsing. */
2391 static struct agent_expr
*
2392 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2394 struct cleanup
*old_cleanups
= 0;
2395 struct expression
**argvec
;
2396 struct agent_expr
*aexpr
= NULL
;
2397 const char *cmdrest
;
2398 const char *format_start
, *format_end
;
2399 struct format_piece
*fpieces
;
2401 struct gdbarch
*gdbarch
= get_current_arch ();
2408 if (*cmdrest
== ',')
2410 cmdrest
= skip_spaces_const (cmdrest
);
2412 if (*cmdrest
++ != '"')
2413 error (_("No format string following the location"));
2415 format_start
= cmdrest
;
2417 fpieces
= parse_format_string (&cmdrest
);
2419 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2421 format_end
= cmdrest
;
2423 if (*cmdrest
++ != '"')
2424 error (_("Bad format string, non-terminated '\"'."));
2426 cmdrest
= skip_spaces_const (cmdrest
);
2428 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2429 error (_("Invalid argument syntax"));
2431 if (*cmdrest
== ',')
2433 cmdrest
= skip_spaces_const (cmdrest
);
2435 /* For each argument, make an expression. */
2437 argvec
= (struct expression
**) alloca (strlen (cmd
)
2438 * sizeof (struct expression
*));
2441 while (*cmdrest
!= '\0')
2446 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2447 argvec
[nargs
++] = expr
.release ();
2449 if (*cmdrest
== ',')
2453 /* We don't want to stop processing, so catch any errors
2454 that may show up. */
2457 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2458 format_start
, format_end
- format_start
,
2459 fpieces
, nargs
, argvec
);
2461 CATCH (ex
, RETURN_MASK_ERROR
)
2463 /* If we got here, it means the command could not be parsed to a valid
2464 bytecode expression and thus can't be evaluated on the target's side.
2465 It's no use iterating through the other commands. */
2470 do_cleanups (old_cleanups
);
2472 /* We have a valid agent expression, return it. */
2476 /* Based on location BL, create a list of breakpoint commands to be
2477 passed on to the target. If we have duplicated locations with
2478 different commands, we will add any such to the list. */
2481 build_target_command_list (struct bp_location
*bl
)
2483 struct bp_location
**locp
= NULL
, **loc2p
;
2484 int null_command_or_parse_error
= 0;
2485 int modified
= bl
->needs_update
;
2486 struct bp_location
*loc
;
2488 /* Release commands left over from a previous insert. */
2489 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2491 if (!target_can_run_breakpoint_commands ())
2494 /* For now, limit to agent-style dprintf breakpoints. */
2495 if (dprintf_style
!= dprintf_style_agent
)
2498 /* For now, if we have any duplicate location that isn't a dprintf,
2499 don't install the target-side commands, as that would make the
2500 breakpoint not be reported to the core, and we'd lose
2502 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2505 if (is_breakpoint (loc
->owner
)
2506 && loc
->pspace
->num
== bl
->pspace
->num
2507 && loc
->owner
->type
!= bp_dprintf
)
2511 /* Do a first pass to check for locations with no assigned
2512 conditions or conditions that fail to parse to a valid agent expression
2513 bytecode. If any of these happen, then it's no use to send conditions
2514 to the target since this location will always trigger and generate a
2515 response back to GDB. */
2516 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2519 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2523 struct agent_expr
*aexpr
;
2525 /* Re-parse the commands since something changed. In that
2526 case we already freed the command bytecodes (see
2527 force_breakpoint_reinsertion). We just
2528 need to parse the command to bytecodes again. */
2529 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2530 loc
->owner
->extra_string
);
2531 loc
->cmd_bytecode
= aexpr
;
2534 /* If we have a NULL bytecode expression, it means something
2535 went wrong or we have a null command expression. */
2536 if (!loc
->cmd_bytecode
)
2538 null_command_or_parse_error
= 1;
2544 /* If anything failed, then we're not doing target-side commands,
2546 if (null_command_or_parse_error
)
2548 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2551 if (is_breakpoint (loc
->owner
)
2552 && loc
->pspace
->num
== bl
->pspace
->num
)
2554 /* Only go as far as the first NULL bytecode is
2556 if (loc
->cmd_bytecode
== NULL
)
2559 free_agent_expr (loc
->cmd_bytecode
);
2560 loc
->cmd_bytecode
= NULL
;
2565 /* No NULL commands or failed bytecode generation. Build a command list
2566 for this location's address. */
2567 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2570 if (loc
->owner
->extra_string
2571 && is_breakpoint (loc
->owner
)
2572 && loc
->pspace
->num
== bl
->pspace
->num
2573 && loc
->owner
->enable_state
== bp_enabled
2575 /* Add the command to the vector. This will be used later
2576 to send the commands to the target. */
2577 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2581 bl
->target_info
.persist
= 0;
2582 /* Maybe flag this location as persistent. */
2583 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2584 bl
->target_info
.persist
= 1;
2587 /* Return the kind of breakpoint on address *ADDR. Get the kind
2588 of breakpoint according to ADDR except single-step breakpoint.
2589 Get the kind of single-step breakpoint according to the current
2593 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2595 if (bl
->owner
->type
== bp_single_step
)
2597 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2598 struct regcache
*regcache
;
2600 regcache
= get_thread_regcache (thr
->ptid
);
2602 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2606 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2609 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2610 location. Any error messages are printed to TMP_ERROR_STREAM; and
2611 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2612 Returns 0 for success, 1 if the bp_location type is not supported or
2615 NOTE drow/2003-09-09: This routine could be broken down to an
2616 object-style method for each breakpoint or catchpoint type. */
2618 insert_bp_location (struct bp_location
*bl
,
2619 struct ui_file
*tmp_error_stream
,
2620 int *disabled_breaks
,
2621 int *hw_breakpoint_error
,
2622 int *hw_bp_error_explained_already
)
2624 enum errors bp_err
= GDB_NO_ERROR
;
2625 const char *bp_err_message
= NULL
;
2627 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2630 /* Note we don't initialize bl->target_info, as that wipes out
2631 the breakpoint location's shadow_contents if the breakpoint
2632 is still inserted at that location. This in turn breaks
2633 target_read_memory which depends on these buffers when
2634 a memory read is requested at the breakpoint location:
2635 Once the target_info has been wiped, we fail to see that
2636 we have a breakpoint inserted at that address and thus
2637 read the breakpoint instead of returning the data saved in
2638 the breakpoint location's shadow contents. */
2639 bl
->target_info
.reqstd_address
= bl
->address
;
2640 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2641 bl
->target_info
.length
= bl
->length
;
2643 /* When working with target-side conditions, we must pass all the conditions
2644 for the same breakpoint address down to the target since GDB will not
2645 insert those locations. With a list of breakpoint conditions, the target
2646 can decide when to stop and notify GDB. */
2648 if (is_breakpoint (bl
->owner
))
2650 build_target_condition_list (bl
);
2651 build_target_command_list (bl
);
2652 /* Reset the modification marker. */
2653 bl
->needs_update
= 0;
2656 if (bl
->loc_type
== bp_loc_software_breakpoint
2657 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2659 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2661 /* If the explicitly specified breakpoint type
2662 is not hardware breakpoint, check the memory map to see
2663 if the breakpoint address is in read only memory or not.
2665 Two important cases are:
2666 - location type is not hardware breakpoint, memory
2667 is readonly. We change the type of the location to
2668 hardware breakpoint.
2669 - location type is hardware breakpoint, memory is
2670 read-write. This means we've previously made the
2671 location hardware one, but then the memory map changed,
2674 When breakpoints are removed, remove_breakpoints will use
2675 location types we've just set here, the only possible
2676 problem is that memory map has changed during running
2677 program, but it's not going to work anyway with current
2679 struct mem_region
*mr
2680 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2684 if (automatic_hardware_breakpoints
)
2686 enum bp_loc_type new_type
;
2688 if (mr
->attrib
.mode
!= MEM_RW
)
2689 new_type
= bp_loc_hardware_breakpoint
;
2691 new_type
= bp_loc_software_breakpoint
;
2693 if (new_type
!= bl
->loc_type
)
2695 static int said
= 0;
2697 bl
->loc_type
= new_type
;
2700 fprintf_filtered (gdb_stdout
,
2701 _("Note: automatically using "
2702 "hardware breakpoints for "
2703 "read-only addresses.\n"));
2708 else if (bl
->loc_type
== bp_loc_software_breakpoint
2709 && mr
->attrib
.mode
!= MEM_RW
)
2711 fprintf_unfiltered (tmp_error_stream
,
2712 _("Cannot insert breakpoint %d.\n"
2713 "Cannot set software breakpoint "
2714 "at read-only address %s\n"),
2716 paddress (bl
->gdbarch
, bl
->address
));
2722 /* First check to see if we have to handle an overlay. */
2723 if (overlay_debugging
== ovly_off
2724 || bl
->section
== NULL
2725 || !(section_is_overlay (bl
->section
)))
2727 /* No overlay handling: just set the breakpoint. */
2732 val
= bl
->owner
->ops
->insert_location (bl
);
2734 bp_err
= GENERIC_ERROR
;
2736 CATCH (e
, RETURN_MASK_ALL
)
2739 bp_err_message
= e
.message
;
2745 /* This breakpoint is in an overlay section.
2746 Shall we set a breakpoint at the LMA? */
2747 if (!overlay_events_enabled
)
2749 /* Yes -- overlay event support is not active,
2750 so we must try to set a breakpoint at the LMA.
2751 This will not work for a hardware breakpoint. */
2752 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2753 warning (_("hardware breakpoint %d not supported in overlay!"),
2757 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2759 /* Set a software (trap) breakpoint at the LMA. */
2760 bl
->overlay_target_info
= bl
->target_info
;
2761 bl
->overlay_target_info
.reqstd_address
= addr
;
2763 /* No overlay handling: just set the breakpoint. */
2768 bl
->overlay_target_info
.kind
2769 = breakpoint_kind (bl
, &addr
);
2770 bl
->overlay_target_info
.placed_address
= addr
;
2771 val
= target_insert_breakpoint (bl
->gdbarch
,
2772 &bl
->overlay_target_info
);
2774 bp_err
= GENERIC_ERROR
;
2776 CATCH (e
, RETURN_MASK_ALL
)
2779 bp_err_message
= e
.message
;
2783 if (bp_err
!= GDB_NO_ERROR
)
2784 fprintf_unfiltered (tmp_error_stream
,
2785 "Overlay breakpoint %d "
2786 "failed: in ROM?\n",
2790 /* Shall we set a breakpoint at the VMA? */
2791 if (section_is_mapped (bl
->section
))
2793 /* Yes. This overlay section is mapped into memory. */
2798 val
= bl
->owner
->ops
->insert_location (bl
);
2800 bp_err
= GENERIC_ERROR
;
2802 CATCH (e
, RETURN_MASK_ALL
)
2805 bp_err_message
= e
.message
;
2811 /* No. This breakpoint will not be inserted.
2812 No error, but do not mark the bp as 'inserted'. */
2817 if (bp_err
!= GDB_NO_ERROR
)
2819 /* Can't set the breakpoint. */
2821 /* In some cases, we might not be able to insert a
2822 breakpoint in a shared library that has already been
2823 removed, but we have not yet processed the shlib unload
2824 event. Unfortunately, some targets that implement
2825 breakpoint insertion themselves can't tell why the
2826 breakpoint insertion failed (e.g., the remote target
2827 doesn't define error codes), so we must treat generic
2828 errors as memory errors. */
2829 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2830 && bl
->loc_type
== bp_loc_software_breakpoint
2831 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2832 || shared_objfile_contains_address_p (bl
->pspace
,
2835 /* See also: disable_breakpoints_in_shlibs. */
2836 bl
->shlib_disabled
= 1;
2837 observer_notify_breakpoint_modified (bl
->owner
);
2838 if (!*disabled_breaks
)
2840 fprintf_unfiltered (tmp_error_stream
,
2841 "Cannot insert breakpoint %d.\n",
2843 fprintf_unfiltered (tmp_error_stream
,
2844 "Temporarily disabling shared "
2845 "library breakpoints:\n");
2847 *disabled_breaks
= 1;
2848 fprintf_unfiltered (tmp_error_stream
,
2849 "breakpoint #%d\n", bl
->owner
->number
);
2854 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2856 *hw_breakpoint_error
= 1;
2857 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2858 fprintf_unfiltered (tmp_error_stream
,
2859 "Cannot insert hardware breakpoint %d%s",
2860 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2861 if (bp_err_message
!= NULL
)
2862 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2866 if (bp_err_message
== NULL
)
2869 = memory_error_message (TARGET_XFER_E_IO
,
2870 bl
->gdbarch
, bl
->address
);
2871 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2873 fprintf_unfiltered (tmp_error_stream
,
2874 "Cannot insert breakpoint %d.\n"
2876 bl
->owner
->number
, message
);
2877 do_cleanups (old_chain
);
2881 fprintf_unfiltered (tmp_error_stream
,
2882 "Cannot insert breakpoint %d: %s\n",
2897 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2898 /* NOTE drow/2003-09-08: This state only exists for removing
2899 watchpoints. It's not clear that it's necessary... */
2900 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2904 gdb_assert (bl
->owner
->ops
!= NULL
2905 && bl
->owner
->ops
->insert_location
!= NULL
);
2907 val
= bl
->owner
->ops
->insert_location (bl
);
2909 /* If trying to set a read-watchpoint, and it turns out it's not
2910 supported, try emulating one with an access watchpoint. */
2911 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2913 struct bp_location
*loc
, **loc_temp
;
2915 /* But don't try to insert it, if there's already another
2916 hw_access location that would be considered a duplicate
2918 ALL_BP_LOCATIONS (loc
, loc_temp
)
2920 && loc
->watchpoint_type
== hw_access
2921 && watchpoint_locations_match (bl
, loc
))
2925 bl
->target_info
= loc
->target_info
;
2926 bl
->watchpoint_type
= hw_access
;
2933 bl
->watchpoint_type
= hw_access
;
2934 val
= bl
->owner
->ops
->insert_location (bl
);
2937 /* Back to the original value. */
2938 bl
->watchpoint_type
= hw_read
;
2942 bl
->inserted
= (val
== 0);
2945 else if (bl
->owner
->type
== bp_catchpoint
)
2949 gdb_assert (bl
->owner
->ops
!= NULL
2950 && bl
->owner
->ops
->insert_location
!= NULL
);
2952 val
= bl
->owner
->ops
->insert_location (bl
);
2955 bl
->owner
->enable_state
= bp_disabled
;
2959 Error inserting catchpoint %d: Your system does not support this type\n\
2960 of catchpoint."), bl
->owner
->number
);
2962 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2965 bl
->inserted
= (val
== 0);
2967 /* We've already printed an error message if there was a problem
2968 inserting this catchpoint, and we've disabled the catchpoint,
2969 so just return success. */
2976 /* This function is called when program space PSPACE is about to be
2977 deleted. It takes care of updating breakpoints to not reference
2981 breakpoint_program_space_exit (struct program_space
*pspace
)
2983 struct breakpoint
*b
, *b_temp
;
2984 struct bp_location
*loc
, **loc_temp
;
2986 /* Remove any breakpoint that was set through this program space. */
2987 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2989 if (b
->pspace
== pspace
)
2990 delete_breakpoint (b
);
2993 /* Breakpoints set through other program spaces could have locations
2994 bound to PSPACE as well. Remove those. */
2995 ALL_BP_LOCATIONS (loc
, loc_temp
)
2997 struct bp_location
*tmp
;
2999 if (loc
->pspace
== pspace
)
3001 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3002 if (loc
->owner
->loc
== loc
)
3003 loc
->owner
->loc
= loc
->next
;
3005 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3006 if (tmp
->next
== loc
)
3008 tmp
->next
= loc
->next
;
3014 /* Now update the global location list to permanently delete the
3015 removed locations above. */
3016 update_global_location_list (UGLL_DONT_INSERT
);
3019 /* Make sure all breakpoints are inserted in inferior.
3020 Throws exception on any error.
3021 A breakpoint that is already inserted won't be inserted
3022 again, so calling this function twice is safe. */
3024 insert_breakpoints (void)
3026 struct breakpoint
*bpt
;
3028 ALL_BREAKPOINTS (bpt
)
3029 if (is_hardware_watchpoint (bpt
))
3031 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3033 update_watchpoint (w
, 0 /* don't reparse. */);
3036 /* Updating watchpoints creates new locations, so update the global
3037 location list. Explicitly tell ugll to insert locations and
3038 ignore breakpoints_always_inserted_mode. */
3039 update_global_location_list (UGLL_INSERT
);
3042 /* Invoke CALLBACK for each of bp_location. */
3045 iterate_over_bp_locations (walk_bp_location_callback callback
)
3047 struct bp_location
*loc
, **loc_tmp
;
3049 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3051 callback (loc
, NULL
);
3055 /* This is used when we need to synch breakpoint conditions between GDB and the
3056 target. It is the case with deleting and disabling of breakpoints when using
3057 always-inserted mode. */
3060 update_inserted_breakpoint_locations (void)
3062 struct bp_location
*bl
, **blp_tmp
;
3065 int disabled_breaks
= 0;
3066 int hw_breakpoint_error
= 0;
3067 int hw_bp_details_reported
= 0;
3069 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3070 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3072 /* Explicitly mark the warning -- this will only be printed if
3073 there was an error. */
3074 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3076 save_current_space_and_thread ();
3078 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3080 /* We only want to update software breakpoints and hardware
3082 if (!is_breakpoint (bl
->owner
))
3085 /* We only want to update locations that are already inserted
3086 and need updating. This is to avoid unwanted insertion during
3087 deletion of breakpoints. */
3088 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3091 switch_to_program_space_and_thread (bl
->pspace
);
3093 /* For targets that support global breakpoints, there's no need
3094 to select an inferior to insert breakpoint to. In fact, even
3095 if we aren't attached to any process yet, we should still
3096 insert breakpoints. */
3097 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3098 && ptid_equal (inferior_ptid
, null_ptid
))
3101 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3102 &hw_breakpoint_error
, &hw_bp_details_reported
);
3109 target_terminal_ours_for_output ();
3110 error_stream (tmp_error_stream
);
3113 do_cleanups (cleanups
);
3116 /* Used when starting or continuing the program. */
3119 insert_breakpoint_locations (void)
3121 struct breakpoint
*bpt
;
3122 struct bp_location
*bl
, **blp_tmp
;
3125 int disabled_breaks
= 0;
3126 int hw_breakpoint_error
= 0;
3127 int hw_bp_error_explained_already
= 0;
3129 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3130 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3132 /* Explicitly mark the warning -- this will only be printed if
3133 there was an error. */
3134 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3136 save_current_space_and_thread ();
3138 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3140 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3143 /* There is no point inserting thread-specific breakpoints if
3144 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3145 has BL->OWNER always non-NULL. */
3146 if (bl
->owner
->thread
!= -1
3147 && !valid_global_thread_id (bl
->owner
->thread
))
3150 switch_to_program_space_and_thread (bl
->pspace
);
3152 /* For targets that support global breakpoints, there's no need
3153 to select an inferior to insert breakpoint to. In fact, even
3154 if we aren't attached to any process yet, we should still
3155 insert breakpoints. */
3156 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3157 && ptid_equal (inferior_ptid
, null_ptid
))
3160 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3161 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3166 /* If we failed to insert all locations of a watchpoint, remove
3167 them, as half-inserted watchpoint is of limited use. */
3168 ALL_BREAKPOINTS (bpt
)
3170 int some_failed
= 0;
3171 struct bp_location
*loc
;
3173 if (!is_hardware_watchpoint (bpt
))
3176 if (!breakpoint_enabled (bpt
))
3179 if (bpt
->disposition
== disp_del_at_next_stop
)
3182 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3183 if (!loc
->inserted
&& should_be_inserted (loc
))
3190 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3192 remove_breakpoint (loc
);
3194 hw_breakpoint_error
= 1;
3195 fprintf_unfiltered (tmp_error_stream
,
3196 "Could not insert hardware watchpoint %d.\n",
3204 /* If a hardware breakpoint or watchpoint was inserted, add a
3205 message about possibly exhausted resources. */
3206 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3208 fprintf_unfiltered (tmp_error_stream
,
3209 "Could not insert hardware breakpoints:\n\
3210 You may have requested too many hardware breakpoints/watchpoints.\n");
3212 target_terminal_ours_for_output ();
3213 error_stream (tmp_error_stream
);
3216 do_cleanups (cleanups
);
3219 /* Used when the program stops.
3220 Returns zero if successful, or non-zero if there was a problem
3221 removing a breakpoint location. */
3224 remove_breakpoints (void)
3226 struct bp_location
*bl
, **blp_tmp
;
3229 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3231 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3232 val
|= remove_breakpoint (bl
);
3237 /* When a thread exits, remove breakpoints that are related to
3241 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3243 struct breakpoint
*b
, *b_tmp
;
3245 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3247 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3249 b
->disposition
= disp_del_at_next_stop
;
3251 printf_filtered (_("\
3252 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3253 b
->number
, print_thread_id (tp
));
3255 /* Hide it from the user. */
3261 /* Remove breakpoints of process PID. */
3264 remove_breakpoints_pid (int pid
)
3266 struct bp_location
*bl
, **blp_tmp
;
3268 struct inferior
*inf
= find_inferior_pid (pid
);
3270 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3272 if (bl
->pspace
!= inf
->pspace
)
3275 if (bl
->inserted
&& !bl
->target_info
.persist
)
3277 val
= remove_breakpoint (bl
);
3286 reattach_breakpoints (int pid
)
3288 struct cleanup
*old_chain
;
3289 struct bp_location
*bl
, **blp_tmp
;
3291 struct ui_file
*tmp_error_stream
;
3292 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3293 struct inferior
*inf
;
3294 struct thread_info
*tp
;
3296 tp
= any_live_thread_of_process (pid
);
3300 inf
= find_inferior_pid (pid
);
3301 old_chain
= save_inferior_ptid ();
3303 inferior_ptid
= tp
->ptid
;
3305 tmp_error_stream
= mem_fileopen ();
3306 make_cleanup_ui_file_delete (tmp_error_stream
);
3308 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3310 if (bl
->pspace
!= inf
->pspace
)
3316 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3319 do_cleanups (old_chain
);
3324 do_cleanups (old_chain
);
3328 static int internal_breakpoint_number
= -1;
3330 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3331 If INTERNAL is non-zero, the breakpoint number will be populated
3332 from internal_breakpoint_number and that variable decremented.
3333 Otherwise the breakpoint number will be populated from
3334 breakpoint_count and that value incremented. Internal breakpoints
3335 do not set the internal var bpnum. */
3337 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3340 b
->number
= internal_breakpoint_number
--;
3343 set_breakpoint_count (breakpoint_count
+ 1);
3344 b
->number
= breakpoint_count
;
3348 static struct breakpoint
*
3349 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3350 CORE_ADDR address
, enum bptype type
,
3351 const struct breakpoint_ops
*ops
)
3353 struct symtab_and_line sal
;
3354 struct breakpoint
*b
;
3356 init_sal (&sal
); /* Initialize to zeroes. */
3359 sal
.section
= find_pc_overlay (sal
.pc
);
3360 sal
.pspace
= current_program_space
;
3362 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3363 b
->number
= internal_breakpoint_number
--;
3364 b
->disposition
= disp_donttouch
;
3369 static const char *const longjmp_names
[] =
3371 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3373 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3375 /* Per-objfile data private to breakpoint.c. */
3376 struct breakpoint_objfile_data
3378 /* Minimal symbol for "_ovly_debug_event" (if any). */
3379 struct bound_minimal_symbol overlay_msym
;
3381 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3382 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3384 /* True if we have looked for longjmp probes. */
3385 int longjmp_searched
;
3387 /* SystemTap probe points for longjmp (if any). */
3388 VEC (probe_p
) *longjmp_probes
;
3390 /* Minimal symbol for "std::terminate()" (if any). */
3391 struct bound_minimal_symbol terminate_msym
;
3393 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3394 struct bound_minimal_symbol exception_msym
;
3396 /* True if we have looked for exception probes. */
3397 int exception_searched
;
3399 /* SystemTap probe points for unwinding (if any). */
3400 VEC (probe_p
) *exception_probes
;
3403 static const struct objfile_data
*breakpoint_objfile_key
;
3405 /* Minimal symbol not found sentinel. */
3406 static struct minimal_symbol msym_not_found
;
3408 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3411 msym_not_found_p (const struct minimal_symbol
*msym
)
3413 return msym
== &msym_not_found
;
3416 /* Return per-objfile data needed by breakpoint.c.
3417 Allocate the data if necessary. */
3419 static struct breakpoint_objfile_data
*
3420 get_breakpoint_objfile_data (struct objfile
*objfile
)
3422 struct breakpoint_objfile_data
*bp_objfile_data
;
3424 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3425 objfile_data (objfile
, breakpoint_objfile_key
));
3426 if (bp_objfile_data
== NULL
)
3429 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3431 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3432 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3434 return bp_objfile_data
;
3438 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3440 struct breakpoint_objfile_data
*bp_objfile_data
3441 = (struct breakpoint_objfile_data
*) data
;
3443 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3444 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3448 create_overlay_event_breakpoint (void)
3450 struct objfile
*objfile
;
3451 const char *const func_name
= "_ovly_debug_event";
3453 ALL_OBJFILES (objfile
)
3455 struct breakpoint
*b
;
3456 struct breakpoint_objfile_data
*bp_objfile_data
;
3458 struct explicit_location explicit_loc
;
3460 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3462 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3465 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3467 struct bound_minimal_symbol m
;
3469 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3470 if (m
.minsym
== NULL
)
3472 /* Avoid future lookups in this objfile. */
3473 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3476 bp_objfile_data
->overlay_msym
= m
;
3479 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3480 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3482 &internal_breakpoint_ops
);
3483 initialize_explicit_location (&explicit_loc
);
3484 explicit_loc
.function_name
= ASTRDUP (func_name
);
3485 b
->location
= new_explicit_location (&explicit_loc
);
3487 if (overlay_debugging
== ovly_auto
)
3489 b
->enable_state
= bp_enabled
;
3490 overlay_events_enabled
= 1;
3494 b
->enable_state
= bp_disabled
;
3495 overlay_events_enabled
= 0;
3501 create_longjmp_master_breakpoint (void)
3503 struct program_space
*pspace
;
3504 struct cleanup
*old_chain
;
3506 old_chain
= save_current_program_space ();
3508 ALL_PSPACES (pspace
)
3510 struct objfile
*objfile
;
3512 set_current_program_space (pspace
);
3514 ALL_OBJFILES (objfile
)
3517 struct gdbarch
*gdbarch
;
3518 struct breakpoint_objfile_data
*bp_objfile_data
;
3520 gdbarch
= get_objfile_arch (objfile
);
3522 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3524 if (!bp_objfile_data
->longjmp_searched
)
3528 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3531 /* We are only interested in checking one element. */
3532 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3534 if (!can_evaluate_probe_arguments (p
))
3536 /* We cannot use the probe interface here, because it does
3537 not know how to evaluate arguments. */
3538 VEC_free (probe_p
, ret
);
3542 bp_objfile_data
->longjmp_probes
= ret
;
3543 bp_objfile_data
->longjmp_searched
= 1;
3546 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3549 struct probe
*probe
;
3550 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3553 VEC_iterate (probe_p
,
3554 bp_objfile_data
->longjmp_probes
,
3558 struct breakpoint
*b
;
3560 b
= create_internal_breakpoint (gdbarch
,
3561 get_probe_address (probe
,
3564 &internal_breakpoint_ops
);
3566 = new_probe_location ("-probe-stap libc:longjmp");
3567 b
->enable_state
= bp_disabled
;
3573 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3576 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3578 struct breakpoint
*b
;
3579 const char *func_name
;
3581 struct explicit_location explicit_loc
;
3583 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3586 func_name
= longjmp_names
[i
];
3587 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3589 struct bound_minimal_symbol m
;
3591 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3592 if (m
.minsym
== NULL
)
3594 /* Prevent future lookups in this objfile. */
3595 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3598 bp_objfile_data
->longjmp_msym
[i
] = m
;
3601 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3602 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3603 &internal_breakpoint_ops
);
3604 initialize_explicit_location (&explicit_loc
);
3605 explicit_loc
.function_name
= ASTRDUP (func_name
);
3606 b
->location
= new_explicit_location (&explicit_loc
);
3607 b
->enable_state
= bp_disabled
;
3612 do_cleanups (old_chain
);
3615 /* Create a master std::terminate breakpoint. */
3617 create_std_terminate_master_breakpoint (void)
3619 struct program_space
*pspace
;
3620 struct cleanup
*old_chain
;
3621 const char *const func_name
= "std::terminate()";
3623 old_chain
= save_current_program_space ();
3625 ALL_PSPACES (pspace
)
3627 struct objfile
*objfile
;
3630 set_current_program_space (pspace
);
3632 ALL_OBJFILES (objfile
)
3634 struct breakpoint
*b
;
3635 struct breakpoint_objfile_data
*bp_objfile_data
;
3636 struct explicit_location explicit_loc
;
3638 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3640 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3643 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3645 struct bound_minimal_symbol m
;
3647 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3648 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3649 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3651 /* Prevent future lookups in this objfile. */
3652 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3655 bp_objfile_data
->terminate_msym
= m
;
3658 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3659 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3660 bp_std_terminate_master
,
3661 &internal_breakpoint_ops
);
3662 initialize_explicit_location (&explicit_loc
);
3663 explicit_loc
.function_name
= ASTRDUP (func_name
);
3664 b
->location
= new_explicit_location (&explicit_loc
);
3665 b
->enable_state
= bp_disabled
;
3669 do_cleanups (old_chain
);
3672 /* Install a master breakpoint on the unwinder's debug hook. */
3675 create_exception_master_breakpoint (void)
3677 struct objfile
*objfile
;
3678 const char *const func_name
= "_Unwind_DebugHook";
3680 ALL_OBJFILES (objfile
)
3682 struct breakpoint
*b
;
3683 struct gdbarch
*gdbarch
;
3684 struct breakpoint_objfile_data
*bp_objfile_data
;
3686 struct explicit_location explicit_loc
;
3688 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3690 /* We prefer the SystemTap probe point if it exists. */
3691 if (!bp_objfile_data
->exception_searched
)
3695 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3699 /* We are only interested in checking one element. */
3700 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3702 if (!can_evaluate_probe_arguments (p
))
3704 /* We cannot use the probe interface here, because it does
3705 not know how to evaluate arguments. */
3706 VEC_free (probe_p
, ret
);
3710 bp_objfile_data
->exception_probes
= ret
;
3711 bp_objfile_data
->exception_searched
= 1;
3714 if (bp_objfile_data
->exception_probes
!= NULL
)
3716 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3718 struct probe
*probe
;
3721 VEC_iterate (probe_p
,
3722 bp_objfile_data
->exception_probes
,
3726 struct breakpoint
*b
;
3728 b
= create_internal_breakpoint (gdbarch
,
3729 get_probe_address (probe
,
3731 bp_exception_master
,
3732 &internal_breakpoint_ops
);
3734 = new_probe_location ("-probe-stap libgcc:unwind");
3735 b
->enable_state
= bp_disabled
;
3741 /* Otherwise, try the hook function. */
3743 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3746 gdbarch
= get_objfile_arch (objfile
);
3748 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3750 struct bound_minimal_symbol debug_hook
;
3752 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3753 if (debug_hook
.minsym
== NULL
)
3755 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3759 bp_objfile_data
->exception_msym
= debug_hook
;
3762 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3763 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3765 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3766 &internal_breakpoint_ops
);
3767 initialize_explicit_location (&explicit_loc
);
3768 explicit_loc
.function_name
= ASTRDUP (func_name
);
3769 b
->location
= new_explicit_location (&explicit_loc
);
3770 b
->enable_state
= bp_disabled
;
3774 /* Does B have a location spec? */
3777 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3779 return b
->location
!= NULL
&& event_location_empty_p (b
->location
);
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 (breakpoint_event_location_empty_p (b
))
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
, DETACH_BREAKPOINT
);
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
, enum remove_bp_reason reason
)
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
, reason
);
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
,
4015 /* Did we set a breakpoint at the VMA?
4016 If so, we will have marked the breakpoint 'inserted'. */
4019 /* Yes -- remove it. Previously we did not bother to
4020 remove the breakpoint if the section had been
4021 unmapped, but let's not rely on that being safe. We
4022 don't know what the overlay manager might do. */
4024 /* However, we should remove *software* breakpoints only
4025 if the section is still mapped, or else we overwrite
4026 wrong code with the saved shadow contents. */
4027 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4028 || section_is_mapped (bl
->section
))
4029 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4035 /* No -- not inserted, so no need to remove. No error. */
4040 /* In some cases, we might not be able to remove a breakpoint in
4041 a shared library that has already been removed, but we have
4042 not yet processed the shlib unload event. Similarly for an
4043 unloaded add-symbol-file object - the user might not yet have
4044 had the chance to remove-symbol-file it. shlib_disabled will
4045 be set if the library/object has already been removed, but
4046 the breakpoint hasn't been uninserted yet, e.g., after
4047 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4048 always-inserted mode. */
4050 && (bl
->loc_type
== bp_loc_software_breakpoint
4051 && (bl
->shlib_disabled
4052 || solib_name_from_address (bl
->pspace
, bl
->address
)
4053 || shared_objfile_contains_address_p (bl
->pspace
,
4059 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4061 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4063 gdb_assert (bl
->owner
->ops
!= NULL
4064 && bl
->owner
->ops
->remove_location
!= NULL
);
4066 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4067 bl
->owner
->ops
->remove_location (bl
, reason
);
4069 /* Failure to remove any of the hardware watchpoints comes here. */
4070 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4071 warning (_("Could not remove hardware watchpoint %d."),
4074 else if (bl
->owner
->type
== bp_catchpoint
4075 && breakpoint_enabled (bl
->owner
)
4078 gdb_assert (bl
->owner
->ops
!= NULL
4079 && bl
->owner
->ops
->remove_location
!= NULL
);
4081 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4085 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4092 remove_breakpoint (struct bp_location
*bl
)
4095 struct cleanup
*old_chain
;
4097 /* BL is never in moribund_locations by our callers. */
4098 gdb_assert (bl
->owner
!= NULL
);
4100 /* The type of none suggests that owner is actually deleted.
4101 This should not ever happen. */
4102 gdb_assert (bl
->owner
->type
!= bp_none
);
4104 old_chain
= save_current_space_and_thread ();
4106 switch_to_program_space_and_thread (bl
->pspace
);
4108 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4110 do_cleanups (old_chain
);
4114 /* Clear the "inserted" flag in all breakpoints. */
4117 mark_breakpoints_out (void)
4119 struct bp_location
*bl
, **blp_tmp
;
4121 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4122 if (bl
->pspace
== current_program_space
)
4126 /* Clear the "inserted" flag in all breakpoints and delete any
4127 breakpoints which should go away between runs of the program.
4129 Plus other such housekeeping that has to be done for breakpoints
4132 Note: this function gets called at the end of a run (by
4133 generic_mourn_inferior) and when a run begins (by
4134 init_wait_for_inferior). */
4139 breakpoint_init_inferior (enum inf_context context
)
4141 struct breakpoint
*b
, *b_tmp
;
4142 struct bp_location
*bl
;
4144 struct program_space
*pspace
= current_program_space
;
4146 /* If breakpoint locations are shared across processes, then there's
4148 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4151 mark_breakpoints_out ();
4153 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4155 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4161 case bp_longjmp_call_dummy
:
4163 /* If the call dummy breakpoint is at the entry point it will
4164 cause problems when the inferior is rerun, so we better get
4167 case bp_watchpoint_scope
:
4169 /* Also get rid of scope breakpoints. */
4171 case bp_shlib_event
:
4173 /* Also remove solib event breakpoints. Their addresses may
4174 have changed since the last time we ran the program.
4175 Actually we may now be debugging against different target;
4176 and so the solib backend that installed this breakpoint may
4177 not be used in by the target. E.g.,
4179 (gdb) file prog-linux
4180 (gdb) run # native linux target
4183 (gdb) file prog-win.exe
4184 (gdb) tar rem :9999 # remote Windows gdbserver.
4187 case bp_step_resume
:
4189 /* Also remove step-resume breakpoints. */
4191 case bp_single_step
:
4193 /* Also remove single-step breakpoints. */
4195 delete_breakpoint (b
);
4199 case bp_hardware_watchpoint
:
4200 case bp_read_watchpoint
:
4201 case bp_access_watchpoint
:
4203 struct watchpoint
*w
= (struct watchpoint
*) b
;
4205 /* Likewise for watchpoints on local expressions. */
4206 if (w
->exp_valid_block
!= NULL
)
4207 delete_breakpoint (b
);
4210 /* Get rid of existing locations, which are no longer
4211 valid. New ones will be created in
4212 update_watchpoint, when the inferior is restarted.
4213 The next update_global_location_list call will
4214 garbage collect them. */
4217 if (context
== inf_starting
)
4219 /* Reset val field to force reread of starting value in
4220 insert_breakpoints. */
4222 value_free (w
->val
);
4234 /* Get rid of the moribund locations. */
4235 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4236 decref_bp_location (&bl
);
4237 VEC_free (bp_location_p
, moribund_locations
);
4240 /* These functions concern about actual breakpoints inserted in the
4241 target --- to e.g. check if we need to do decr_pc adjustment or if
4242 we need to hop over the bkpt --- so we check for address space
4243 match, not program space. */
4245 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4246 exists at PC. It returns ordinary_breakpoint_here if it's an
4247 ordinary breakpoint, or permanent_breakpoint_here if it's a
4248 permanent breakpoint.
4249 - When continuing from a location with an ordinary breakpoint, we
4250 actually single step once before calling insert_breakpoints.
4251 - When continuing from a location with a permanent breakpoint, we
4252 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4253 the target, to advance the PC past the breakpoint. */
4255 enum breakpoint_here
4256 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4258 struct bp_location
*bl
, **blp_tmp
;
4259 int any_breakpoint_here
= 0;
4261 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4263 if (bl
->loc_type
!= bp_loc_software_breakpoint
4264 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4267 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4268 if ((breakpoint_enabled (bl
->owner
)
4270 && breakpoint_location_address_match (bl
, aspace
, pc
))
4272 if (overlay_debugging
4273 && section_is_overlay (bl
->section
)
4274 && !section_is_mapped (bl
->section
))
4275 continue; /* unmapped overlay -- can't be a match */
4276 else if (bl
->permanent
)
4277 return permanent_breakpoint_here
;
4279 any_breakpoint_here
= 1;
4283 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4286 /* See breakpoint.h. */
4289 breakpoint_in_range_p (struct address_space
*aspace
,
4290 CORE_ADDR addr
, ULONGEST len
)
4292 struct bp_location
*bl
, **blp_tmp
;
4294 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4296 if (bl
->loc_type
!= bp_loc_software_breakpoint
4297 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4300 if ((breakpoint_enabled (bl
->owner
)
4302 && breakpoint_location_address_range_overlap (bl
, aspace
,
4305 if (overlay_debugging
4306 && section_is_overlay (bl
->section
)
4307 && !section_is_mapped (bl
->section
))
4309 /* Unmapped overlay -- can't be a match. */
4320 /* Return true if there's a moribund breakpoint at PC. */
4323 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4325 struct bp_location
*loc
;
4328 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4329 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4335 /* Returns non-zero iff BL is inserted at PC, in address space
4339 bp_location_inserted_here_p (struct bp_location
*bl
,
4340 struct address_space
*aspace
, CORE_ADDR pc
)
4343 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4346 if (overlay_debugging
4347 && section_is_overlay (bl
->section
)
4348 && !section_is_mapped (bl
->section
))
4349 return 0; /* unmapped overlay -- can't be a match */
4356 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4359 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4361 struct bp_location
**blp
, **blp_tmp
= NULL
;
4363 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4365 struct bp_location
*bl
= *blp
;
4367 if (bl
->loc_type
!= bp_loc_software_breakpoint
4368 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4371 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4377 /* This function returns non-zero iff there is a software breakpoint
4381 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4384 struct bp_location
**blp
, **blp_tmp
= NULL
;
4386 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4388 struct bp_location
*bl
= *blp
;
4390 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4393 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4400 /* See breakpoint.h. */
4403 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4406 struct bp_location
**blp
, **blp_tmp
= NULL
;
4408 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4410 struct bp_location
*bl
= *blp
;
4412 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4415 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4423 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4424 CORE_ADDR addr
, ULONGEST len
)
4426 struct breakpoint
*bpt
;
4428 ALL_BREAKPOINTS (bpt
)
4430 struct bp_location
*loc
;
4432 if (bpt
->type
!= bp_hardware_watchpoint
4433 && bpt
->type
!= bp_access_watchpoint
)
4436 if (!breakpoint_enabled (bpt
))
4439 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4440 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4444 /* Check for intersection. */
4445 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4446 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4455 /* bpstat stuff. External routines' interfaces are documented
4459 is_catchpoint (struct breakpoint
*ep
)
4461 return (ep
->type
== bp_catchpoint
);
4464 /* Frees any storage that is part of a bpstat. Does not walk the
4468 bpstat_free (bpstat bs
)
4470 if (bs
->old_val
!= NULL
)
4471 value_free (bs
->old_val
);
4472 decref_counted_command_line (&bs
->commands
);
4473 decref_bp_location (&bs
->bp_location_at
);
4477 /* Clear a bpstat so that it says we are not at any breakpoint.
4478 Also free any storage that is part of a bpstat. */
4481 bpstat_clear (bpstat
*bsp
)
4498 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4499 is part of the bpstat is copied as well. */
4502 bpstat_copy (bpstat bs
)
4506 bpstat retval
= NULL
;
4511 for (; bs
!= NULL
; bs
= bs
->next
)
4513 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4514 memcpy (tmp
, bs
, sizeof (*tmp
));
4515 incref_counted_command_line (tmp
->commands
);
4516 incref_bp_location (tmp
->bp_location_at
);
4517 if (bs
->old_val
!= NULL
)
4519 tmp
->old_val
= value_copy (bs
->old_val
);
4520 release_value (tmp
->old_val
);
4524 /* This is the first thing in the chain. */
4534 /* Find the bpstat associated with this breakpoint. */
4537 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4542 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4544 if (bsp
->breakpoint_at
== breakpoint
)
4550 /* See breakpoint.h. */
4553 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4555 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4557 if (bsp
->breakpoint_at
== NULL
)
4559 /* A moribund location can never explain a signal other than
4561 if (sig
== GDB_SIGNAL_TRAP
)
4566 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4575 /* Put in *NUM the breakpoint number of the first breakpoint we are
4576 stopped at. *BSP upon return is a bpstat which points to the
4577 remaining breakpoints stopped at (but which is not guaranteed to be
4578 good for anything but further calls to bpstat_num).
4580 Return 0 if passed a bpstat which does not indicate any breakpoints.
4581 Return -1 if stopped at a breakpoint that has been deleted since
4583 Return 1 otherwise. */
4586 bpstat_num (bpstat
*bsp
, int *num
)
4588 struct breakpoint
*b
;
4591 return 0; /* No more breakpoint values */
4593 /* We assume we'll never have several bpstats that correspond to a
4594 single breakpoint -- otherwise, this function might return the
4595 same number more than once and this will look ugly. */
4596 b
= (*bsp
)->breakpoint_at
;
4597 *bsp
= (*bsp
)->next
;
4599 return -1; /* breakpoint that's been deleted since */
4601 *num
= b
->number
; /* We have its number */
4605 /* See breakpoint.h. */
4608 bpstat_clear_actions (void)
4610 struct thread_info
*tp
;
4613 if (ptid_equal (inferior_ptid
, null_ptid
))
4616 tp
= find_thread_ptid (inferior_ptid
);
4620 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4622 decref_counted_command_line (&bs
->commands
);
4624 if (bs
->old_val
!= NULL
)
4626 value_free (bs
->old_val
);
4632 /* Called when a command is about to proceed the inferior. */
4635 breakpoint_about_to_proceed (void)
4637 if (!ptid_equal (inferior_ptid
, null_ptid
))
4639 struct thread_info
*tp
= inferior_thread ();
4641 /* Allow inferior function calls in breakpoint commands to not
4642 interrupt the command list. When the call finishes
4643 successfully, the inferior will be standing at the same
4644 breakpoint as if nothing happened. */
4645 if (tp
->control
.in_infcall
)
4649 breakpoint_proceeded
= 1;
4652 /* Stub for cleaning up our state if we error-out of a breakpoint
4655 cleanup_executing_breakpoints (void *ignore
)
4657 executing_breakpoint_commands
= 0;
4660 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4661 or its equivalent. */
4664 command_line_is_silent (struct command_line
*cmd
)
4666 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4669 /* Execute all the commands associated with all the breakpoints at
4670 this location. Any of these commands could cause the process to
4671 proceed beyond this point, etc. We look out for such changes by
4672 checking the global "breakpoint_proceeded" after each command.
4674 Returns true if a breakpoint command resumed the inferior. In that
4675 case, it is the caller's responsibility to recall it again with the
4676 bpstat of the current thread. */
4679 bpstat_do_actions_1 (bpstat
*bsp
)
4682 struct cleanup
*old_chain
;
4685 /* Avoid endless recursion if a `source' command is contained
4687 if (executing_breakpoint_commands
)
4690 executing_breakpoint_commands
= 1;
4691 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4693 prevent_dont_repeat ();
4695 /* This pointer will iterate over the list of bpstat's. */
4698 breakpoint_proceeded
= 0;
4699 for (; bs
!= NULL
; bs
= bs
->next
)
4701 struct counted_command_line
*ccmd
;
4702 struct command_line
*cmd
;
4703 struct cleanup
*this_cmd_tree_chain
;
4705 /* Take ownership of the BSP's command tree, if it has one.
4707 The command tree could legitimately contain commands like
4708 'step' and 'next', which call clear_proceed_status, which
4709 frees stop_bpstat's command tree. To make sure this doesn't
4710 free the tree we're executing out from under us, we need to
4711 take ownership of the tree ourselves. Since a given bpstat's
4712 commands are only executed once, we don't need to copy it; we
4713 can clear the pointer in the bpstat, and make sure we free
4714 the tree when we're done. */
4715 ccmd
= bs
->commands
;
4716 bs
->commands
= NULL
;
4717 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4718 cmd
= ccmd
? ccmd
->commands
: NULL
;
4719 if (command_line_is_silent (cmd
))
4721 /* The action has been already done by bpstat_stop_status. */
4727 execute_control_command (cmd
);
4729 if (breakpoint_proceeded
)
4735 /* We can free this command tree now. */
4736 do_cleanups (this_cmd_tree_chain
);
4738 if (breakpoint_proceeded
)
4740 if (current_ui
->async
)
4741 /* If we are in async mode, then the target might be still
4742 running, not stopped at any breakpoint, so nothing for
4743 us to do here -- just return to the event loop. */
4746 /* In sync mode, when execute_control_command returns
4747 we're already standing on the next breakpoint.
4748 Breakpoint commands for that stop were not run, since
4749 execute_command does not run breakpoint commands --
4750 only command_line_handler does, but that one is not
4751 involved in execution of breakpoint commands. So, we
4752 can now execute breakpoint commands. It should be
4753 noted that making execute_command do bpstat actions is
4754 not an option -- in this case we'll have recursive
4755 invocation of bpstat for each breakpoint with a
4756 command, and can easily blow up GDB stack. Instead, we
4757 return true, which will trigger the caller to recall us
4758 with the new stop_bpstat. */
4763 do_cleanups (old_chain
);
4768 bpstat_do_actions (void)
4770 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4772 /* Do any commands attached to breakpoint we are stopped at. */
4773 while (!ptid_equal (inferior_ptid
, null_ptid
)
4774 && target_has_execution
4775 && !is_exited (inferior_ptid
)
4776 && !is_executing (inferior_ptid
))
4777 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4778 and only return when it is stopped at the next breakpoint, we
4779 keep doing breakpoint actions until it returns false to
4780 indicate the inferior was not resumed. */
4781 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4784 discard_cleanups (cleanup_if_error
);
4787 /* Print out the (old or new) value associated with a watchpoint. */
4790 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4793 fprintf_unfiltered (stream
, _("<unreadable>"));
4796 struct value_print_options opts
;
4797 get_user_print_options (&opts
);
4798 value_print (val
, stream
, &opts
);
4802 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4803 debugging multiple threads. */
4806 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4808 if (ui_out_is_mi_like_p (uiout
))
4811 ui_out_text (uiout
, "\n");
4813 if (show_thread_that_caused_stop ())
4816 struct thread_info
*thr
= inferior_thread ();
4818 ui_out_text (uiout
, "Thread ");
4819 ui_out_field_fmt (uiout
, "thread-id", "%s", print_thread_id (thr
));
4821 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4824 ui_out_text (uiout
, " \"");
4825 ui_out_field_fmt (uiout
, "name", "%s", name
);
4826 ui_out_text (uiout
, "\"");
4829 ui_out_text (uiout
, " hit ");
4833 /* Generic routine for printing messages indicating why we
4834 stopped. The behavior of this function depends on the value
4835 'print_it' in the bpstat structure. Under some circumstances we
4836 may decide not to print anything here and delegate the task to
4839 static enum print_stop_action
4840 print_bp_stop_message (bpstat bs
)
4842 switch (bs
->print_it
)
4845 /* Nothing should be printed for this bpstat entry. */
4846 return PRINT_UNKNOWN
;
4850 /* We still want to print the frame, but we already printed the
4851 relevant messages. */
4852 return PRINT_SRC_AND_LOC
;
4855 case print_it_normal
:
4857 struct breakpoint
*b
= bs
->breakpoint_at
;
4859 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4860 which has since been deleted. */
4862 return PRINT_UNKNOWN
;
4864 /* Normal case. Call the breakpoint's print_it method. */
4865 return b
->ops
->print_it (bs
);
4870 internal_error (__FILE__
, __LINE__
,
4871 _("print_bp_stop_message: unrecognized enum value"));
4876 /* A helper function that prints a shared library stopped event. */
4879 print_solib_event (int is_catchpoint
)
4882 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4884 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4888 if (any_added
|| any_deleted
)
4889 ui_out_text (current_uiout
,
4890 _("Stopped due to shared library event:\n"));
4892 ui_out_text (current_uiout
,
4893 _("Stopped due to shared library event (no "
4894 "libraries added or removed)\n"));
4897 if (ui_out_is_mi_like_p (current_uiout
))
4898 ui_out_field_string (current_uiout
, "reason",
4899 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4903 struct cleanup
*cleanup
;
4907 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4908 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4911 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4916 ui_out_text (current_uiout
, " ");
4917 ui_out_field_string (current_uiout
, "library", name
);
4918 ui_out_text (current_uiout
, "\n");
4921 do_cleanups (cleanup
);
4926 struct so_list
*iter
;
4928 struct cleanup
*cleanup
;
4930 ui_out_text (current_uiout
, _(" Inferior loaded "));
4931 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4934 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4939 ui_out_text (current_uiout
, " ");
4940 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4941 ui_out_text (current_uiout
, "\n");
4944 do_cleanups (cleanup
);
4948 /* Print a message indicating what happened. This is called from
4949 normal_stop(). The input to this routine is the head of the bpstat
4950 list - a list of the eventpoints that caused this stop. KIND is
4951 the target_waitkind for the stopping event. This
4952 routine calls the generic print routine for printing a message
4953 about reasons for stopping. This will print (for example) the
4954 "Breakpoint n," part of the output. The return value of this
4957 PRINT_UNKNOWN: Means we printed nothing.
4958 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4959 code to print the location. An example is
4960 "Breakpoint 1, " which should be followed by
4962 PRINT_SRC_ONLY: Means we printed something, but there is no need
4963 to also print the location part of the message.
4964 An example is the catch/throw messages, which
4965 don't require a location appended to the end.
4966 PRINT_NOTHING: We have done some printing and we don't need any
4967 further info to be printed. */
4969 enum print_stop_action
4970 bpstat_print (bpstat bs
, int kind
)
4972 enum print_stop_action val
;
4974 /* Maybe another breakpoint in the chain caused us to stop.
4975 (Currently all watchpoints go on the bpstat whether hit or not.
4976 That probably could (should) be changed, provided care is taken
4977 with respect to bpstat_explains_signal). */
4978 for (; bs
; bs
= bs
->next
)
4980 val
= print_bp_stop_message (bs
);
4981 if (val
== PRINT_SRC_ONLY
4982 || val
== PRINT_SRC_AND_LOC
4983 || val
== PRINT_NOTHING
)
4987 /* If we had hit a shared library event breakpoint,
4988 print_bp_stop_message would print out this message. If we hit an
4989 OS-level shared library event, do the same thing. */
4990 if (kind
== TARGET_WAITKIND_LOADED
)
4992 print_solib_event (0);
4993 return PRINT_NOTHING
;
4996 /* We reached the end of the chain, or we got a null BS to start
4997 with and nothing was printed. */
4998 return PRINT_UNKNOWN
;
5001 /* Evaluate the expression EXP and return 1 if value is zero.
5002 This returns the inverse of the condition because it is called
5003 from catch_errors which returns 0 if an exception happened, and if an
5004 exception happens we want execution to stop.
5005 The argument is a "struct expression *" that has been cast to a
5006 "void *" to make it pass through catch_errors. */
5009 breakpoint_cond_eval (void *exp
)
5011 struct value
*mark
= value_mark ();
5012 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
5014 value_free_to_mark (mark
);
5018 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5021 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5025 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5027 **bs_link_pointer
= bs
;
5028 *bs_link_pointer
= &bs
->next
;
5029 bs
->breakpoint_at
= bl
->owner
;
5030 bs
->bp_location_at
= bl
;
5031 incref_bp_location (bl
);
5032 /* If the condition is false, etc., don't do the commands. */
5033 bs
->commands
= NULL
;
5035 bs
->print_it
= print_it_normal
;
5039 /* The target has stopped with waitstatus WS. Check if any hardware
5040 watchpoints have triggered, according to the target. */
5043 watchpoints_triggered (struct target_waitstatus
*ws
)
5045 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5047 struct breakpoint
*b
;
5049 if (!stopped_by_watchpoint
)
5051 /* We were not stopped by a watchpoint. Mark all watchpoints
5052 as not triggered. */
5054 if (is_hardware_watchpoint (b
))
5056 struct watchpoint
*w
= (struct watchpoint
*) b
;
5058 w
->watchpoint_triggered
= watch_triggered_no
;
5064 if (!target_stopped_data_address (¤t_target
, &addr
))
5066 /* We were stopped by a watchpoint, but we don't know where.
5067 Mark all watchpoints as unknown. */
5069 if (is_hardware_watchpoint (b
))
5071 struct watchpoint
*w
= (struct watchpoint
*) b
;
5073 w
->watchpoint_triggered
= watch_triggered_unknown
;
5079 /* The target could report the data address. Mark watchpoints
5080 affected by this data address as triggered, and all others as not
5084 if (is_hardware_watchpoint (b
))
5086 struct watchpoint
*w
= (struct watchpoint
*) b
;
5087 struct bp_location
*loc
;
5089 w
->watchpoint_triggered
= watch_triggered_no
;
5090 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5092 if (is_masked_watchpoint (b
))
5094 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5095 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5097 if (newaddr
== start
)
5099 w
->watchpoint_triggered
= watch_triggered_yes
;
5103 /* Exact match not required. Within range is sufficient. */
5104 else if (target_watchpoint_addr_within_range (¤t_target
,
5108 w
->watchpoint_triggered
= watch_triggered_yes
;
5117 /* Possible return values for watchpoint_check (this can't be an enum
5118 because of check_errors). */
5119 /* The watchpoint has been deleted. */
5120 #define WP_DELETED 1
5121 /* The value has changed. */
5122 #define WP_VALUE_CHANGED 2
5123 /* The value has not changed. */
5124 #define WP_VALUE_NOT_CHANGED 3
5125 /* Ignore this watchpoint, no matter if the value changed or not. */
5128 #define BP_TEMPFLAG 1
5129 #define BP_HARDWAREFLAG 2
5131 /* Evaluate watchpoint condition expression and check if its value
5134 P should be a pointer to struct bpstat, but is defined as a void *
5135 in order for this function to be usable with catch_errors. */
5138 watchpoint_check (void *p
)
5140 bpstat bs
= (bpstat
) p
;
5141 struct watchpoint
*b
;
5142 struct frame_info
*fr
;
5143 int within_current_scope
;
5145 /* BS is built from an existing struct breakpoint. */
5146 gdb_assert (bs
->breakpoint_at
!= NULL
);
5147 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5149 /* If this is a local watchpoint, we only want to check if the
5150 watchpoint frame is in scope if the current thread is the thread
5151 that was used to create the watchpoint. */
5152 if (!watchpoint_in_thread_scope (b
))
5155 if (b
->exp_valid_block
== NULL
)
5156 within_current_scope
= 1;
5159 struct frame_info
*frame
= get_current_frame ();
5160 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5161 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5163 /* stack_frame_destroyed_p() returns a non-zero value if we're
5164 still in the function but the stack frame has already been
5165 invalidated. Since we can't rely on the values of local
5166 variables after the stack has been destroyed, we are treating
5167 the watchpoint in that state as `not changed' without further
5168 checking. Don't mark watchpoints as changed if the current
5169 frame is in an epilogue - even if they are in some other
5170 frame, our view of the stack is likely to be wrong and
5171 frame_find_by_id could error out. */
5172 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5175 fr
= frame_find_by_id (b
->watchpoint_frame
);
5176 within_current_scope
= (fr
!= NULL
);
5178 /* If we've gotten confused in the unwinder, we might have
5179 returned a frame that can't describe this variable. */
5180 if (within_current_scope
)
5182 struct symbol
*function
;
5184 function
= get_frame_function (fr
);
5185 if (function
== NULL
5186 || !contained_in (b
->exp_valid_block
,
5187 SYMBOL_BLOCK_VALUE (function
)))
5188 within_current_scope
= 0;
5191 if (within_current_scope
)
5192 /* If we end up stopping, the current frame will get selected
5193 in normal_stop. So this call to select_frame won't affect
5198 if (within_current_scope
)
5200 /* We use value_{,free_to_}mark because it could be a *long*
5201 time before we return to the command level and call
5202 free_all_values. We can't call free_all_values because we
5203 might be in the middle of evaluating a function call. */
5207 struct value
*new_val
;
5209 if (is_masked_watchpoint (&b
->base
))
5210 /* Since we don't know the exact trigger address (from
5211 stopped_data_address), just tell the user we've triggered
5212 a mask watchpoint. */
5213 return WP_VALUE_CHANGED
;
5215 mark
= value_mark ();
5216 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5218 if (b
->val_bitsize
!= 0)
5219 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5221 /* We use value_equal_contents instead of value_equal because
5222 the latter coerces an array to a pointer, thus comparing just
5223 the address of the array instead of its contents. This is
5224 not what we want. */
5225 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5226 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5228 if (new_val
!= NULL
)
5230 release_value (new_val
);
5231 value_free_to_mark (mark
);
5233 bs
->old_val
= b
->val
;
5236 return WP_VALUE_CHANGED
;
5240 /* Nothing changed. */
5241 value_free_to_mark (mark
);
5242 return WP_VALUE_NOT_CHANGED
;
5247 /* This seems like the only logical thing to do because
5248 if we temporarily ignored the watchpoint, then when
5249 we reenter the block in which it is valid it contains
5250 garbage (in the case of a function, it may have two
5251 garbage values, one before and one after the prologue).
5252 So we can't even detect the first assignment to it and
5253 watch after that (since the garbage may or may not equal
5254 the first value assigned). */
5255 /* We print all the stop information in
5256 breakpoint_ops->print_it, but in this case, by the time we
5257 call breakpoint_ops->print_it this bp will be deleted
5258 already. So we have no choice but print the information
5261 SWITCH_THRU_ALL_UIS ()
5263 struct ui_out
*uiout
= current_uiout
;
5265 if (ui_out_is_mi_like_p (uiout
))
5267 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5268 ui_out_text (uiout
, "\nWatchpoint ");
5269 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5271 " deleted because the program has left the block in\n"
5272 "which its expression is valid.\n");
5275 /* Make sure the watchpoint's commands aren't executed. */
5276 decref_counted_command_line (&b
->base
.commands
);
5277 watchpoint_del_at_next_stop (b
);
5283 /* Return true if it looks like target has stopped due to hitting
5284 breakpoint location BL. This function does not check if we should
5285 stop, only if BL explains the stop. */
5288 bpstat_check_location (const struct bp_location
*bl
,
5289 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5290 const struct target_waitstatus
*ws
)
5292 struct breakpoint
*b
= bl
->owner
;
5294 /* BL is from an existing breakpoint. */
5295 gdb_assert (b
!= NULL
);
5297 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5300 /* Determine if the watched values have actually changed, and we
5301 should stop. If not, set BS->stop to 0. */
5304 bpstat_check_watchpoint (bpstat bs
)
5306 const struct bp_location
*bl
;
5307 struct watchpoint
*b
;
5309 /* BS is built for existing struct breakpoint. */
5310 bl
= bs
->bp_location_at
;
5311 gdb_assert (bl
!= NULL
);
5312 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5313 gdb_assert (b
!= NULL
);
5316 int must_check_value
= 0;
5318 if (b
->base
.type
== bp_watchpoint
)
5319 /* For a software watchpoint, we must always check the
5321 must_check_value
= 1;
5322 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5323 /* We have a hardware watchpoint (read, write, or access)
5324 and the target earlier reported an address watched by
5326 must_check_value
= 1;
5327 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5328 && b
->base
.type
== bp_hardware_watchpoint
)
5329 /* We were stopped by a hardware watchpoint, but the target could
5330 not report the data address. We must check the watchpoint's
5331 value. Access and read watchpoints are out of luck; without
5332 a data address, we can't figure it out. */
5333 must_check_value
= 1;
5335 if (must_check_value
)
5338 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5340 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5341 int e
= catch_errors (watchpoint_check
, bs
, message
,
5343 do_cleanups (cleanups
);
5347 /* We've already printed what needs to be printed. */
5348 bs
->print_it
= print_it_done
;
5352 bs
->print_it
= print_it_noop
;
5355 case WP_VALUE_CHANGED
:
5356 if (b
->base
.type
== bp_read_watchpoint
)
5358 /* There are two cases to consider here:
5360 1. We're watching the triggered memory for reads.
5361 In that case, trust the target, and always report
5362 the watchpoint hit to the user. Even though
5363 reads don't cause value changes, the value may
5364 have changed since the last time it was read, and
5365 since we're not trapping writes, we will not see
5366 those, and as such we should ignore our notion of
5369 2. We're watching the triggered memory for both
5370 reads and writes. There are two ways this may
5373 2.1. This is a target that can't break on data
5374 reads only, but can break on accesses (reads or
5375 writes), such as e.g., x86. We detect this case
5376 at the time we try to insert read watchpoints.
5378 2.2. Otherwise, the target supports read
5379 watchpoints, but, the user set an access or write
5380 watchpoint watching the same memory as this read
5383 If we're watching memory writes as well as reads,
5384 ignore watchpoint hits when we find that the
5385 value hasn't changed, as reads don't cause
5386 changes. This still gives false positives when
5387 the program writes the same value to memory as
5388 what there was already in memory (we will confuse
5389 it for a read), but it's much better than
5392 int other_write_watchpoint
= 0;
5394 if (bl
->watchpoint_type
== hw_read
)
5396 struct breakpoint
*other_b
;
5398 ALL_BREAKPOINTS (other_b
)
5399 if (other_b
->type
== bp_hardware_watchpoint
5400 || other_b
->type
== bp_access_watchpoint
)
5402 struct watchpoint
*other_w
=
5403 (struct watchpoint
*) other_b
;
5405 if (other_w
->watchpoint_triggered
5406 == watch_triggered_yes
)
5408 other_write_watchpoint
= 1;
5414 if (other_write_watchpoint
5415 || bl
->watchpoint_type
== hw_access
)
5417 /* We're watching the same memory for writes,
5418 and the value changed since the last time we
5419 updated it, so this trap must be for a write.
5421 bs
->print_it
= print_it_noop
;
5426 case WP_VALUE_NOT_CHANGED
:
5427 if (b
->base
.type
== bp_hardware_watchpoint
5428 || b
->base
.type
== bp_watchpoint
)
5430 /* Don't stop: write watchpoints shouldn't fire if
5431 the value hasn't changed. */
5432 bs
->print_it
= print_it_noop
;
5440 /* Error from catch_errors. */
5442 SWITCH_THRU_ALL_UIS ()
5444 printf_filtered (_("Watchpoint %d deleted.\n"),
5447 watchpoint_del_at_next_stop (b
);
5448 /* We've already printed what needs to be printed. */
5449 bs
->print_it
= print_it_done
;
5454 else /* must_check_value == 0 */
5456 /* This is a case where some watchpoint(s) triggered, but
5457 not at the address of this watchpoint, or else no
5458 watchpoint triggered after all. So don't print
5459 anything for this watchpoint. */
5460 bs
->print_it
= print_it_noop
;
5466 /* For breakpoints that are currently marked as telling gdb to stop,
5467 check conditions (condition proper, frame, thread and ignore count)
5468 of breakpoint referred to by BS. If we should not stop for this
5469 breakpoint, set BS->stop to 0. */
5472 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5474 const struct bp_location
*bl
;
5475 struct breakpoint
*b
;
5476 int value_is_zero
= 0;
5477 struct expression
*cond
;
5479 gdb_assert (bs
->stop
);
5481 /* BS is built for existing struct breakpoint. */
5482 bl
= bs
->bp_location_at
;
5483 gdb_assert (bl
!= NULL
);
5484 b
= bs
->breakpoint_at
;
5485 gdb_assert (b
!= NULL
);
5487 /* Even if the target evaluated the condition on its end and notified GDB, we
5488 need to do so again since GDB does not know if we stopped due to a
5489 breakpoint or a single step breakpoint. */
5491 if (frame_id_p (b
->frame_id
)
5492 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5498 /* If this is a thread/task-specific breakpoint, don't waste cpu
5499 evaluating the condition if this isn't the specified
5501 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5502 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5509 /* Evaluate extension language breakpoints that have a "stop" method
5511 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5513 if (is_watchpoint (b
))
5515 struct watchpoint
*w
= (struct watchpoint
*) b
;
5517 cond
= w
->cond_exp
.get ();
5520 cond
= bl
->cond
.get ();
5522 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5524 int within_current_scope
= 1;
5525 struct watchpoint
* w
;
5527 /* We use value_mark and value_free_to_mark because it could
5528 be a long time before we return to the command level and
5529 call free_all_values. We can't call free_all_values
5530 because we might be in the middle of evaluating a
5532 struct value
*mark
= value_mark ();
5534 if (is_watchpoint (b
))
5535 w
= (struct watchpoint
*) b
;
5539 /* Need to select the frame, with all that implies so that
5540 the conditions will have the right context. Because we
5541 use the frame, we will not see an inlined function's
5542 variables when we arrive at a breakpoint at the start
5543 of the inlined function; the current frame will be the
5545 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5546 select_frame (get_current_frame ());
5549 struct frame_info
*frame
;
5551 /* For local watchpoint expressions, which particular
5552 instance of a local is being watched matters, so we
5553 keep track of the frame to evaluate the expression
5554 in. To evaluate the condition however, it doesn't
5555 really matter which instantiation of the function
5556 where the condition makes sense triggers the
5557 watchpoint. This allows an expression like "watch
5558 global if q > 10" set in `func', catch writes to
5559 global on all threads that call `func', or catch
5560 writes on all recursive calls of `func' by a single
5561 thread. We simply always evaluate the condition in
5562 the innermost frame that's executing where it makes
5563 sense to evaluate the condition. It seems
5565 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5567 select_frame (frame
);
5569 within_current_scope
= 0;
5571 if (within_current_scope
)
5573 = catch_errors (breakpoint_cond_eval
, cond
,
5574 "Error in testing breakpoint condition:\n",
5578 warning (_("Watchpoint condition cannot be tested "
5579 "in the current scope"));
5580 /* If we failed to set the right context for this
5581 watchpoint, unconditionally report it. */
5584 /* FIXME-someday, should give breakpoint #. */
5585 value_free_to_mark (mark
);
5588 if (cond
&& value_is_zero
)
5592 else if (b
->ignore_count
> 0)
5596 /* Increase the hit count even though we don't stop. */
5598 observer_notify_breakpoint_modified (b
);
5602 /* Returns true if we need to track moribund locations of LOC's type
5603 on the current target. */
5606 need_moribund_for_location_type (struct bp_location
*loc
)
5608 return ((loc
->loc_type
== bp_loc_software_breakpoint
5609 && !target_supports_stopped_by_sw_breakpoint ())
5610 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5611 && !target_supports_stopped_by_hw_breakpoint ()));
5615 /* Get a bpstat associated with having just stopped at address
5616 BP_ADDR in thread PTID.
5618 Determine whether we stopped at a breakpoint, etc, or whether we
5619 don't understand this stop. Result is a chain of bpstat's such
5622 if we don't understand the stop, the result is a null pointer.
5624 if we understand why we stopped, the result is not null.
5626 Each element of the chain refers to a particular breakpoint or
5627 watchpoint at which we have stopped. (We may have stopped for
5628 several reasons concurrently.)
5630 Each element of the chain has valid next, breakpoint_at,
5631 commands, FIXME??? fields. */
5634 bpstat_stop_status (struct address_space
*aspace
,
5635 CORE_ADDR bp_addr
, ptid_t ptid
,
5636 const struct target_waitstatus
*ws
)
5638 struct breakpoint
*b
= NULL
;
5639 struct bp_location
*bl
;
5640 struct bp_location
*loc
;
5641 /* First item of allocated bpstat's. */
5642 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5643 /* Pointer to the last thing in the chain currently. */
5646 int need_remove_insert
;
5649 /* First, build the bpstat chain with locations that explain a
5650 target stop, while being careful to not set the target running,
5651 as that may invalidate locations (in particular watchpoint
5652 locations are recreated). Resuming will happen here with
5653 breakpoint conditions or watchpoint expressions that include
5654 inferior function calls. */
5658 if (!breakpoint_enabled (b
))
5661 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5663 /* For hardware watchpoints, we look only at the first
5664 location. The watchpoint_check function will work on the
5665 entire expression, not the individual locations. For
5666 read watchpoints, the watchpoints_triggered function has
5667 checked all locations already. */
5668 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5671 if (!bl
->enabled
|| bl
->shlib_disabled
)
5674 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5677 /* Come here if it's a watchpoint, or if the break address
5680 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5683 /* Assume we stop. Should we find a watchpoint that is not
5684 actually triggered, or if the condition of the breakpoint
5685 evaluates as false, we'll reset 'stop' to 0. */
5689 /* If this is a scope breakpoint, mark the associated
5690 watchpoint as triggered so that we will handle the
5691 out-of-scope event. We'll get to the watchpoint next
5693 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5695 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5697 w
->watchpoint_triggered
= watch_triggered_yes
;
5702 /* Check if a moribund breakpoint explains the stop. */
5703 if (!target_supports_stopped_by_sw_breakpoint ()
5704 || !target_supports_stopped_by_hw_breakpoint ())
5706 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5708 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5709 && need_moribund_for_location_type (loc
))
5711 bs
= bpstat_alloc (loc
, &bs_link
);
5712 /* For hits of moribund locations, we should just proceed. */
5715 bs
->print_it
= print_it_noop
;
5720 /* A bit of special processing for shlib breakpoints. We need to
5721 process solib loading here, so that the lists of loaded and
5722 unloaded libraries are correct before we handle "catch load" and
5724 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5726 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5728 handle_solib_event ();
5733 /* Now go through the locations that caused the target to stop, and
5734 check whether we're interested in reporting this stop to higher
5735 layers, or whether we should resume the target transparently. */
5739 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5744 b
= bs
->breakpoint_at
;
5745 b
->ops
->check_status (bs
);
5748 bpstat_check_breakpoint_conditions (bs
, ptid
);
5753 observer_notify_breakpoint_modified (b
);
5755 /* We will stop here. */
5756 if (b
->disposition
== disp_disable
)
5758 --(b
->enable_count
);
5759 if (b
->enable_count
<= 0)
5760 b
->enable_state
= bp_disabled
;
5765 bs
->commands
= b
->commands
;
5766 incref_counted_command_line (bs
->commands
);
5767 if (command_line_is_silent (bs
->commands
5768 ? bs
->commands
->commands
: NULL
))
5771 b
->ops
->after_condition_true (bs
);
5776 /* Print nothing for this entry if we don't stop or don't
5778 if (!bs
->stop
|| !bs
->print
)
5779 bs
->print_it
= print_it_noop
;
5782 /* If we aren't stopping, the value of some hardware watchpoint may
5783 not have changed, but the intermediate memory locations we are
5784 watching may have. Don't bother if we're stopping; this will get
5786 need_remove_insert
= 0;
5787 if (! bpstat_causes_stop (bs_head
))
5788 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5790 && bs
->breakpoint_at
5791 && is_hardware_watchpoint (bs
->breakpoint_at
))
5793 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5795 update_watchpoint (w
, 0 /* don't reparse. */);
5796 need_remove_insert
= 1;
5799 if (need_remove_insert
)
5800 update_global_location_list (UGLL_MAY_INSERT
);
5801 else if (removed_any
)
5802 update_global_location_list (UGLL_DONT_INSERT
);
5808 handle_jit_event (void)
5810 struct frame_info
*frame
;
5811 struct gdbarch
*gdbarch
;
5814 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5816 /* Switch terminal for any messages produced by
5817 breakpoint_re_set. */
5818 target_terminal_ours_for_output ();
5820 frame
= get_current_frame ();
5821 gdbarch
= get_frame_arch (frame
);
5823 jit_event_handler (gdbarch
);
5825 target_terminal_inferior ();
5828 /* Prepare WHAT final decision for infrun. */
5830 /* Decide what infrun needs to do with this bpstat. */
5833 bpstat_what (bpstat bs_head
)
5835 struct bpstat_what retval
;
5838 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5839 retval
.call_dummy
= STOP_NONE
;
5840 retval
.is_longjmp
= 0;
5842 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5844 /* Extract this BS's action. After processing each BS, we check
5845 if its action overrides all we've seem so far. */
5846 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5849 if (bs
->breakpoint_at
== NULL
)
5851 /* I suspect this can happen if it was a momentary
5852 breakpoint which has since been deleted. */
5856 bptype
= bs
->breakpoint_at
->type
;
5863 case bp_hardware_breakpoint
:
5864 case bp_single_step
:
5867 case bp_shlib_event
:
5871 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5873 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5876 this_action
= BPSTAT_WHAT_SINGLE
;
5879 case bp_hardware_watchpoint
:
5880 case bp_read_watchpoint
:
5881 case bp_access_watchpoint
:
5885 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5887 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5891 /* There was a watchpoint, but we're not stopping.
5892 This requires no further action. */
5896 case bp_longjmp_call_dummy
:
5900 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5901 retval
.is_longjmp
= bptype
!= bp_exception
;
5904 this_action
= BPSTAT_WHAT_SINGLE
;
5906 case bp_longjmp_resume
:
5907 case bp_exception_resume
:
5910 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5911 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5914 this_action
= BPSTAT_WHAT_SINGLE
;
5916 case bp_step_resume
:
5918 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5921 /* It is for the wrong frame. */
5922 this_action
= BPSTAT_WHAT_SINGLE
;
5925 case bp_hp_step_resume
:
5927 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5930 /* It is for the wrong frame. */
5931 this_action
= BPSTAT_WHAT_SINGLE
;
5934 case bp_watchpoint_scope
:
5935 case bp_thread_event
:
5936 case bp_overlay_event
:
5937 case bp_longjmp_master
:
5938 case bp_std_terminate_master
:
5939 case bp_exception_master
:
5940 this_action
= BPSTAT_WHAT_SINGLE
;
5946 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5948 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5952 /* There was a catchpoint, but we're not stopping.
5953 This requires no further action. */
5957 this_action
= BPSTAT_WHAT_SINGLE
;
5960 /* Make sure the action is stop (silent or noisy),
5961 so infrun.c pops the dummy frame. */
5962 retval
.call_dummy
= STOP_STACK_DUMMY
;
5963 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5965 case bp_std_terminate
:
5966 /* Make sure the action is stop (silent or noisy),
5967 so infrun.c pops the dummy frame. */
5968 retval
.call_dummy
= STOP_STD_TERMINATE
;
5969 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5972 case bp_fast_tracepoint
:
5973 case bp_static_tracepoint
:
5974 /* Tracepoint hits should not be reported back to GDB, and
5975 if one got through somehow, it should have been filtered
5977 internal_error (__FILE__
, __LINE__
,
5978 _("bpstat_what: tracepoint encountered"));
5980 case bp_gnu_ifunc_resolver
:
5981 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5982 this_action
= BPSTAT_WHAT_SINGLE
;
5984 case bp_gnu_ifunc_resolver_return
:
5985 /* The breakpoint will be removed, execution will restart from the
5986 PC of the former breakpoint. */
5987 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5992 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5994 this_action
= BPSTAT_WHAT_SINGLE
;
5998 internal_error (__FILE__
, __LINE__
,
5999 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
6002 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6009 bpstat_run_callbacks (bpstat bs_head
)
6013 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6015 struct breakpoint
*b
= bs
->breakpoint_at
;
6022 handle_jit_event ();
6024 case bp_gnu_ifunc_resolver
:
6025 gnu_ifunc_resolver_stop (b
);
6027 case bp_gnu_ifunc_resolver_return
:
6028 gnu_ifunc_resolver_return_stop (b
);
6034 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6035 without hardware support). This isn't related to a specific bpstat,
6036 just to things like whether watchpoints are set. */
6039 bpstat_should_step (void)
6041 struct breakpoint
*b
;
6044 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6050 bpstat_causes_stop (bpstat bs
)
6052 for (; bs
!= NULL
; bs
= bs
->next
)
6061 /* Compute a string of spaces suitable to indent the next line
6062 so it starts at the position corresponding to the table column
6063 named COL_NAME in the currently active table of UIOUT. */
6066 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6068 static char wrap_indent
[80];
6069 int i
, total_width
, width
, align
;
6073 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
6075 if (strcmp (text
, col_name
) == 0)
6077 gdb_assert (total_width
< sizeof wrap_indent
);
6078 memset (wrap_indent
, ' ', total_width
);
6079 wrap_indent
[total_width
] = 0;
6084 total_width
+= width
+ 1;
6090 /* Determine if the locations of this breakpoint will have their conditions
6091 evaluated by the target, host or a mix of both. Returns the following:
6093 "host": Host evals condition.
6094 "host or target": Host or Target evals condition.
6095 "target": Target evals condition.
6099 bp_condition_evaluator (struct breakpoint
*b
)
6101 struct bp_location
*bl
;
6102 char host_evals
= 0;
6103 char target_evals
= 0;
6108 if (!is_breakpoint (b
))
6111 if (gdb_evaluates_breakpoint_condition_p ()
6112 || !target_supports_evaluation_of_breakpoint_conditions ())
6113 return condition_evaluation_host
;
6115 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6117 if (bl
->cond_bytecode
)
6123 if (host_evals
&& target_evals
)
6124 return condition_evaluation_both
;
6125 else if (target_evals
)
6126 return condition_evaluation_target
;
6128 return condition_evaluation_host
;
6131 /* Determine the breakpoint location's condition evaluator. This is
6132 similar to bp_condition_evaluator, but for locations. */
6135 bp_location_condition_evaluator (struct bp_location
*bl
)
6137 if (bl
&& !is_breakpoint (bl
->owner
))
6140 if (gdb_evaluates_breakpoint_condition_p ()
6141 || !target_supports_evaluation_of_breakpoint_conditions ())
6142 return condition_evaluation_host
;
6144 if (bl
&& bl
->cond_bytecode
)
6145 return condition_evaluation_target
;
6147 return condition_evaluation_host
;
6150 /* Print the LOC location out of the list of B->LOC locations. */
6153 print_breakpoint_location (struct breakpoint
*b
,
6154 struct bp_location
*loc
)
6156 struct ui_out
*uiout
= current_uiout
;
6157 struct cleanup
*old_chain
= save_current_program_space ();
6159 if (loc
!= NULL
&& loc
->shlib_disabled
)
6163 set_current_program_space (loc
->pspace
);
6165 if (b
->display_canonical
)
6166 ui_out_field_string (uiout
, "what",
6167 event_location_to_string (b
->location
));
6168 else if (loc
&& loc
->symtab
)
6171 = find_pc_sect_function (loc
->address
, loc
->section
);
6174 ui_out_text (uiout
, "in ");
6175 ui_out_field_string (uiout
, "func",
6176 SYMBOL_PRINT_NAME (sym
));
6177 ui_out_text (uiout
, " ");
6178 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6179 ui_out_text (uiout
, "at ");
6181 ui_out_field_string (uiout
, "file",
6182 symtab_to_filename_for_display (loc
->symtab
));
6183 ui_out_text (uiout
, ":");
6185 if (ui_out_is_mi_like_p (uiout
))
6186 ui_out_field_string (uiout
, "fullname",
6187 symtab_to_fullname (loc
->symtab
));
6189 ui_out_field_int (uiout
, "line", loc
->line_number
);
6193 struct ui_file
*stb
= mem_fileopen ();
6194 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6196 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6198 ui_out_field_stream (uiout
, "at", stb
);
6200 do_cleanups (stb_chain
);
6204 ui_out_field_string (uiout
, "pending",
6205 event_location_to_string (b
->location
));
6206 /* If extra_string is available, it could be holding a condition
6207 or dprintf arguments. In either case, make sure it is printed,
6208 too, but only for non-MI streams. */
6209 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6211 if (b
->type
== bp_dprintf
)
6212 ui_out_text (uiout
, ",");
6214 ui_out_text (uiout
, " ");
6215 ui_out_text (uiout
, b
->extra_string
);
6219 if (loc
&& is_breakpoint (b
)
6220 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6221 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6223 ui_out_text (uiout
, " (");
6224 ui_out_field_string (uiout
, "evaluated-by",
6225 bp_location_condition_evaluator (loc
));
6226 ui_out_text (uiout
, ")");
6229 do_cleanups (old_chain
);
6233 bptype_string (enum bptype type
)
6235 struct ep_type_description
6240 static struct ep_type_description bptypes
[] =
6242 {bp_none
, "?deleted?"},
6243 {bp_breakpoint
, "breakpoint"},
6244 {bp_hardware_breakpoint
, "hw breakpoint"},
6245 {bp_single_step
, "sw single-step"},
6246 {bp_until
, "until"},
6247 {bp_finish
, "finish"},
6248 {bp_watchpoint
, "watchpoint"},
6249 {bp_hardware_watchpoint
, "hw watchpoint"},
6250 {bp_read_watchpoint
, "read watchpoint"},
6251 {bp_access_watchpoint
, "acc watchpoint"},
6252 {bp_longjmp
, "longjmp"},
6253 {bp_longjmp_resume
, "longjmp resume"},
6254 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6255 {bp_exception
, "exception"},
6256 {bp_exception_resume
, "exception resume"},
6257 {bp_step_resume
, "step resume"},
6258 {bp_hp_step_resume
, "high-priority step resume"},
6259 {bp_watchpoint_scope
, "watchpoint scope"},
6260 {bp_call_dummy
, "call dummy"},
6261 {bp_std_terminate
, "std::terminate"},
6262 {bp_shlib_event
, "shlib events"},
6263 {bp_thread_event
, "thread events"},
6264 {bp_overlay_event
, "overlay events"},
6265 {bp_longjmp_master
, "longjmp master"},
6266 {bp_std_terminate_master
, "std::terminate master"},
6267 {bp_exception_master
, "exception master"},
6268 {bp_catchpoint
, "catchpoint"},
6269 {bp_tracepoint
, "tracepoint"},
6270 {bp_fast_tracepoint
, "fast tracepoint"},
6271 {bp_static_tracepoint
, "static tracepoint"},
6272 {bp_dprintf
, "dprintf"},
6273 {bp_jit_event
, "jit events"},
6274 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6275 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6278 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6279 || ((int) type
!= bptypes
[(int) type
].type
))
6280 internal_error (__FILE__
, __LINE__
,
6281 _("bptypes table does not describe type #%d."),
6284 return bptypes
[(int) type
].description
;
6287 /* For MI, output a field named 'thread-groups' with a list as the value.
6288 For CLI, prefix the list with the string 'inf'. */
6291 output_thread_groups (struct ui_out
*uiout
,
6292 const char *field_name
,
6296 struct cleanup
*back_to
;
6297 int is_mi
= ui_out_is_mi_like_p (uiout
);
6301 /* For backward compatibility, don't display inferiors in CLI unless
6302 there are several. Always display them for MI. */
6303 if (!is_mi
&& mi_only
)
6306 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6308 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6314 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6315 ui_out_field_string (uiout
, NULL
, mi_group
);
6320 ui_out_text (uiout
, " inf ");
6322 ui_out_text (uiout
, ", ");
6324 ui_out_text (uiout
, plongest (inf
));
6328 do_cleanups (back_to
);
6331 /* Print B to gdb_stdout. */
6334 print_one_breakpoint_location (struct breakpoint
*b
,
6335 struct bp_location
*loc
,
6337 struct bp_location
**last_loc
,
6340 struct command_line
*l
;
6341 static char bpenables
[] = "nynny";
6343 struct ui_out
*uiout
= current_uiout
;
6344 int header_of_multiple
= 0;
6345 int part_of_multiple
= (loc
!= NULL
);
6346 struct value_print_options opts
;
6348 get_user_print_options (&opts
);
6350 gdb_assert (!loc
|| loc_number
!= 0);
6351 /* See comment in print_one_breakpoint concerning treatment of
6352 breakpoints with single disabled location. */
6355 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6356 header_of_multiple
= 1;
6364 if (part_of_multiple
)
6367 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6368 ui_out_field_string (uiout
, "number", formatted
);
6373 ui_out_field_int (uiout
, "number", b
->number
);
6378 if (part_of_multiple
)
6379 ui_out_field_skip (uiout
, "type");
6381 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6385 if (part_of_multiple
)
6386 ui_out_field_skip (uiout
, "disp");
6388 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6393 if (part_of_multiple
)
6394 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6396 ui_out_field_fmt (uiout
, "enabled", "%c",
6397 bpenables
[(int) b
->enable_state
]);
6398 ui_out_spaces (uiout
, 2);
6402 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6404 /* Although the print_one can possibly print all locations,
6405 calling it here is not likely to get any nice result. So,
6406 make sure there's just one location. */
6407 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6408 b
->ops
->print_one (b
, last_loc
);
6414 internal_error (__FILE__
, __LINE__
,
6415 _("print_one_breakpoint: bp_none encountered\n"));
6419 case bp_hardware_watchpoint
:
6420 case bp_read_watchpoint
:
6421 case bp_access_watchpoint
:
6423 struct watchpoint
*w
= (struct watchpoint
*) b
;
6425 /* Field 4, the address, is omitted (which makes the columns
6426 not line up too nicely with the headers, but the effect
6427 is relatively readable). */
6428 if (opts
.addressprint
)
6429 ui_out_field_skip (uiout
, "addr");
6431 ui_out_field_string (uiout
, "what", w
->exp_string
);
6436 case bp_hardware_breakpoint
:
6437 case bp_single_step
:
6441 case bp_longjmp_resume
:
6442 case bp_longjmp_call_dummy
:
6444 case bp_exception_resume
:
6445 case bp_step_resume
:
6446 case bp_hp_step_resume
:
6447 case bp_watchpoint_scope
:
6449 case bp_std_terminate
:
6450 case bp_shlib_event
:
6451 case bp_thread_event
:
6452 case bp_overlay_event
:
6453 case bp_longjmp_master
:
6454 case bp_std_terminate_master
:
6455 case bp_exception_master
:
6457 case bp_fast_tracepoint
:
6458 case bp_static_tracepoint
:
6461 case bp_gnu_ifunc_resolver
:
6462 case bp_gnu_ifunc_resolver_return
:
6463 if (opts
.addressprint
)
6466 if (header_of_multiple
)
6467 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6468 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6469 ui_out_field_string (uiout
, "addr", "<PENDING>");
6471 ui_out_field_core_addr (uiout
, "addr",
6472 loc
->gdbarch
, loc
->address
);
6475 if (!header_of_multiple
)
6476 print_breakpoint_location (b
, loc
);
6483 if (loc
!= NULL
&& !header_of_multiple
)
6485 struct inferior
*inf
;
6486 VEC(int) *inf_num
= NULL
;
6491 if (inf
->pspace
== loc
->pspace
)
6492 VEC_safe_push (int, inf_num
, inf
->num
);
6495 /* For backward compatibility, don't display inferiors in CLI unless
6496 there are several. Always display for MI. */
6498 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6499 && (number_of_program_spaces () > 1
6500 || number_of_inferiors () > 1)
6501 /* LOC is for existing B, it cannot be in
6502 moribund_locations and thus having NULL OWNER. */
6503 && loc
->owner
->type
!= bp_catchpoint
))
6505 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6506 VEC_free (int, inf_num
);
6509 if (!part_of_multiple
)
6511 if (b
->thread
!= -1)
6513 /* FIXME: This seems to be redundant and lost here; see the
6514 "stop only in" line a little further down. */
6515 ui_out_text (uiout
, " thread ");
6516 ui_out_field_int (uiout
, "thread", b
->thread
);
6518 else if (b
->task
!= 0)
6520 ui_out_text (uiout
, " task ");
6521 ui_out_field_int (uiout
, "task", b
->task
);
6525 ui_out_text (uiout
, "\n");
6527 if (!part_of_multiple
)
6528 b
->ops
->print_one_detail (b
, uiout
);
6530 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6533 ui_out_text (uiout
, "\tstop only in stack frame at ");
6534 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6536 ui_out_field_core_addr (uiout
, "frame",
6537 b
->gdbarch
, b
->frame_id
.stack_addr
);
6538 ui_out_text (uiout
, "\n");
6541 if (!part_of_multiple
&& b
->cond_string
)
6544 if (is_tracepoint (b
))
6545 ui_out_text (uiout
, "\ttrace only if ");
6547 ui_out_text (uiout
, "\tstop only if ");
6548 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6550 /* Print whether the target is doing the breakpoint's condition
6551 evaluation. If GDB is doing the evaluation, don't print anything. */
6552 if (is_breakpoint (b
)
6553 && breakpoint_condition_evaluation_mode ()
6554 == condition_evaluation_target
)
6556 ui_out_text (uiout
, " (");
6557 ui_out_field_string (uiout
, "evaluated-by",
6558 bp_condition_evaluator (b
));
6559 ui_out_text (uiout
, " evals)");
6561 ui_out_text (uiout
, "\n");
6564 if (!part_of_multiple
&& b
->thread
!= -1)
6566 /* FIXME should make an annotation for this. */
6567 ui_out_text (uiout
, "\tstop only in thread ");
6568 if (ui_out_is_mi_like_p (uiout
))
6569 ui_out_field_int (uiout
, "thread", b
->thread
);
6572 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6574 ui_out_field_string (uiout
, "thread", print_thread_id (thr
));
6576 ui_out_text (uiout
, "\n");
6579 if (!part_of_multiple
)
6583 /* FIXME should make an annotation for this. */
6584 if (is_catchpoint (b
))
6585 ui_out_text (uiout
, "\tcatchpoint");
6586 else if (is_tracepoint (b
))
6587 ui_out_text (uiout
, "\ttracepoint");
6589 ui_out_text (uiout
, "\tbreakpoint");
6590 ui_out_text (uiout
, " already hit ");
6591 ui_out_field_int (uiout
, "times", b
->hit_count
);
6592 if (b
->hit_count
== 1)
6593 ui_out_text (uiout
, " time\n");
6595 ui_out_text (uiout
, " times\n");
6599 /* Output the count also if it is zero, but only if this is mi. */
6600 if (ui_out_is_mi_like_p (uiout
))
6601 ui_out_field_int (uiout
, "times", b
->hit_count
);
6605 if (!part_of_multiple
&& b
->ignore_count
)
6608 ui_out_text (uiout
, "\tignore next ");
6609 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6610 ui_out_text (uiout
, " hits\n");
6613 /* Note that an enable count of 1 corresponds to "enable once"
6614 behavior, which is reported by the combination of enablement and
6615 disposition, so we don't need to mention it here. */
6616 if (!part_of_multiple
&& b
->enable_count
> 1)
6619 ui_out_text (uiout
, "\tdisable after ");
6620 /* Tweak the wording to clarify that ignore and enable counts
6621 are distinct, and have additive effect. */
6622 if (b
->ignore_count
)
6623 ui_out_text (uiout
, "additional ");
6625 ui_out_text (uiout
, "next ");
6626 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6627 ui_out_text (uiout
, " hits\n");
6630 if (!part_of_multiple
&& is_tracepoint (b
))
6632 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6634 if (tp
->traceframe_usage
)
6636 ui_out_text (uiout
, "\ttrace buffer usage ");
6637 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6638 ui_out_text (uiout
, " bytes\n");
6642 l
= b
->commands
? b
->commands
->commands
: NULL
;
6643 if (!part_of_multiple
&& l
)
6645 struct cleanup
*script_chain
;
6648 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6649 print_command_lines (uiout
, l
, 4);
6650 do_cleanups (script_chain
);
6653 if (is_tracepoint (b
))
6655 struct tracepoint
*t
= (struct tracepoint
*) b
;
6657 if (!part_of_multiple
&& t
->pass_count
)
6659 annotate_field (10);
6660 ui_out_text (uiout
, "\tpass count ");
6661 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6662 ui_out_text (uiout
, " \n");
6665 /* Don't display it when tracepoint or tracepoint location is
6667 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6669 annotate_field (11);
6671 if (ui_out_is_mi_like_p (uiout
))
6672 ui_out_field_string (uiout
, "installed",
6673 loc
->inserted
? "y" : "n");
6677 ui_out_text (uiout
, "\t");
6679 ui_out_text (uiout
, "\tnot ");
6680 ui_out_text (uiout
, "installed on target\n");
6685 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6687 if (is_watchpoint (b
))
6689 struct watchpoint
*w
= (struct watchpoint
*) b
;
6691 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6693 else if (b
->location
!= NULL
6694 && event_location_to_string (b
->location
) != NULL
)
6695 ui_out_field_string (uiout
, "original-location",
6696 event_location_to_string (b
->location
));
6701 print_one_breakpoint (struct breakpoint
*b
,
6702 struct bp_location
**last_loc
,
6705 struct cleanup
*bkpt_chain
;
6706 struct ui_out
*uiout
= current_uiout
;
6708 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6710 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6711 do_cleanups (bkpt_chain
);
6713 /* If this breakpoint has custom print function,
6714 it's already printed. Otherwise, print individual
6715 locations, if any. */
6716 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6718 /* If breakpoint has a single location that is disabled, we
6719 print it as if it had several locations, since otherwise it's
6720 hard to represent "breakpoint enabled, location disabled"
6723 Note that while hardware watchpoints have several locations
6724 internally, that's not a property exposed to user. */
6726 && !is_hardware_watchpoint (b
)
6727 && (b
->loc
->next
|| !b
->loc
->enabled
))
6729 struct bp_location
*loc
;
6732 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6734 struct cleanup
*inner2
=
6735 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6736 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6737 do_cleanups (inner2
);
6744 breakpoint_address_bits (struct breakpoint
*b
)
6746 int print_address_bits
= 0;
6747 struct bp_location
*loc
;
6749 /* Software watchpoints that aren't watching memory don't have an
6750 address to print. */
6751 if (is_no_memory_software_watchpoint (b
))
6754 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6758 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6759 if (addr_bit
> print_address_bits
)
6760 print_address_bits
= addr_bit
;
6763 return print_address_bits
;
6766 struct captured_breakpoint_query_args
6772 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6774 struct captured_breakpoint_query_args
*args
6775 = (struct captured_breakpoint_query_args
*) data
;
6776 struct breakpoint
*b
;
6777 struct bp_location
*dummy_loc
= NULL
;
6781 if (args
->bnum
== b
->number
)
6783 print_one_breakpoint (b
, &dummy_loc
, 0);
6791 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6792 char **error_message
)
6794 struct captured_breakpoint_query_args args
;
6797 /* For the moment we don't trust print_one_breakpoint() to not throw
6799 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6800 error_message
, RETURN_MASK_ALL
) < 0)
6806 /* Return true if this breakpoint was set by the user, false if it is
6807 internal or momentary. */
6810 user_breakpoint_p (struct breakpoint
*b
)
6812 return b
->number
> 0;
6815 /* See breakpoint.h. */
6818 pending_breakpoint_p (struct breakpoint
*b
)
6820 return b
->loc
== NULL
;
6823 /* Print information on user settable breakpoint (watchpoint, etc)
6824 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6825 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6826 FILTER is non-NULL, call it on each breakpoint and only include the
6827 ones for which it returns non-zero. Return the total number of
6828 breakpoints listed. */
6831 breakpoint_1 (char *args
, int allflag
,
6832 int (*filter
) (const struct breakpoint
*))
6834 struct breakpoint
*b
;
6835 struct bp_location
*last_loc
= NULL
;
6836 int nr_printable_breakpoints
;
6837 struct cleanup
*bkpttbl_chain
;
6838 struct value_print_options opts
;
6839 int print_address_bits
= 0;
6840 int print_type_col_width
= 14;
6841 struct ui_out
*uiout
= current_uiout
;
6843 get_user_print_options (&opts
);
6845 /* Compute the number of rows in the table, as well as the size
6846 required for address fields. */
6847 nr_printable_breakpoints
= 0;
6850 /* If we have a filter, only list the breakpoints it accepts. */
6851 if (filter
&& !filter (b
))
6854 /* If we have an "args" string, it is a list of breakpoints to
6855 accept. Skip the others. */
6856 if (args
!= NULL
&& *args
!= '\0')
6858 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6860 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6864 if (allflag
|| user_breakpoint_p (b
))
6866 int addr_bit
, type_len
;
6868 addr_bit
= breakpoint_address_bits (b
);
6869 if (addr_bit
> print_address_bits
)
6870 print_address_bits
= addr_bit
;
6872 type_len
= strlen (bptype_string (b
->type
));
6873 if (type_len
> print_type_col_width
)
6874 print_type_col_width
= type_len
;
6876 nr_printable_breakpoints
++;
6880 if (opts
.addressprint
)
6882 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6883 nr_printable_breakpoints
,
6887 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6888 nr_printable_breakpoints
,
6891 if (nr_printable_breakpoints
> 0)
6892 annotate_breakpoints_headers ();
6893 if (nr_printable_breakpoints
> 0)
6895 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6896 if (nr_printable_breakpoints
> 0)
6898 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6899 "type", "Type"); /* 2 */
6900 if (nr_printable_breakpoints
> 0)
6902 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6903 if (nr_printable_breakpoints
> 0)
6905 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6906 if (opts
.addressprint
)
6908 if (nr_printable_breakpoints
> 0)
6910 if (print_address_bits
<= 32)
6911 ui_out_table_header (uiout
, 10, ui_left
,
6912 "addr", "Address"); /* 5 */
6914 ui_out_table_header (uiout
, 18, ui_left
,
6915 "addr", "Address"); /* 5 */
6917 if (nr_printable_breakpoints
> 0)
6919 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6920 ui_out_table_body (uiout
);
6921 if (nr_printable_breakpoints
> 0)
6922 annotate_breakpoints_table ();
6927 /* If we have a filter, only list the breakpoints it accepts. */
6928 if (filter
&& !filter (b
))
6931 /* If we have an "args" string, it is a list of breakpoints to
6932 accept. Skip the others. */
6934 if (args
!= NULL
&& *args
!= '\0')
6936 if (allflag
) /* maintenance info breakpoint */
6938 if (parse_and_eval_long (args
) != b
->number
)
6941 else /* all others */
6943 if (!number_is_in_list (args
, b
->number
))
6947 /* We only print out user settable breakpoints unless the
6949 if (allflag
|| user_breakpoint_p (b
))
6950 print_one_breakpoint (b
, &last_loc
, allflag
);
6953 do_cleanups (bkpttbl_chain
);
6955 if (nr_printable_breakpoints
== 0)
6957 /* If there's a filter, let the caller decide how to report
6961 if (args
== NULL
|| *args
== '\0')
6962 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6964 ui_out_message (uiout
, 0,
6965 "No breakpoint or watchpoint matching '%s'.\n",
6971 if (last_loc
&& !server_command
)
6972 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6975 /* FIXME? Should this be moved up so that it is only called when
6976 there have been breakpoints? */
6977 annotate_breakpoints_table_end ();
6979 return nr_printable_breakpoints
;
6982 /* Display the value of default-collect in a way that is generally
6983 compatible with the breakpoint list. */
6986 default_collect_info (void)
6988 struct ui_out
*uiout
= current_uiout
;
6990 /* If it has no value (which is frequently the case), say nothing; a
6991 message like "No default-collect." gets in user's face when it's
6993 if (!*default_collect
)
6996 /* The following phrase lines up nicely with per-tracepoint collect
6998 ui_out_text (uiout
, "default collect ");
6999 ui_out_field_string (uiout
, "default-collect", default_collect
);
7000 ui_out_text (uiout
, " \n");
7004 breakpoints_info (char *args
, int from_tty
)
7006 breakpoint_1 (args
, 0, NULL
);
7008 default_collect_info ();
7012 watchpoints_info (char *args
, int from_tty
)
7014 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
7015 struct ui_out
*uiout
= current_uiout
;
7017 if (num_printed
== 0)
7019 if (args
== NULL
|| *args
== '\0')
7020 ui_out_message (uiout
, 0, "No watchpoints.\n");
7022 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
7027 maintenance_info_breakpoints (char *args
, int from_tty
)
7029 breakpoint_1 (args
, 1, NULL
);
7031 default_collect_info ();
7035 breakpoint_has_pc (struct breakpoint
*b
,
7036 struct program_space
*pspace
,
7037 CORE_ADDR pc
, struct obj_section
*section
)
7039 struct bp_location
*bl
= b
->loc
;
7041 for (; bl
; bl
= bl
->next
)
7043 if (bl
->pspace
== pspace
7044 && bl
->address
== pc
7045 && (!overlay_debugging
|| bl
->section
== section
))
7051 /* Print a message describing any user-breakpoints set at PC. This
7052 concerns with logical breakpoints, so we match program spaces, not
7056 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7057 struct program_space
*pspace
, CORE_ADDR pc
,
7058 struct obj_section
*section
, int thread
)
7061 struct breakpoint
*b
;
7064 others
+= (user_breakpoint_p (b
)
7065 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7069 printf_filtered (_("Note: breakpoint "));
7070 else /* if (others == ???) */
7071 printf_filtered (_("Note: breakpoints "));
7073 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7076 printf_filtered ("%d", b
->number
);
7077 if (b
->thread
== -1 && thread
!= -1)
7078 printf_filtered (" (all threads)");
7079 else if (b
->thread
!= -1)
7080 printf_filtered (" (thread %d)", b
->thread
);
7081 printf_filtered ("%s%s ",
7082 ((b
->enable_state
== bp_disabled
7083 || b
->enable_state
== bp_call_disabled
)
7087 : ((others
== 1) ? " and" : ""));
7089 printf_filtered (_("also set at pc "));
7090 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7091 printf_filtered (".\n");
7096 /* Return true iff it is meaningful to use the address member of
7097 BPT locations. For some breakpoint types, the locations' address members
7098 are irrelevant and it makes no sense to attempt to compare them to other
7099 addresses (or use them for any other purpose either).
7101 More specifically, each of the following breakpoint types will
7102 always have a zero valued location address and we don't want to mark
7103 breakpoints of any of these types to be a duplicate of an actual
7104 breakpoint location at address zero:
7112 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7114 enum bptype type
= bpt
->type
;
7116 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7119 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7120 true if LOC1 and LOC2 represent the same watchpoint location. */
7123 watchpoint_locations_match (struct bp_location
*loc1
,
7124 struct bp_location
*loc2
)
7126 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7127 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7129 /* Both of them must exist. */
7130 gdb_assert (w1
!= NULL
);
7131 gdb_assert (w2
!= NULL
);
7133 /* If the target can evaluate the condition expression in hardware,
7134 then we we need to insert both watchpoints even if they are at
7135 the same place. Otherwise the watchpoint will only trigger when
7136 the condition of whichever watchpoint was inserted evaluates to
7137 true, not giving a chance for GDB to check the condition of the
7138 other watchpoint. */
7140 && target_can_accel_watchpoint_condition (loc1
->address
,
7142 loc1
->watchpoint_type
,
7143 w1
->cond_exp
.get ()))
7145 && target_can_accel_watchpoint_condition (loc2
->address
,
7147 loc2
->watchpoint_type
,
7148 w2
->cond_exp
.get ())))
7151 /* Note that this checks the owner's type, not the location's. In
7152 case the target does not support read watchpoints, but does
7153 support access watchpoints, we'll have bp_read_watchpoint
7154 watchpoints with hw_access locations. Those should be considered
7155 duplicates of hw_read locations. The hw_read locations will
7156 become hw_access locations later. */
7157 return (loc1
->owner
->type
== loc2
->owner
->type
7158 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7159 && loc1
->address
== loc2
->address
7160 && loc1
->length
== loc2
->length
);
7163 /* See breakpoint.h. */
7166 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7167 struct address_space
*aspace2
, CORE_ADDR addr2
)
7169 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7170 || aspace1
== aspace2
)
7174 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7175 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7176 matches ASPACE2. On targets that have global breakpoints, the address
7177 space doesn't really matter. */
7180 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7181 int len1
, struct address_space
*aspace2
,
7184 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7185 || aspace1
== aspace2
)
7186 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7189 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7190 a ranged breakpoint. In most targets, a match happens only if ASPACE
7191 matches the breakpoint's address space. On targets that have global
7192 breakpoints, the address space doesn't really matter. */
7195 breakpoint_location_address_match (struct bp_location
*bl
,
7196 struct address_space
*aspace
,
7199 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7202 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7203 bl
->address
, bl
->length
,
7207 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7208 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7209 match happens only if ASPACE matches the breakpoint's address
7210 space. On targets that have global breakpoints, the address space
7211 doesn't really matter. */
7214 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7215 struct address_space
*aspace
,
7216 CORE_ADDR addr
, int len
)
7218 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7219 || bl
->pspace
->aspace
== aspace
)
7221 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7223 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7229 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7230 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7231 true, otherwise returns false. */
7234 tracepoint_locations_match (struct bp_location
*loc1
,
7235 struct bp_location
*loc2
)
7237 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7238 /* Since tracepoint locations are never duplicated with others', tracepoint
7239 locations at the same address of different tracepoints are regarded as
7240 different locations. */
7241 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7246 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7247 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7248 represent the same location. */
7251 breakpoint_locations_match (struct bp_location
*loc1
,
7252 struct bp_location
*loc2
)
7254 int hw_point1
, hw_point2
;
7256 /* Both of them must not be in moribund_locations. */
7257 gdb_assert (loc1
->owner
!= NULL
);
7258 gdb_assert (loc2
->owner
!= NULL
);
7260 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7261 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7263 if (hw_point1
!= hw_point2
)
7266 return watchpoint_locations_match (loc1
, loc2
);
7267 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7268 return tracepoint_locations_match (loc1
, loc2
);
7270 /* We compare bp_location.length in order to cover ranged breakpoints. */
7271 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7272 loc2
->pspace
->aspace
, loc2
->address
)
7273 && loc1
->length
== loc2
->length
);
7277 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7278 int bnum
, int have_bnum
)
7280 /* The longest string possibly returned by hex_string_custom
7281 is 50 chars. These must be at least that big for safety. */
7285 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7286 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7288 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7289 bnum
, astr1
, astr2
);
7291 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7294 /* Adjust a breakpoint's address to account for architectural
7295 constraints on breakpoint placement. Return the adjusted address.
7296 Note: Very few targets require this kind of adjustment. For most
7297 targets, this function is simply the identity function. */
7300 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7301 CORE_ADDR bpaddr
, enum bptype bptype
)
7303 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7305 /* Very few targets need any kind of breakpoint adjustment. */
7308 else if (bptype
== bp_watchpoint
7309 || bptype
== bp_hardware_watchpoint
7310 || bptype
== bp_read_watchpoint
7311 || bptype
== bp_access_watchpoint
7312 || bptype
== bp_catchpoint
)
7314 /* Watchpoints and the various bp_catch_* eventpoints should not
7315 have their addresses modified. */
7318 else if (bptype
== bp_single_step
)
7320 /* Single-step breakpoints should not have their addresses
7321 modified. If there's any architectural constrain that
7322 applies to this address, then it should have already been
7323 taken into account when the breakpoint was created in the
7324 first place. If we didn't do this, stepping through e.g.,
7325 Thumb-2 IT blocks would break. */
7330 CORE_ADDR adjusted_bpaddr
;
7332 /* Some targets have architectural constraints on the placement
7333 of breakpoint instructions. Obtain the adjusted address. */
7334 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7336 /* An adjusted breakpoint address can significantly alter
7337 a user's expectations. Print a warning if an adjustment
7339 if (adjusted_bpaddr
!= bpaddr
)
7340 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7342 return adjusted_bpaddr
;
7347 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7348 struct breakpoint
*owner
)
7350 memset (loc
, 0, sizeof (*loc
));
7352 gdb_assert (ops
!= NULL
);
7356 loc
->cond_bytecode
= NULL
;
7357 loc
->shlib_disabled
= 0;
7360 switch (owner
->type
)
7363 case bp_single_step
:
7367 case bp_longjmp_resume
:
7368 case bp_longjmp_call_dummy
:
7370 case bp_exception_resume
:
7371 case bp_step_resume
:
7372 case bp_hp_step_resume
:
7373 case bp_watchpoint_scope
:
7375 case bp_std_terminate
:
7376 case bp_shlib_event
:
7377 case bp_thread_event
:
7378 case bp_overlay_event
:
7380 case bp_longjmp_master
:
7381 case bp_std_terminate_master
:
7382 case bp_exception_master
:
7383 case bp_gnu_ifunc_resolver
:
7384 case bp_gnu_ifunc_resolver_return
:
7386 loc
->loc_type
= bp_loc_software_breakpoint
;
7387 mark_breakpoint_location_modified (loc
);
7389 case bp_hardware_breakpoint
:
7390 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7391 mark_breakpoint_location_modified (loc
);
7393 case bp_hardware_watchpoint
:
7394 case bp_read_watchpoint
:
7395 case bp_access_watchpoint
:
7396 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7401 case bp_fast_tracepoint
:
7402 case bp_static_tracepoint
:
7403 loc
->loc_type
= bp_loc_other
;
7406 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7412 /* Allocate a struct bp_location. */
7414 static struct bp_location
*
7415 allocate_bp_location (struct breakpoint
*bpt
)
7417 return bpt
->ops
->allocate_location (bpt
);
7421 free_bp_location (struct bp_location
*loc
)
7423 loc
->ops
->dtor (loc
);
7427 /* Increment reference count. */
7430 incref_bp_location (struct bp_location
*bl
)
7435 /* Decrement reference count. If the reference count reaches 0,
7436 destroy the bp_location. Sets *BLP to NULL. */
7439 decref_bp_location (struct bp_location
**blp
)
7441 gdb_assert ((*blp
)->refc
> 0);
7443 if (--(*blp
)->refc
== 0)
7444 free_bp_location (*blp
);
7448 /* Add breakpoint B at the end of the global breakpoint chain. */
7451 add_to_breakpoint_chain (struct breakpoint
*b
)
7453 struct breakpoint
*b1
;
7455 /* Add this breakpoint to the end of the chain so that a list of
7456 breakpoints will come out in order of increasing numbers. */
7458 b1
= breakpoint_chain
;
7460 breakpoint_chain
= b
;
7469 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7472 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7473 struct gdbarch
*gdbarch
,
7475 const struct breakpoint_ops
*ops
)
7477 memset (b
, 0, sizeof (*b
));
7479 gdb_assert (ops
!= NULL
);
7483 b
->gdbarch
= gdbarch
;
7484 b
->language
= current_language
->la_language
;
7485 b
->input_radix
= input_radix
;
7487 b
->enable_state
= bp_enabled
;
7490 b
->ignore_count
= 0;
7492 b
->frame_id
= null_frame_id
;
7493 b
->condition_not_parsed
= 0;
7494 b
->py_bp_object
= NULL
;
7495 b
->related_breakpoint
= b
;
7499 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7500 that has type BPTYPE and has no locations as yet. */
7502 static struct breakpoint
*
7503 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7505 const struct breakpoint_ops
*ops
)
7507 struct breakpoint
*b
= new breakpoint ();
7509 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7510 add_to_breakpoint_chain (b
);
7514 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7515 resolutions should be made as the user specified the location explicitly
7519 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7521 gdb_assert (loc
->owner
!= NULL
);
7523 if (loc
->owner
->type
== bp_breakpoint
7524 || loc
->owner
->type
== bp_hardware_breakpoint
7525 || is_tracepoint (loc
->owner
))
7528 const char *function_name
;
7529 CORE_ADDR func_addr
;
7531 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7532 &func_addr
, NULL
, &is_gnu_ifunc
);
7534 if (is_gnu_ifunc
&& !explicit_loc
)
7536 struct breakpoint
*b
= loc
->owner
;
7538 gdb_assert (loc
->pspace
== current_program_space
);
7539 if (gnu_ifunc_resolve_name (function_name
,
7540 &loc
->requested_address
))
7542 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7543 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7544 loc
->requested_address
,
7547 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7548 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7550 /* Create only the whole new breakpoint of this type but do not
7551 mess more complicated breakpoints with multiple locations. */
7552 b
->type
= bp_gnu_ifunc_resolver
;
7553 /* Remember the resolver's address for use by the return
7555 loc
->related_address
= func_addr
;
7560 loc
->function_name
= xstrdup (function_name
);
7564 /* Attempt to determine architecture of location identified by SAL. */
7566 get_sal_arch (struct symtab_and_line sal
)
7569 return get_objfile_arch (sal
.section
->objfile
);
7571 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7576 /* Low level routine for partially initializing a breakpoint of type
7577 BPTYPE. The newly created breakpoint's address, section, source
7578 file name, and line number are provided by SAL.
7580 It is expected that the caller will complete the initialization of
7581 the newly created breakpoint struct as well as output any status
7582 information regarding the creation of a new breakpoint. */
7585 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7586 struct symtab_and_line sal
, enum bptype bptype
,
7587 const struct breakpoint_ops
*ops
)
7589 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7591 add_location_to_breakpoint (b
, &sal
);
7593 if (bptype
!= bp_catchpoint
)
7594 gdb_assert (sal
.pspace
!= NULL
);
7596 /* Store the program space that was used to set the breakpoint,
7597 except for ordinary breakpoints, which are independent of the
7599 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7600 b
->pspace
= sal
.pspace
;
7603 /* set_raw_breakpoint is a low level routine for allocating and
7604 partially initializing a breakpoint of type BPTYPE. The newly
7605 created breakpoint's address, section, source file name, and line
7606 number are provided by SAL. The newly created and partially
7607 initialized breakpoint is added to the breakpoint chain and
7608 is also returned as the value of this function.
7610 It is expected that the caller will complete the initialization of
7611 the newly created breakpoint struct as well as output any status
7612 information regarding the creation of a new breakpoint. In
7613 particular, set_raw_breakpoint does NOT set the breakpoint
7614 number! Care should be taken to not allow an error to occur
7615 prior to completing the initialization of the breakpoint. If this
7616 should happen, a bogus breakpoint will be left on the chain. */
7619 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7620 struct symtab_and_line sal
, enum bptype bptype
,
7621 const struct breakpoint_ops
*ops
)
7623 struct breakpoint
*b
= new breakpoint ();
7625 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7626 add_to_breakpoint_chain (b
);
7630 /* Call this routine when stepping and nexting to enable a breakpoint
7631 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7632 initiated the operation. */
7635 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7637 struct breakpoint
*b
, *b_tmp
;
7638 int thread
= tp
->global_num
;
7640 /* To avoid having to rescan all objfile symbols at every step,
7641 we maintain a list of continually-inserted but always disabled
7642 longjmp "master" breakpoints. Here, we simply create momentary
7643 clones of those and enable them for the requested thread. */
7644 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7645 if (b
->pspace
== current_program_space
7646 && (b
->type
== bp_longjmp_master
7647 || b
->type
== bp_exception_master
))
7649 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7650 struct breakpoint
*clone
;
7652 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7653 after their removal. */
7654 clone
= momentary_breakpoint_from_master (b
, type
,
7655 &longjmp_breakpoint_ops
, 1);
7656 clone
->thread
= thread
;
7659 tp
->initiating_frame
= frame
;
7662 /* Delete all longjmp breakpoints from THREAD. */
7664 delete_longjmp_breakpoint (int thread
)
7666 struct breakpoint
*b
, *b_tmp
;
7668 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7669 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7671 if (b
->thread
== thread
)
7672 delete_breakpoint (b
);
7677 delete_longjmp_breakpoint_at_next_stop (int thread
)
7679 struct breakpoint
*b
, *b_tmp
;
7681 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7682 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7684 if (b
->thread
== thread
)
7685 b
->disposition
= disp_del_at_next_stop
;
7689 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7690 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7691 pointer to any of them. Return NULL if this system cannot place longjmp
7695 set_longjmp_breakpoint_for_call_dummy (void)
7697 struct breakpoint
*b
, *retval
= NULL
;
7700 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7702 struct breakpoint
*new_b
;
7704 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7705 &momentary_breakpoint_ops
,
7707 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7709 /* Link NEW_B into the chain of RETVAL breakpoints. */
7711 gdb_assert (new_b
->related_breakpoint
== new_b
);
7714 new_b
->related_breakpoint
= retval
;
7715 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7716 retval
= retval
->related_breakpoint
;
7717 retval
->related_breakpoint
= new_b
;
7723 /* Verify all existing dummy frames and their associated breakpoints for
7724 TP. Remove those which can no longer be found in the current frame
7727 You should call this function only at places where it is safe to currently
7728 unwind the whole stack. Failed stack unwind would discard live dummy
7732 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7734 struct breakpoint
*b
, *b_tmp
;
7736 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7737 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7739 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7741 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7742 dummy_b
= dummy_b
->related_breakpoint
;
7743 if (dummy_b
->type
!= bp_call_dummy
7744 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7747 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7749 while (b
->related_breakpoint
!= b
)
7751 if (b_tmp
== b
->related_breakpoint
)
7752 b_tmp
= b
->related_breakpoint
->next
;
7753 delete_breakpoint (b
->related_breakpoint
);
7755 delete_breakpoint (b
);
7760 enable_overlay_breakpoints (void)
7762 struct breakpoint
*b
;
7765 if (b
->type
== bp_overlay_event
)
7767 b
->enable_state
= bp_enabled
;
7768 update_global_location_list (UGLL_MAY_INSERT
);
7769 overlay_events_enabled
= 1;
7774 disable_overlay_breakpoints (void)
7776 struct breakpoint
*b
;
7779 if (b
->type
== bp_overlay_event
)
7781 b
->enable_state
= bp_disabled
;
7782 update_global_location_list (UGLL_DONT_INSERT
);
7783 overlay_events_enabled
= 0;
7787 /* Set an active std::terminate breakpoint for each std::terminate
7788 master breakpoint. */
7790 set_std_terminate_breakpoint (void)
7792 struct breakpoint
*b
, *b_tmp
;
7794 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7795 if (b
->pspace
== current_program_space
7796 && b
->type
== bp_std_terminate_master
)
7798 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7799 &momentary_breakpoint_ops
, 1);
7803 /* Delete all the std::terminate breakpoints. */
7805 delete_std_terminate_breakpoint (void)
7807 struct breakpoint
*b
, *b_tmp
;
7809 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7810 if (b
->type
== bp_std_terminate
)
7811 delete_breakpoint (b
);
7815 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7817 struct breakpoint
*b
;
7819 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7820 &internal_breakpoint_ops
);
7822 b
->enable_state
= bp_enabled
;
7823 /* location has to be used or breakpoint_re_set will delete me. */
7824 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7826 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7831 struct lang_and_radix
7837 /* Create a breakpoint for JIT code registration and unregistration. */
7840 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7842 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7843 &internal_breakpoint_ops
);
7846 /* Remove JIT code registration and unregistration breakpoint(s). */
7849 remove_jit_event_breakpoints (void)
7851 struct breakpoint
*b
, *b_tmp
;
7853 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7854 if (b
->type
== bp_jit_event
7855 && b
->loc
->pspace
== current_program_space
)
7856 delete_breakpoint (b
);
7860 remove_solib_event_breakpoints (void)
7862 struct breakpoint
*b
, *b_tmp
;
7864 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7865 if (b
->type
== bp_shlib_event
7866 && b
->loc
->pspace
== current_program_space
)
7867 delete_breakpoint (b
);
7870 /* See breakpoint.h. */
7873 remove_solib_event_breakpoints_at_next_stop (void)
7875 struct breakpoint
*b
, *b_tmp
;
7877 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7878 if (b
->type
== bp_shlib_event
7879 && b
->loc
->pspace
== current_program_space
)
7880 b
->disposition
= disp_del_at_next_stop
;
7883 /* Helper for create_solib_event_breakpoint /
7884 create_and_insert_solib_event_breakpoint. Allows specifying which
7885 INSERT_MODE to pass through to update_global_location_list. */
7887 static struct breakpoint
*
7888 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7889 enum ugll_insert_mode insert_mode
)
7891 struct breakpoint
*b
;
7893 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7894 &internal_breakpoint_ops
);
7895 update_global_location_list_nothrow (insert_mode
);
7900 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7902 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7905 /* See breakpoint.h. */
7908 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7910 struct breakpoint
*b
;
7912 /* Explicitly tell update_global_location_list to insert
7914 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7915 if (!b
->loc
->inserted
)
7917 delete_breakpoint (b
);
7923 /* Disable any breakpoints that are on code in shared libraries. Only
7924 apply to enabled breakpoints, disabled ones can just stay disabled. */
7927 disable_breakpoints_in_shlibs (void)
7929 struct bp_location
*loc
, **locp_tmp
;
7931 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7933 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7934 struct breakpoint
*b
= loc
->owner
;
7936 /* We apply the check to all breakpoints, including disabled for
7937 those with loc->duplicate set. This is so that when breakpoint
7938 becomes enabled, or the duplicate is removed, gdb will try to
7939 insert all breakpoints. If we don't set shlib_disabled here,
7940 we'll try to insert those breakpoints and fail. */
7941 if (((b
->type
== bp_breakpoint
)
7942 || (b
->type
== bp_jit_event
)
7943 || (b
->type
== bp_hardware_breakpoint
)
7944 || (is_tracepoint (b
)))
7945 && loc
->pspace
== current_program_space
7946 && !loc
->shlib_disabled
7947 && solib_name_from_address (loc
->pspace
, loc
->address
)
7950 loc
->shlib_disabled
= 1;
7955 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7956 notification of unloaded_shlib. Only apply to enabled breakpoints,
7957 disabled ones can just stay disabled. */
7960 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7962 struct bp_location
*loc
, **locp_tmp
;
7963 int disabled_shlib_breaks
= 0;
7965 /* SunOS a.out shared libraries are always mapped, so do not
7966 disable breakpoints; they will only be reported as unloaded
7967 through clear_solib when GDB discards its shared library
7968 list. See clear_solib for more information. */
7969 if (exec_bfd
!= NULL
7970 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7973 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7975 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7976 struct breakpoint
*b
= loc
->owner
;
7978 if (solib
->pspace
== loc
->pspace
7979 && !loc
->shlib_disabled
7980 && (((b
->type
== bp_breakpoint
7981 || b
->type
== bp_jit_event
7982 || b
->type
== bp_hardware_breakpoint
)
7983 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7984 || loc
->loc_type
== bp_loc_software_breakpoint
))
7985 || is_tracepoint (b
))
7986 && solib_contains_address_p (solib
, loc
->address
))
7988 loc
->shlib_disabled
= 1;
7989 /* At this point, we cannot rely on remove_breakpoint
7990 succeeding so we must mark the breakpoint as not inserted
7991 to prevent future errors occurring in remove_breakpoints. */
7994 /* This may cause duplicate notifications for the same breakpoint. */
7995 observer_notify_breakpoint_modified (b
);
7997 if (!disabled_shlib_breaks
)
7999 target_terminal_ours_for_output ();
8000 warning (_("Temporarily disabling breakpoints "
8001 "for unloaded shared library \"%s\""),
8004 disabled_shlib_breaks
= 1;
8009 /* Disable any breakpoints and tracepoints in OBJFILE upon
8010 notification of free_objfile. Only apply to enabled breakpoints,
8011 disabled ones can just stay disabled. */
8014 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
8016 struct breakpoint
*b
;
8018 if (objfile
== NULL
)
8021 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8022 managed by the user with add-symbol-file/remove-symbol-file.
8023 Similarly to how breakpoints in shared libraries are handled in
8024 response to "nosharedlibrary", mark breakpoints in such modules
8025 shlib_disabled so they end up uninserted on the next global
8026 location list update. Shared libraries not loaded by the user
8027 aren't handled here -- they're already handled in
8028 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8029 solib_unloaded observer. We skip objfiles that are not
8030 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8032 if ((objfile
->flags
& OBJF_SHARED
) == 0
8033 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8038 struct bp_location
*loc
;
8039 int bp_modified
= 0;
8041 if (!is_breakpoint (b
) && !is_tracepoint (b
))
8044 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
8046 CORE_ADDR loc_addr
= loc
->address
;
8048 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8049 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8052 if (loc
->shlib_disabled
!= 0)
8055 if (objfile
->pspace
!= loc
->pspace
)
8058 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8059 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8062 if (is_addr_in_objfile (loc_addr
, objfile
))
8064 loc
->shlib_disabled
= 1;
8065 /* At this point, we don't know whether the object was
8066 unmapped from the inferior or not, so leave the
8067 inserted flag alone. We'll handle failure to
8068 uninsert quietly, in case the object was indeed
8071 mark_breakpoint_location_modified (loc
);
8078 observer_notify_breakpoint_modified (b
);
8082 /* FORK & VFORK catchpoints. */
8084 /* An instance of this type is used to represent a fork or vfork
8085 catchpoint. It includes a "struct breakpoint" as a kind of base
8086 class; users downcast to "struct breakpoint *" when needed. A
8087 breakpoint is really of this type iff its ops pointer points to
8088 CATCH_FORK_BREAKPOINT_OPS. */
8090 struct fork_catchpoint
8092 /* The base class. */
8093 struct breakpoint base
;
8095 /* Process id of a child process whose forking triggered this
8096 catchpoint. This field is only valid immediately after this
8097 catchpoint has triggered. */
8098 ptid_t forked_inferior_pid
;
8101 /* Implement the "insert" breakpoint_ops method for fork
8105 insert_catch_fork (struct bp_location
*bl
)
8107 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8110 /* Implement the "remove" breakpoint_ops method for fork
8114 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8116 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8119 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8123 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8124 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8125 const struct target_waitstatus
*ws
)
8127 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8129 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8132 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8136 /* Implement the "print_it" breakpoint_ops method for fork
8139 static enum print_stop_action
8140 print_it_catch_fork (bpstat bs
)
8142 struct ui_out
*uiout
= current_uiout
;
8143 struct breakpoint
*b
= bs
->breakpoint_at
;
8144 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8146 annotate_catchpoint (b
->number
);
8147 maybe_print_thread_hit_breakpoint (uiout
);
8148 if (b
->disposition
== disp_del
)
8149 ui_out_text (uiout
, "Temporary catchpoint ");
8151 ui_out_text (uiout
, "Catchpoint ");
8152 if (ui_out_is_mi_like_p (uiout
))
8154 ui_out_field_string (uiout
, "reason",
8155 async_reason_lookup (EXEC_ASYNC_FORK
));
8156 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8158 ui_out_field_int (uiout
, "bkptno", b
->number
);
8159 ui_out_text (uiout
, " (forked process ");
8160 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8161 ui_out_text (uiout
, "), ");
8162 return PRINT_SRC_AND_LOC
;
8165 /* Implement the "print_one" breakpoint_ops method for fork
8169 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8171 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8172 struct value_print_options opts
;
8173 struct ui_out
*uiout
= current_uiout
;
8175 get_user_print_options (&opts
);
8177 /* Field 4, the address, is omitted (which makes the columns not
8178 line up too nicely with the headers, but the effect is relatively
8180 if (opts
.addressprint
)
8181 ui_out_field_skip (uiout
, "addr");
8183 ui_out_text (uiout
, "fork");
8184 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8186 ui_out_text (uiout
, ", process ");
8187 ui_out_field_int (uiout
, "what",
8188 ptid_get_pid (c
->forked_inferior_pid
));
8189 ui_out_spaces (uiout
, 1);
8192 if (ui_out_is_mi_like_p (uiout
))
8193 ui_out_field_string (uiout
, "catch-type", "fork");
8196 /* Implement the "print_mention" breakpoint_ops method for fork
8200 print_mention_catch_fork (struct breakpoint
*b
)
8202 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8205 /* Implement the "print_recreate" breakpoint_ops method for fork
8209 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8211 fprintf_unfiltered (fp
, "catch fork");
8212 print_recreate_thread (b
, fp
);
8215 /* The breakpoint_ops structure to be used in fork catchpoints. */
8217 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8219 /* Implement the "insert" breakpoint_ops method for vfork
8223 insert_catch_vfork (struct bp_location
*bl
)
8225 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8228 /* Implement the "remove" breakpoint_ops method for vfork
8232 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8234 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8237 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8241 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8242 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8243 const struct target_waitstatus
*ws
)
8245 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8247 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8250 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8254 /* Implement the "print_it" breakpoint_ops method for vfork
8257 static enum print_stop_action
8258 print_it_catch_vfork (bpstat bs
)
8260 struct ui_out
*uiout
= current_uiout
;
8261 struct breakpoint
*b
= bs
->breakpoint_at
;
8262 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8264 annotate_catchpoint (b
->number
);
8265 maybe_print_thread_hit_breakpoint (uiout
);
8266 if (b
->disposition
== disp_del
)
8267 ui_out_text (uiout
, "Temporary catchpoint ");
8269 ui_out_text (uiout
, "Catchpoint ");
8270 if (ui_out_is_mi_like_p (uiout
))
8272 ui_out_field_string (uiout
, "reason",
8273 async_reason_lookup (EXEC_ASYNC_VFORK
));
8274 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8276 ui_out_field_int (uiout
, "bkptno", b
->number
);
8277 ui_out_text (uiout
, " (vforked process ");
8278 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8279 ui_out_text (uiout
, "), ");
8280 return PRINT_SRC_AND_LOC
;
8283 /* Implement the "print_one" breakpoint_ops method for vfork
8287 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8289 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8290 struct value_print_options opts
;
8291 struct ui_out
*uiout
= current_uiout
;
8293 get_user_print_options (&opts
);
8294 /* Field 4, the address, is omitted (which makes the columns not
8295 line up too nicely with the headers, but the effect is relatively
8297 if (opts
.addressprint
)
8298 ui_out_field_skip (uiout
, "addr");
8300 ui_out_text (uiout
, "vfork");
8301 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8303 ui_out_text (uiout
, ", process ");
8304 ui_out_field_int (uiout
, "what",
8305 ptid_get_pid (c
->forked_inferior_pid
));
8306 ui_out_spaces (uiout
, 1);
8309 if (ui_out_is_mi_like_p (uiout
))
8310 ui_out_field_string (uiout
, "catch-type", "vfork");
8313 /* Implement the "print_mention" breakpoint_ops method for vfork
8317 print_mention_catch_vfork (struct breakpoint
*b
)
8319 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8322 /* Implement the "print_recreate" breakpoint_ops method for vfork
8326 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8328 fprintf_unfiltered (fp
, "catch vfork");
8329 print_recreate_thread (b
, fp
);
8332 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8334 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8336 /* An instance of this type is used to represent an solib catchpoint.
8337 It includes a "struct breakpoint" as a kind of base class; users
8338 downcast to "struct breakpoint *" when needed. A breakpoint is
8339 really of this type iff its ops pointer points to
8340 CATCH_SOLIB_BREAKPOINT_OPS. */
8342 struct solib_catchpoint
8344 /* The base class. */
8345 struct breakpoint base
;
8347 /* True for "catch load", false for "catch unload". */
8348 unsigned char is_load
;
8350 /* Regular expression to match, if any. COMPILED is only valid when
8351 REGEX is non-NULL. */
8357 dtor_catch_solib (struct breakpoint
*b
)
8359 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8362 regfree (&self
->compiled
);
8363 xfree (self
->regex
);
8365 base_breakpoint_ops
.dtor (b
);
8369 insert_catch_solib (struct bp_location
*ignore
)
8375 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8381 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8382 struct address_space
*aspace
,
8384 const struct target_waitstatus
*ws
)
8386 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8387 struct breakpoint
*other
;
8389 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8392 ALL_BREAKPOINTS (other
)
8394 struct bp_location
*other_bl
;
8396 if (other
== bl
->owner
)
8399 if (other
->type
!= bp_shlib_event
)
8402 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8405 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8407 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8416 check_status_catch_solib (struct bpstats
*bs
)
8418 struct solib_catchpoint
*self
8419 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8424 struct so_list
*iter
;
8427 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8432 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8441 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8446 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8452 bs
->print_it
= print_it_noop
;
8455 static enum print_stop_action
8456 print_it_catch_solib (bpstat bs
)
8458 struct breakpoint
*b
= bs
->breakpoint_at
;
8459 struct ui_out
*uiout
= current_uiout
;
8461 annotate_catchpoint (b
->number
);
8462 maybe_print_thread_hit_breakpoint (uiout
);
8463 if (b
->disposition
== disp_del
)
8464 ui_out_text (uiout
, "Temporary catchpoint ");
8466 ui_out_text (uiout
, "Catchpoint ");
8467 ui_out_field_int (uiout
, "bkptno", b
->number
);
8468 ui_out_text (uiout
, "\n");
8469 if (ui_out_is_mi_like_p (uiout
))
8470 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8471 print_solib_event (1);
8472 return PRINT_SRC_AND_LOC
;
8476 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8478 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8479 struct value_print_options opts
;
8480 struct ui_out
*uiout
= current_uiout
;
8483 get_user_print_options (&opts
);
8484 /* Field 4, the address, is omitted (which makes the columns not
8485 line up too nicely with the headers, but the effect is relatively
8487 if (opts
.addressprint
)
8490 ui_out_field_skip (uiout
, "addr");
8497 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8499 msg
= xstrdup (_("load of library"));
8504 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8506 msg
= xstrdup (_("unload of library"));
8508 ui_out_field_string (uiout
, "what", msg
);
8511 if (ui_out_is_mi_like_p (uiout
))
8512 ui_out_field_string (uiout
, "catch-type",
8513 self
->is_load
? "load" : "unload");
8517 print_mention_catch_solib (struct breakpoint
*b
)
8519 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8521 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8522 self
->is_load
? "load" : "unload");
8526 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8528 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8530 fprintf_unfiltered (fp
, "%s %s",
8531 b
->disposition
== disp_del
? "tcatch" : "catch",
8532 self
->is_load
? "load" : "unload");
8534 fprintf_unfiltered (fp
, " %s", self
->regex
);
8535 fprintf_unfiltered (fp
, "\n");
8538 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8540 /* Shared helper function (MI and CLI) for creating and installing
8541 a shared object event catchpoint. If IS_LOAD is non-zero then
8542 the events to be caught are load events, otherwise they are
8543 unload events. If IS_TEMP is non-zero the catchpoint is a
8544 temporary one. If ENABLED is non-zero the catchpoint is
8545 created in an enabled state. */
8548 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8550 struct solib_catchpoint
*c
;
8551 struct gdbarch
*gdbarch
= get_current_arch ();
8552 struct cleanup
*cleanup
;
8556 arg
= skip_spaces (arg
);
8558 c
= new solib_catchpoint ();
8559 cleanup
= make_cleanup (xfree
, c
);
8565 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8568 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8570 make_cleanup (xfree
, err
);
8571 error (_("Invalid regexp (%s): %s"), err
, arg
);
8573 c
->regex
= xstrdup (arg
);
8576 c
->is_load
= is_load
;
8577 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8578 &catch_solib_breakpoint_ops
);
8580 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8582 discard_cleanups (cleanup
);
8583 install_breakpoint (0, &c
->base
, 1);
8586 /* A helper function that does all the work for "catch load" and
8590 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8591 struct cmd_list_element
*command
)
8594 const int enabled
= 1;
8596 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8598 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8602 catch_load_command_1 (char *arg
, int from_tty
,
8603 struct cmd_list_element
*command
)
8605 catch_load_or_unload (arg
, from_tty
, 1, command
);
8609 catch_unload_command_1 (char *arg
, int from_tty
,
8610 struct cmd_list_element
*command
)
8612 catch_load_or_unload (arg
, from_tty
, 0, command
);
8615 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8616 is non-zero, then make the breakpoint temporary. If COND_STRING is
8617 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8618 the breakpoint_ops structure associated to the catchpoint. */
8621 init_catchpoint (struct breakpoint
*b
,
8622 struct gdbarch
*gdbarch
, int tempflag
,
8624 const struct breakpoint_ops
*ops
)
8626 struct symtab_and_line sal
;
8629 sal
.pspace
= current_program_space
;
8631 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8633 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8634 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8638 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8640 add_to_breakpoint_chain (b
);
8641 set_breakpoint_number (internal
, b
);
8642 if (is_tracepoint (b
))
8643 set_tracepoint_count (breakpoint_count
);
8646 observer_notify_breakpoint_created (b
);
8649 update_global_location_list (UGLL_MAY_INSERT
);
8653 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8654 int tempflag
, char *cond_string
,
8655 const struct breakpoint_ops
*ops
)
8657 struct fork_catchpoint
*c
= new fork_catchpoint ();
8659 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8661 c
->forked_inferior_pid
= null_ptid
;
8663 install_breakpoint (0, &c
->base
, 1);
8666 /* Exec catchpoints. */
8668 /* An instance of this type is used to represent an exec catchpoint.
8669 It includes a "struct breakpoint" as a kind of base class; users
8670 downcast to "struct breakpoint *" when needed. A breakpoint is
8671 really of this type iff its ops pointer points to
8672 CATCH_EXEC_BREAKPOINT_OPS. */
8674 struct exec_catchpoint
8676 /* The base class. */
8677 struct breakpoint base
;
8679 /* Filename of a program whose exec triggered this catchpoint.
8680 This field is only valid immediately after this catchpoint has
8682 char *exec_pathname
;
8685 /* Implement the "dtor" breakpoint_ops method for exec
8689 dtor_catch_exec (struct breakpoint
*b
)
8691 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8693 xfree (c
->exec_pathname
);
8695 base_breakpoint_ops
.dtor (b
);
8699 insert_catch_exec (struct bp_location
*bl
)
8701 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8705 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8707 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8711 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8712 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8713 const struct target_waitstatus
*ws
)
8715 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8717 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8720 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8724 static enum print_stop_action
8725 print_it_catch_exec (bpstat bs
)
8727 struct ui_out
*uiout
= current_uiout
;
8728 struct breakpoint
*b
= bs
->breakpoint_at
;
8729 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8731 annotate_catchpoint (b
->number
);
8732 maybe_print_thread_hit_breakpoint (uiout
);
8733 if (b
->disposition
== disp_del
)
8734 ui_out_text (uiout
, "Temporary catchpoint ");
8736 ui_out_text (uiout
, "Catchpoint ");
8737 if (ui_out_is_mi_like_p (uiout
))
8739 ui_out_field_string (uiout
, "reason",
8740 async_reason_lookup (EXEC_ASYNC_EXEC
));
8741 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8743 ui_out_field_int (uiout
, "bkptno", b
->number
);
8744 ui_out_text (uiout
, " (exec'd ");
8745 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8746 ui_out_text (uiout
, "), ");
8748 return PRINT_SRC_AND_LOC
;
8752 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8754 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8755 struct value_print_options opts
;
8756 struct ui_out
*uiout
= current_uiout
;
8758 get_user_print_options (&opts
);
8760 /* Field 4, the address, is omitted (which makes the columns
8761 not line up too nicely with the headers, but the effect
8762 is relatively readable). */
8763 if (opts
.addressprint
)
8764 ui_out_field_skip (uiout
, "addr");
8766 ui_out_text (uiout
, "exec");
8767 if (c
->exec_pathname
!= NULL
)
8769 ui_out_text (uiout
, ", program \"");
8770 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8771 ui_out_text (uiout
, "\" ");
8774 if (ui_out_is_mi_like_p (uiout
))
8775 ui_out_field_string (uiout
, "catch-type", "exec");
8779 print_mention_catch_exec (struct breakpoint
*b
)
8781 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8784 /* Implement the "print_recreate" breakpoint_ops method for exec
8788 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8790 fprintf_unfiltered (fp
, "catch exec");
8791 print_recreate_thread (b
, fp
);
8794 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8797 hw_breakpoint_used_count (void)
8800 struct breakpoint
*b
;
8801 struct bp_location
*bl
;
8805 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8806 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8808 /* Special types of hardware breakpoints may use more than
8810 i
+= b
->ops
->resources_needed (bl
);
8817 /* Returns the resources B would use if it were a hardware
8821 hw_watchpoint_use_count (struct breakpoint
*b
)
8824 struct bp_location
*bl
;
8826 if (!breakpoint_enabled (b
))
8829 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8831 /* Special types of hardware watchpoints may use more than
8833 i
+= b
->ops
->resources_needed (bl
);
8839 /* Returns the sum the used resources of all hardware watchpoints of
8840 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8841 the sum of the used resources of all hardware watchpoints of other
8842 types _not_ TYPE. */
8845 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8846 enum bptype type
, int *other_type_used
)
8849 struct breakpoint
*b
;
8851 *other_type_used
= 0;
8856 if (!breakpoint_enabled (b
))
8859 if (b
->type
== type
)
8860 i
+= hw_watchpoint_use_count (b
);
8861 else if (is_hardware_watchpoint (b
))
8862 *other_type_used
= 1;
8869 disable_watchpoints_before_interactive_call_start (void)
8871 struct breakpoint
*b
;
8875 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8877 b
->enable_state
= bp_call_disabled
;
8878 update_global_location_list (UGLL_DONT_INSERT
);
8884 enable_watchpoints_after_interactive_call_stop (void)
8886 struct breakpoint
*b
;
8890 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8892 b
->enable_state
= bp_enabled
;
8893 update_global_location_list (UGLL_MAY_INSERT
);
8899 disable_breakpoints_before_startup (void)
8901 current_program_space
->executing_startup
= 1;
8902 update_global_location_list (UGLL_DONT_INSERT
);
8906 enable_breakpoints_after_startup (void)
8908 current_program_space
->executing_startup
= 0;
8909 breakpoint_re_set ();
8912 /* Create a new single-step breakpoint for thread THREAD, with no
8915 static struct breakpoint
*
8916 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8918 struct breakpoint
*b
= new breakpoint ();
8920 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8921 &momentary_breakpoint_ops
);
8923 b
->disposition
= disp_donttouch
;
8924 b
->frame_id
= null_frame_id
;
8927 gdb_assert (b
->thread
!= 0);
8929 add_to_breakpoint_chain (b
);
8934 /* Set a momentary breakpoint of type TYPE at address specified by
8935 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8939 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8940 struct frame_id frame_id
, enum bptype type
)
8942 struct breakpoint
*b
;
8944 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8946 gdb_assert (!frame_id_artificial_p (frame_id
));
8948 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8949 b
->enable_state
= bp_enabled
;
8950 b
->disposition
= disp_donttouch
;
8951 b
->frame_id
= frame_id
;
8953 /* If we're debugging a multi-threaded program, then we want
8954 momentary breakpoints to be active in only a single thread of
8956 if (in_thread_list (inferior_ptid
))
8957 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8959 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8964 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8965 The new breakpoint will have type TYPE, use OPS as its
8966 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8968 static struct breakpoint
*
8969 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8971 const struct breakpoint_ops
*ops
,
8974 struct breakpoint
*copy
;
8976 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8977 copy
->loc
= allocate_bp_location (copy
);
8978 set_breakpoint_location_function (copy
->loc
, 1);
8980 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8981 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8982 copy
->loc
->address
= orig
->loc
->address
;
8983 copy
->loc
->section
= orig
->loc
->section
;
8984 copy
->loc
->pspace
= orig
->loc
->pspace
;
8985 copy
->loc
->probe
= orig
->loc
->probe
;
8986 copy
->loc
->line_number
= orig
->loc
->line_number
;
8987 copy
->loc
->symtab
= orig
->loc
->symtab
;
8988 copy
->loc
->enabled
= loc_enabled
;
8989 copy
->frame_id
= orig
->frame_id
;
8990 copy
->thread
= orig
->thread
;
8991 copy
->pspace
= orig
->pspace
;
8993 copy
->enable_state
= bp_enabled
;
8994 copy
->disposition
= disp_donttouch
;
8995 copy
->number
= internal_breakpoint_number
--;
8997 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9001 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9005 clone_momentary_breakpoint (struct breakpoint
*orig
)
9007 /* If there's nothing to clone, then return nothing. */
9011 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9015 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9018 struct symtab_and_line sal
;
9020 sal
= find_pc_line (pc
, 0);
9022 sal
.section
= find_pc_overlay (pc
);
9023 sal
.explicit_pc
= 1;
9025 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9029 /* Tell the user we have just set a breakpoint B. */
9032 mention (struct breakpoint
*b
)
9034 b
->ops
->print_mention (b
);
9035 if (ui_out_is_mi_like_p (current_uiout
))
9037 printf_filtered ("\n");
9041 static int bp_loc_is_permanent (struct bp_location
*loc
);
9043 static struct bp_location
*
9044 add_location_to_breakpoint (struct breakpoint
*b
,
9045 const struct symtab_and_line
*sal
)
9047 struct bp_location
*loc
, **tmp
;
9048 CORE_ADDR adjusted_address
;
9049 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9051 if (loc_gdbarch
== NULL
)
9052 loc_gdbarch
= b
->gdbarch
;
9054 /* Adjust the breakpoint's address prior to allocating a location.
9055 Once we call allocate_bp_location(), that mostly uninitialized
9056 location will be placed on the location chain. Adjustment of the
9057 breakpoint may cause target_read_memory() to be called and we do
9058 not want its scan of the location chain to find a breakpoint and
9059 location that's only been partially initialized. */
9060 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9063 /* Sort the locations by their ADDRESS. */
9064 loc
= allocate_bp_location (b
);
9065 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9066 tmp
= &((*tmp
)->next
))
9071 loc
->requested_address
= sal
->pc
;
9072 loc
->address
= adjusted_address
;
9073 loc
->pspace
= sal
->pspace
;
9074 loc
->probe
.probe
= sal
->probe
;
9075 loc
->probe
.objfile
= sal
->objfile
;
9076 gdb_assert (loc
->pspace
!= NULL
);
9077 loc
->section
= sal
->section
;
9078 loc
->gdbarch
= loc_gdbarch
;
9079 loc
->line_number
= sal
->line
;
9080 loc
->symtab
= sal
->symtab
;
9082 set_breakpoint_location_function (loc
,
9083 sal
->explicit_pc
|| sal
->explicit_line
);
9085 /* While by definition, permanent breakpoints are already present in the
9086 code, we don't mark the location as inserted. Normally one would expect
9087 that GDB could rely on that breakpoint instruction to stop the program,
9088 thus removing the need to insert its own breakpoint, except that executing
9089 the breakpoint instruction can kill the target instead of reporting a
9090 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9091 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9092 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9093 breakpoint be inserted normally results in QEMU knowing about the GDB
9094 breakpoint, and thus trap before the breakpoint instruction is executed.
9095 (If GDB later needs to continue execution past the permanent breakpoint,
9096 it manually increments the PC, thus avoiding executing the breakpoint
9098 if (bp_loc_is_permanent (loc
))
9105 /* See breakpoint.h. */
9108 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9112 const gdb_byte
*bpoint
;
9113 gdb_byte
*target_mem
;
9114 struct cleanup
*cleanup
;
9118 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9120 /* Software breakpoints unsupported? */
9124 target_mem
= (gdb_byte
*) alloca (len
);
9126 /* Enable the automatic memory restoration from breakpoints while
9127 we read the memory. Otherwise we could say about our temporary
9128 breakpoints they are permanent. */
9129 cleanup
= make_show_memory_breakpoints_cleanup (0);
9131 if (target_read_memory (address
, target_mem
, len
) == 0
9132 && memcmp (target_mem
, bpoint
, len
) == 0)
9135 do_cleanups (cleanup
);
9140 /* Return 1 if LOC is pointing to a permanent breakpoint,
9141 return 0 otherwise. */
9144 bp_loc_is_permanent (struct bp_location
*loc
)
9146 struct cleanup
*cleanup
;
9149 gdb_assert (loc
!= NULL
);
9151 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9152 attempt to read from the addresses the locations of these breakpoint types
9153 point to. program_breakpoint_here_p, below, will attempt to read
9155 if (!breakpoint_address_is_meaningful (loc
->owner
))
9158 cleanup
= save_current_space_and_thread ();
9159 switch_to_program_space_and_thread (loc
->pspace
);
9161 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9163 do_cleanups (cleanup
);
9168 /* Build a command list for the dprintf corresponding to the current
9169 settings of the dprintf style options. */
9172 update_dprintf_command_list (struct breakpoint
*b
)
9174 char *dprintf_args
= b
->extra_string
;
9175 char *printf_line
= NULL
;
9180 dprintf_args
= skip_spaces (dprintf_args
);
9182 /* Allow a comma, as it may have terminated a location, but don't
9184 if (*dprintf_args
== ',')
9186 dprintf_args
= skip_spaces (dprintf_args
);
9188 if (*dprintf_args
!= '"')
9189 error (_("Bad format string, missing '\"'."));
9191 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9192 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9193 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9195 if (!dprintf_function
)
9196 error (_("No function supplied for dprintf call"));
9198 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9199 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9204 printf_line
= xstrprintf ("call (void) %s (%s)",
9208 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9210 if (target_can_run_breakpoint_commands ())
9211 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9214 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9215 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9219 internal_error (__FILE__
, __LINE__
,
9220 _("Invalid dprintf style."));
9222 gdb_assert (printf_line
!= NULL
);
9223 /* Manufacture a printf sequence. */
9225 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9227 printf_cmd_line
->control_type
= simple_control
;
9228 printf_cmd_line
->body_count
= 0;
9229 printf_cmd_line
->body_list
= NULL
;
9230 printf_cmd_line
->next
= NULL
;
9231 printf_cmd_line
->line
= printf_line
;
9233 breakpoint_set_commands (b
, printf_cmd_line
);
9237 /* Update all dprintf commands, making their command lists reflect
9238 current style settings. */
9241 update_dprintf_commands (char *args
, int from_tty
,
9242 struct cmd_list_element
*c
)
9244 struct breakpoint
*b
;
9248 if (b
->type
== bp_dprintf
)
9249 update_dprintf_command_list (b
);
9253 /* Create a breakpoint with SAL as location. Use LOCATION
9254 as a description of the location, and COND_STRING
9255 as condition expression. If LOCATION is NULL then create an
9256 "address location" from the address in the SAL. */
9259 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9260 struct symtabs_and_lines sals
,
9261 struct event_location
*location
,
9262 char *filter
, char *cond_string
,
9264 enum bptype type
, enum bpdisp disposition
,
9265 int thread
, int task
, int ignore_count
,
9266 const struct breakpoint_ops
*ops
, int from_tty
,
9267 int enabled
, int internal
, unsigned flags
,
9268 int display_canonical
)
9272 if (type
== bp_hardware_breakpoint
)
9274 int target_resources_ok
;
9276 i
= hw_breakpoint_used_count ();
9277 target_resources_ok
=
9278 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9280 if (target_resources_ok
== 0)
9281 error (_("No hardware breakpoint support in the target."));
9282 else if (target_resources_ok
< 0)
9283 error (_("Hardware breakpoints used exceeds limit."));
9286 gdb_assert (sals
.nelts
> 0);
9288 for (i
= 0; i
< sals
.nelts
; ++i
)
9290 struct symtab_and_line sal
= sals
.sals
[i
];
9291 struct bp_location
*loc
;
9295 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9297 loc_gdbarch
= gdbarch
;
9299 describe_other_breakpoints (loc_gdbarch
,
9300 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9305 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9309 b
->cond_string
= cond_string
;
9310 b
->extra_string
= extra_string
;
9311 b
->ignore_count
= ignore_count
;
9312 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9313 b
->disposition
= disposition
;
9315 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9316 b
->loc
->inserted
= 1;
9318 if (type
== bp_static_tracepoint
)
9320 struct tracepoint
*t
= (struct tracepoint
*) b
;
9321 struct static_tracepoint_marker marker
;
9323 if (strace_marker_p (b
))
9325 /* We already know the marker exists, otherwise, we
9326 wouldn't see a sal for it. */
9327 const char *p
= &event_location_to_string (b
->location
)[3];
9331 p
= skip_spaces_const (p
);
9333 endp
= skip_to_space_const (p
);
9335 marker_str
= savestring (p
, endp
- p
);
9336 t
->static_trace_marker_id
= marker_str
;
9338 printf_filtered (_("Probed static tracepoint "
9340 t
->static_trace_marker_id
);
9342 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9344 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9345 release_static_tracepoint_marker (&marker
);
9347 printf_filtered (_("Probed static tracepoint "
9349 t
->static_trace_marker_id
);
9352 warning (_("Couldn't determine the static "
9353 "tracepoint marker to probe"));
9360 loc
= add_location_to_breakpoint (b
, &sal
);
9361 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9367 const char *arg
= b
->cond_string
;
9369 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9370 block_for_pc (loc
->address
), 0);
9372 error (_("Garbage '%s' follows condition"), arg
);
9375 /* Dynamic printf requires and uses additional arguments on the
9376 command line, otherwise it's an error. */
9377 if (type
== bp_dprintf
)
9379 if (b
->extra_string
)
9380 update_dprintf_command_list (b
);
9382 error (_("Format string required"));
9384 else if (b
->extra_string
)
9385 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9388 b
->display_canonical
= display_canonical
;
9389 if (location
!= NULL
)
9390 b
->location
= location
;
9393 const char *addr_string
= NULL
;
9394 int addr_string_len
= 0;
9396 if (location
!= NULL
)
9397 addr_string
= event_location_to_string (location
);
9398 if (addr_string
!= NULL
)
9399 addr_string_len
= strlen (addr_string
);
9401 b
->location
= new_address_location (b
->loc
->address
,
9402 addr_string
, addr_string_len
);
9408 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9409 struct symtabs_and_lines sals
,
9410 struct event_location
*location
,
9411 char *filter
, char *cond_string
,
9413 enum bptype type
, enum bpdisp disposition
,
9414 int thread
, int task
, int ignore_count
,
9415 const struct breakpoint_ops
*ops
, int from_tty
,
9416 int enabled
, int internal
, unsigned flags
,
9417 int display_canonical
)
9419 struct breakpoint
*b
;
9420 struct cleanup
*old_chain
;
9422 if (is_tracepoint_type (type
))
9424 struct tracepoint
*t
;
9426 t
= new tracepoint ();
9430 b
= new breakpoint ();
9432 old_chain
= make_cleanup (xfree
, b
);
9434 init_breakpoint_sal (b
, gdbarch
,
9436 filter
, cond_string
, extra_string
,
9438 thread
, task
, ignore_count
,
9440 enabled
, internal
, flags
,
9442 discard_cleanups (old_chain
);
9444 install_breakpoint (internal
, b
, 0);
9447 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9448 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9449 value. COND_STRING, if not NULL, specified the condition to be
9450 used for all breakpoints. Essentially the only case where
9451 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9452 function. In that case, it's still not possible to specify
9453 separate conditions for different overloaded functions, so
9454 we take just a single condition string.
9456 NOTE: If the function succeeds, the caller is expected to cleanup
9457 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9458 array contents). If the function fails (error() is called), the
9459 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9460 COND and SALS arrays and each of those arrays contents. */
9463 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9464 struct linespec_result
*canonical
,
9465 char *cond_string
, char *extra_string
,
9466 enum bptype type
, enum bpdisp disposition
,
9467 int thread
, int task
, int ignore_count
,
9468 const struct breakpoint_ops
*ops
, int from_tty
,
9469 int enabled
, int internal
, unsigned flags
)
9472 struct linespec_sals
*lsal
;
9474 if (canonical
->pre_expanded
)
9475 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9477 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9479 /* Note that 'location' can be NULL in the case of a plain
9480 'break', without arguments. */
9481 struct event_location
*location
9482 = (canonical
->location
!= NULL
9483 ? copy_event_location (canonical
->location
) : NULL
);
9484 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9485 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9487 make_cleanup (xfree
, filter_string
);
9488 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9491 cond_string
, extra_string
,
9493 thread
, task
, ignore_count
, ops
,
9494 from_tty
, enabled
, internal
, flags
,
9495 canonical
->special_display
);
9496 discard_cleanups (inner
);
9500 /* Parse LOCATION which is assumed to be a SAL specification possibly
9501 followed by conditionals. On return, SALS contains an array of SAL
9502 addresses found. LOCATION points to the end of the SAL (for
9503 linespec locations).
9505 The array and the line spec strings are allocated on the heap, it is
9506 the caller's responsibility to free them. */
9509 parse_breakpoint_sals (const struct event_location
*location
,
9510 struct linespec_result
*canonical
)
9512 struct symtab_and_line cursal
;
9514 if (event_location_type (location
) == LINESPEC_LOCATION
)
9516 const char *address
= get_linespec_location (location
);
9518 if (address
== NULL
)
9520 /* The last displayed codepoint, if it's valid, is our default
9521 breakpoint address. */
9522 if (last_displayed_sal_is_valid ())
9524 struct linespec_sals lsal
;
9525 struct symtab_and_line sal
;
9528 init_sal (&sal
); /* Initialize to zeroes. */
9529 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9531 /* Set sal's pspace, pc, symtab, and line to the values
9532 corresponding to the last call to print_frame_info.
9533 Be sure to reinitialize LINE with NOTCURRENT == 0
9534 as the breakpoint line number is inappropriate otherwise.
9535 find_pc_line would adjust PC, re-set it back. */
9536 get_last_displayed_sal (&sal
);
9538 sal
= find_pc_line (pc
, 0);
9540 /* "break" without arguments is equivalent to "break *PC"
9541 where PC is the last displayed codepoint's address. So
9542 make sure to set sal.explicit_pc to prevent GDB from
9543 trying to expand the list of sals to include all other
9544 instances with the same symtab and line. */
9546 sal
.explicit_pc
= 1;
9548 lsal
.sals
.sals
[0] = sal
;
9549 lsal
.sals
.nelts
= 1;
9550 lsal
.canonical
= NULL
;
9552 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9556 error (_("No default breakpoint address now."));
9560 /* Force almost all breakpoints to be in terms of the
9561 current_source_symtab (which is decode_line_1's default).
9562 This should produce the results we want almost all of the
9563 time while leaving default_breakpoint_* alone.
9565 ObjC: However, don't match an Objective-C method name which
9566 may have a '+' or '-' succeeded by a '['. */
9567 cursal
= get_current_source_symtab_and_line ();
9568 if (last_displayed_sal_is_valid ())
9570 const char *address
= NULL
;
9572 if (event_location_type (location
) == LINESPEC_LOCATION
)
9573 address
= get_linespec_location (location
);
9577 && strchr ("+-", address
[0]) != NULL
9578 && address
[1] != '['))
9580 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9581 get_last_displayed_symtab (),
9582 get_last_displayed_line (),
9583 canonical
, NULL
, NULL
);
9588 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9589 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9593 /* Convert each SAL into a real PC. Verify that the PC can be
9594 inserted as a breakpoint. If it can't throw an error. */
9597 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9601 for (i
= 0; i
< sals
->nelts
; i
++)
9602 resolve_sal_pc (&sals
->sals
[i
]);
9605 /* Fast tracepoints may have restrictions on valid locations. For
9606 instance, a fast tracepoint using a jump instead of a trap will
9607 likely have to overwrite more bytes than a trap would, and so can
9608 only be placed where the instruction is longer than the jump, or a
9609 multi-instruction sequence does not have a jump into the middle of
9613 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9614 struct symtabs_and_lines
*sals
)
9617 struct symtab_and_line
*sal
;
9619 struct cleanup
*old_chain
;
9621 for (i
= 0; i
< sals
->nelts
; i
++)
9623 struct gdbarch
*sarch
;
9625 sal
= &sals
->sals
[i
];
9627 sarch
= get_sal_arch (*sal
);
9628 /* We fall back to GDBARCH if there is no architecture
9629 associated with SAL. */
9632 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9633 old_chain
= make_cleanup (xfree
, msg
);
9636 error (_("May not have a fast tracepoint at %s%s"),
9637 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9639 do_cleanups (old_chain
);
9643 /* Given TOK, a string specification of condition and thread, as
9644 accepted by the 'break' command, extract the condition
9645 string and thread number and set *COND_STRING and *THREAD.
9646 PC identifies the context at which the condition should be parsed.
9647 If no condition is found, *COND_STRING is set to NULL.
9648 If no thread is found, *THREAD is set to -1. */
9651 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9652 char **cond_string
, int *thread
, int *task
,
9655 *cond_string
= NULL
;
9662 const char *end_tok
;
9664 const char *cond_start
= NULL
;
9665 const char *cond_end
= NULL
;
9667 tok
= skip_spaces_const (tok
);
9669 if ((*tok
== '"' || *tok
== ',') && rest
)
9671 *rest
= savestring (tok
, strlen (tok
));
9675 end_tok
= skip_to_space_const (tok
);
9677 toklen
= end_tok
- tok
;
9679 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9681 tok
= cond_start
= end_tok
+ 1;
9682 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9684 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9686 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9689 struct thread_info
*thr
;
9692 thr
= parse_thread_id (tok
, &tmptok
);
9694 error (_("Junk after thread keyword."));
9695 *thread
= thr
->global_num
;
9698 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9703 *task
= strtol (tok
, &tmptok
, 0);
9705 error (_("Junk after task keyword."));
9706 if (!valid_task_id (*task
))
9707 error (_("Unknown task %d."), *task
);
9712 *rest
= savestring (tok
, strlen (tok
));
9716 error (_("Junk at end of arguments."));
9720 /* Decode a static tracepoint marker spec. */
9722 static struct symtabs_and_lines
9723 decode_static_tracepoint_spec (const char **arg_p
)
9725 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9726 struct symtabs_and_lines sals
;
9727 struct cleanup
*old_chain
;
9728 const char *p
= &(*arg_p
)[3];
9733 p
= skip_spaces_const (p
);
9735 endp
= skip_to_space_const (p
);
9737 marker_str
= savestring (p
, endp
- p
);
9738 old_chain
= make_cleanup (xfree
, marker_str
);
9740 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9741 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9742 error (_("No known static tracepoint marker named %s"), marker_str
);
9744 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9745 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9747 for (i
= 0; i
< sals
.nelts
; i
++)
9749 struct static_tracepoint_marker
*marker
;
9751 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9753 init_sal (&sals
.sals
[i
]);
9755 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9756 sals
.sals
[i
].pc
= marker
->address
;
9758 release_static_tracepoint_marker (marker
);
9761 do_cleanups (old_chain
);
9767 /* See breakpoint.h. */
9770 create_breakpoint (struct gdbarch
*gdbarch
,
9771 const struct event_location
*location
, char *cond_string
,
9772 int thread
, char *extra_string
,
9774 int tempflag
, enum bptype type_wanted
,
9776 enum auto_boolean pending_break_support
,
9777 const struct breakpoint_ops
*ops
,
9778 int from_tty
, int enabled
, int internal
,
9781 struct linespec_result canonical
;
9782 struct cleanup
*old_chain
;
9783 struct cleanup
*bkpt_chain
= NULL
;
9786 int prev_bkpt_count
= breakpoint_count
;
9788 gdb_assert (ops
!= NULL
);
9790 /* If extra_string isn't useful, set it to NULL. */
9791 if (extra_string
!= NULL
&& *extra_string
== '\0')
9792 extra_string
= NULL
;
9794 init_linespec_result (&canonical
);
9798 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9800 CATCH (e
, RETURN_MASK_ERROR
)
9802 /* If caller is interested in rc value from parse, set
9804 if (e
.error
== NOT_FOUND_ERROR
)
9806 /* If pending breakpoint support is turned off, throw
9809 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9810 throw_exception (e
);
9812 exception_print (gdb_stderr
, e
);
9814 /* If pending breakpoint support is auto query and the user
9815 selects no, then simply return the error code. */
9816 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9817 && !nquery (_("Make %s pending on future shared library load? "),
9818 bptype_string (type_wanted
)))
9821 /* At this point, either the user was queried about setting
9822 a pending breakpoint and selected yes, or pending
9823 breakpoint behavior is on and thus a pending breakpoint
9824 is defaulted on behalf of the user. */
9828 throw_exception (e
);
9832 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9835 /* Create a chain of things that always need to be cleaned up. */
9836 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9838 /* ----------------------------- SNIP -----------------------------
9839 Anything added to the cleanup chain beyond this point is assumed
9840 to be part of a breakpoint. If the breakpoint create succeeds
9841 then the memory is not reclaimed. */
9842 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9844 /* Resolve all line numbers to PC's and verify that the addresses
9845 are ok for the target. */
9849 struct linespec_sals
*iter
;
9851 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9852 breakpoint_sals_to_pc (&iter
->sals
);
9855 /* Fast tracepoints may have additional restrictions on location. */
9856 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9859 struct linespec_sals
*iter
;
9861 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9862 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9865 /* Verify that condition can be parsed, before setting any
9866 breakpoints. Allocate a separate condition expression for each
9873 struct linespec_sals
*lsal
;
9875 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9877 /* Here we only parse 'arg' to separate condition
9878 from thread number, so parsing in context of first
9879 sal is OK. When setting the breakpoint we'll
9880 re-parse it in context of each sal. */
9882 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9883 &cond_string
, &thread
, &task
, &rest
);
9885 make_cleanup (xfree
, cond_string
);
9887 make_cleanup (xfree
, rest
);
9889 extra_string
= rest
;
9891 extra_string
= NULL
;
9895 if (type_wanted
!= bp_dprintf
9896 && extra_string
!= NULL
&& *extra_string
!= '\0')
9897 error (_("Garbage '%s' at end of location"), extra_string
);
9899 /* Create a private copy of condition string. */
9902 cond_string
= xstrdup (cond_string
);
9903 make_cleanup (xfree
, cond_string
);
9905 /* Create a private copy of any extra string. */
9908 extra_string
= xstrdup (extra_string
);
9909 make_cleanup (xfree
, extra_string
);
9913 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9914 cond_string
, extra_string
, type_wanted
,
9915 tempflag
? disp_del
: disp_donttouch
,
9916 thread
, task
, ignore_count
, ops
,
9917 from_tty
, enabled
, internal
, flags
);
9921 struct breakpoint
*b
;
9923 if (is_tracepoint_type (type_wanted
))
9925 struct tracepoint
*t
;
9927 t
= new tracepoint ();
9931 b
= new breakpoint ();
9933 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9934 b
->location
= copy_event_location (location
);
9937 b
->cond_string
= NULL
;
9940 /* Create a private copy of condition string. */
9943 cond_string
= xstrdup (cond_string
);
9944 make_cleanup (xfree
, cond_string
);
9946 b
->cond_string
= cond_string
;
9950 /* Create a private copy of any extra string. */
9951 if (extra_string
!= NULL
)
9953 extra_string
= xstrdup (extra_string
);
9954 make_cleanup (xfree
, extra_string
);
9956 b
->extra_string
= extra_string
;
9957 b
->ignore_count
= ignore_count
;
9958 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9959 b
->condition_not_parsed
= 1;
9960 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9961 if ((type_wanted
!= bp_breakpoint
9962 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9963 b
->pspace
= current_program_space
;
9965 install_breakpoint (internal
, b
, 0);
9968 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9970 warning (_("Multiple breakpoints were set.\nUse the "
9971 "\"delete\" command to delete unwanted breakpoints."));
9972 prev_breakpoint_count
= prev_bkpt_count
;
9975 /* That's it. Discard the cleanups for data inserted into the
9977 discard_cleanups (bkpt_chain
);
9978 /* But cleanup everything else. */
9979 do_cleanups (old_chain
);
9981 /* error call may happen here - have BKPT_CHAIN already discarded. */
9982 update_global_location_list (UGLL_MAY_INSERT
);
9987 /* Set a breakpoint.
9988 ARG is a string describing breakpoint address,
9989 condition, and thread.
9990 FLAG specifies if a breakpoint is hardware on,
9991 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9995 break_command_1 (char *arg
, int flag
, int from_tty
)
9997 int tempflag
= flag
& BP_TEMPFLAG
;
9998 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9999 ? bp_hardware_breakpoint
10001 struct breakpoint_ops
*ops
;
10002 struct event_location
*location
;
10003 struct cleanup
*cleanup
;
10005 location
= string_to_event_location (&arg
, current_language
);
10006 cleanup
= make_cleanup_delete_event_location (location
);
10008 /* Matching breakpoints on probes. */
10009 if (location
!= NULL
10010 && event_location_type (location
) == PROBE_LOCATION
)
10011 ops
= &bkpt_probe_breakpoint_ops
;
10013 ops
= &bkpt_breakpoint_ops
;
10015 create_breakpoint (get_current_arch (),
10017 NULL
, 0, arg
, 1 /* parse arg */,
10018 tempflag
, type_wanted
,
10019 0 /* Ignore count */,
10020 pending_break_support
,
10026 do_cleanups (cleanup
);
10029 /* Helper function for break_command_1 and disassemble_command. */
10032 resolve_sal_pc (struct symtab_and_line
*sal
)
10036 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10038 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10039 error (_("No line %d in file \"%s\"."),
10040 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10043 /* If this SAL corresponds to a breakpoint inserted using a line
10044 number, then skip the function prologue if necessary. */
10045 if (sal
->explicit_line
)
10046 skip_prologue_sal (sal
);
10049 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10051 const struct blockvector
*bv
;
10052 const struct block
*b
;
10053 struct symbol
*sym
;
10055 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10056 SYMTAB_COMPUNIT (sal
->symtab
));
10059 sym
= block_linkage_function (b
);
10062 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10063 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10068 /* It really is worthwhile to have the section, so we'll
10069 just have to look harder. This case can be executed
10070 if we have line numbers but no functions (as can
10071 happen in assembly source). */
10073 struct bound_minimal_symbol msym
;
10074 struct cleanup
*old_chain
= save_current_space_and_thread ();
10076 switch_to_program_space_and_thread (sal
->pspace
);
10078 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10080 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10082 do_cleanups (old_chain
);
10089 break_command (char *arg
, int from_tty
)
10091 break_command_1 (arg
, 0, from_tty
);
10095 tbreak_command (char *arg
, int from_tty
)
10097 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10101 hbreak_command (char *arg
, int from_tty
)
10103 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10107 thbreak_command (char *arg
, int from_tty
)
10109 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10113 stop_command (char *arg
, int from_tty
)
10115 printf_filtered (_("Specify the type of breakpoint to set.\n\
10116 Usage: stop in <function | address>\n\
10117 stop at <line>\n"));
10121 stopin_command (char *arg
, int from_tty
)
10125 if (arg
== (char *) NULL
)
10127 else if (*arg
!= '*')
10129 char *argptr
= arg
;
10132 /* Look for a ':'. If this is a line number specification, then
10133 say it is bad, otherwise, it should be an address or
10134 function/method name. */
10135 while (*argptr
&& !hasColon
)
10137 hasColon
= (*argptr
== ':');
10142 badInput
= (*argptr
!= ':'); /* Not a class::method */
10144 badInput
= isdigit (*arg
); /* a simple line number */
10148 printf_filtered (_("Usage: stop in <function | address>\n"));
10150 break_command_1 (arg
, 0, from_tty
);
10154 stopat_command (char *arg
, int from_tty
)
10158 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10162 char *argptr
= arg
;
10165 /* Look for a ':'. If there is a '::' then get out, otherwise
10166 it is probably a line number. */
10167 while (*argptr
&& !hasColon
)
10169 hasColon
= (*argptr
== ':');
10174 badInput
= (*argptr
== ':'); /* we have class::method */
10176 badInput
= !isdigit (*arg
); /* not a line number */
10180 printf_filtered (_("Usage: stop at <line>\n"));
10182 break_command_1 (arg
, 0, from_tty
);
10185 /* The dynamic printf command is mostly like a regular breakpoint, but
10186 with a prewired command list consisting of a single output command,
10187 built from extra arguments supplied on the dprintf command
10191 dprintf_command (char *arg
, int from_tty
)
10193 struct event_location
*location
;
10194 struct cleanup
*cleanup
;
10196 location
= string_to_event_location (&arg
, current_language
);
10197 cleanup
= make_cleanup_delete_event_location (location
);
10199 /* If non-NULL, ARG should have been advanced past the location;
10200 the next character must be ','. */
10203 if (arg
[0] != ',' || arg
[1] == '\0')
10204 error (_("Format string required"));
10207 /* Skip the comma. */
10212 create_breakpoint (get_current_arch (),
10214 NULL
, 0, arg
, 1 /* parse arg */,
10216 0 /* Ignore count */,
10217 pending_break_support
,
10218 &dprintf_breakpoint_ops
,
10223 do_cleanups (cleanup
);
10227 agent_printf_command (char *arg
, int from_tty
)
10229 error (_("May only run agent-printf on the target"));
10232 /* Implement the "breakpoint_hit" breakpoint_ops method for
10233 ranged breakpoints. */
10236 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10237 struct address_space
*aspace
,
10239 const struct target_waitstatus
*ws
)
10241 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10242 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10245 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10246 bl
->length
, aspace
, bp_addr
);
10249 /* Implement the "resources_needed" breakpoint_ops method for
10250 ranged breakpoints. */
10253 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10255 return target_ranged_break_num_registers ();
10258 /* Implement the "print_it" breakpoint_ops method for
10259 ranged breakpoints. */
10261 static enum print_stop_action
10262 print_it_ranged_breakpoint (bpstat bs
)
10264 struct breakpoint
*b
= bs
->breakpoint_at
;
10265 struct bp_location
*bl
= b
->loc
;
10266 struct ui_out
*uiout
= current_uiout
;
10268 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10270 /* Ranged breakpoints have only one location. */
10271 gdb_assert (bl
&& bl
->next
== NULL
);
10273 annotate_breakpoint (b
->number
);
10275 maybe_print_thread_hit_breakpoint (uiout
);
10277 if (b
->disposition
== disp_del
)
10278 ui_out_text (uiout
, "Temporary ranged breakpoint ");
10280 ui_out_text (uiout
, "Ranged breakpoint ");
10281 if (ui_out_is_mi_like_p (uiout
))
10283 ui_out_field_string (uiout
, "reason",
10284 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10285 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10287 ui_out_field_int (uiout
, "bkptno", b
->number
);
10288 ui_out_text (uiout
, ", ");
10290 return PRINT_SRC_AND_LOC
;
10293 /* Implement the "print_one" breakpoint_ops method for
10294 ranged breakpoints. */
10297 print_one_ranged_breakpoint (struct breakpoint
*b
,
10298 struct bp_location
**last_loc
)
10300 struct bp_location
*bl
= b
->loc
;
10301 struct value_print_options opts
;
10302 struct ui_out
*uiout
= current_uiout
;
10304 /* Ranged breakpoints have only one location. */
10305 gdb_assert (bl
&& bl
->next
== NULL
);
10307 get_user_print_options (&opts
);
10309 if (opts
.addressprint
)
10310 /* We don't print the address range here, it will be printed later
10311 by print_one_detail_ranged_breakpoint. */
10312 ui_out_field_skip (uiout
, "addr");
10313 annotate_field (5);
10314 print_breakpoint_location (b
, bl
);
10318 /* Implement the "print_one_detail" breakpoint_ops method for
10319 ranged breakpoints. */
10322 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10323 struct ui_out
*uiout
)
10325 CORE_ADDR address_start
, address_end
;
10326 struct bp_location
*bl
= b
->loc
;
10327 struct ui_file
*stb
= mem_fileopen ();
10328 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10332 address_start
= bl
->address
;
10333 address_end
= address_start
+ bl
->length
- 1;
10335 ui_out_text (uiout
, "\taddress range: ");
10336 fprintf_unfiltered (stb
, "[%s, %s]",
10337 print_core_address (bl
->gdbarch
, address_start
),
10338 print_core_address (bl
->gdbarch
, address_end
));
10339 ui_out_field_stream (uiout
, "addr", stb
);
10340 ui_out_text (uiout
, "\n");
10342 do_cleanups (cleanup
);
10345 /* Implement the "print_mention" breakpoint_ops method for
10346 ranged breakpoints. */
10349 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10351 struct bp_location
*bl
= b
->loc
;
10352 struct ui_out
*uiout
= current_uiout
;
10355 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10357 if (ui_out_is_mi_like_p (uiout
))
10360 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10361 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10362 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10365 /* Implement the "print_recreate" breakpoint_ops method for
10366 ranged breakpoints. */
10369 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10371 fprintf_unfiltered (fp
, "break-range %s, %s",
10372 event_location_to_string (b
->location
),
10373 event_location_to_string (b
->location_range_end
));
10374 print_recreate_thread (b
, fp
);
10377 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10379 static struct breakpoint_ops ranged_breakpoint_ops
;
10381 /* Find the address where the end of the breakpoint range should be
10382 placed, given the SAL of the end of the range. This is so that if
10383 the user provides a line number, the end of the range is set to the
10384 last instruction of the given line. */
10387 find_breakpoint_range_end (struct symtab_and_line sal
)
10391 /* If the user provided a PC value, use it. Otherwise,
10392 find the address of the end of the given location. */
10393 if (sal
.explicit_pc
)
10400 ret
= find_line_pc_range (sal
, &start
, &end
);
10402 error (_("Could not find location of the end of the range."));
10404 /* find_line_pc_range returns the start of the next line. */
10411 /* Implement the "break-range" CLI command. */
10414 break_range_command (char *arg
, int from_tty
)
10416 char *arg_start
, *addr_string_start
;
10417 struct linespec_result canonical_start
, canonical_end
;
10418 int bp_count
, can_use_bp
, length
;
10420 struct breakpoint
*b
;
10421 struct symtab_and_line sal_start
, sal_end
;
10422 struct cleanup
*cleanup_bkpt
;
10423 struct linespec_sals
*lsal_start
, *lsal_end
;
10424 struct event_location
*start_location
, *end_location
;
10426 /* We don't support software ranged breakpoints. */
10427 if (target_ranged_break_num_registers () < 0)
10428 error (_("This target does not support hardware ranged breakpoints."));
10430 bp_count
= hw_breakpoint_used_count ();
10431 bp_count
+= target_ranged_break_num_registers ();
10432 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10434 if (can_use_bp
< 0)
10435 error (_("Hardware breakpoints used exceeds limit."));
10437 arg
= skip_spaces (arg
);
10438 if (arg
== NULL
|| arg
[0] == '\0')
10439 error(_("No address range specified."));
10441 init_linespec_result (&canonical_start
);
10444 start_location
= string_to_event_location (&arg
, current_language
);
10445 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10446 parse_breakpoint_sals (start_location
, &canonical_start
);
10447 make_cleanup_destroy_linespec_result (&canonical_start
);
10450 error (_("Too few arguments."));
10451 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10452 error (_("Could not find location of the beginning of the range."));
10454 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10456 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10457 || lsal_start
->sals
.nelts
!= 1)
10458 error (_("Cannot create a ranged breakpoint with multiple locations."));
10460 sal_start
= lsal_start
->sals
.sals
[0];
10461 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10462 make_cleanup (xfree
, addr_string_start
);
10464 arg
++; /* Skip the comma. */
10465 arg
= skip_spaces (arg
);
10467 /* Parse the end location. */
10469 init_linespec_result (&canonical_end
);
10472 /* We call decode_line_full directly here instead of using
10473 parse_breakpoint_sals because we need to specify the start location's
10474 symtab and line as the default symtab and line for the end of the
10475 range. This makes it possible to have ranges like "foo.c:27, +14",
10476 where +14 means 14 lines from the start location. */
10477 end_location
= string_to_event_location (&arg
, current_language
);
10478 make_cleanup_delete_event_location (end_location
);
10479 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
10480 sal_start
.symtab
, sal_start
.line
,
10481 &canonical_end
, NULL
, NULL
);
10483 make_cleanup_destroy_linespec_result (&canonical_end
);
10485 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10486 error (_("Could not find location of the end of the range."));
10488 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10489 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10490 || lsal_end
->sals
.nelts
!= 1)
10491 error (_("Cannot create a ranged breakpoint with multiple locations."));
10493 sal_end
= lsal_end
->sals
.sals
[0];
10495 end
= find_breakpoint_range_end (sal_end
);
10496 if (sal_start
.pc
> end
)
10497 error (_("Invalid address range, end precedes start."));
10499 length
= end
- sal_start
.pc
+ 1;
10501 /* Length overflowed. */
10502 error (_("Address range too large."));
10503 else if (length
== 1)
10505 /* This range is simple enough to be handled by
10506 the `hbreak' command. */
10507 hbreak_command (addr_string_start
, 1);
10509 do_cleanups (cleanup_bkpt
);
10514 /* Now set up the breakpoint. */
10515 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10516 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10517 set_breakpoint_count (breakpoint_count
+ 1);
10518 b
->number
= breakpoint_count
;
10519 b
->disposition
= disp_donttouch
;
10520 b
->location
= copy_event_location (start_location
);
10521 b
->location_range_end
= copy_event_location (end_location
);
10522 b
->loc
->length
= length
;
10524 do_cleanups (cleanup_bkpt
);
10527 observer_notify_breakpoint_created (b
);
10528 update_global_location_list (UGLL_MAY_INSERT
);
10531 /* Return non-zero if EXP is verified as constant. Returned zero
10532 means EXP is variable. Also the constant detection may fail for
10533 some constant expressions and in such case still falsely return
10537 watchpoint_exp_is_const (const struct expression
*exp
)
10539 int i
= exp
->nelts
;
10545 /* We are only interested in the descriptor of each element. */
10546 operator_length (exp
, i
, &oplenp
, &argsp
);
10549 switch (exp
->elts
[i
].opcode
)
10559 case BINOP_LOGICAL_AND
:
10560 case BINOP_LOGICAL_OR
:
10561 case BINOP_BITWISE_AND
:
10562 case BINOP_BITWISE_IOR
:
10563 case BINOP_BITWISE_XOR
:
10565 case BINOP_NOTEQUAL
:
10592 case OP_OBJC_NSSTRING
:
10595 case UNOP_LOGICAL_NOT
:
10596 case UNOP_COMPLEMENT
:
10601 case UNOP_CAST_TYPE
:
10602 case UNOP_REINTERPRET_CAST
:
10603 case UNOP_DYNAMIC_CAST
:
10604 /* Unary, binary and ternary operators: We have to check
10605 their operands. If they are constant, then so is the
10606 result of that operation. For instance, if A and B are
10607 determined to be constants, then so is "A + B".
10609 UNOP_IND is one exception to the rule above, because the
10610 value of *ADDR is not necessarily a constant, even when
10615 /* Check whether the associated symbol is a constant.
10617 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10618 possible that a buggy compiler could mark a variable as
10619 constant even when it is not, and TYPE_CONST would return
10620 true in this case, while SYMBOL_CLASS wouldn't.
10622 We also have to check for function symbols because they
10623 are always constant. */
10625 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10627 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10628 && SYMBOL_CLASS (s
) != LOC_CONST
10629 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10634 /* The default action is to return 0 because we are using
10635 the optimistic approach here: If we don't know something,
10636 then it is not a constant. */
10645 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10648 dtor_watchpoint (struct breakpoint
*self
)
10650 struct watchpoint
*w
= (struct watchpoint
*) self
;
10652 xfree (w
->exp_string
);
10653 xfree (w
->exp_string_reparse
);
10654 value_free (w
->val
);
10656 base_breakpoint_ops
.dtor (self
);
10659 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10662 re_set_watchpoint (struct breakpoint
*b
)
10664 struct watchpoint
*w
= (struct watchpoint
*) b
;
10666 /* Watchpoint can be either on expression using entirely global
10667 variables, or it can be on local variables.
10669 Watchpoints of the first kind are never auto-deleted, and even
10670 persist across program restarts. Since they can use variables
10671 from shared libraries, we need to reparse expression as libraries
10672 are loaded and unloaded.
10674 Watchpoints on local variables can also change meaning as result
10675 of solib event. For example, if a watchpoint uses both a local
10676 and a global variables in expression, it's a local watchpoint,
10677 but unloading of a shared library will make the expression
10678 invalid. This is not a very common use case, but we still
10679 re-evaluate expression, to avoid surprises to the user.
10681 Note that for local watchpoints, we re-evaluate it only if
10682 watchpoints frame id is still valid. If it's not, it means the
10683 watchpoint is out of scope and will be deleted soon. In fact,
10684 I'm not sure we'll ever be called in this case.
10686 If a local watchpoint's frame id is still valid, then
10687 w->exp_valid_block is likewise valid, and we can safely use it.
10689 Don't do anything about disabled watchpoints, since they will be
10690 reevaluated again when enabled. */
10691 update_watchpoint (w
, 1 /* reparse */);
10694 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10697 insert_watchpoint (struct bp_location
*bl
)
10699 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10700 int length
= w
->exact
? 1 : bl
->length
;
10702 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10703 w
->cond_exp
.get ());
10706 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10709 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10711 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10712 int length
= w
->exact
? 1 : bl
->length
;
10714 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10715 w
->cond_exp
.get ());
10719 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10720 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10721 const struct target_waitstatus
*ws
)
10723 struct breakpoint
*b
= bl
->owner
;
10724 struct watchpoint
*w
= (struct watchpoint
*) b
;
10726 /* Continuable hardware watchpoints are treated as non-existent if the
10727 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10728 some data address). Otherwise gdb won't stop on a break instruction
10729 in the code (not from a breakpoint) when a hardware watchpoint has
10730 been defined. Also skip watchpoints which we know did not trigger
10731 (did not match the data address). */
10732 if (is_hardware_watchpoint (b
)
10733 && w
->watchpoint_triggered
== watch_triggered_no
)
10740 check_status_watchpoint (bpstat bs
)
10742 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10744 bpstat_check_watchpoint (bs
);
10747 /* Implement the "resources_needed" breakpoint_ops method for
10748 hardware watchpoints. */
10751 resources_needed_watchpoint (const struct bp_location
*bl
)
10753 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10754 int length
= w
->exact
? 1 : bl
->length
;
10756 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10759 /* Implement the "works_in_software_mode" breakpoint_ops method for
10760 hardware watchpoints. */
10763 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10765 /* Read and access watchpoints only work with hardware support. */
10766 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10769 static enum print_stop_action
10770 print_it_watchpoint (bpstat bs
)
10772 struct cleanup
*old_chain
;
10773 struct breakpoint
*b
;
10774 struct ui_file
*stb
;
10775 enum print_stop_action result
;
10776 struct watchpoint
*w
;
10777 struct ui_out
*uiout
= current_uiout
;
10779 gdb_assert (bs
->bp_location_at
!= NULL
);
10781 b
= bs
->breakpoint_at
;
10782 w
= (struct watchpoint
*) b
;
10784 stb
= mem_fileopen ();
10785 old_chain
= make_cleanup_ui_file_delete (stb
);
10787 annotate_watchpoint (b
->number
);
10788 maybe_print_thread_hit_breakpoint (uiout
);
10792 case bp_watchpoint
:
10793 case bp_hardware_watchpoint
:
10794 if (ui_out_is_mi_like_p (uiout
))
10795 ui_out_field_string
10797 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10799 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10800 ui_out_text (uiout
, "\nOld value = ");
10801 watchpoint_value_print (bs
->old_val
, stb
);
10802 ui_out_field_stream (uiout
, "old", stb
);
10803 ui_out_text (uiout
, "\nNew value = ");
10804 watchpoint_value_print (w
->val
, stb
);
10805 ui_out_field_stream (uiout
, "new", stb
);
10806 ui_out_text (uiout
, "\n");
10807 /* More than one watchpoint may have been triggered. */
10808 result
= PRINT_UNKNOWN
;
10811 case bp_read_watchpoint
:
10812 if (ui_out_is_mi_like_p (uiout
))
10813 ui_out_field_string
10815 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10817 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10818 ui_out_text (uiout
, "\nValue = ");
10819 watchpoint_value_print (w
->val
, stb
);
10820 ui_out_field_stream (uiout
, "value", stb
);
10821 ui_out_text (uiout
, "\n");
10822 result
= PRINT_UNKNOWN
;
10825 case bp_access_watchpoint
:
10826 if (bs
->old_val
!= NULL
)
10828 if (ui_out_is_mi_like_p (uiout
))
10829 ui_out_field_string
10831 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10833 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10834 ui_out_text (uiout
, "\nOld value = ");
10835 watchpoint_value_print (bs
->old_val
, stb
);
10836 ui_out_field_stream (uiout
, "old", stb
);
10837 ui_out_text (uiout
, "\nNew value = ");
10842 if (ui_out_is_mi_like_p (uiout
))
10843 ui_out_field_string
10845 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10846 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10847 ui_out_text (uiout
, "\nValue = ");
10849 watchpoint_value_print (w
->val
, stb
);
10850 ui_out_field_stream (uiout
, "new", stb
);
10851 ui_out_text (uiout
, "\n");
10852 result
= PRINT_UNKNOWN
;
10855 result
= PRINT_UNKNOWN
;
10858 do_cleanups (old_chain
);
10862 /* Implement the "print_mention" breakpoint_ops method for hardware
10866 print_mention_watchpoint (struct breakpoint
*b
)
10868 struct cleanup
*ui_out_chain
;
10869 struct watchpoint
*w
= (struct watchpoint
*) b
;
10870 struct ui_out
*uiout
= current_uiout
;
10874 case bp_watchpoint
:
10875 ui_out_text (uiout
, "Watchpoint ");
10876 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10878 case bp_hardware_watchpoint
:
10879 ui_out_text (uiout
, "Hardware watchpoint ");
10880 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10882 case bp_read_watchpoint
:
10883 ui_out_text (uiout
, "Hardware read watchpoint ");
10884 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10886 case bp_access_watchpoint
:
10887 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10888 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10891 internal_error (__FILE__
, __LINE__
,
10892 _("Invalid hardware watchpoint type."));
10895 ui_out_field_int (uiout
, "number", b
->number
);
10896 ui_out_text (uiout
, ": ");
10897 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10898 do_cleanups (ui_out_chain
);
10901 /* Implement the "print_recreate" breakpoint_ops method for
10905 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10907 struct watchpoint
*w
= (struct watchpoint
*) b
;
10911 case bp_watchpoint
:
10912 case bp_hardware_watchpoint
:
10913 fprintf_unfiltered (fp
, "watch");
10915 case bp_read_watchpoint
:
10916 fprintf_unfiltered (fp
, "rwatch");
10918 case bp_access_watchpoint
:
10919 fprintf_unfiltered (fp
, "awatch");
10922 internal_error (__FILE__
, __LINE__
,
10923 _("Invalid watchpoint type."));
10926 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10927 print_recreate_thread (b
, fp
);
10930 /* Implement the "explains_signal" breakpoint_ops method for
10934 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10936 /* A software watchpoint cannot cause a signal other than
10937 GDB_SIGNAL_TRAP. */
10938 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10944 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10946 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10948 /* Implement the "insert" breakpoint_ops method for
10949 masked hardware watchpoints. */
10952 insert_masked_watchpoint (struct bp_location
*bl
)
10954 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10956 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10957 bl
->watchpoint_type
);
10960 /* Implement the "remove" breakpoint_ops method for
10961 masked hardware watchpoints. */
10964 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10966 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10968 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10969 bl
->watchpoint_type
);
10972 /* Implement the "resources_needed" breakpoint_ops method for
10973 masked hardware watchpoints. */
10976 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10978 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10980 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10983 /* Implement the "works_in_software_mode" breakpoint_ops method for
10984 masked hardware watchpoints. */
10987 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10992 /* Implement the "print_it" breakpoint_ops method for
10993 masked hardware watchpoints. */
10995 static enum print_stop_action
10996 print_it_masked_watchpoint (bpstat bs
)
10998 struct breakpoint
*b
= bs
->breakpoint_at
;
10999 struct ui_out
*uiout
= current_uiout
;
11001 /* Masked watchpoints have only one location. */
11002 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11004 annotate_watchpoint (b
->number
);
11005 maybe_print_thread_hit_breakpoint (uiout
);
11009 case bp_hardware_watchpoint
:
11010 if (ui_out_is_mi_like_p (uiout
))
11011 ui_out_field_string
11013 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11016 case bp_read_watchpoint
:
11017 if (ui_out_is_mi_like_p (uiout
))
11018 ui_out_field_string
11020 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11023 case bp_access_watchpoint
:
11024 if (ui_out_is_mi_like_p (uiout
))
11025 ui_out_field_string
11027 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11030 internal_error (__FILE__
, __LINE__
,
11031 _("Invalid hardware watchpoint type."));
11035 ui_out_text (uiout
, _("\n\
11036 Check the underlying instruction at PC for the memory\n\
11037 address and value which triggered this watchpoint.\n"));
11038 ui_out_text (uiout
, "\n");
11040 /* More than one watchpoint may have been triggered. */
11041 return PRINT_UNKNOWN
;
11044 /* Implement the "print_one_detail" breakpoint_ops method for
11045 masked hardware watchpoints. */
11048 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11049 struct ui_out
*uiout
)
11051 struct watchpoint
*w
= (struct watchpoint
*) b
;
11053 /* Masked watchpoints have only one location. */
11054 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11056 ui_out_text (uiout
, "\tmask ");
11057 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11058 ui_out_text (uiout
, "\n");
11061 /* Implement the "print_mention" breakpoint_ops method for
11062 masked hardware watchpoints. */
11065 print_mention_masked_watchpoint (struct breakpoint
*b
)
11067 struct watchpoint
*w
= (struct watchpoint
*) b
;
11068 struct ui_out
*uiout
= current_uiout
;
11069 struct cleanup
*ui_out_chain
;
11073 case bp_hardware_watchpoint
:
11074 ui_out_text (uiout
, "Masked hardware watchpoint ");
11075 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11077 case bp_read_watchpoint
:
11078 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11079 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11081 case bp_access_watchpoint
:
11082 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11083 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11086 internal_error (__FILE__
, __LINE__
,
11087 _("Invalid hardware watchpoint type."));
11090 ui_out_field_int (uiout
, "number", b
->number
);
11091 ui_out_text (uiout
, ": ");
11092 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11093 do_cleanups (ui_out_chain
);
11096 /* Implement the "print_recreate" breakpoint_ops method for
11097 masked hardware watchpoints. */
11100 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11102 struct watchpoint
*w
= (struct watchpoint
*) b
;
11107 case bp_hardware_watchpoint
:
11108 fprintf_unfiltered (fp
, "watch");
11110 case bp_read_watchpoint
:
11111 fprintf_unfiltered (fp
, "rwatch");
11113 case bp_access_watchpoint
:
11114 fprintf_unfiltered (fp
, "awatch");
11117 internal_error (__FILE__
, __LINE__
,
11118 _("Invalid hardware watchpoint type."));
11121 sprintf_vma (tmp
, w
->hw_wp_mask
);
11122 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11123 print_recreate_thread (b
, fp
);
11126 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11128 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11130 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11133 is_masked_watchpoint (const struct breakpoint
*b
)
11135 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11138 /* accessflag: hw_write: watch write,
11139 hw_read: watch read,
11140 hw_access: watch access (read or write) */
11142 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11143 int just_location
, int internal
)
11145 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11146 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11147 struct value
*val
, *mark
, *result
;
11148 int saved_bitpos
= 0, saved_bitsize
= 0;
11149 struct frame_info
*frame
;
11150 const char *exp_start
= NULL
;
11151 const char *exp_end
= NULL
;
11152 const char *tok
, *end_tok
;
11154 const char *cond_start
= NULL
;
11155 const char *cond_end
= NULL
;
11156 enum bptype bp_type
;
11159 /* Flag to indicate whether we are going to use masks for
11160 the hardware watchpoint. */
11162 CORE_ADDR mask
= 0;
11163 struct watchpoint
*w
;
11165 struct cleanup
*back_to
;
11167 /* Make sure that we actually have parameters to parse. */
11168 if (arg
!= NULL
&& arg
[0] != '\0')
11170 const char *value_start
;
11172 exp_end
= arg
+ strlen (arg
);
11174 /* Look for "parameter value" pairs at the end
11175 of the arguments string. */
11176 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11178 /* Skip whitespace at the end of the argument list. */
11179 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11182 /* Find the beginning of the last token.
11183 This is the value of the parameter. */
11184 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11186 value_start
= tok
+ 1;
11188 /* Skip whitespace. */
11189 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11194 /* Find the beginning of the second to last token.
11195 This is the parameter itself. */
11196 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11199 toklen
= end_tok
- tok
+ 1;
11201 if (toklen
== 6 && startswith (tok
, "thread"))
11203 struct thread_info
*thr
;
11204 /* At this point we've found a "thread" token, which means
11205 the user is trying to set a watchpoint that triggers
11206 only in a specific thread. */
11210 error(_("You can specify only one thread."));
11212 /* Extract the thread ID from the next token. */
11213 thr
= parse_thread_id (value_start
, &endp
);
11215 /* Check if the user provided a valid thread ID. */
11216 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11217 invalid_thread_id_error (value_start
);
11219 thread
= thr
->global_num
;
11221 else if (toklen
== 4 && startswith (tok
, "mask"))
11223 /* We've found a "mask" token, which means the user wants to
11224 create a hardware watchpoint that is going to have the mask
11226 struct value
*mask_value
, *mark
;
11229 error(_("You can specify only one mask."));
11231 use_mask
= just_location
= 1;
11233 mark
= value_mark ();
11234 mask_value
= parse_to_comma_and_eval (&value_start
);
11235 mask
= value_as_address (mask_value
);
11236 value_free_to_mark (mark
);
11239 /* We didn't recognize what we found. We should stop here. */
11242 /* Truncate the string and get rid of the "parameter value" pair before
11243 the arguments string is parsed by the parse_exp_1 function. */
11250 /* Parse the rest of the arguments. From here on out, everything
11251 is in terms of a newly allocated string instead of the original
11253 innermost_block
= NULL
;
11254 expression
= savestring (arg
, exp_end
- arg
);
11255 back_to
= make_cleanup (xfree
, expression
);
11256 exp_start
= arg
= expression
;
11257 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11259 /* Remove trailing whitespace from the expression before saving it.
11260 This makes the eventual display of the expression string a bit
11262 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11265 /* Checking if the expression is not constant. */
11266 if (watchpoint_exp_is_const (exp
.get ()))
11270 len
= exp_end
- exp_start
;
11271 while (len
> 0 && isspace (exp_start
[len
- 1]))
11273 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11276 exp_valid_block
= innermost_block
;
11277 mark
= value_mark ();
11278 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11280 if (val
!= NULL
&& just_location
)
11282 saved_bitpos
= value_bitpos (val
);
11283 saved_bitsize
= value_bitsize (val
);
11290 exp_valid_block
= NULL
;
11291 val
= value_addr (result
);
11292 release_value (val
);
11293 value_free_to_mark (mark
);
11297 ret
= target_masked_watch_num_registers (value_as_address (val
),
11300 error (_("This target does not support masked watchpoints."));
11301 else if (ret
== -2)
11302 error (_("Invalid mask or memory region."));
11305 else if (val
!= NULL
)
11306 release_value (val
);
11308 tok
= skip_spaces_const (arg
);
11309 end_tok
= skip_to_space_const (tok
);
11311 toklen
= end_tok
- tok
;
11312 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11314 innermost_block
= NULL
;
11315 tok
= cond_start
= end_tok
+ 1;
11316 parse_exp_1 (&tok
, 0, 0, 0);
11318 /* The watchpoint expression may not be local, but the condition
11319 may still be. E.g.: `watch global if local > 0'. */
11320 cond_exp_valid_block
= innermost_block
;
11325 error (_("Junk at end of command."));
11327 frame
= block_innermost_frame (exp_valid_block
);
11329 /* If the expression is "local", then set up a "watchpoint scope"
11330 breakpoint at the point where we've left the scope of the watchpoint
11331 expression. Create the scope breakpoint before the watchpoint, so
11332 that we will encounter it first in bpstat_stop_status. */
11333 if (exp_valid_block
&& frame
)
11335 if (frame_id_p (frame_unwind_caller_id (frame
)))
11338 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11339 frame_unwind_caller_pc (frame
),
11340 bp_watchpoint_scope
,
11341 &momentary_breakpoint_ops
);
11343 scope_breakpoint
->enable_state
= bp_enabled
;
11345 /* Automatically delete the breakpoint when it hits. */
11346 scope_breakpoint
->disposition
= disp_del
;
11348 /* Only break in the proper frame (help with recursion). */
11349 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11351 /* Set the address at which we will stop. */
11352 scope_breakpoint
->loc
->gdbarch
11353 = frame_unwind_caller_arch (frame
);
11354 scope_breakpoint
->loc
->requested_address
11355 = frame_unwind_caller_pc (frame
);
11356 scope_breakpoint
->loc
->address
11357 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11358 scope_breakpoint
->loc
->requested_address
,
11359 scope_breakpoint
->type
);
11363 /* Now set up the breakpoint. We create all watchpoints as hardware
11364 watchpoints here even if hardware watchpoints are turned off, a call
11365 to update_watchpoint later in this function will cause the type to
11366 drop back to bp_watchpoint (software watchpoint) if required. */
11368 if (accessflag
== hw_read
)
11369 bp_type
= bp_read_watchpoint
;
11370 else if (accessflag
== hw_access
)
11371 bp_type
= bp_access_watchpoint
;
11373 bp_type
= bp_hardware_watchpoint
;
11375 w
= new watchpoint ();
11378 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11379 &masked_watchpoint_breakpoint_ops
);
11381 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11382 &watchpoint_breakpoint_ops
);
11383 b
->thread
= thread
;
11384 b
->disposition
= disp_donttouch
;
11385 b
->pspace
= current_program_space
;
11386 w
->exp
= gdb::move (exp
);
11387 w
->exp_valid_block
= exp_valid_block
;
11388 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11391 struct type
*t
= value_type (val
);
11392 CORE_ADDR addr
= value_as_address (val
);
11395 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11396 name
= type_to_string (t
);
11398 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11399 core_addr_to_string (addr
));
11402 w
->exp_string
= xstrprintf ("-location %.*s",
11403 (int) (exp_end
- exp_start
), exp_start
);
11405 /* The above expression is in C. */
11406 b
->language
= language_c
;
11409 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11413 w
->hw_wp_mask
= mask
;
11418 w
->val_bitpos
= saved_bitpos
;
11419 w
->val_bitsize
= saved_bitsize
;
11424 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11426 b
->cond_string
= 0;
11430 w
->watchpoint_frame
= get_frame_id (frame
);
11431 w
->watchpoint_thread
= inferior_ptid
;
11435 w
->watchpoint_frame
= null_frame_id
;
11436 w
->watchpoint_thread
= null_ptid
;
11439 if (scope_breakpoint
!= NULL
)
11441 /* The scope breakpoint is related to the watchpoint. We will
11442 need to act on them together. */
11443 b
->related_breakpoint
= scope_breakpoint
;
11444 scope_breakpoint
->related_breakpoint
= b
;
11447 if (!just_location
)
11448 value_free_to_mark (mark
);
11452 /* Finally update the new watchpoint. This creates the locations
11453 that should be inserted. */
11454 update_watchpoint (w
, 1);
11456 CATCH (e
, RETURN_MASK_ALL
)
11458 delete_breakpoint (b
);
11459 throw_exception (e
);
11463 install_breakpoint (internal
, b
, 1);
11464 do_cleanups (back_to
);
11467 /* Return count of debug registers needed to watch the given expression.
11468 If the watchpoint cannot be handled in hardware return zero. */
11471 can_use_hardware_watchpoint (struct value
*v
)
11473 int found_memory_cnt
= 0;
11474 struct value
*head
= v
;
11476 /* Did the user specifically forbid us to use hardware watchpoints? */
11477 if (!can_use_hw_watchpoints
)
11480 /* Make sure that the value of the expression depends only upon
11481 memory contents, and values computed from them within GDB. If we
11482 find any register references or function calls, we can't use a
11483 hardware watchpoint.
11485 The idea here is that evaluating an expression generates a series
11486 of values, one holding the value of every subexpression. (The
11487 expression a*b+c has five subexpressions: a, b, a*b, c, and
11488 a*b+c.) GDB's values hold almost enough information to establish
11489 the criteria given above --- they identify memory lvalues,
11490 register lvalues, computed values, etcetera. So we can evaluate
11491 the expression, and then scan the chain of values that leaves
11492 behind to decide whether we can detect any possible change to the
11493 expression's final value using only hardware watchpoints.
11495 However, I don't think that the values returned by inferior
11496 function calls are special in any way. So this function may not
11497 notice that an expression involving an inferior function call
11498 can't be watched with hardware watchpoints. FIXME. */
11499 for (; v
; v
= value_next (v
))
11501 if (VALUE_LVAL (v
) == lval_memory
)
11503 if (v
!= head
&& value_lazy (v
))
11504 /* A lazy memory lvalue in the chain is one that GDB never
11505 needed to fetch; we either just used its address (e.g.,
11506 `a' in `a.b') or we never needed it at all (e.g., `a'
11507 in `a,b'). This doesn't apply to HEAD; if that is
11508 lazy then it was not readable, but watch it anyway. */
11512 /* Ahh, memory we actually used! Check if we can cover
11513 it with hardware watchpoints. */
11514 struct type
*vtype
= check_typedef (value_type (v
));
11516 /* We only watch structs and arrays if user asked for it
11517 explicitly, never if they just happen to appear in a
11518 middle of some value chain. */
11520 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11521 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11523 CORE_ADDR vaddr
= value_address (v
);
11527 len
= (target_exact_watchpoints
11528 && is_scalar_type_recursive (vtype
))?
11529 1 : TYPE_LENGTH (value_type (v
));
11531 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11535 found_memory_cnt
+= num_regs
;
11539 else if (VALUE_LVAL (v
) != not_lval
11540 && deprecated_value_modifiable (v
) == 0)
11541 return 0; /* These are values from the history (e.g., $1). */
11542 else if (VALUE_LVAL (v
) == lval_register
)
11543 return 0; /* Cannot watch a register with a HW watchpoint. */
11546 /* The expression itself looks suitable for using a hardware
11547 watchpoint, but give the target machine a chance to reject it. */
11548 return found_memory_cnt
;
11552 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11554 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11557 /* A helper function that looks for the "-location" argument and then
11558 calls watch_command_1. */
11561 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11563 int just_location
= 0;
11566 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11567 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11569 arg
= skip_spaces (arg
);
11573 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11577 watch_command (char *arg
, int from_tty
)
11579 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11583 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11585 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11589 rwatch_command (char *arg
, int from_tty
)
11591 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11595 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11597 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11601 awatch_command (char *arg
, int from_tty
)
11603 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11607 /* Data for the FSM that manages the until(location)/advance commands
11608 in infcmd.c. Here because it uses the mechanisms of
11611 struct until_break_fsm
11613 /* The base class. */
11614 struct thread_fsm thread_fsm
;
11616 /* The thread that as current when the command was executed. */
11619 /* The breakpoint set at the destination location. */
11620 struct breakpoint
*location_breakpoint
;
11622 /* Breakpoint set at the return address in the caller frame. May be
11624 struct breakpoint
*caller_breakpoint
;
11627 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11628 struct thread_info
*thread
);
11629 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11630 struct thread_info
*thread
);
11631 static enum async_reply_reason
11632 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11634 /* until_break_fsm's vtable. */
11636 static struct thread_fsm_ops until_break_fsm_ops
=
11639 until_break_fsm_clean_up
,
11640 until_break_fsm_should_stop
,
11641 NULL
, /* return_value */
11642 until_break_fsm_async_reply_reason
,
11645 /* Allocate a new until_break_command_fsm. */
11647 static struct until_break_fsm
*
11648 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11649 struct breakpoint
*location_breakpoint
,
11650 struct breakpoint
*caller_breakpoint
)
11652 struct until_break_fsm
*sm
;
11654 sm
= XCNEW (struct until_break_fsm
);
11655 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11657 sm
->thread
= thread
;
11658 sm
->location_breakpoint
= location_breakpoint
;
11659 sm
->caller_breakpoint
= caller_breakpoint
;
11664 /* Implementation of the 'should_stop' FSM method for the
11665 until(location)/advance commands. */
11668 until_break_fsm_should_stop (struct thread_fsm
*self
,
11669 struct thread_info
*tp
)
11671 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11673 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11674 sm
->location_breakpoint
) != NULL
11675 || (sm
->caller_breakpoint
!= NULL
11676 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11677 sm
->caller_breakpoint
) != NULL
))
11678 thread_fsm_set_finished (self
);
11683 /* Implementation of the 'clean_up' FSM method for the
11684 until(location)/advance commands. */
11687 until_break_fsm_clean_up (struct thread_fsm
*self
,
11688 struct thread_info
*thread
)
11690 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11692 /* Clean up our temporary breakpoints. */
11693 if (sm
->location_breakpoint
!= NULL
)
11695 delete_breakpoint (sm
->location_breakpoint
);
11696 sm
->location_breakpoint
= NULL
;
11698 if (sm
->caller_breakpoint
!= NULL
)
11700 delete_breakpoint (sm
->caller_breakpoint
);
11701 sm
->caller_breakpoint
= NULL
;
11703 delete_longjmp_breakpoint (sm
->thread
);
11706 /* Implementation of the 'async_reply_reason' FSM method for the
11707 until(location)/advance commands. */
11709 static enum async_reply_reason
11710 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11712 return EXEC_ASYNC_LOCATION_REACHED
;
11716 until_break_command (char *arg
, int from_tty
, int anywhere
)
11718 struct symtabs_and_lines sals
;
11719 struct symtab_and_line sal
;
11720 struct frame_info
*frame
;
11721 struct gdbarch
*frame_gdbarch
;
11722 struct frame_id stack_frame_id
;
11723 struct frame_id caller_frame_id
;
11724 struct breakpoint
*location_breakpoint
;
11725 struct breakpoint
*caller_breakpoint
= NULL
;
11726 struct cleanup
*old_chain
, *cleanup
;
11728 struct thread_info
*tp
;
11729 struct event_location
*location
;
11730 struct until_break_fsm
*sm
;
11732 clear_proceed_status (0);
11734 /* Set a breakpoint where the user wants it and at return from
11737 location
= string_to_event_location (&arg
, current_language
);
11738 cleanup
= make_cleanup_delete_event_location (location
);
11740 if (last_displayed_sal_is_valid ())
11741 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
11742 get_last_displayed_symtab (),
11743 get_last_displayed_line ());
11745 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11746 NULL
, (struct symtab
*) NULL
, 0);
11748 if (sals
.nelts
!= 1)
11749 error (_("Couldn't get information on specified line."));
11751 sal
= sals
.sals
[0];
11752 xfree (sals
.sals
); /* malloc'd, so freed. */
11755 error (_("Junk at end of arguments."));
11757 resolve_sal_pc (&sal
);
11759 tp
= inferior_thread ();
11760 thread
= tp
->global_num
;
11762 old_chain
= make_cleanup (null_cleanup
, NULL
);
11764 /* Note linespec handling above invalidates the frame chain.
11765 Installing a breakpoint also invalidates the frame chain (as it
11766 may need to switch threads), so do any frame handling before
11769 frame
= get_selected_frame (NULL
);
11770 frame_gdbarch
= get_frame_arch (frame
);
11771 stack_frame_id
= get_stack_frame_id (frame
);
11772 caller_frame_id
= frame_unwind_caller_id (frame
);
11774 /* Keep within the current frame, or in frames called by the current
11777 if (frame_id_p (caller_frame_id
))
11779 struct symtab_and_line sal2
;
11780 struct gdbarch
*caller_gdbarch
;
11782 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11783 sal2
.pc
= frame_unwind_caller_pc (frame
);
11784 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11785 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11789 make_cleanup_delete_breakpoint (caller_breakpoint
);
11791 set_longjmp_breakpoint (tp
, caller_frame_id
);
11792 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11795 /* set_momentary_breakpoint could invalidate FRAME. */
11799 /* If the user told us to continue until a specified location,
11800 we don't specify a frame at which we need to stop. */
11801 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11802 null_frame_id
, bp_until
);
11804 /* Otherwise, specify the selected frame, because we want to stop
11805 only at the very same frame. */
11806 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11807 stack_frame_id
, bp_until
);
11808 make_cleanup_delete_breakpoint (location_breakpoint
);
11810 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11811 location_breakpoint
, caller_breakpoint
);
11812 tp
->thread_fsm
= &sm
->thread_fsm
;
11814 discard_cleanups (old_chain
);
11816 proceed (-1, GDB_SIGNAL_DEFAULT
);
11818 do_cleanups (cleanup
);
11821 /* This function attempts to parse an optional "if <cond>" clause
11822 from the arg string. If one is not found, it returns NULL.
11824 Else, it returns a pointer to the condition string. (It does not
11825 attempt to evaluate the string against a particular block.) And,
11826 it updates arg to point to the first character following the parsed
11827 if clause in the arg string. */
11830 ep_parse_optional_if_clause (char **arg
)
11834 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11837 /* Skip the "if" keyword. */
11840 /* Skip any extra leading whitespace, and record the start of the
11841 condition string. */
11842 *arg
= skip_spaces (*arg
);
11843 cond_string
= *arg
;
11845 /* Assume that the condition occupies the remainder of the arg
11847 (*arg
) += strlen (cond_string
);
11849 return cond_string
;
11852 /* Commands to deal with catching events, such as signals, exceptions,
11853 process start/exit, etc. */
11857 catch_fork_temporary
, catch_vfork_temporary
,
11858 catch_fork_permanent
, catch_vfork_permanent
11863 catch_fork_command_1 (char *arg
, int from_tty
,
11864 struct cmd_list_element
*command
)
11866 struct gdbarch
*gdbarch
= get_current_arch ();
11867 char *cond_string
= NULL
;
11868 catch_fork_kind fork_kind
;
11871 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11872 tempflag
= (fork_kind
== catch_fork_temporary
11873 || fork_kind
== catch_vfork_temporary
);
11877 arg
= skip_spaces (arg
);
11879 /* The allowed syntax is:
11881 catch [v]fork if <cond>
11883 First, check if there's an if clause. */
11884 cond_string
= ep_parse_optional_if_clause (&arg
);
11886 if ((*arg
!= '\0') && !isspace (*arg
))
11887 error (_("Junk at end of arguments."));
11889 /* If this target supports it, create a fork or vfork catchpoint
11890 and enable reporting of such events. */
11893 case catch_fork_temporary
:
11894 case catch_fork_permanent
:
11895 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11896 &catch_fork_breakpoint_ops
);
11898 case catch_vfork_temporary
:
11899 case catch_vfork_permanent
:
11900 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11901 &catch_vfork_breakpoint_ops
);
11904 error (_("unsupported or unknown fork kind; cannot catch it"));
11910 catch_exec_command_1 (char *arg
, int from_tty
,
11911 struct cmd_list_element
*command
)
11913 struct exec_catchpoint
*c
;
11914 struct gdbarch
*gdbarch
= get_current_arch ();
11916 char *cond_string
= NULL
;
11918 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11922 arg
= skip_spaces (arg
);
11924 /* The allowed syntax is:
11926 catch exec if <cond>
11928 First, check if there's an if clause. */
11929 cond_string
= ep_parse_optional_if_clause (&arg
);
11931 if ((*arg
!= '\0') && !isspace (*arg
))
11932 error (_("Junk at end of arguments."));
11934 c
= new exec_catchpoint ();
11935 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11936 &catch_exec_breakpoint_ops
);
11937 c
->exec_pathname
= NULL
;
11939 install_breakpoint (0, &c
->base
, 1);
11943 init_ada_exception_breakpoint (struct breakpoint
*b
,
11944 struct gdbarch
*gdbarch
,
11945 struct symtab_and_line sal
,
11947 const struct breakpoint_ops
*ops
,
11954 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11956 loc_gdbarch
= gdbarch
;
11958 describe_other_breakpoints (loc_gdbarch
,
11959 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11960 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11961 version for exception catchpoints, because two catchpoints
11962 used for different exception names will use the same address.
11963 In this case, a "breakpoint ... also set at..." warning is
11964 unproductive. Besides, the warning phrasing is also a bit
11965 inappropriate, we should use the word catchpoint, and tell
11966 the user what type of catchpoint it is. The above is good
11967 enough for now, though. */
11970 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11972 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11973 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11974 b
->location
= string_to_event_location (&addr_string
,
11975 language_def (language_ada
));
11976 b
->language
= language_ada
;
11980 catch_command (char *arg
, int from_tty
)
11982 error (_("Catch requires an event name."));
11987 tcatch_command (char *arg
, int from_tty
)
11989 error (_("Catch requires an event name."));
11992 /* A qsort comparison function that sorts breakpoints in order. */
11995 compare_breakpoints (const void *a
, const void *b
)
11997 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11998 uintptr_t ua
= (uintptr_t) *ba
;
11999 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
12000 uintptr_t ub
= (uintptr_t) *bb
;
12002 if ((*ba
)->number
< (*bb
)->number
)
12004 else if ((*ba
)->number
> (*bb
)->number
)
12007 /* Now sort by address, in case we see, e..g, two breakpoints with
12011 return ua
> ub
? 1 : 0;
12014 /* Delete breakpoints by address or line. */
12017 clear_command (char *arg
, int from_tty
)
12019 struct breakpoint
*b
, *prev
;
12020 VEC(breakpoint_p
) *found
= 0;
12023 struct symtabs_and_lines sals
;
12024 struct symtab_and_line sal
;
12026 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12030 sals
= decode_line_with_current_source (arg
,
12031 (DECODE_LINE_FUNFIRSTLINE
12032 | DECODE_LINE_LIST_MODE
));
12033 make_cleanup (xfree
, sals
.sals
);
12038 sals
.sals
= XNEW (struct symtab_and_line
);
12039 make_cleanup (xfree
, sals
.sals
);
12040 init_sal (&sal
); /* Initialize to zeroes. */
12042 /* Set sal's line, symtab, pc, and pspace to the values
12043 corresponding to the last call to print_frame_info. If the
12044 codepoint is not valid, this will set all the fields to 0. */
12045 get_last_displayed_sal (&sal
);
12046 if (sal
.symtab
== 0)
12047 error (_("No source file specified."));
12049 sals
.sals
[0] = sal
;
12055 /* We don't call resolve_sal_pc here. That's not as bad as it
12056 seems, because all existing breakpoints typically have both
12057 file/line and pc set. So, if clear is given file/line, we can
12058 match this to existing breakpoint without obtaining pc at all.
12060 We only support clearing given the address explicitly
12061 present in breakpoint table. Say, we've set breakpoint
12062 at file:line. There were several PC values for that file:line,
12063 due to optimization, all in one block.
12065 We've picked one PC value. If "clear" is issued with another
12066 PC corresponding to the same file:line, the breakpoint won't
12067 be cleared. We probably can still clear the breakpoint, but
12068 since the other PC value is never presented to user, user
12069 can only find it by guessing, and it does not seem important
12070 to support that. */
12072 /* For each line spec given, delete bps which correspond to it. Do
12073 it in two passes, solely to preserve the current behavior that
12074 from_tty is forced true if we delete more than one
12078 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12079 for (i
= 0; i
< sals
.nelts
; i
++)
12081 const char *sal_fullname
;
12083 /* If exact pc given, clear bpts at that pc.
12084 If line given (pc == 0), clear all bpts on specified line.
12085 If defaulting, clear all bpts on default line
12088 defaulting sal.pc != 0 tests to do
12093 1 0 <can't happen> */
12095 sal
= sals
.sals
[i
];
12096 sal_fullname
= (sal
.symtab
== NULL
12097 ? NULL
: symtab_to_fullname (sal
.symtab
));
12099 /* Find all matching breakpoints and add them to 'found'. */
12100 ALL_BREAKPOINTS (b
)
12103 /* Are we going to delete b? */
12104 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12106 struct bp_location
*loc
= b
->loc
;
12107 for (; loc
; loc
= loc
->next
)
12109 /* If the user specified file:line, don't allow a PC
12110 match. This matches historical gdb behavior. */
12111 int pc_match
= (!sal
.explicit_line
12113 && (loc
->pspace
== sal
.pspace
)
12114 && (loc
->address
== sal
.pc
)
12115 && (!section_is_overlay (loc
->section
)
12116 || loc
->section
== sal
.section
));
12117 int line_match
= 0;
12119 if ((default_match
|| sal
.explicit_line
)
12120 && loc
->symtab
!= NULL
12121 && sal_fullname
!= NULL
12122 && sal
.pspace
== loc
->pspace
12123 && loc
->line_number
== sal
.line
12124 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12125 sal_fullname
) == 0)
12128 if (pc_match
|| line_match
)
12137 VEC_safe_push(breakpoint_p
, found
, b
);
12141 /* Now go thru the 'found' chain and delete them. */
12142 if (VEC_empty(breakpoint_p
, found
))
12145 error (_("No breakpoint at %s."), arg
);
12147 error (_("No breakpoint at this line."));
12150 /* Remove duplicates from the vec. */
12151 qsort (VEC_address (breakpoint_p
, found
),
12152 VEC_length (breakpoint_p
, found
),
12153 sizeof (breakpoint_p
),
12154 compare_breakpoints
);
12155 prev
= VEC_index (breakpoint_p
, found
, 0);
12156 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12160 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12165 if (VEC_length(breakpoint_p
, found
) > 1)
12166 from_tty
= 1; /* Always report if deleted more than one. */
12169 if (VEC_length(breakpoint_p
, found
) == 1)
12170 printf_unfiltered (_("Deleted breakpoint "));
12172 printf_unfiltered (_("Deleted breakpoints "));
12175 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12178 printf_unfiltered ("%d ", b
->number
);
12179 delete_breakpoint (b
);
12182 putchar_unfiltered ('\n');
12184 do_cleanups (cleanups
);
12187 /* Delete breakpoint in BS if they are `delete' breakpoints and
12188 all breakpoints that are marked for deletion, whether hit or not.
12189 This is called after any breakpoint is hit, or after errors. */
12192 breakpoint_auto_delete (bpstat bs
)
12194 struct breakpoint
*b
, *b_tmp
;
12196 for (; bs
; bs
= bs
->next
)
12197 if (bs
->breakpoint_at
12198 && bs
->breakpoint_at
->disposition
== disp_del
12200 delete_breakpoint (bs
->breakpoint_at
);
12202 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12204 if (b
->disposition
== disp_del_at_next_stop
)
12205 delete_breakpoint (b
);
12209 /* A comparison function for bp_location AP and BP being interfaced to
12210 qsort. Sort elements primarily by their ADDRESS (no matter what
12211 does breakpoint_address_is_meaningful say for its OWNER),
12212 secondarily by ordering first permanent elements and
12213 terciarily just ensuring the array is sorted stable way despite
12214 qsort being an unstable algorithm. */
12217 bp_location_compare (const void *ap
, const void *bp
)
12219 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12220 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12222 if (a
->address
!= b
->address
)
12223 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12225 /* Sort locations at the same address by their pspace number, keeping
12226 locations of the same inferior (in a multi-inferior environment)
12229 if (a
->pspace
->num
!= b
->pspace
->num
)
12230 return ((a
->pspace
->num
> b
->pspace
->num
)
12231 - (a
->pspace
->num
< b
->pspace
->num
));
12233 /* Sort permanent breakpoints first. */
12234 if (a
->permanent
!= b
->permanent
)
12235 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12237 /* Make the internal GDB representation stable across GDB runs
12238 where A and B memory inside GDB can differ. Breakpoint locations of
12239 the same type at the same address can be sorted in arbitrary order. */
12241 if (a
->owner
->number
!= b
->owner
->number
)
12242 return ((a
->owner
->number
> b
->owner
->number
)
12243 - (a
->owner
->number
< b
->owner
->number
));
12245 return (a
> b
) - (a
< b
);
12248 /* Set bp_location_placed_address_before_address_max and
12249 bp_location_shadow_len_after_address_max according to the current
12250 content of the bp_location array. */
12253 bp_location_target_extensions_update (void)
12255 struct bp_location
*bl
, **blp_tmp
;
12257 bp_location_placed_address_before_address_max
= 0;
12258 bp_location_shadow_len_after_address_max
= 0;
12260 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12262 CORE_ADDR start
, end
, addr
;
12264 if (!bp_location_has_shadow (bl
))
12267 start
= bl
->target_info
.placed_address
;
12268 end
= start
+ bl
->target_info
.shadow_len
;
12270 gdb_assert (bl
->address
>= start
);
12271 addr
= bl
->address
- start
;
12272 if (addr
> bp_location_placed_address_before_address_max
)
12273 bp_location_placed_address_before_address_max
= addr
;
12275 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12277 gdb_assert (bl
->address
< end
);
12278 addr
= end
- bl
->address
;
12279 if (addr
> bp_location_shadow_len_after_address_max
)
12280 bp_location_shadow_len_after_address_max
= addr
;
12284 /* Download tracepoint locations if they haven't been. */
12287 download_tracepoint_locations (void)
12289 struct breakpoint
*b
;
12290 struct cleanup
*old_chain
;
12291 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12293 old_chain
= save_current_space_and_thread ();
12295 ALL_TRACEPOINTS (b
)
12297 struct bp_location
*bl
;
12298 struct tracepoint
*t
;
12299 int bp_location_downloaded
= 0;
12301 if ((b
->type
== bp_fast_tracepoint
12302 ? !may_insert_fast_tracepoints
12303 : !may_insert_tracepoints
))
12306 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12308 if (target_can_download_tracepoint ())
12309 can_download_tracepoint
= TRIBOOL_TRUE
;
12311 can_download_tracepoint
= TRIBOOL_FALSE
;
12314 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12317 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12319 /* In tracepoint, locations are _never_ duplicated, so
12320 should_be_inserted is equivalent to
12321 unduplicated_should_be_inserted. */
12322 if (!should_be_inserted (bl
) || bl
->inserted
)
12325 switch_to_program_space_and_thread (bl
->pspace
);
12327 target_download_tracepoint (bl
);
12330 bp_location_downloaded
= 1;
12332 t
= (struct tracepoint
*) b
;
12333 t
->number_on_target
= b
->number
;
12334 if (bp_location_downloaded
)
12335 observer_notify_breakpoint_modified (b
);
12338 do_cleanups (old_chain
);
12341 /* Swap the insertion/duplication state between two locations. */
12344 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12346 const int left_inserted
= left
->inserted
;
12347 const int left_duplicate
= left
->duplicate
;
12348 const int left_needs_update
= left
->needs_update
;
12349 const struct bp_target_info left_target_info
= left
->target_info
;
12351 /* Locations of tracepoints can never be duplicated. */
12352 if (is_tracepoint (left
->owner
))
12353 gdb_assert (!left
->duplicate
);
12354 if (is_tracepoint (right
->owner
))
12355 gdb_assert (!right
->duplicate
);
12357 left
->inserted
= right
->inserted
;
12358 left
->duplicate
= right
->duplicate
;
12359 left
->needs_update
= right
->needs_update
;
12360 left
->target_info
= right
->target_info
;
12361 right
->inserted
= left_inserted
;
12362 right
->duplicate
= left_duplicate
;
12363 right
->needs_update
= left_needs_update
;
12364 right
->target_info
= left_target_info
;
12367 /* Force the re-insertion of the locations at ADDRESS. This is called
12368 once a new/deleted/modified duplicate location is found and we are evaluating
12369 conditions on the target's side. Such conditions need to be updated on
12373 force_breakpoint_reinsertion (struct bp_location
*bl
)
12375 struct bp_location
**locp
= NULL
, **loc2p
;
12376 struct bp_location
*loc
;
12377 CORE_ADDR address
= 0;
12380 address
= bl
->address
;
12381 pspace_num
= bl
->pspace
->num
;
12383 /* This is only meaningful if the target is
12384 evaluating conditions and if the user has
12385 opted for condition evaluation on the target's
12387 if (gdb_evaluates_breakpoint_condition_p ()
12388 || !target_supports_evaluation_of_breakpoint_conditions ())
12391 /* Flag all breakpoint locations with this address and
12392 the same program space as the location
12393 as "its condition has changed". We need to
12394 update the conditions on the target's side. */
12395 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12399 if (!is_breakpoint (loc
->owner
)
12400 || pspace_num
!= loc
->pspace
->num
)
12403 /* Flag the location appropriately. We use a different state to
12404 let everyone know that we already updated the set of locations
12405 with addr bl->address and program space bl->pspace. This is so
12406 we don't have to keep calling these functions just to mark locations
12407 that have already been marked. */
12408 loc
->condition_changed
= condition_updated
;
12410 /* Free the agent expression bytecode as well. We will compute
12412 if (loc
->cond_bytecode
)
12414 free_agent_expr (loc
->cond_bytecode
);
12415 loc
->cond_bytecode
= NULL
;
12419 /* Called whether new breakpoints are created, or existing breakpoints
12420 deleted, to update the global location list and recompute which
12421 locations are duplicate of which.
12423 The INSERT_MODE flag determines whether locations may not, may, or
12424 shall be inserted now. See 'enum ugll_insert_mode' for more
12428 update_global_location_list (enum ugll_insert_mode insert_mode
)
12430 struct breakpoint
*b
;
12431 struct bp_location
**locp
, *loc
;
12432 struct cleanup
*cleanups
;
12433 /* Last breakpoint location address that was marked for update. */
12434 CORE_ADDR last_addr
= 0;
12435 /* Last breakpoint location program space that was marked for update. */
12436 int last_pspace_num
= -1;
12438 /* Used in the duplicates detection below. When iterating over all
12439 bp_locations, points to the first bp_location of a given address.
12440 Breakpoints and watchpoints of different types are never
12441 duplicates of each other. Keep one pointer for each type of
12442 breakpoint/watchpoint, so we only need to loop over all locations
12444 struct bp_location
*bp_loc_first
; /* breakpoint */
12445 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12446 struct bp_location
*awp_loc_first
; /* access watchpoint */
12447 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12449 /* Saved former bp_location array which we compare against the newly
12450 built bp_location from the current state of ALL_BREAKPOINTS. */
12451 struct bp_location
**old_location
, **old_locp
;
12452 unsigned old_location_count
;
12454 old_location
= bp_location
;
12455 old_location_count
= bp_location_count
;
12456 bp_location
= NULL
;
12457 bp_location_count
= 0;
12458 cleanups
= make_cleanup (xfree
, old_location
);
12460 ALL_BREAKPOINTS (b
)
12461 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12462 bp_location_count
++;
12464 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12465 locp
= bp_location
;
12466 ALL_BREAKPOINTS (b
)
12467 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12469 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12470 bp_location_compare
);
12472 bp_location_target_extensions_update ();
12474 /* Identify bp_location instances that are no longer present in the
12475 new list, and therefore should be freed. Note that it's not
12476 necessary that those locations should be removed from inferior --
12477 if there's another location at the same address (previously
12478 marked as duplicate), we don't need to remove/insert the
12481 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12482 and former bp_location array state respectively. */
12484 locp
= bp_location
;
12485 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12488 struct bp_location
*old_loc
= *old_locp
;
12489 struct bp_location
**loc2p
;
12491 /* Tells if 'old_loc' is found among the new locations. If
12492 not, we have to free it. */
12493 int found_object
= 0;
12494 /* Tells if the location should remain inserted in the target. */
12495 int keep_in_target
= 0;
12498 /* Skip LOCP entries which will definitely never be needed.
12499 Stop either at or being the one matching OLD_LOC. */
12500 while (locp
< bp_location
+ bp_location_count
12501 && (*locp
)->address
< old_loc
->address
)
12505 (loc2p
< bp_location
+ bp_location_count
12506 && (*loc2p
)->address
== old_loc
->address
);
12509 /* Check if this is a new/duplicated location or a duplicated
12510 location that had its condition modified. If so, we want to send
12511 its condition to the target if evaluation of conditions is taking
12513 if ((*loc2p
)->condition_changed
== condition_modified
12514 && (last_addr
!= old_loc
->address
12515 || last_pspace_num
!= old_loc
->pspace
->num
))
12517 force_breakpoint_reinsertion (*loc2p
);
12518 last_pspace_num
= old_loc
->pspace
->num
;
12521 if (*loc2p
== old_loc
)
12525 /* We have already handled this address, update it so that we don't
12526 have to go through updates again. */
12527 last_addr
= old_loc
->address
;
12529 /* Target-side condition evaluation: Handle deleted locations. */
12531 force_breakpoint_reinsertion (old_loc
);
12533 /* If this location is no longer present, and inserted, look if
12534 there's maybe a new location at the same address. If so,
12535 mark that one inserted, and don't remove this one. This is
12536 needed so that we don't have a time window where a breakpoint
12537 at certain location is not inserted. */
12539 if (old_loc
->inserted
)
12541 /* If the location is inserted now, we might have to remove
12544 if (found_object
&& should_be_inserted (old_loc
))
12546 /* The location is still present in the location list,
12547 and still should be inserted. Don't do anything. */
12548 keep_in_target
= 1;
12552 /* This location still exists, but it won't be kept in the
12553 target since it may have been disabled. We proceed to
12554 remove its target-side condition. */
12556 /* The location is either no longer present, or got
12557 disabled. See if there's another location at the
12558 same address, in which case we don't need to remove
12559 this one from the target. */
12561 /* OLD_LOC comes from existing struct breakpoint. */
12562 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12565 (loc2p
< bp_location
+ bp_location_count
12566 && (*loc2p
)->address
== old_loc
->address
);
12569 struct bp_location
*loc2
= *loc2p
;
12571 if (breakpoint_locations_match (loc2
, old_loc
))
12573 /* Read watchpoint locations are switched to
12574 access watchpoints, if the former are not
12575 supported, but the latter are. */
12576 if (is_hardware_watchpoint (old_loc
->owner
))
12578 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12579 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12582 /* loc2 is a duplicated location. We need to check
12583 if it should be inserted in case it will be
12585 if (loc2
!= old_loc
12586 && unduplicated_should_be_inserted (loc2
))
12588 swap_insertion (old_loc
, loc2
);
12589 keep_in_target
= 1;
12597 if (!keep_in_target
)
12599 if (remove_breakpoint (old_loc
))
12601 /* This is just about all we can do. We could keep
12602 this location on the global list, and try to
12603 remove it next time, but there's no particular
12604 reason why we will succeed next time.
12606 Note that at this point, old_loc->owner is still
12607 valid, as delete_breakpoint frees the breakpoint
12608 only after calling us. */
12609 printf_filtered (_("warning: Error removing "
12610 "breakpoint %d\n"),
12611 old_loc
->owner
->number
);
12619 if (removed
&& target_is_non_stop_p ()
12620 && need_moribund_for_location_type (old_loc
))
12622 /* This location was removed from the target. In
12623 non-stop mode, a race condition is possible where
12624 we've removed a breakpoint, but stop events for that
12625 breakpoint are already queued and will arrive later.
12626 We apply an heuristic to be able to distinguish such
12627 SIGTRAPs from other random SIGTRAPs: we keep this
12628 breakpoint location for a bit, and will retire it
12629 after we see some number of events. The theory here
12630 is that reporting of events should, "on the average",
12631 be fair, so after a while we'll see events from all
12632 threads that have anything of interest, and no longer
12633 need to keep this breakpoint location around. We
12634 don't hold locations forever so to reduce chances of
12635 mistaking a non-breakpoint SIGTRAP for a breakpoint
12638 The heuristic failing can be disastrous on
12639 decr_pc_after_break targets.
12641 On decr_pc_after_break targets, like e.g., x86-linux,
12642 if we fail to recognize a late breakpoint SIGTRAP,
12643 because events_till_retirement has reached 0 too
12644 soon, we'll fail to do the PC adjustment, and report
12645 a random SIGTRAP to the user. When the user resumes
12646 the inferior, it will most likely immediately crash
12647 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12648 corrupted, because of being resumed e.g., in the
12649 middle of a multi-byte instruction, or skipped a
12650 one-byte instruction. This was actually seen happen
12651 on native x86-linux, and should be less rare on
12652 targets that do not support new thread events, like
12653 remote, due to the heuristic depending on
12656 Mistaking a random SIGTRAP for a breakpoint trap
12657 causes similar symptoms (PC adjustment applied when
12658 it shouldn't), but then again, playing with SIGTRAPs
12659 behind the debugger's back is asking for trouble.
12661 Since hardware watchpoint traps are always
12662 distinguishable from other traps, so we don't need to
12663 apply keep hardware watchpoint moribund locations
12664 around. We simply always ignore hardware watchpoint
12665 traps we can no longer explain. */
12667 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12668 old_loc
->owner
= NULL
;
12670 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12674 old_loc
->owner
= NULL
;
12675 decref_bp_location (&old_loc
);
12680 /* Rescan breakpoints at the same address and section, marking the
12681 first one as "first" and any others as "duplicates". This is so
12682 that the bpt instruction is only inserted once. If we have a
12683 permanent breakpoint at the same place as BPT, make that one the
12684 official one, and the rest as duplicates. Permanent breakpoints
12685 are sorted first for the same address.
12687 Do the same for hardware watchpoints, but also considering the
12688 watchpoint's type (regular/access/read) and length. */
12690 bp_loc_first
= NULL
;
12691 wp_loc_first
= NULL
;
12692 awp_loc_first
= NULL
;
12693 rwp_loc_first
= NULL
;
12694 ALL_BP_LOCATIONS (loc
, locp
)
12696 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12698 struct bp_location
**loc_first_p
;
12701 if (!unduplicated_should_be_inserted (loc
)
12702 || !breakpoint_address_is_meaningful (b
)
12703 /* Don't detect duplicate for tracepoint locations because they are
12704 never duplicated. See the comments in field `duplicate' of
12705 `struct bp_location'. */
12706 || is_tracepoint (b
))
12708 /* Clear the condition modification flag. */
12709 loc
->condition_changed
= condition_unchanged
;
12713 if (b
->type
== bp_hardware_watchpoint
)
12714 loc_first_p
= &wp_loc_first
;
12715 else if (b
->type
== bp_read_watchpoint
)
12716 loc_first_p
= &rwp_loc_first
;
12717 else if (b
->type
== bp_access_watchpoint
)
12718 loc_first_p
= &awp_loc_first
;
12720 loc_first_p
= &bp_loc_first
;
12722 if (*loc_first_p
== NULL
12723 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12724 || !breakpoint_locations_match (loc
, *loc_first_p
))
12726 *loc_first_p
= loc
;
12727 loc
->duplicate
= 0;
12729 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12731 loc
->needs_update
= 1;
12732 /* Clear the condition modification flag. */
12733 loc
->condition_changed
= condition_unchanged
;
12739 /* This and the above ensure the invariant that the first location
12740 is not duplicated, and is the inserted one.
12741 All following are marked as duplicated, and are not inserted. */
12743 swap_insertion (loc
, *loc_first_p
);
12744 loc
->duplicate
= 1;
12746 /* Clear the condition modification flag. */
12747 loc
->condition_changed
= condition_unchanged
;
12750 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12752 if (insert_mode
!= UGLL_DONT_INSERT
)
12753 insert_breakpoint_locations ();
12756 /* Even though the caller told us to not insert new
12757 locations, we may still need to update conditions on the
12758 target's side of breakpoints that were already inserted
12759 if the target is evaluating breakpoint conditions. We
12760 only update conditions for locations that are marked
12762 update_inserted_breakpoint_locations ();
12766 if (insert_mode
!= UGLL_DONT_INSERT
)
12767 download_tracepoint_locations ();
12769 do_cleanups (cleanups
);
12773 breakpoint_retire_moribund (void)
12775 struct bp_location
*loc
;
12778 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12779 if (--(loc
->events_till_retirement
) == 0)
12781 decref_bp_location (&loc
);
12782 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12788 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12793 update_global_location_list (insert_mode
);
12795 CATCH (e
, RETURN_MASK_ERROR
)
12801 /* Clear BKP from a BPS. */
12804 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12808 for (bs
= bps
; bs
; bs
= bs
->next
)
12809 if (bs
->breakpoint_at
== bpt
)
12811 bs
->breakpoint_at
= NULL
;
12812 bs
->old_val
= NULL
;
12813 /* bs->commands will be freed later. */
12817 /* Callback for iterate_over_threads. */
12819 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12821 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12823 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12827 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12831 say_where (struct breakpoint
*b
)
12833 struct value_print_options opts
;
12835 get_user_print_options (&opts
);
12837 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12839 if (b
->loc
== NULL
)
12841 /* For pending locations, the output differs slightly based
12842 on b->extra_string. If this is non-NULL, it contains either
12843 a condition or dprintf arguments. */
12844 if (b
->extra_string
== NULL
)
12846 printf_filtered (_(" (%s) pending."),
12847 event_location_to_string (b
->location
));
12849 else if (b
->type
== bp_dprintf
)
12851 printf_filtered (_(" (%s,%s) pending."),
12852 event_location_to_string (b
->location
),
12857 printf_filtered (_(" (%s %s) pending."),
12858 event_location_to_string (b
->location
),
12864 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12866 printf_filtered (" at ");
12867 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12870 if (b
->loc
->symtab
!= NULL
)
12872 /* If there is a single location, we can print the location
12874 if (b
->loc
->next
== NULL
)
12875 printf_filtered (": file %s, line %d.",
12876 symtab_to_filename_for_display (b
->loc
->symtab
),
12877 b
->loc
->line_number
);
12879 /* This is not ideal, but each location may have a
12880 different file name, and this at least reflects the
12881 real situation somewhat. */
12882 printf_filtered (": %s.",
12883 event_location_to_string (b
->location
));
12888 struct bp_location
*loc
= b
->loc
;
12890 for (; loc
; loc
= loc
->next
)
12892 printf_filtered (" (%d locations)", n
);
12897 /* Default bp_location_ops methods. */
12900 bp_location_dtor (struct bp_location
*self
)
12902 if (self
->cond_bytecode
)
12903 free_agent_expr (self
->cond_bytecode
);
12904 xfree (self
->function_name
);
12906 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12907 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12910 static const struct bp_location_ops bp_location_ops
=
12915 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12919 base_breakpoint_dtor (struct breakpoint
*self
)
12921 decref_counted_command_line (&self
->commands
);
12922 xfree (self
->cond_string
);
12923 xfree (self
->extra_string
);
12924 xfree (self
->filter
);
12925 delete_event_location (self
->location
);
12926 delete_event_location (self
->location_range_end
);
12929 static struct bp_location
*
12930 base_breakpoint_allocate_location (struct breakpoint
*self
)
12932 struct bp_location
*loc
;
12934 loc
= new struct bp_location ();
12935 init_bp_location (loc
, &bp_location_ops
, self
);
12940 base_breakpoint_re_set (struct breakpoint
*b
)
12942 /* Nothing to re-set. */
12945 #define internal_error_pure_virtual_called() \
12946 gdb_assert_not_reached ("pure virtual function called")
12949 base_breakpoint_insert_location (struct bp_location
*bl
)
12951 internal_error_pure_virtual_called ();
12955 base_breakpoint_remove_location (struct bp_location
*bl
,
12956 enum remove_bp_reason reason
)
12958 internal_error_pure_virtual_called ();
12962 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12963 struct address_space
*aspace
,
12965 const struct target_waitstatus
*ws
)
12967 internal_error_pure_virtual_called ();
12971 base_breakpoint_check_status (bpstat bs
)
12976 /* A "works_in_software_mode" breakpoint_ops method that just internal
12980 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12982 internal_error_pure_virtual_called ();
12985 /* A "resources_needed" breakpoint_ops method that just internal
12989 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12991 internal_error_pure_virtual_called ();
12994 static enum print_stop_action
12995 base_breakpoint_print_it (bpstat bs
)
12997 internal_error_pure_virtual_called ();
13001 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13002 struct ui_out
*uiout
)
13008 base_breakpoint_print_mention (struct breakpoint
*b
)
13010 internal_error_pure_virtual_called ();
13014 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13016 internal_error_pure_virtual_called ();
13020 base_breakpoint_create_sals_from_location
13021 (const struct event_location
*location
,
13022 struct linespec_result
*canonical
,
13023 enum bptype type_wanted
)
13025 internal_error_pure_virtual_called ();
13029 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13030 struct linespec_result
*c
,
13032 char *extra_string
,
13033 enum bptype type_wanted
,
13034 enum bpdisp disposition
,
13036 int task
, int ignore_count
,
13037 const struct breakpoint_ops
*o
,
13038 int from_tty
, int enabled
,
13039 int internal
, unsigned flags
)
13041 internal_error_pure_virtual_called ();
13045 base_breakpoint_decode_location (struct breakpoint
*b
,
13046 const struct event_location
*location
,
13047 struct program_space
*search_pspace
,
13048 struct symtabs_and_lines
*sals
)
13050 internal_error_pure_virtual_called ();
13053 /* The default 'explains_signal' method. */
13056 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13061 /* The default "after_condition_true" method. */
13064 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13066 /* Nothing to do. */
13069 struct breakpoint_ops base_breakpoint_ops
=
13071 base_breakpoint_dtor
,
13072 base_breakpoint_allocate_location
,
13073 base_breakpoint_re_set
,
13074 base_breakpoint_insert_location
,
13075 base_breakpoint_remove_location
,
13076 base_breakpoint_breakpoint_hit
,
13077 base_breakpoint_check_status
,
13078 base_breakpoint_resources_needed
,
13079 base_breakpoint_works_in_software_mode
,
13080 base_breakpoint_print_it
,
13082 base_breakpoint_print_one_detail
,
13083 base_breakpoint_print_mention
,
13084 base_breakpoint_print_recreate
,
13085 base_breakpoint_create_sals_from_location
,
13086 base_breakpoint_create_breakpoints_sal
,
13087 base_breakpoint_decode_location
,
13088 base_breakpoint_explains_signal
,
13089 base_breakpoint_after_condition_true
,
13092 /* Default breakpoint_ops methods. */
13095 bkpt_re_set (struct breakpoint
*b
)
13097 /* FIXME: is this still reachable? */
13098 if (breakpoint_event_location_empty_p (b
))
13100 /* Anything without a location can't be re-set. */
13101 delete_breakpoint (b
);
13105 breakpoint_re_set_default (b
);
13109 bkpt_insert_location (struct bp_location
*bl
)
13111 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
13113 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
13114 bl
->target_info
.placed_address
= addr
;
13116 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13117 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13119 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13123 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13125 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13126 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13128 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13132 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13133 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13134 const struct target_waitstatus
*ws
)
13136 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13137 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13140 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13144 if (overlay_debugging
/* unmapped overlay section */
13145 && section_is_overlay (bl
->section
)
13146 && !section_is_mapped (bl
->section
))
13153 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13154 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13155 const struct target_waitstatus
*ws
)
13157 if (dprintf_style
== dprintf_style_agent
13158 && target_can_run_breakpoint_commands ())
13160 /* An agent-style dprintf never causes a stop. If we see a trap
13161 for this address it must be for a breakpoint that happens to
13162 be set at the same address. */
13166 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13170 bkpt_resources_needed (const struct bp_location
*bl
)
13172 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13177 static enum print_stop_action
13178 bkpt_print_it (bpstat bs
)
13180 struct breakpoint
*b
;
13181 const struct bp_location
*bl
;
13183 struct ui_out
*uiout
= current_uiout
;
13185 gdb_assert (bs
->bp_location_at
!= NULL
);
13187 bl
= bs
->bp_location_at
;
13188 b
= bs
->breakpoint_at
;
13190 bp_temp
= b
->disposition
== disp_del
;
13191 if (bl
->address
!= bl
->requested_address
)
13192 breakpoint_adjustment_warning (bl
->requested_address
,
13195 annotate_breakpoint (b
->number
);
13196 maybe_print_thread_hit_breakpoint (uiout
);
13199 ui_out_text (uiout
, "Temporary breakpoint ");
13201 ui_out_text (uiout
, "Breakpoint ");
13202 if (ui_out_is_mi_like_p (uiout
))
13204 ui_out_field_string (uiout
, "reason",
13205 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13206 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13208 ui_out_field_int (uiout
, "bkptno", b
->number
);
13209 ui_out_text (uiout
, ", ");
13211 return PRINT_SRC_AND_LOC
;
13215 bkpt_print_mention (struct breakpoint
*b
)
13217 if (ui_out_is_mi_like_p (current_uiout
))
13222 case bp_breakpoint
:
13223 case bp_gnu_ifunc_resolver
:
13224 if (b
->disposition
== disp_del
)
13225 printf_filtered (_("Temporary breakpoint"));
13227 printf_filtered (_("Breakpoint"));
13228 printf_filtered (_(" %d"), b
->number
);
13229 if (b
->type
== bp_gnu_ifunc_resolver
)
13230 printf_filtered (_(" at gnu-indirect-function resolver"));
13232 case bp_hardware_breakpoint
:
13233 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13236 printf_filtered (_("Dprintf %d"), b
->number
);
13244 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13246 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13247 fprintf_unfiltered (fp
, "tbreak");
13248 else if (tp
->type
== bp_breakpoint
)
13249 fprintf_unfiltered (fp
, "break");
13250 else if (tp
->type
== bp_hardware_breakpoint
13251 && tp
->disposition
== disp_del
)
13252 fprintf_unfiltered (fp
, "thbreak");
13253 else if (tp
->type
== bp_hardware_breakpoint
)
13254 fprintf_unfiltered (fp
, "hbreak");
13256 internal_error (__FILE__
, __LINE__
,
13257 _("unhandled breakpoint type %d"), (int) tp
->type
);
13259 fprintf_unfiltered (fp
, " %s",
13260 event_location_to_string (tp
->location
));
13262 /* Print out extra_string if this breakpoint is pending. It might
13263 contain, for example, conditions that were set by the user. */
13264 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13265 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13267 print_recreate_thread (tp
, fp
);
13271 bkpt_create_sals_from_location (const struct event_location
*location
,
13272 struct linespec_result
*canonical
,
13273 enum bptype type_wanted
)
13275 create_sals_from_location_default (location
, canonical
, type_wanted
);
13279 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13280 struct linespec_result
*canonical
,
13282 char *extra_string
,
13283 enum bptype type_wanted
,
13284 enum bpdisp disposition
,
13286 int task
, int ignore_count
,
13287 const struct breakpoint_ops
*ops
,
13288 int from_tty
, int enabled
,
13289 int internal
, unsigned flags
)
13291 create_breakpoints_sal_default (gdbarch
, canonical
,
13292 cond_string
, extra_string
,
13294 disposition
, thread
, task
,
13295 ignore_count
, ops
, from_tty
,
13296 enabled
, internal
, flags
);
13300 bkpt_decode_location (struct breakpoint
*b
,
13301 const struct event_location
*location
,
13302 struct program_space
*search_pspace
,
13303 struct symtabs_and_lines
*sals
)
13305 decode_location_default (b
, location
, search_pspace
, sals
);
13308 /* Virtual table for internal breakpoints. */
13311 internal_bkpt_re_set (struct breakpoint
*b
)
13315 /* Delete overlay event and longjmp master breakpoints; they
13316 will be reset later by breakpoint_re_set. */
13317 case bp_overlay_event
:
13318 case bp_longjmp_master
:
13319 case bp_std_terminate_master
:
13320 case bp_exception_master
:
13321 delete_breakpoint (b
);
13324 /* This breakpoint is special, it's set up when the inferior
13325 starts and we really don't want to touch it. */
13326 case bp_shlib_event
:
13328 /* Like bp_shlib_event, this breakpoint type is special. Once
13329 it is set up, we do not want to touch it. */
13330 case bp_thread_event
:
13336 internal_bkpt_check_status (bpstat bs
)
13338 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13340 /* If requested, stop when the dynamic linker notifies GDB of
13341 events. This allows the user to get control and place
13342 breakpoints in initializer routines for dynamically loaded
13343 objects (among other things). */
13344 bs
->stop
= stop_on_solib_events
;
13345 bs
->print
= stop_on_solib_events
;
13351 static enum print_stop_action
13352 internal_bkpt_print_it (bpstat bs
)
13354 struct breakpoint
*b
;
13356 b
= bs
->breakpoint_at
;
13360 case bp_shlib_event
:
13361 /* Did we stop because the user set the stop_on_solib_events
13362 variable? (If so, we report this as a generic, "Stopped due
13363 to shlib event" message.) */
13364 print_solib_event (0);
13367 case bp_thread_event
:
13368 /* Not sure how we will get here.
13369 GDB should not stop for these breakpoints. */
13370 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13373 case bp_overlay_event
:
13374 /* By analogy with the thread event, GDB should not stop for these. */
13375 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13378 case bp_longjmp_master
:
13379 /* These should never be enabled. */
13380 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13383 case bp_std_terminate_master
:
13384 /* These should never be enabled. */
13385 printf_filtered (_("std::terminate Master Breakpoint: "
13386 "gdb should not stop!\n"));
13389 case bp_exception_master
:
13390 /* These should never be enabled. */
13391 printf_filtered (_("Exception Master Breakpoint: "
13392 "gdb should not stop!\n"));
13396 return PRINT_NOTHING
;
13400 internal_bkpt_print_mention (struct breakpoint
*b
)
13402 /* Nothing to mention. These breakpoints are internal. */
13405 /* Virtual table for momentary breakpoints */
13408 momentary_bkpt_re_set (struct breakpoint
*b
)
13410 /* Keep temporary breakpoints, which can be encountered when we step
13411 over a dlopen call and solib_add is resetting the breakpoints.
13412 Otherwise these should have been blown away via the cleanup chain
13413 or by breakpoint_init_inferior when we rerun the executable. */
13417 momentary_bkpt_check_status (bpstat bs
)
13419 /* Nothing. The point of these breakpoints is causing a stop. */
13422 static enum print_stop_action
13423 momentary_bkpt_print_it (bpstat bs
)
13425 return PRINT_UNKNOWN
;
13429 momentary_bkpt_print_mention (struct breakpoint
*b
)
13431 /* Nothing to mention. These breakpoints are internal. */
13434 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13436 It gets cleared already on the removal of the first one of such placed
13437 breakpoints. This is OK as they get all removed altogether. */
13440 longjmp_bkpt_dtor (struct breakpoint
*self
)
13442 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13445 tp
->initiating_frame
= null_frame_id
;
13447 momentary_breakpoint_ops
.dtor (self
);
13450 /* Specific methods for probe breakpoints. */
13453 bkpt_probe_insert_location (struct bp_location
*bl
)
13455 int v
= bkpt_insert_location (bl
);
13459 /* The insertion was successful, now let's set the probe's semaphore
13461 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13462 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13471 bkpt_probe_remove_location (struct bp_location
*bl
,
13472 enum remove_bp_reason reason
)
13474 /* Let's clear the semaphore before removing the location. */
13475 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13476 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13480 return bkpt_remove_location (bl
, reason
);
13484 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13485 struct linespec_result
*canonical
,
13486 enum bptype type_wanted
)
13488 struct linespec_sals lsal
;
13490 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13491 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13492 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13496 bkpt_probe_decode_location (struct breakpoint
*b
,
13497 const struct event_location
*location
,
13498 struct program_space
*search_pspace
,
13499 struct symtabs_and_lines
*sals
)
13501 *sals
= parse_probes (location
, search_pspace
, NULL
);
13503 error (_("probe not found"));
13506 /* The breakpoint_ops structure to be used in tracepoints. */
13509 tracepoint_re_set (struct breakpoint
*b
)
13511 breakpoint_re_set_default (b
);
13515 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13516 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13517 const struct target_waitstatus
*ws
)
13519 /* By definition, the inferior does not report stops at
13525 tracepoint_print_one_detail (const struct breakpoint
*self
,
13526 struct ui_out
*uiout
)
13528 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13529 if (tp
->static_trace_marker_id
)
13531 gdb_assert (self
->type
== bp_static_tracepoint
);
13533 ui_out_text (uiout
, "\tmarker id is ");
13534 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13535 tp
->static_trace_marker_id
);
13536 ui_out_text (uiout
, "\n");
13541 tracepoint_print_mention (struct breakpoint
*b
)
13543 if (ui_out_is_mi_like_p (current_uiout
))
13548 case bp_tracepoint
:
13549 printf_filtered (_("Tracepoint"));
13550 printf_filtered (_(" %d"), b
->number
);
13552 case bp_fast_tracepoint
:
13553 printf_filtered (_("Fast tracepoint"));
13554 printf_filtered (_(" %d"), b
->number
);
13556 case bp_static_tracepoint
:
13557 printf_filtered (_("Static tracepoint"));
13558 printf_filtered (_(" %d"), b
->number
);
13561 internal_error (__FILE__
, __LINE__
,
13562 _("unhandled tracepoint type %d"), (int) b
->type
);
13569 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13571 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13573 if (self
->type
== bp_fast_tracepoint
)
13574 fprintf_unfiltered (fp
, "ftrace");
13575 else if (self
->type
== bp_static_tracepoint
)
13576 fprintf_unfiltered (fp
, "strace");
13577 else if (self
->type
== bp_tracepoint
)
13578 fprintf_unfiltered (fp
, "trace");
13580 internal_error (__FILE__
, __LINE__
,
13581 _("unhandled tracepoint type %d"), (int) self
->type
);
13583 fprintf_unfiltered (fp
, " %s",
13584 event_location_to_string (self
->location
));
13585 print_recreate_thread (self
, fp
);
13587 if (tp
->pass_count
)
13588 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13592 tracepoint_create_sals_from_location (const struct event_location
*location
,
13593 struct linespec_result
*canonical
,
13594 enum bptype type_wanted
)
13596 create_sals_from_location_default (location
, canonical
, type_wanted
);
13600 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13601 struct linespec_result
*canonical
,
13603 char *extra_string
,
13604 enum bptype type_wanted
,
13605 enum bpdisp disposition
,
13607 int task
, int ignore_count
,
13608 const struct breakpoint_ops
*ops
,
13609 int from_tty
, int enabled
,
13610 int internal
, unsigned flags
)
13612 create_breakpoints_sal_default (gdbarch
, canonical
,
13613 cond_string
, extra_string
,
13615 disposition
, thread
, task
,
13616 ignore_count
, ops
, from_tty
,
13617 enabled
, internal
, flags
);
13621 tracepoint_decode_location (struct breakpoint
*b
,
13622 const struct event_location
*location
,
13623 struct program_space
*search_pspace
,
13624 struct symtabs_and_lines
*sals
)
13626 decode_location_default (b
, location
, search_pspace
, sals
);
13629 struct breakpoint_ops tracepoint_breakpoint_ops
;
13631 /* The breakpoint_ops structure to be use on tracepoints placed in a
13635 tracepoint_probe_create_sals_from_location
13636 (const struct event_location
*location
,
13637 struct linespec_result
*canonical
,
13638 enum bptype type_wanted
)
13640 /* We use the same method for breakpoint on probes. */
13641 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13645 tracepoint_probe_decode_location (struct breakpoint
*b
,
13646 const struct event_location
*location
,
13647 struct program_space
*search_pspace
,
13648 struct symtabs_and_lines
*sals
)
13650 /* We use the same method for breakpoint on probes. */
13651 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13654 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13656 /* Dprintf breakpoint_ops methods. */
13659 dprintf_re_set (struct breakpoint
*b
)
13661 breakpoint_re_set_default (b
);
13663 /* extra_string should never be non-NULL for dprintf. */
13664 gdb_assert (b
->extra_string
!= NULL
);
13666 /* 1 - connect to target 1, that can run breakpoint commands.
13667 2 - create a dprintf, which resolves fine.
13668 3 - disconnect from target 1
13669 4 - connect to target 2, that can NOT run breakpoint commands.
13671 After steps #3/#4, you'll want the dprintf command list to
13672 be updated, because target 1 and 2 may well return different
13673 answers for target_can_run_breakpoint_commands().
13674 Given absence of finer grained resetting, we get to do
13675 it all the time. */
13676 if (b
->extra_string
!= NULL
)
13677 update_dprintf_command_list (b
);
13680 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13683 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13685 fprintf_unfiltered (fp
, "dprintf %s,%s",
13686 event_location_to_string (tp
->location
),
13688 print_recreate_thread (tp
, fp
);
13691 /* Implement the "after_condition_true" breakpoint_ops method for
13694 dprintf's are implemented with regular commands in their command
13695 list, but we run the commands here instead of before presenting the
13696 stop to the user, as dprintf's don't actually cause a stop. This
13697 also makes it so that the commands of multiple dprintfs at the same
13698 address are all handled. */
13701 dprintf_after_condition_true (struct bpstats
*bs
)
13703 struct cleanup
*old_chain
;
13704 struct bpstats tmp_bs
= { NULL
};
13705 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13707 /* dprintf's never cause a stop. This wasn't set in the
13708 check_status hook instead because that would make the dprintf's
13709 condition not be evaluated. */
13712 /* Run the command list here. Take ownership of it instead of
13713 copying. We never want these commands to run later in
13714 bpstat_do_actions, if a breakpoint that causes a stop happens to
13715 be set at same address as this dprintf, or even if running the
13716 commands here throws. */
13717 tmp_bs
.commands
= bs
->commands
;
13718 bs
->commands
= NULL
;
13719 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13721 bpstat_do_actions_1 (&tmp_bs_p
);
13723 /* 'tmp_bs.commands' will usually be NULL by now, but
13724 bpstat_do_actions_1 may return early without processing the whole
13726 do_cleanups (old_chain
);
13729 /* The breakpoint_ops structure to be used on static tracepoints with
13733 strace_marker_create_sals_from_location (const struct event_location
*location
,
13734 struct linespec_result
*canonical
,
13735 enum bptype type_wanted
)
13737 struct linespec_sals lsal
;
13738 const char *arg_start
, *arg
;
13740 struct cleanup
*cleanup
;
13742 arg
= arg_start
= get_linespec_location (location
);
13743 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13745 str
= savestring (arg_start
, arg
- arg_start
);
13746 cleanup
= make_cleanup (xfree
, str
);
13747 canonical
->location
= new_linespec_location (&str
);
13748 do_cleanups (cleanup
);
13750 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13751 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13755 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13756 struct linespec_result
*canonical
,
13758 char *extra_string
,
13759 enum bptype type_wanted
,
13760 enum bpdisp disposition
,
13762 int task
, int ignore_count
,
13763 const struct breakpoint_ops
*ops
,
13764 int from_tty
, int enabled
,
13765 int internal
, unsigned flags
)
13768 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13769 canonical
->sals
, 0);
13771 /* If the user is creating a static tracepoint by marker id
13772 (strace -m MARKER_ID), then store the sals index, so that
13773 breakpoint_re_set can try to match up which of the newly
13774 found markers corresponds to this one, and, don't try to
13775 expand multiple locations for each sal, given than SALS
13776 already should contain all sals for MARKER_ID. */
13778 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13780 struct symtabs_and_lines expanded
;
13781 struct tracepoint
*tp
;
13782 struct cleanup
*old_chain
;
13783 struct event_location
*location
;
13785 expanded
.nelts
= 1;
13786 expanded
.sals
= &lsal
->sals
.sals
[i
];
13788 location
= copy_event_location (canonical
->location
);
13789 old_chain
= make_cleanup_delete_event_location (location
);
13791 tp
= new tracepoint ();
13792 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13794 cond_string
, extra_string
,
13795 type_wanted
, disposition
,
13796 thread
, task
, ignore_count
, ops
,
13797 from_tty
, enabled
, internal
, flags
,
13798 canonical
->special_display
);
13799 /* Given that its possible to have multiple markers with
13800 the same string id, if the user is creating a static
13801 tracepoint by marker id ("strace -m MARKER_ID"), then
13802 store the sals index, so that breakpoint_re_set can
13803 try to match up which of the newly found markers
13804 corresponds to this one */
13805 tp
->static_trace_marker_id_idx
= i
;
13807 install_breakpoint (internal
, &tp
->base
, 0);
13809 discard_cleanups (old_chain
);
13814 strace_marker_decode_location (struct breakpoint
*b
,
13815 const struct event_location
*location
,
13816 struct program_space
*search_pspace
,
13817 struct symtabs_and_lines
*sals
)
13819 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13820 const char *s
= get_linespec_location (location
);
13822 *sals
= decode_static_tracepoint_spec (&s
);
13823 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13825 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13829 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13832 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13835 strace_marker_p (struct breakpoint
*b
)
13837 return b
->ops
== &strace_marker_breakpoint_ops
;
13840 /* Delete a breakpoint and clean up all traces of it in the data
13844 delete_breakpoint (struct breakpoint
*bpt
)
13846 struct breakpoint
*b
;
13848 gdb_assert (bpt
!= NULL
);
13850 /* Has this bp already been deleted? This can happen because
13851 multiple lists can hold pointers to bp's. bpstat lists are
13854 One example of this happening is a watchpoint's scope bp. When
13855 the scope bp triggers, we notice that the watchpoint is out of
13856 scope, and delete it. We also delete its scope bp. But the
13857 scope bp is marked "auto-deleting", and is already on a bpstat.
13858 That bpstat is then checked for auto-deleting bp's, which are
13861 A real solution to this problem might involve reference counts in
13862 bp's, and/or giving them pointers back to their referencing
13863 bpstat's, and teaching delete_breakpoint to only free a bp's
13864 storage when no more references were extent. A cheaper bandaid
13866 if (bpt
->type
== bp_none
)
13869 /* At least avoid this stale reference until the reference counting
13870 of breakpoints gets resolved. */
13871 if (bpt
->related_breakpoint
!= bpt
)
13873 struct breakpoint
*related
;
13874 struct watchpoint
*w
;
13876 if (bpt
->type
== bp_watchpoint_scope
)
13877 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13878 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13879 w
= (struct watchpoint
*) bpt
;
13883 watchpoint_del_at_next_stop (w
);
13885 /* Unlink bpt from the bpt->related_breakpoint ring. */
13886 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13887 related
= related
->related_breakpoint
);
13888 related
->related_breakpoint
= bpt
->related_breakpoint
;
13889 bpt
->related_breakpoint
= bpt
;
13892 /* watch_command_1 creates a watchpoint but only sets its number if
13893 update_watchpoint succeeds in creating its bp_locations. If there's
13894 a problem in that process, we'll be asked to delete the half-created
13895 watchpoint. In that case, don't announce the deletion. */
13897 observer_notify_breakpoint_deleted (bpt
);
13899 if (breakpoint_chain
== bpt
)
13900 breakpoint_chain
= bpt
->next
;
13902 ALL_BREAKPOINTS (b
)
13903 if (b
->next
== bpt
)
13905 b
->next
= bpt
->next
;
13909 /* Be sure no bpstat's are pointing at the breakpoint after it's
13911 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13912 in all threads for now. Note that we cannot just remove bpstats
13913 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13914 commands are associated with the bpstat; if we remove it here,
13915 then the later call to bpstat_do_actions (&stop_bpstat); in
13916 event-top.c won't do anything, and temporary breakpoints with
13917 commands won't work. */
13919 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13921 /* Now that breakpoint is removed from breakpoint list, update the
13922 global location list. This will remove locations that used to
13923 belong to this breakpoint. Do this before freeing the breakpoint
13924 itself, since remove_breakpoint looks at location's owner. It
13925 might be better design to have location completely
13926 self-contained, but it's not the case now. */
13927 update_global_location_list (UGLL_DONT_INSERT
);
13929 bpt
->ops
->dtor (bpt
);
13930 /* On the chance that someone will soon try again to delete this
13931 same bp, we mark it as deleted before freeing its storage. */
13932 bpt
->type
= bp_none
;
13937 do_delete_breakpoint_cleanup (void *b
)
13939 delete_breakpoint ((struct breakpoint
*) b
);
13943 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13945 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13948 /* Iterator function to call a user-provided callback function once
13949 for each of B and its related breakpoints. */
13952 iterate_over_related_breakpoints (struct breakpoint
*b
,
13953 void (*function
) (struct breakpoint
*,
13957 struct breakpoint
*related
;
13962 struct breakpoint
*next
;
13964 /* FUNCTION may delete RELATED. */
13965 next
= related
->related_breakpoint
;
13967 if (next
== related
)
13969 /* RELATED is the last ring entry. */
13970 function (related
, data
);
13972 /* FUNCTION may have deleted it, so we'd never reach back to
13973 B. There's nothing left to do anyway, so just break
13978 function (related
, data
);
13982 while (related
!= b
);
13986 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13988 delete_breakpoint (b
);
13991 /* A callback for map_breakpoint_numbers that calls
13992 delete_breakpoint. */
13995 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13997 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14001 delete_command (char *arg
, int from_tty
)
14003 struct breakpoint
*b
, *b_tmp
;
14009 int breaks_to_delete
= 0;
14011 /* Delete all breakpoints if no argument. Do not delete
14012 internal breakpoints, these have to be deleted with an
14013 explicit breakpoint number argument. */
14014 ALL_BREAKPOINTS (b
)
14015 if (user_breakpoint_p (b
))
14017 breaks_to_delete
= 1;
14021 /* Ask user only if there are some breakpoints to delete. */
14023 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14025 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14026 if (user_breakpoint_p (b
))
14027 delete_breakpoint (b
);
14031 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14034 /* Return true if all locations of B bound to PSPACE are pending. If
14035 PSPACE is NULL, all locations of all program spaces are
14039 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
14041 struct bp_location
*loc
;
14043 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14044 if ((pspace
== NULL
14045 || loc
->pspace
== pspace
)
14046 && !loc
->shlib_disabled
14047 && !loc
->pspace
->executing_startup
)
14052 /* Subroutine of update_breakpoint_locations to simplify it.
14053 Return non-zero if multiple fns in list LOC have the same name.
14054 Null names are ignored. */
14057 ambiguous_names_p (struct bp_location
*loc
)
14059 struct bp_location
*l
;
14060 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14061 (int (*) (const void *,
14062 const void *)) streq
,
14063 NULL
, xcalloc
, xfree
);
14065 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14068 const char *name
= l
->function_name
;
14070 /* Allow for some names to be NULL, ignore them. */
14074 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14076 /* NOTE: We can assume slot != NULL here because xcalloc never
14080 htab_delete (htab
);
14086 htab_delete (htab
);
14090 /* When symbols change, it probably means the sources changed as well,
14091 and it might mean the static tracepoint markers are no longer at
14092 the same address or line numbers they used to be at last we
14093 checked. Losing your static tracepoints whenever you rebuild is
14094 undesirable. This function tries to resync/rematch gdb static
14095 tracepoints with the markers on the target, for static tracepoints
14096 that have not been set by marker id. Static tracepoint that have
14097 been set by marker id are reset by marker id in breakpoint_re_set.
14100 1) For a tracepoint set at a specific address, look for a marker at
14101 the old PC. If one is found there, assume to be the same marker.
14102 If the name / string id of the marker found is different from the
14103 previous known name, assume that means the user renamed the marker
14104 in the sources, and output a warning.
14106 2) For a tracepoint set at a given line number, look for a marker
14107 at the new address of the old line number. If one is found there,
14108 assume to be the same marker. If the name / string id of the
14109 marker found is different from the previous known name, assume that
14110 means the user renamed the marker in the sources, and output a
14113 3) If a marker is no longer found at the same address or line, it
14114 may mean the marker no longer exists. But it may also just mean
14115 the code changed a bit. Maybe the user added a few lines of code
14116 that made the marker move up or down (in line number terms). Ask
14117 the target for info about the marker with the string id as we knew
14118 it. If found, update line number and address in the matching
14119 static tracepoint. This will get confused if there's more than one
14120 marker with the same ID (possible in UST, although unadvised
14121 precisely because it confuses tools). */
14123 static struct symtab_and_line
14124 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14126 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14127 struct static_tracepoint_marker marker
;
14132 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14134 if (target_static_tracepoint_marker_at (pc
, &marker
))
14136 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14137 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14139 tp
->static_trace_marker_id
, marker
.str_id
);
14141 xfree (tp
->static_trace_marker_id
);
14142 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14143 release_static_tracepoint_marker (&marker
);
14148 /* Old marker wasn't found on target at lineno. Try looking it up
14150 if (!sal
.explicit_pc
14152 && sal
.symtab
!= NULL
14153 && tp
->static_trace_marker_id
!= NULL
)
14155 VEC(static_tracepoint_marker_p
) *markers
;
14158 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14160 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14162 struct symtab_and_line sal2
;
14163 struct symbol
*sym
;
14164 struct static_tracepoint_marker
*tpmarker
;
14165 struct ui_out
*uiout
= current_uiout
;
14166 struct explicit_location explicit_loc
;
14168 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14170 xfree (tp
->static_trace_marker_id
);
14171 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14173 warning (_("marker for static tracepoint %d (%s) not "
14174 "found at previous line number"),
14175 b
->number
, tp
->static_trace_marker_id
);
14179 sal2
.pc
= tpmarker
->address
;
14181 sal2
= find_pc_line (tpmarker
->address
, 0);
14182 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14183 ui_out_text (uiout
, "Now in ");
14186 ui_out_field_string (uiout
, "func",
14187 SYMBOL_PRINT_NAME (sym
));
14188 ui_out_text (uiout
, " at ");
14190 ui_out_field_string (uiout
, "file",
14191 symtab_to_filename_for_display (sal2
.symtab
));
14192 ui_out_text (uiout
, ":");
14194 if (ui_out_is_mi_like_p (uiout
))
14196 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14198 ui_out_field_string (uiout
, "fullname", fullname
);
14201 ui_out_field_int (uiout
, "line", sal2
.line
);
14202 ui_out_text (uiout
, "\n");
14204 b
->loc
->line_number
= sal2
.line
;
14205 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14207 delete_event_location (b
->location
);
14208 initialize_explicit_location (&explicit_loc
);
14209 explicit_loc
.source_filename
14210 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14211 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14212 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14213 b
->location
= new_explicit_location (&explicit_loc
);
14215 /* Might be nice to check if function changed, and warn if
14218 release_static_tracepoint_marker (tpmarker
);
14224 /* Returns 1 iff locations A and B are sufficiently same that
14225 we don't need to report breakpoint as changed. */
14228 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14232 if (a
->address
!= b
->address
)
14235 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14238 if (a
->enabled
!= b
->enabled
)
14245 if ((a
== NULL
) != (b
== NULL
))
14251 /* Split all locations of B that are bound to PSPACE out of B's
14252 location list to a separate list and return that list's head. If
14253 PSPACE is NULL, hoist out all locations of B. */
14255 static struct bp_location
*
14256 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14258 struct bp_location head
;
14259 struct bp_location
*i
= b
->loc
;
14260 struct bp_location
**i_link
= &b
->loc
;
14261 struct bp_location
*hoisted
= &head
;
14263 if (pspace
== NULL
)
14274 if (i
->pspace
== pspace
)
14289 /* Create new breakpoint locations for B (a hardware or software
14290 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14291 zero, then B is a ranged breakpoint. Only recreates locations for
14292 FILTER_PSPACE. Locations of other program spaces are left
14296 update_breakpoint_locations (struct breakpoint
*b
,
14297 struct program_space
*filter_pspace
,
14298 struct symtabs_and_lines sals
,
14299 struct symtabs_and_lines sals_end
)
14302 struct bp_location
*existing_locations
;
14304 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14306 /* Ranged breakpoints have only one start location and one end
14308 b
->enable_state
= bp_disabled
;
14309 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14310 "multiple locations found\n"),
14315 /* If there's no new locations, and all existing locations are
14316 pending, don't do anything. This optimizes the common case where
14317 all locations are in the same shared library, that was unloaded.
14318 We'd like to retain the location, so that when the library is
14319 loaded again, we don't loose the enabled/disabled status of the
14320 individual locations. */
14321 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14324 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14326 for (i
= 0; i
< sals
.nelts
; ++i
)
14328 struct bp_location
*new_loc
;
14330 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14332 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14334 /* Reparse conditions, they might contain references to the
14336 if (b
->cond_string
!= NULL
)
14340 s
= b
->cond_string
;
14343 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14344 block_for_pc (sals
.sals
[i
].pc
),
14347 CATCH (e
, RETURN_MASK_ERROR
)
14349 warning (_("failed to reevaluate condition "
14350 "for breakpoint %d: %s"),
14351 b
->number
, e
.message
);
14352 new_loc
->enabled
= 0;
14357 if (sals_end
.nelts
)
14359 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14361 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14365 /* If possible, carry over 'disable' status from existing
14368 struct bp_location
*e
= existing_locations
;
14369 /* If there are multiple breakpoints with the same function name,
14370 e.g. for inline functions, comparing function names won't work.
14371 Instead compare pc addresses; this is just a heuristic as things
14372 may have moved, but in practice it gives the correct answer
14373 often enough until a better solution is found. */
14374 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14376 for (; e
; e
= e
->next
)
14378 if (!e
->enabled
&& e
->function_name
)
14380 struct bp_location
*l
= b
->loc
;
14381 if (have_ambiguous_names
)
14383 for (; l
; l
= l
->next
)
14384 if (breakpoint_locations_match (e
, l
))
14392 for (; l
; l
= l
->next
)
14393 if (l
->function_name
14394 && strcmp (e
->function_name
, l
->function_name
) == 0)
14404 if (!locations_are_equal (existing_locations
, b
->loc
))
14405 observer_notify_breakpoint_modified (b
);
14408 /* Find the SaL locations corresponding to the given LOCATION.
14409 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14411 static struct symtabs_and_lines
14412 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14413 struct program_space
*search_pspace
, int *found
)
14415 struct symtabs_and_lines sals
= {0};
14416 struct gdb_exception exception
= exception_none
;
14418 gdb_assert (b
->ops
!= NULL
);
14422 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14424 CATCH (e
, RETURN_MASK_ERROR
)
14426 int not_found_and_ok
= 0;
14430 /* For pending breakpoints, it's expected that parsing will
14431 fail until the right shared library is loaded. User has
14432 already told to create pending breakpoints and don't need
14433 extra messages. If breakpoint is in bp_shlib_disabled
14434 state, then user already saw the message about that
14435 breakpoint being disabled, and don't want to see more
14437 if (e
.error
== NOT_FOUND_ERROR
14438 && (b
->condition_not_parsed
14440 && search_pspace
!= NULL
14441 && b
->loc
->pspace
!= search_pspace
)
14442 || (b
->loc
&& b
->loc
->shlib_disabled
)
14443 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14444 || b
->enable_state
== bp_disabled
))
14445 not_found_and_ok
= 1;
14447 if (!not_found_and_ok
)
14449 /* We surely don't want to warn about the same breakpoint
14450 10 times. One solution, implemented here, is disable
14451 the breakpoint on error. Another solution would be to
14452 have separate 'warning emitted' flag. Since this
14453 happens only when a binary has changed, I don't know
14454 which approach is better. */
14455 b
->enable_state
= bp_disabled
;
14456 throw_exception (e
);
14461 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14465 for (i
= 0; i
< sals
.nelts
; ++i
)
14466 resolve_sal_pc (&sals
.sals
[i
]);
14467 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14469 char *cond_string
, *extra_string
;
14472 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14473 &cond_string
, &thread
, &task
,
14475 gdb_assert (b
->cond_string
== NULL
);
14477 b
->cond_string
= cond_string
;
14478 b
->thread
= thread
;
14482 xfree (b
->extra_string
);
14483 b
->extra_string
= extra_string
;
14485 b
->condition_not_parsed
= 0;
14488 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14489 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14499 /* The default re_set method, for typical hardware or software
14500 breakpoints. Reevaluate the breakpoint and recreate its
14504 breakpoint_re_set_default (struct breakpoint
*b
)
14507 struct symtabs_and_lines sals
, sals_end
;
14508 struct symtabs_and_lines expanded
= {0};
14509 struct symtabs_and_lines expanded_end
= {0};
14510 struct program_space
*filter_pspace
= current_program_space
;
14512 sals
= location_to_sals (b
, b
->location
, filter_pspace
, &found
);
14515 make_cleanup (xfree
, sals
.sals
);
14519 if (b
->location_range_end
!= NULL
)
14521 sals_end
= location_to_sals (b
, b
->location_range_end
,
14522 filter_pspace
, &found
);
14525 make_cleanup (xfree
, sals_end
.sals
);
14526 expanded_end
= sals_end
;
14530 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14533 /* Default method for creating SALs from an address string. It basically
14534 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14537 create_sals_from_location_default (const struct event_location
*location
,
14538 struct linespec_result
*canonical
,
14539 enum bptype type_wanted
)
14541 parse_breakpoint_sals (location
, canonical
);
14544 /* Call create_breakpoints_sal for the given arguments. This is the default
14545 function for the `create_breakpoints_sal' method of
14549 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14550 struct linespec_result
*canonical
,
14552 char *extra_string
,
14553 enum bptype type_wanted
,
14554 enum bpdisp disposition
,
14556 int task
, int ignore_count
,
14557 const struct breakpoint_ops
*ops
,
14558 int from_tty
, int enabled
,
14559 int internal
, unsigned flags
)
14561 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14563 type_wanted
, disposition
,
14564 thread
, task
, ignore_count
, ops
, from_tty
,
14565 enabled
, internal
, flags
);
14568 /* Decode the line represented by S by calling decode_line_full. This is the
14569 default function for the `decode_location' method of breakpoint_ops. */
14572 decode_location_default (struct breakpoint
*b
,
14573 const struct event_location
*location
,
14574 struct program_space
*search_pspace
,
14575 struct symtabs_and_lines
*sals
)
14577 struct linespec_result canonical
;
14579 init_linespec_result (&canonical
);
14580 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14581 (struct symtab
*) NULL
, 0,
14582 &canonical
, multiple_symbols_all
,
14585 /* We should get 0 or 1 resulting SALs. */
14586 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14588 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14590 struct linespec_sals
*lsal
;
14592 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14593 *sals
= lsal
->sals
;
14594 /* Arrange it so the destructor does not free the
14596 lsal
->sals
.sals
= NULL
;
14599 destroy_linespec_result (&canonical
);
14602 /* Prepare the global context for a re-set of breakpoint B. */
14604 static struct cleanup
*
14605 prepare_re_set_context (struct breakpoint
*b
)
14607 input_radix
= b
->input_radix
;
14608 set_language (b
->language
);
14610 return make_cleanup (null_cleanup
, NULL
);
14613 /* Reset a breakpoint given it's struct breakpoint * BINT.
14614 The value we return ends up being the return value from catch_errors.
14615 Unused in this case. */
14618 breakpoint_re_set_one (void *bint
)
14620 /* Get past catch_errs. */
14621 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14622 struct cleanup
*cleanups
;
14624 cleanups
= prepare_re_set_context (b
);
14625 b
->ops
->re_set (b
);
14626 do_cleanups (cleanups
);
14630 /* Re-set breakpoint locations for the current program space.
14631 Locations bound to other program spaces are left untouched. */
14634 breakpoint_re_set (void)
14636 struct breakpoint
*b
, *b_tmp
;
14637 enum language save_language
;
14638 int save_input_radix
;
14639 struct cleanup
*old_chain
;
14641 save_language
= current_language
->la_language
;
14642 save_input_radix
= input_radix
;
14643 old_chain
= save_current_space_and_thread ();
14645 /* Note: we must not try to insert locations until after all
14646 breakpoints have been re-set. Otherwise, e.g., when re-setting
14647 breakpoint 1, we'd insert the locations of breakpoint 2, which
14648 hadn't been re-set yet, and thus may have stale locations. */
14650 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14652 /* Format possible error msg. */
14653 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14655 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14656 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14657 do_cleanups (cleanups
);
14659 set_language (save_language
);
14660 input_radix
= save_input_radix
;
14662 jit_breakpoint_re_set ();
14664 do_cleanups (old_chain
);
14666 create_overlay_event_breakpoint ();
14667 create_longjmp_master_breakpoint ();
14668 create_std_terminate_master_breakpoint ();
14669 create_exception_master_breakpoint ();
14671 /* Now we can insert. */
14672 update_global_location_list (UGLL_MAY_INSERT
);
14675 /* Reset the thread number of this breakpoint:
14677 - If the breakpoint is for all threads, leave it as-is.
14678 - Else, reset it to the current thread for inferior_ptid. */
14680 breakpoint_re_set_thread (struct breakpoint
*b
)
14682 if (b
->thread
!= -1)
14684 if (in_thread_list (inferior_ptid
))
14685 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14687 /* We're being called after following a fork. The new fork is
14688 selected as current, and unless this was a vfork will have a
14689 different program space from the original thread. Reset that
14691 b
->loc
->pspace
= current_program_space
;
14695 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14696 If from_tty is nonzero, it prints a message to that effect,
14697 which ends with a period (no newline). */
14700 set_ignore_count (int bptnum
, int count
, int from_tty
)
14702 struct breakpoint
*b
;
14707 ALL_BREAKPOINTS (b
)
14708 if (b
->number
== bptnum
)
14710 if (is_tracepoint (b
))
14712 if (from_tty
&& count
!= 0)
14713 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14718 b
->ignore_count
= count
;
14722 printf_filtered (_("Will stop next time "
14723 "breakpoint %d is reached."),
14725 else if (count
== 1)
14726 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14729 printf_filtered (_("Will ignore next %d "
14730 "crossings of breakpoint %d."),
14733 observer_notify_breakpoint_modified (b
);
14737 error (_("No breakpoint number %d."), bptnum
);
14740 /* Command to set ignore-count of breakpoint N to COUNT. */
14743 ignore_command (char *args
, int from_tty
)
14749 error_no_arg (_("a breakpoint number"));
14751 num
= get_number (&p
);
14753 error (_("bad breakpoint number: '%s'"), args
);
14755 error (_("Second argument (specified ignore-count) is missing."));
14757 set_ignore_count (num
,
14758 longest_to_int (value_as_long (parse_and_eval (p
))),
14761 printf_filtered ("\n");
14764 /* Call FUNCTION on each of the breakpoints
14765 whose numbers are given in ARGS. */
14768 map_breakpoint_numbers (const char *args
,
14769 void (*function
) (struct breakpoint
*,
14774 struct breakpoint
*b
, *tmp
;
14776 if (args
== 0 || *args
== '\0')
14777 error_no_arg (_("one or more breakpoint numbers"));
14779 number_or_range_parser
parser (args
);
14781 while (!parser
.finished ())
14783 const char *p
= parser
.cur_tok ();
14784 bool match
= false;
14786 num
= parser
.get_number ();
14789 warning (_("bad breakpoint number at or near '%s'"), p
);
14793 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14794 if (b
->number
== num
)
14797 function (b
, data
);
14801 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14806 static struct bp_location
*
14807 find_location_by_number (char *number
)
14809 char *dot
= strchr (number
, '.');
14813 struct breakpoint
*b
;
14814 struct bp_location
*loc
;
14819 bp_num
= get_number (&p1
);
14821 error (_("Bad breakpoint number '%s'"), number
);
14823 ALL_BREAKPOINTS (b
)
14824 if (b
->number
== bp_num
)
14829 if (!b
|| b
->number
!= bp_num
)
14830 error (_("Bad breakpoint number '%s'"), number
);
14833 loc_num
= get_number (&p1
);
14835 error (_("Bad breakpoint location number '%s'"), number
);
14839 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14842 error (_("Bad breakpoint location number '%s'"), dot
+1);
14848 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14849 If from_tty is nonzero, it prints a message to that effect,
14850 which ends with a period (no newline). */
14853 disable_breakpoint (struct breakpoint
*bpt
)
14855 /* Never disable a watchpoint scope breakpoint; we want to
14856 hit them when we leave scope so we can delete both the
14857 watchpoint and its scope breakpoint at that time. */
14858 if (bpt
->type
== bp_watchpoint_scope
)
14861 bpt
->enable_state
= bp_disabled
;
14863 /* Mark breakpoint locations modified. */
14864 mark_breakpoint_modified (bpt
);
14866 if (target_supports_enable_disable_tracepoint ()
14867 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14869 struct bp_location
*location
;
14871 for (location
= bpt
->loc
; location
; location
= location
->next
)
14872 target_disable_tracepoint (location
);
14875 update_global_location_list (UGLL_DONT_INSERT
);
14877 observer_notify_breakpoint_modified (bpt
);
14880 /* A callback for iterate_over_related_breakpoints. */
14883 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14885 disable_breakpoint (b
);
14888 /* A callback for map_breakpoint_numbers that calls
14889 disable_breakpoint. */
14892 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14894 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14898 disable_command (char *args
, int from_tty
)
14902 struct breakpoint
*bpt
;
14904 ALL_BREAKPOINTS (bpt
)
14905 if (user_breakpoint_p (bpt
))
14906 disable_breakpoint (bpt
);
14910 char *num
= extract_arg (&args
);
14914 if (strchr (num
, '.'))
14916 struct bp_location
*loc
= find_location_by_number (num
);
14923 mark_breakpoint_location_modified (loc
);
14925 if (target_supports_enable_disable_tracepoint ()
14926 && current_trace_status ()->running
&& loc
->owner
14927 && is_tracepoint (loc
->owner
))
14928 target_disable_tracepoint (loc
);
14930 update_global_location_list (UGLL_DONT_INSERT
);
14933 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14934 num
= extract_arg (&args
);
14940 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14943 int target_resources_ok
;
14945 if (bpt
->type
== bp_hardware_breakpoint
)
14948 i
= hw_breakpoint_used_count ();
14949 target_resources_ok
=
14950 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14952 if (target_resources_ok
== 0)
14953 error (_("No hardware breakpoint support in the target."));
14954 else if (target_resources_ok
< 0)
14955 error (_("Hardware breakpoints used exceeds limit."));
14958 if (is_watchpoint (bpt
))
14960 /* Initialize it just to avoid a GCC false warning. */
14961 enum enable_state orig_enable_state
= bp_disabled
;
14965 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14967 orig_enable_state
= bpt
->enable_state
;
14968 bpt
->enable_state
= bp_enabled
;
14969 update_watchpoint (w
, 1 /* reparse */);
14971 CATCH (e
, RETURN_MASK_ALL
)
14973 bpt
->enable_state
= orig_enable_state
;
14974 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14981 bpt
->enable_state
= bp_enabled
;
14983 /* Mark breakpoint locations modified. */
14984 mark_breakpoint_modified (bpt
);
14986 if (target_supports_enable_disable_tracepoint ()
14987 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14989 struct bp_location
*location
;
14991 for (location
= bpt
->loc
; location
; location
= location
->next
)
14992 target_enable_tracepoint (location
);
14995 bpt
->disposition
= disposition
;
14996 bpt
->enable_count
= count
;
14997 update_global_location_list (UGLL_MAY_INSERT
);
14999 observer_notify_breakpoint_modified (bpt
);
15004 enable_breakpoint (struct breakpoint
*bpt
)
15006 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15010 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15012 enable_breakpoint (bpt
);
15015 /* A callback for map_breakpoint_numbers that calls
15016 enable_breakpoint. */
15019 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15021 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15024 /* The enable command enables the specified breakpoints (or all defined
15025 breakpoints) so they once again become (or continue to be) effective
15026 in stopping the inferior. */
15029 enable_command (char *args
, int from_tty
)
15033 struct breakpoint
*bpt
;
15035 ALL_BREAKPOINTS (bpt
)
15036 if (user_breakpoint_p (bpt
))
15037 enable_breakpoint (bpt
);
15041 char *num
= extract_arg (&args
);
15045 if (strchr (num
, '.'))
15047 struct bp_location
*loc
= find_location_by_number (num
);
15054 mark_breakpoint_location_modified (loc
);
15056 if (target_supports_enable_disable_tracepoint ()
15057 && current_trace_status ()->running
&& loc
->owner
15058 && is_tracepoint (loc
->owner
))
15059 target_enable_tracepoint (loc
);
15061 update_global_location_list (UGLL_MAY_INSERT
);
15064 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15065 num
= extract_arg (&args
);
15070 /* This struct packages up disposition data for application to multiple
15080 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15082 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15084 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15088 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15090 struct disp_data disp
= { disp_disable
, 1 };
15092 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15096 enable_once_command (char *args
, int from_tty
)
15098 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15102 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15104 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15106 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15110 enable_count_command (char *args
, int from_tty
)
15115 error_no_arg (_("hit count"));
15117 count
= get_number (&args
);
15119 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15123 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15125 struct disp_data disp
= { disp_del
, 1 };
15127 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15131 enable_delete_command (char *args
, int from_tty
)
15133 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15137 set_breakpoint_cmd (char *args
, int from_tty
)
15142 show_breakpoint_cmd (char *args
, int from_tty
)
15146 /* Invalidate last known value of any hardware watchpoint if
15147 the memory which that value represents has been written to by
15151 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15152 CORE_ADDR addr
, ssize_t len
,
15153 const bfd_byte
*data
)
15155 struct breakpoint
*bp
;
15157 ALL_BREAKPOINTS (bp
)
15158 if (bp
->enable_state
== bp_enabled
15159 && bp
->type
== bp_hardware_watchpoint
)
15161 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15163 if (wp
->val_valid
&& wp
->val
)
15165 struct bp_location
*loc
;
15167 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15168 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15169 && loc
->address
+ loc
->length
> addr
15170 && addr
+ len
> loc
->address
)
15172 value_free (wp
->val
);
15180 /* Create and insert a breakpoint for software single step. */
15183 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15184 struct address_space
*aspace
,
15187 struct thread_info
*tp
= inferior_thread ();
15188 struct symtab_and_line sal
;
15189 CORE_ADDR pc
= next_pc
;
15191 if (tp
->control
.single_step_breakpoints
== NULL
)
15193 tp
->control
.single_step_breakpoints
15194 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15197 sal
= find_pc_line (pc
, 0);
15199 sal
.section
= find_pc_overlay (pc
);
15200 sal
.explicit_pc
= 1;
15201 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15203 update_global_location_list (UGLL_INSERT
);
15206 /* Insert single step breakpoints according to the current state. */
15209 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
15211 struct frame_info
*frame
= get_current_frame ();
15212 VEC (CORE_ADDR
) * next_pcs
;
15214 next_pcs
= gdbarch_software_single_step (gdbarch
, frame
);
15216 if (next_pcs
!= NULL
)
15220 struct address_space
*aspace
= get_frame_address_space (frame
);
15222 for (i
= 0; VEC_iterate (CORE_ADDR
, next_pcs
, i
, pc
); i
++)
15223 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
15225 VEC_free (CORE_ADDR
, next_pcs
);
15233 /* See breakpoint.h. */
15236 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15237 struct address_space
*aspace
,
15240 struct bp_location
*loc
;
15242 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15244 && breakpoint_location_address_match (loc
, aspace
, pc
))
15250 /* Check whether a software single-step breakpoint is inserted at
15254 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15257 struct breakpoint
*bpt
;
15259 ALL_BREAKPOINTS (bpt
)
15261 if (bpt
->type
== bp_single_step
15262 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15268 /* Tracepoint-specific operations. */
15270 /* Set tracepoint count to NUM. */
15272 set_tracepoint_count (int num
)
15274 tracepoint_count
= num
;
15275 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15279 trace_command (char *arg
, int from_tty
)
15281 struct breakpoint_ops
*ops
;
15282 struct event_location
*location
;
15283 struct cleanup
*back_to
;
15285 location
= string_to_event_location (&arg
, current_language
);
15286 back_to
= make_cleanup_delete_event_location (location
);
15287 if (location
!= NULL
15288 && event_location_type (location
) == PROBE_LOCATION
)
15289 ops
= &tracepoint_probe_breakpoint_ops
;
15291 ops
= &tracepoint_breakpoint_ops
;
15293 create_breakpoint (get_current_arch (),
15295 NULL
, 0, arg
, 1 /* parse arg */,
15297 bp_tracepoint
/* type_wanted */,
15298 0 /* Ignore count */,
15299 pending_break_support
,
15303 0 /* internal */, 0);
15304 do_cleanups (back_to
);
15308 ftrace_command (char *arg
, int from_tty
)
15310 struct event_location
*location
;
15311 struct cleanup
*back_to
;
15313 location
= string_to_event_location (&arg
, current_language
);
15314 back_to
= make_cleanup_delete_event_location (location
);
15315 create_breakpoint (get_current_arch (),
15317 NULL
, 0, arg
, 1 /* parse arg */,
15319 bp_fast_tracepoint
/* type_wanted */,
15320 0 /* Ignore count */,
15321 pending_break_support
,
15322 &tracepoint_breakpoint_ops
,
15325 0 /* internal */, 0);
15326 do_cleanups (back_to
);
15329 /* strace command implementation. Creates a static tracepoint. */
15332 strace_command (char *arg
, int from_tty
)
15334 struct breakpoint_ops
*ops
;
15335 struct event_location
*location
;
15336 struct cleanup
*back_to
;
15338 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15339 or with a normal static tracepoint. */
15340 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15342 ops
= &strace_marker_breakpoint_ops
;
15343 location
= new_linespec_location (&arg
);
15347 ops
= &tracepoint_breakpoint_ops
;
15348 location
= string_to_event_location (&arg
, current_language
);
15351 back_to
= make_cleanup_delete_event_location (location
);
15352 create_breakpoint (get_current_arch (),
15354 NULL
, 0, arg
, 1 /* parse arg */,
15356 bp_static_tracepoint
/* type_wanted */,
15357 0 /* Ignore count */,
15358 pending_break_support
,
15362 0 /* internal */, 0);
15363 do_cleanups (back_to
);
15366 /* Set up a fake reader function that gets command lines from a linked
15367 list that was acquired during tracepoint uploading. */
15369 static struct uploaded_tp
*this_utp
;
15370 static int next_cmd
;
15373 read_uploaded_action (void)
15377 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15384 /* Given information about a tracepoint as recorded on a target (which
15385 can be either a live system or a trace file), attempt to create an
15386 equivalent GDB tracepoint. This is not a reliable process, since
15387 the target does not necessarily have all the information used when
15388 the tracepoint was originally defined. */
15390 struct tracepoint
*
15391 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15393 char *addr_str
, small_buf
[100];
15394 struct tracepoint
*tp
;
15395 struct event_location
*location
;
15396 struct cleanup
*cleanup
;
15398 if (utp
->at_string
)
15399 addr_str
= utp
->at_string
;
15402 /* In the absence of a source location, fall back to raw
15403 address. Since there is no way to confirm that the address
15404 means the same thing as when the trace was started, warn the
15406 warning (_("Uploaded tracepoint %d has no "
15407 "source location, using raw address"),
15409 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15410 addr_str
= small_buf
;
15413 /* There's not much we can do with a sequence of bytecodes. */
15414 if (utp
->cond
&& !utp
->cond_string
)
15415 warning (_("Uploaded tracepoint %d condition "
15416 "has no source form, ignoring it"),
15419 location
= string_to_event_location (&addr_str
, current_language
);
15420 cleanup
= make_cleanup_delete_event_location (location
);
15421 if (!create_breakpoint (get_current_arch (),
15423 utp
->cond_string
, -1, addr_str
,
15424 0 /* parse cond/thread */,
15426 utp
->type
/* type_wanted */,
15427 0 /* Ignore count */,
15428 pending_break_support
,
15429 &tracepoint_breakpoint_ops
,
15431 utp
->enabled
/* enabled */,
15433 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15435 do_cleanups (cleanup
);
15439 do_cleanups (cleanup
);
15441 /* Get the tracepoint we just created. */
15442 tp
= get_tracepoint (tracepoint_count
);
15443 gdb_assert (tp
!= NULL
);
15447 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15450 trace_pass_command (small_buf
, 0);
15453 /* If we have uploaded versions of the original commands, set up a
15454 special-purpose "reader" function and call the usual command line
15455 reader, then pass the result to the breakpoint command-setting
15457 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15459 struct command_line
*cmd_list
;
15464 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15466 breakpoint_set_commands (&tp
->base
, cmd_list
);
15468 else if (!VEC_empty (char_ptr
, utp
->actions
)
15469 || !VEC_empty (char_ptr
, utp
->step_actions
))
15470 warning (_("Uploaded tracepoint %d actions "
15471 "have no source form, ignoring them"),
15474 /* Copy any status information that might be available. */
15475 tp
->base
.hit_count
= utp
->hit_count
;
15476 tp
->traceframe_usage
= utp
->traceframe_usage
;
15481 /* Print information on tracepoint number TPNUM_EXP, or all if
15485 tracepoints_info (char *args
, int from_tty
)
15487 struct ui_out
*uiout
= current_uiout
;
15490 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15492 if (num_printed
== 0)
15494 if (args
== NULL
|| *args
== '\0')
15495 ui_out_message (uiout
, 0, "No tracepoints.\n");
15497 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15500 default_collect_info ();
15503 /* The 'enable trace' command enables tracepoints.
15504 Not supported by all targets. */
15506 enable_trace_command (char *args
, int from_tty
)
15508 enable_command (args
, from_tty
);
15511 /* The 'disable trace' command disables tracepoints.
15512 Not supported by all targets. */
15514 disable_trace_command (char *args
, int from_tty
)
15516 disable_command (args
, from_tty
);
15519 /* Remove a tracepoint (or all if no argument). */
15521 delete_trace_command (char *arg
, int from_tty
)
15523 struct breakpoint
*b
, *b_tmp
;
15529 int breaks_to_delete
= 0;
15531 /* Delete all breakpoints if no argument.
15532 Do not delete internal or call-dummy breakpoints, these
15533 have to be deleted with an explicit breakpoint number
15535 ALL_TRACEPOINTS (b
)
15536 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15538 breaks_to_delete
= 1;
15542 /* Ask user only if there are some breakpoints to delete. */
15544 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15546 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15547 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15548 delete_breakpoint (b
);
15552 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15555 /* Helper function for trace_pass_command. */
15558 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15560 tp
->pass_count
= count
;
15561 observer_notify_breakpoint_modified (&tp
->base
);
15563 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15564 tp
->base
.number
, count
);
15567 /* Set passcount for tracepoint.
15569 First command argument is passcount, second is tracepoint number.
15570 If tracepoint number omitted, apply to most recently defined.
15571 Also accepts special argument "all". */
15574 trace_pass_command (char *args
, int from_tty
)
15576 struct tracepoint
*t1
;
15577 unsigned int count
;
15579 if (args
== 0 || *args
== 0)
15580 error (_("passcount command requires an "
15581 "argument (count + optional TP num)"));
15583 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15585 args
= skip_spaces (args
);
15586 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15588 struct breakpoint
*b
;
15590 args
+= 3; /* Skip special argument "all". */
15592 error (_("Junk at end of arguments."));
15594 ALL_TRACEPOINTS (b
)
15596 t1
= (struct tracepoint
*) b
;
15597 trace_pass_set_count (t1
, count
, from_tty
);
15600 else if (*args
== '\0')
15602 t1
= get_tracepoint_by_number (&args
, NULL
);
15604 trace_pass_set_count (t1
, count
, from_tty
);
15608 number_or_range_parser
parser (args
);
15609 while (!parser
.finished ())
15611 t1
= get_tracepoint_by_number (&args
, &parser
);
15613 trace_pass_set_count (t1
, count
, from_tty
);
15618 struct tracepoint
*
15619 get_tracepoint (int num
)
15621 struct breakpoint
*t
;
15623 ALL_TRACEPOINTS (t
)
15624 if (t
->number
== num
)
15625 return (struct tracepoint
*) t
;
15630 /* Find the tracepoint with the given target-side number (which may be
15631 different from the tracepoint number after disconnecting and
15634 struct tracepoint
*
15635 get_tracepoint_by_number_on_target (int num
)
15637 struct breakpoint
*b
;
15639 ALL_TRACEPOINTS (b
)
15641 struct tracepoint
*t
= (struct tracepoint
*) b
;
15643 if (t
->number_on_target
== num
)
15650 /* Utility: parse a tracepoint number and look it up in the list.
15651 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15652 If the argument is missing, the most recent tracepoint
15653 (tracepoint_count) is returned. */
15655 struct tracepoint
*
15656 get_tracepoint_by_number (char **arg
,
15657 number_or_range_parser
*parser
)
15659 struct breakpoint
*t
;
15661 char *instring
= arg
== NULL
? NULL
: *arg
;
15663 if (parser
!= NULL
)
15665 gdb_assert (!parser
->finished ());
15666 tpnum
= parser
->get_number ();
15668 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15669 tpnum
= tracepoint_count
;
15671 tpnum
= get_number (arg
);
15675 if (instring
&& *instring
)
15676 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15679 printf_filtered (_("No previous tracepoint\n"));
15683 ALL_TRACEPOINTS (t
)
15684 if (t
->number
== tpnum
)
15686 return (struct tracepoint
*) t
;
15689 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15694 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15696 if (b
->thread
!= -1)
15697 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15700 fprintf_unfiltered (fp
, " task %d", b
->task
);
15702 fprintf_unfiltered (fp
, "\n");
15705 /* Save information on user settable breakpoints (watchpoints, etc) to
15706 a new script file named FILENAME. If FILTER is non-NULL, call it
15707 on each breakpoint and only include the ones for which it returns
15711 save_breakpoints (char *filename
, int from_tty
,
15712 int (*filter
) (const struct breakpoint
*))
15714 struct breakpoint
*tp
;
15716 struct cleanup
*cleanup
;
15717 struct ui_file
*fp
;
15718 int extra_trace_bits
= 0;
15720 if (filename
== 0 || *filename
== 0)
15721 error (_("Argument required (file name in which to save)"));
15723 /* See if we have anything to save. */
15724 ALL_BREAKPOINTS (tp
)
15726 /* Skip internal and momentary breakpoints. */
15727 if (!user_breakpoint_p (tp
))
15730 /* If we have a filter, only save the breakpoints it accepts. */
15731 if (filter
&& !filter (tp
))
15736 if (is_tracepoint (tp
))
15738 extra_trace_bits
= 1;
15740 /* We can stop searching. */
15747 warning (_("Nothing to save."));
15751 filename
= tilde_expand (filename
);
15752 cleanup
= make_cleanup (xfree
, filename
);
15753 fp
= gdb_fopen (filename
, "w");
15755 error (_("Unable to open file '%s' for saving (%s)"),
15756 filename
, safe_strerror (errno
));
15757 make_cleanup_ui_file_delete (fp
);
15759 if (extra_trace_bits
)
15760 save_trace_state_variables (fp
);
15762 ALL_BREAKPOINTS (tp
)
15764 /* Skip internal and momentary breakpoints. */
15765 if (!user_breakpoint_p (tp
))
15768 /* If we have a filter, only save the breakpoints it accepts. */
15769 if (filter
&& !filter (tp
))
15772 tp
->ops
->print_recreate (tp
, fp
);
15774 /* Note, we can't rely on tp->number for anything, as we can't
15775 assume the recreated breakpoint numbers will match. Use $bpnum
15778 if (tp
->cond_string
)
15779 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15781 if (tp
->ignore_count
)
15782 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15784 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15786 fprintf_unfiltered (fp
, " commands\n");
15788 ui_out_redirect (current_uiout
, fp
);
15791 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15793 CATCH (ex
, RETURN_MASK_ALL
)
15795 ui_out_redirect (current_uiout
, NULL
);
15796 throw_exception (ex
);
15800 ui_out_redirect (current_uiout
, NULL
);
15801 fprintf_unfiltered (fp
, " end\n");
15804 if (tp
->enable_state
== bp_disabled
)
15805 fprintf_unfiltered (fp
, "disable $bpnum\n");
15807 /* If this is a multi-location breakpoint, check if the locations
15808 should be individually disabled. Watchpoint locations are
15809 special, and not user visible. */
15810 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15812 struct bp_location
*loc
;
15815 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15817 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15821 if (extra_trace_bits
&& *default_collect
)
15822 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15825 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15826 do_cleanups (cleanup
);
15829 /* The `save breakpoints' command. */
15832 save_breakpoints_command (char *args
, int from_tty
)
15834 save_breakpoints (args
, from_tty
, NULL
);
15837 /* The `save tracepoints' command. */
15840 save_tracepoints_command (char *args
, int from_tty
)
15842 save_breakpoints (args
, from_tty
, is_tracepoint
);
15845 /* Create a vector of all tracepoints. */
15847 VEC(breakpoint_p
) *
15848 all_tracepoints (void)
15850 VEC(breakpoint_p
) *tp_vec
= 0;
15851 struct breakpoint
*tp
;
15853 ALL_TRACEPOINTS (tp
)
15855 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15862 /* This help string is used to consolidate all the help string for specifying
15863 locations used by several commands. */
15865 #define LOCATION_HELP_STRING \
15866 "Linespecs are colon-separated lists of location parameters, such as\n\
15867 source filename, function name, label name, and line number.\n\
15868 Example: To specify the start of a label named \"the_top\" in the\n\
15869 function \"fact\" in the file \"factorial.c\", use\n\
15870 \"factorial.c:fact:the_top\".\n\
15872 Address locations begin with \"*\" and specify an exact address in the\n\
15873 program. Example: To specify the fourth byte past the start function\n\
15874 \"main\", use \"*main + 4\".\n\
15876 Explicit locations are similar to linespecs but use an option/argument\n\
15877 syntax to specify location parameters.\n\
15878 Example: To specify the start of the label named \"the_top\" in the\n\
15879 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15880 -function fact -label the_top\".\n"
15882 /* This help string is used for the break, hbreak, tbreak and thbreak
15883 commands. It is defined as a macro to prevent duplication.
15884 COMMAND should be a string constant containing the name of the
15887 #define BREAK_ARGS_HELP(command) \
15888 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15889 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15890 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15891 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15892 `-probe-dtrace' (for a DTrace probe).\n\
15893 LOCATION may be a linespec, address, or explicit location as described\n\
15896 With no LOCATION, uses current execution address of the selected\n\
15897 stack frame. This is useful for breaking on return to a stack frame.\n\
15899 THREADNUM is the number from \"info threads\".\n\
15900 CONDITION is a boolean expression.\n\
15901 \n" LOCATION_HELP_STRING "\n\
15902 Multiple breakpoints at one place are permitted, and useful if their\n\
15903 conditions are different.\n\
15905 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15907 /* List of subcommands for "catch". */
15908 static struct cmd_list_element
*catch_cmdlist
;
15910 /* List of subcommands for "tcatch". */
15911 static struct cmd_list_element
*tcatch_cmdlist
;
15914 add_catch_command (char *name
, char *docstring
,
15915 cmd_sfunc_ftype
*sfunc
,
15916 completer_ftype
*completer
,
15917 void *user_data_catch
,
15918 void *user_data_tcatch
)
15920 struct cmd_list_element
*command
;
15922 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15924 set_cmd_sfunc (command
, sfunc
);
15925 set_cmd_context (command
, user_data_catch
);
15926 set_cmd_completer (command
, completer
);
15928 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15930 set_cmd_sfunc (command
, sfunc
);
15931 set_cmd_context (command
, user_data_tcatch
);
15932 set_cmd_completer (command
, completer
);
15936 save_command (char *arg
, int from_tty
)
15938 printf_unfiltered (_("\"save\" must be followed by "
15939 "the name of a save subcommand.\n"));
15940 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15943 struct breakpoint
*
15944 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15947 struct breakpoint
*b
, *b_tmp
;
15949 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15951 if ((*callback
) (b
, data
))
15958 /* Zero if any of the breakpoint's locations could be a location where
15959 functions have been inlined, nonzero otherwise. */
15962 is_non_inline_function (struct breakpoint
*b
)
15964 /* The shared library event breakpoint is set on the address of a
15965 non-inline function. */
15966 if (b
->type
== bp_shlib_event
)
15972 /* Nonzero if the specified PC cannot be a location where functions
15973 have been inlined. */
15976 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15977 const struct target_waitstatus
*ws
)
15979 struct breakpoint
*b
;
15980 struct bp_location
*bl
;
15982 ALL_BREAKPOINTS (b
)
15984 if (!is_non_inline_function (b
))
15987 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15989 if (!bl
->shlib_disabled
15990 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15998 /* Remove any references to OBJFILE which is going to be freed. */
16001 breakpoint_free_objfile (struct objfile
*objfile
)
16003 struct bp_location
**locp
, *loc
;
16005 ALL_BP_LOCATIONS (loc
, locp
)
16006 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
16007 loc
->symtab
= NULL
;
16011 initialize_breakpoint_ops (void)
16013 static int initialized
= 0;
16015 struct breakpoint_ops
*ops
;
16021 /* The breakpoint_ops structure to be inherit by all kinds of
16022 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16023 internal and momentary breakpoints, etc.). */
16024 ops
= &bkpt_base_breakpoint_ops
;
16025 *ops
= base_breakpoint_ops
;
16026 ops
->re_set
= bkpt_re_set
;
16027 ops
->insert_location
= bkpt_insert_location
;
16028 ops
->remove_location
= bkpt_remove_location
;
16029 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16030 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
16031 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16032 ops
->decode_location
= bkpt_decode_location
;
16034 /* The breakpoint_ops structure to be used in regular breakpoints. */
16035 ops
= &bkpt_breakpoint_ops
;
16036 *ops
= bkpt_base_breakpoint_ops
;
16037 ops
->re_set
= bkpt_re_set
;
16038 ops
->resources_needed
= bkpt_resources_needed
;
16039 ops
->print_it
= bkpt_print_it
;
16040 ops
->print_mention
= bkpt_print_mention
;
16041 ops
->print_recreate
= bkpt_print_recreate
;
16043 /* Ranged breakpoints. */
16044 ops
= &ranged_breakpoint_ops
;
16045 *ops
= bkpt_breakpoint_ops
;
16046 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16047 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16048 ops
->print_it
= print_it_ranged_breakpoint
;
16049 ops
->print_one
= print_one_ranged_breakpoint
;
16050 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16051 ops
->print_mention
= print_mention_ranged_breakpoint
;
16052 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16054 /* Internal breakpoints. */
16055 ops
= &internal_breakpoint_ops
;
16056 *ops
= bkpt_base_breakpoint_ops
;
16057 ops
->re_set
= internal_bkpt_re_set
;
16058 ops
->check_status
= internal_bkpt_check_status
;
16059 ops
->print_it
= internal_bkpt_print_it
;
16060 ops
->print_mention
= internal_bkpt_print_mention
;
16062 /* Momentary breakpoints. */
16063 ops
= &momentary_breakpoint_ops
;
16064 *ops
= bkpt_base_breakpoint_ops
;
16065 ops
->re_set
= momentary_bkpt_re_set
;
16066 ops
->check_status
= momentary_bkpt_check_status
;
16067 ops
->print_it
= momentary_bkpt_print_it
;
16068 ops
->print_mention
= momentary_bkpt_print_mention
;
16070 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16071 ops
= &longjmp_breakpoint_ops
;
16072 *ops
= momentary_breakpoint_ops
;
16073 ops
->dtor
= longjmp_bkpt_dtor
;
16075 /* Probe breakpoints. */
16076 ops
= &bkpt_probe_breakpoint_ops
;
16077 *ops
= bkpt_breakpoint_ops
;
16078 ops
->insert_location
= bkpt_probe_insert_location
;
16079 ops
->remove_location
= bkpt_probe_remove_location
;
16080 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
16081 ops
->decode_location
= bkpt_probe_decode_location
;
16084 ops
= &watchpoint_breakpoint_ops
;
16085 *ops
= base_breakpoint_ops
;
16086 ops
->dtor
= dtor_watchpoint
;
16087 ops
->re_set
= re_set_watchpoint
;
16088 ops
->insert_location
= insert_watchpoint
;
16089 ops
->remove_location
= remove_watchpoint
;
16090 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16091 ops
->check_status
= check_status_watchpoint
;
16092 ops
->resources_needed
= resources_needed_watchpoint
;
16093 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16094 ops
->print_it
= print_it_watchpoint
;
16095 ops
->print_mention
= print_mention_watchpoint
;
16096 ops
->print_recreate
= print_recreate_watchpoint
;
16097 ops
->explains_signal
= explains_signal_watchpoint
;
16099 /* Masked watchpoints. */
16100 ops
= &masked_watchpoint_breakpoint_ops
;
16101 *ops
= watchpoint_breakpoint_ops
;
16102 ops
->insert_location
= insert_masked_watchpoint
;
16103 ops
->remove_location
= remove_masked_watchpoint
;
16104 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16105 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16106 ops
->print_it
= print_it_masked_watchpoint
;
16107 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16108 ops
->print_mention
= print_mention_masked_watchpoint
;
16109 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16112 ops
= &tracepoint_breakpoint_ops
;
16113 *ops
= base_breakpoint_ops
;
16114 ops
->re_set
= tracepoint_re_set
;
16115 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16116 ops
->print_one_detail
= tracepoint_print_one_detail
;
16117 ops
->print_mention
= tracepoint_print_mention
;
16118 ops
->print_recreate
= tracepoint_print_recreate
;
16119 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
16120 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16121 ops
->decode_location
= tracepoint_decode_location
;
16123 /* Probe tracepoints. */
16124 ops
= &tracepoint_probe_breakpoint_ops
;
16125 *ops
= tracepoint_breakpoint_ops
;
16126 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
16127 ops
->decode_location
= tracepoint_probe_decode_location
;
16129 /* Static tracepoints with marker (`-m'). */
16130 ops
= &strace_marker_breakpoint_ops
;
16131 *ops
= tracepoint_breakpoint_ops
;
16132 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16133 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16134 ops
->decode_location
= strace_marker_decode_location
;
16136 /* Fork catchpoints. */
16137 ops
= &catch_fork_breakpoint_ops
;
16138 *ops
= base_breakpoint_ops
;
16139 ops
->insert_location
= insert_catch_fork
;
16140 ops
->remove_location
= remove_catch_fork
;
16141 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16142 ops
->print_it
= print_it_catch_fork
;
16143 ops
->print_one
= print_one_catch_fork
;
16144 ops
->print_mention
= print_mention_catch_fork
;
16145 ops
->print_recreate
= print_recreate_catch_fork
;
16147 /* Vfork catchpoints. */
16148 ops
= &catch_vfork_breakpoint_ops
;
16149 *ops
= base_breakpoint_ops
;
16150 ops
->insert_location
= insert_catch_vfork
;
16151 ops
->remove_location
= remove_catch_vfork
;
16152 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16153 ops
->print_it
= print_it_catch_vfork
;
16154 ops
->print_one
= print_one_catch_vfork
;
16155 ops
->print_mention
= print_mention_catch_vfork
;
16156 ops
->print_recreate
= print_recreate_catch_vfork
;
16158 /* Exec catchpoints. */
16159 ops
= &catch_exec_breakpoint_ops
;
16160 *ops
= base_breakpoint_ops
;
16161 ops
->dtor
= dtor_catch_exec
;
16162 ops
->insert_location
= insert_catch_exec
;
16163 ops
->remove_location
= remove_catch_exec
;
16164 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16165 ops
->print_it
= print_it_catch_exec
;
16166 ops
->print_one
= print_one_catch_exec
;
16167 ops
->print_mention
= print_mention_catch_exec
;
16168 ops
->print_recreate
= print_recreate_catch_exec
;
16170 /* Solib-related catchpoints. */
16171 ops
= &catch_solib_breakpoint_ops
;
16172 *ops
= base_breakpoint_ops
;
16173 ops
->dtor
= dtor_catch_solib
;
16174 ops
->insert_location
= insert_catch_solib
;
16175 ops
->remove_location
= remove_catch_solib
;
16176 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16177 ops
->check_status
= check_status_catch_solib
;
16178 ops
->print_it
= print_it_catch_solib
;
16179 ops
->print_one
= print_one_catch_solib
;
16180 ops
->print_mention
= print_mention_catch_solib
;
16181 ops
->print_recreate
= print_recreate_catch_solib
;
16183 ops
= &dprintf_breakpoint_ops
;
16184 *ops
= bkpt_base_breakpoint_ops
;
16185 ops
->re_set
= dprintf_re_set
;
16186 ops
->resources_needed
= bkpt_resources_needed
;
16187 ops
->print_it
= bkpt_print_it
;
16188 ops
->print_mention
= bkpt_print_mention
;
16189 ops
->print_recreate
= dprintf_print_recreate
;
16190 ops
->after_condition_true
= dprintf_after_condition_true
;
16191 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16194 /* Chain containing all defined "enable breakpoint" subcommands. */
16196 static struct cmd_list_element
*enablebreaklist
= NULL
;
16199 _initialize_breakpoint (void)
16201 struct cmd_list_element
*c
;
16203 initialize_breakpoint_ops ();
16205 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16206 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16207 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16209 breakpoint_objfile_key
16210 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16212 breakpoint_chain
= 0;
16213 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16214 before a breakpoint is set. */
16215 breakpoint_count
= 0;
16217 tracepoint_count
= 0;
16219 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16220 Set ignore-count of breakpoint number N to COUNT.\n\
16221 Usage is `ignore N COUNT'."));
16223 add_com ("commands", class_breakpoint
, commands_command
, _("\
16224 Set commands to be executed when a breakpoint is hit.\n\
16225 Give breakpoint number as argument after \"commands\".\n\
16226 With no argument, the targeted breakpoint is the last one set.\n\
16227 The commands themselves follow starting on the next line.\n\
16228 Type a line containing \"end\" to indicate the end of them.\n\
16229 Give \"silent\" as the first line to make the breakpoint silent;\n\
16230 then no output is printed when it is hit, except what the commands print."));
16232 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16233 Specify breakpoint number N to break only if COND is true.\n\
16234 Usage is `condition N COND', where N is an integer and COND is an\n\
16235 expression to be evaluated whenever breakpoint N is reached."));
16236 set_cmd_completer (c
, condition_completer
);
16238 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16239 Set a temporary breakpoint.\n\
16240 Like \"break\" except the breakpoint is only temporary,\n\
16241 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16242 by using \"enable delete\" on the breakpoint number.\n\
16244 BREAK_ARGS_HELP ("tbreak")));
16245 set_cmd_completer (c
, location_completer
);
16247 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16248 Set a hardware assisted breakpoint.\n\
16249 Like \"break\" except the breakpoint requires hardware support,\n\
16250 some target hardware may not have this support.\n\
16252 BREAK_ARGS_HELP ("hbreak")));
16253 set_cmd_completer (c
, location_completer
);
16255 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16256 Set a temporary hardware assisted breakpoint.\n\
16257 Like \"hbreak\" except the breakpoint is only temporary,\n\
16258 so it will be deleted when hit.\n\
16260 BREAK_ARGS_HELP ("thbreak")));
16261 set_cmd_completer (c
, location_completer
);
16263 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16264 Enable some breakpoints.\n\
16265 Give breakpoint numbers (separated by spaces) as arguments.\n\
16266 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16267 This is used to cancel the effect of the \"disable\" command.\n\
16268 With a subcommand you can enable temporarily."),
16269 &enablelist
, "enable ", 1, &cmdlist
);
16271 add_com_alias ("en", "enable", class_breakpoint
, 1);
16273 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16274 Enable some breakpoints.\n\
16275 Give breakpoint numbers (separated by spaces) as arguments.\n\
16276 This is used to cancel the effect of the \"disable\" command.\n\
16277 May be abbreviated to simply \"enable\".\n"),
16278 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16280 add_cmd ("once", no_class
, enable_once_command
, _("\
16281 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16282 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16285 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16286 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16287 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16290 add_cmd ("count", no_class
, enable_count_command
, _("\
16291 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16292 If a breakpoint is hit while enabled in this fashion,\n\
16293 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16296 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16297 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16298 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16301 add_cmd ("once", no_class
, enable_once_command
, _("\
16302 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16303 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16306 add_cmd ("count", no_class
, enable_count_command
, _("\
16307 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16308 If a breakpoint is hit while enabled in this fashion,\n\
16309 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16312 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16313 Disable some breakpoints.\n\
16314 Arguments are breakpoint numbers with spaces in between.\n\
16315 To disable all breakpoints, give no argument.\n\
16316 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16317 &disablelist
, "disable ", 1, &cmdlist
);
16318 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16319 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16321 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16322 Disable some breakpoints.\n\
16323 Arguments are breakpoint numbers with spaces in between.\n\
16324 To disable all breakpoints, give no argument.\n\
16325 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16326 This command may be abbreviated \"disable\"."),
16329 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16330 Delete some breakpoints or auto-display expressions.\n\
16331 Arguments are breakpoint numbers with spaces in between.\n\
16332 To delete all breakpoints, give no argument.\n\
16334 Also a prefix command for deletion of other GDB objects.\n\
16335 The \"unset\" command is also an alias for \"delete\"."),
16336 &deletelist
, "delete ", 1, &cmdlist
);
16337 add_com_alias ("d", "delete", class_breakpoint
, 1);
16338 add_com_alias ("del", "delete", class_breakpoint
, 1);
16340 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16341 Delete some breakpoints or auto-display expressions.\n\
16342 Arguments are breakpoint numbers with spaces in between.\n\
16343 To delete all breakpoints, give no argument.\n\
16344 This command may be abbreviated \"delete\"."),
16347 add_com ("clear", class_breakpoint
, clear_command
, _("\
16348 Clear breakpoint at specified location.\n\
16349 Argument may be a linespec, explicit, or address location as described below.\n\
16351 With no argument, clears all breakpoints in the line that the selected frame\n\
16352 is executing in.\n"
16353 "\n" LOCATION_HELP_STRING
"\n\
16354 See also the \"delete\" command which clears breakpoints by number."));
16355 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16357 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16358 Set breakpoint at specified location.\n"
16359 BREAK_ARGS_HELP ("break")));
16360 set_cmd_completer (c
, location_completer
);
16362 add_com_alias ("b", "break", class_run
, 1);
16363 add_com_alias ("br", "break", class_run
, 1);
16364 add_com_alias ("bre", "break", class_run
, 1);
16365 add_com_alias ("brea", "break", class_run
, 1);
16369 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16370 Break in function/address or break at a line in the current file."),
16371 &stoplist
, "stop ", 1, &cmdlist
);
16372 add_cmd ("in", class_breakpoint
, stopin_command
,
16373 _("Break in function or address."), &stoplist
);
16374 add_cmd ("at", class_breakpoint
, stopat_command
,
16375 _("Break at a line in the current file."), &stoplist
);
16376 add_com ("status", class_info
, breakpoints_info
, _("\
16377 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16378 The \"Type\" column indicates one of:\n\
16379 \tbreakpoint - normal breakpoint\n\
16380 \twatchpoint - watchpoint\n\
16381 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16382 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16383 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16384 address and file/line number respectively.\n\
16386 Convenience variable \"$_\" and default examine address for \"x\"\n\
16387 are set to the address of the last breakpoint listed unless the command\n\
16388 is prefixed with \"server \".\n\n\
16389 Convenience variable \"$bpnum\" contains the number of the last\n\
16390 breakpoint set."));
16393 add_info ("breakpoints", breakpoints_info
, _("\
16394 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16395 The \"Type\" column indicates one of:\n\
16396 \tbreakpoint - normal breakpoint\n\
16397 \twatchpoint - watchpoint\n\
16398 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16399 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16400 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16401 address and file/line number respectively.\n\
16403 Convenience variable \"$_\" and default examine address for \"x\"\n\
16404 are set to the address of the last breakpoint listed unless the command\n\
16405 is prefixed with \"server \".\n\n\
16406 Convenience variable \"$bpnum\" contains the number of the last\n\
16407 breakpoint set."));
16409 add_info_alias ("b", "breakpoints", 1);
16411 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16412 Status of all breakpoints, or breakpoint number NUMBER.\n\
16413 The \"Type\" column indicates one of:\n\
16414 \tbreakpoint - normal breakpoint\n\
16415 \twatchpoint - watchpoint\n\
16416 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16417 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16418 \tuntil - internal breakpoint used by the \"until\" command\n\
16419 \tfinish - internal breakpoint used by the \"finish\" command\n\
16420 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16421 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16422 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16423 address and file/line number respectively.\n\
16425 Convenience variable \"$_\" and default examine address for \"x\"\n\
16426 are set to the address of the last breakpoint listed unless the command\n\
16427 is prefixed with \"server \".\n\n\
16428 Convenience variable \"$bpnum\" contains the number of the last\n\
16430 &maintenanceinfolist
);
16432 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16433 Set catchpoints to catch events."),
16434 &catch_cmdlist
, "catch ",
16435 0/*allow-unknown*/, &cmdlist
);
16437 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16438 Set temporary catchpoints to catch events."),
16439 &tcatch_cmdlist
, "tcatch ",
16440 0/*allow-unknown*/, &cmdlist
);
16442 add_catch_command ("fork", _("Catch calls to fork."),
16443 catch_fork_command_1
,
16445 (void *) (uintptr_t) catch_fork_permanent
,
16446 (void *) (uintptr_t) catch_fork_temporary
);
16447 add_catch_command ("vfork", _("Catch calls to vfork."),
16448 catch_fork_command_1
,
16450 (void *) (uintptr_t) catch_vfork_permanent
,
16451 (void *) (uintptr_t) catch_vfork_temporary
);
16452 add_catch_command ("exec", _("Catch calls to exec."),
16453 catch_exec_command_1
,
16457 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16458 Usage: catch load [REGEX]\n\
16459 If REGEX is given, only stop for libraries matching the regular expression."),
16460 catch_load_command_1
,
16464 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16465 Usage: catch unload [REGEX]\n\
16466 If REGEX is given, only stop for libraries matching the regular expression."),
16467 catch_unload_command_1
,
16472 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16473 Set a watchpoint for an expression.\n\
16474 Usage: watch [-l|-location] EXPRESSION\n\
16475 A watchpoint stops execution of your program whenever the value of\n\
16476 an expression changes.\n\
16477 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16478 the memory to which it refers."));
16479 set_cmd_completer (c
, expression_completer
);
16481 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16482 Set a read watchpoint for an expression.\n\
16483 Usage: rwatch [-l|-location] EXPRESSION\n\
16484 A watchpoint stops execution of your program whenever the value of\n\
16485 an expression is read.\n\
16486 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16487 the memory to which it refers."));
16488 set_cmd_completer (c
, expression_completer
);
16490 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16491 Set a watchpoint for an expression.\n\
16492 Usage: awatch [-l|-location] EXPRESSION\n\
16493 A watchpoint stops execution of your program whenever the value of\n\
16494 an expression is either read or written.\n\
16495 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16496 the memory to which it refers."));
16497 set_cmd_completer (c
, expression_completer
);
16499 add_info ("watchpoints", watchpoints_info
, _("\
16500 Status of specified watchpoints (all watchpoints if no argument)."));
16502 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16503 respond to changes - contrary to the description. */
16504 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16505 &can_use_hw_watchpoints
, _("\
16506 Set debugger's willingness to use watchpoint hardware."), _("\
16507 Show debugger's willingness to use watchpoint hardware."), _("\
16508 If zero, gdb will not use hardware for new watchpoints, even if\n\
16509 such is available. (However, any hardware watchpoints that were\n\
16510 created before setting this to nonzero, will continue to use watchpoint\n\
16513 show_can_use_hw_watchpoints
,
16514 &setlist
, &showlist
);
16516 can_use_hw_watchpoints
= 1;
16518 /* Tracepoint manipulation commands. */
16520 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16521 Set a tracepoint at specified location.\n\
16523 BREAK_ARGS_HELP ("trace") "\n\
16524 Do \"help tracepoints\" for info on other tracepoint commands."));
16525 set_cmd_completer (c
, location_completer
);
16527 add_com_alias ("tp", "trace", class_alias
, 0);
16528 add_com_alias ("tr", "trace", class_alias
, 1);
16529 add_com_alias ("tra", "trace", class_alias
, 1);
16530 add_com_alias ("trac", "trace", class_alias
, 1);
16532 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16533 Set a fast tracepoint at specified location.\n\
16535 BREAK_ARGS_HELP ("ftrace") "\n\
16536 Do \"help tracepoints\" for info on other tracepoint commands."));
16537 set_cmd_completer (c
, location_completer
);
16539 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16540 Set a static tracepoint at location or marker.\n\
16542 strace [LOCATION] [if CONDITION]\n\
16543 LOCATION may be a linespec, explicit, or address location (described below) \n\
16544 or -m MARKER_ID.\n\n\
16545 If a marker id is specified, probe the marker with that name. With\n\
16546 no LOCATION, uses current execution address of the selected stack frame.\n\
16547 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16548 This collects arbitrary user data passed in the probe point call to the\n\
16549 tracing library. You can inspect it when analyzing the trace buffer,\n\
16550 by printing the $_sdata variable like any other convenience variable.\n\
16552 CONDITION is a boolean expression.\n\
16553 \n" LOCATION_HELP_STRING
"\n\
16554 Multiple tracepoints at one place are permitted, and useful if their\n\
16555 conditions are different.\n\
16557 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16558 Do \"help tracepoints\" for info on other tracepoint commands."));
16559 set_cmd_completer (c
, location_completer
);
16561 add_info ("tracepoints", tracepoints_info
, _("\
16562 Status of specified tracepoints (all tracepoints if no argument).\n\
16563 Convenience variable \"$tpnum\" contains the number of the\n\
16564 last tracepoint set."));
16566 add_info_alias ("tp", "tracepoints", 1);
16568 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16569 Delete specified tracepoints.\n\
16570 Arguments are tracepoint numbers, separated by spaces.\n\
16571 No argument means delete all tracepoints."),
16573 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16575 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16576 Disable specified tracepoints.\n\
16577 Arguments are tracepoint numbers, separated by spaces.\n\
16578 No argument means disable all tracepoints."),
16580 deprecate_cmd (c
, "disable");
16582 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16583 Enable specified tracepoints.\n\
16584 Arguments are tracepoint numbers, separated by spaces.\n\
16585 No argument means enable all tracepoints."),
16587 deprecate_cmd (c
, "enable");
16589 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16590 Set the passcount for a tracepoint.\n\
16591 The trace will end when the tracepoint has been passed 'count' times.\n\
16592 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16593 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16595 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16596 _("Save breakpoint definitions as a script."),
16597 &save_cmdlist
, "save ",
16598 0/*allow-unknown*/, &cmdlist
);
16600 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16601 Save current breakpoint definitions as a script.\n\
16602 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16603 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16604 session to restore them."),
16606 set_cmd_completer (c
, filename_completer
);
16608 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16609 Save current tracepoint definitions as a script.\n\
16610 Use the 'source' command in another debug session to restore them."),
16612 set_cmd_completer (c
, filename_completer
);
16614 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16615 deprecate_cmd (c
, "save tracepoints");
16617 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16618 Breakpoint specific settings\n\
16619 Configure various breakpoint-specific variables such as\n\
16620 pending breakpoint behavior"),
16621 &breakpoint_set_cmdlist
, "set breakpoint ",
16622 0/*allow-unknown*/, &setlist
);
16623 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16624 Breakpoint specific settings\n\
16625 Configure various breakpoint-specific variables such as\n\
16626 pending breakpoint behavior"),
16627 &breakpoint_show_cmdlist
, "show breakpoint ",
16628 0/*allow-unknown*/, &showlist
);
16630 add_setshow_auto_boolean_cmd ("pending", no_class
,
16631 &pending_break_support
, _("\
16632 Set debugger's behavior regarding pending breakpoints."), _("\
16633 Show debugger's behavior regarding pending breakpoints."), _("\
16634 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16635 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16636 an error. If auto, an unrecognized breakpoint location results in a\n\
16637 user-query to see if a pending breakpoint should be created."),
16639 show_pending_break_support
,
16640 &breakpoint_set_cmdlist
,
16641 &breakpoint_show_cmdlist
);
16643 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16645 add_setshow_boolean_cmd ("auto-hw", no_class
,
16646 &automatic_hardware_breakpoints
, _("\
16647 Set automatic usage of hardware breakpoints."), _("\
16648 Show automatic usage of hardware breakpoints."), _("\
16649 If set, the debugger will automatically use hardware breakpoints for\n\
16650 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16651 a warning will be emitted for such breakpoints."),
16653 show_automatic_hardware_breakpoints
,
16654 &breakpoint_set_cmdlist
,
16655 &breakpoint_show_cmdlist
);
16657 add_setshow_boolean_cmd ("always-inserted", class_support
,
16658 &always_inserted_mode
, _("\
16659 Set mode for inserting breakpoints."), _("\
16660 Show mode for inserting breakpoints."), _("\
16661 When this mode is on, breakpoints are inserted immediately as soon as\n\
16662 they're created, kept inserted even when execution stops, and removed\n\
16663 only when the user deletes them. When this mode is off (the default),\n\
16664 breakpoints are inserted only when execution continues, and removed\n\
16665 when execution stops."),
16667 &show_always_inserted_mode
,
16668 &breakpoint_set_cmdlist
,
16669 &breakpoint_show_cmdlist
);
16671 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16672 condition_evaluation_enums
,
16673 &condition_evaluation_mode_1
, _("\
16674 Set mode of breakpoint condition evaluation."), _("\
16675 Show mode of breakpoint condition evaluation."), _("\
16676 When this is set to \"host\", breakpoint conditions will be\n\
16677 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16678 breakpoint conditions will be downloaded to the target (if the target\n\
16679 supports such feature) and conditions will be evaluated on the target's side.\n\
16680 If this is set to \"auto\" (default), this will be automatically set to\n\
16681 \"target\" if it supports condition evaluation, otherwise it will\n\
16682 be set to \"gdb\""),
16683 &set_condition_evaluation_mode
,
16684 &show_condition_evaluation_mode
,
16685 &breakpoint_set_cmdlist
,
16686 &breakpoint_show_cmdlist
);
16688 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16689 Set a breakpoint for an address range.\n\
16690 break-range START-LOCATION, END-LOCATION\n\
16691 where START-LOCATION and END-LOCATION can be one of the following:\n\
16692 LINENUM, for that line in the current file,\n\
16693 FILE:LINENUM, for that line in that file,\n\
16694 +OFFSET, for that number of lines after the current line\n\
16695 or the start of the range\n\
16696 FUNCTION, for the first line in that function,\n\
16697 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16698 *ADDRESS, for the instruction at that address.\n\
16700 The breakpoint will stop execution of the inferior whenever it executes\n\
16701 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16702 range (including START-LOCATION and END-LOCATION)."));
16704 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16705 Set a dynamic printf at specified location.\n\
16706 dprintf location,format string,arg1,arg2,...\n\
16707 location may be a linespec, explicit, or address location.\n"
16708 "\n" LOCATION_HELP_STRING
));
16709 set_cmd_completer (c
, location_completer
);
16711 add_setshow_enum_cmd ("dprintf-style", class_support
,
16712 dprintf_style_enums
, &dprintf_style
, _("\
16713 Set the style of usage for dynamic printf."), _("\
16714 Show the style of usage for dynamic printf."), _("\
16715 This setting chooses how GDB will do a dynamic printf.\n\
16716 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16717 console, as with the \"printf\" command.\n\
16718 If the value is \"call\", the print is done by calling a function in your\n\
16719 program; by default printf(), but you can choose a different function or\n\
16720 output stream by setting dprintf-function and dprintf-channel."),
16721 update_dprintf_commands
, NULL
,
16722 &setlist
, &showlist
);
16724 dprintf_function
= xstrdup ("printf");
16725 add_setshow_string_cmd ("dprintf-function", class_support
,
16726 &dprintf_function
, _("\
16727 Set the function to use for dynamic printf"), _("\
16728 Show the function to use for dynamic printf"), NULL
,
16729 update_dprintf_commands
, NULL
,
16730 &setlist
, &showlist
);
16732 dprintf_channel
= xstrdup ("");
16733 add_setshow_string_cmd ("dprintf-channel", class_support
,
16734 &dprintf_channel
, _("\
16735 Set the channel to use for dynamic printf"), _("\
16736 Show the channel to use for dynamic printf"), NULL
,
16737 update_dprintf_commands
, NULL
,
16738 &setlist
, &showlist
);
16740 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16741 &disconnected_dprintf
, _("\
16742 Set whether dprintf continues after GDB disconnects."), _("\
16743 Show whether dprintf continues after GDB disconnects."), _("\
16744 Use this to let dprintf commands continue to hit and produce output\n\
16745 even if GDB disconnects or detaches from the target."),
16748 &setlist
, &showlist
);
16750 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16751 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16752 (target agent only) This is useful for formatted output in user-defined commands."));
16754 automatic_hardware_breakpoints
= 1;
16756 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16757 observer_attach_thread_exit (remove_threaded_breakpoints
);