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 (char *, void (*) (struct breakpoint
*,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint
*);
116 create_sals_from_location_default (const struct event_location
*location
,
117 struct linespec_result
*canonical
,
118 enum bptype type_wanted
);
120 static void create_breakpoints_sal_default (struct gdbarch
*,
121 struct linespec_result
*,
122 char *, char *, enum bptype
,
123 enum bpdisp
, int, int,
125 const struct breakpoint_ops
*,
126 int, int, int, unsigned);
128 static void decode_location_default (struct breakpoint
*b
,
129 const struct event_location
*location
,
130 struct program_space
*search_pspace
,
131 struct symtabs_and_lines
*sals
);
133 static void clear_command (char *, int);
135 static void catch_command (char *, int);
137 static int can_use_hardware_watchpoint (struct value
*);
139 static void break_command_1 (char *, int, int);
141 static void mention (struct breakpoint
*);
143 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
145 const struct breakpoint_ops
*);
146 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
147 const struct symtab_and_line
*);
149 /* This function is used in gdbtk sources and thus can not be made
151 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
152 struct symtab_and_line
,
154 const struct breakpoint_ops
*);
156 static struct breakpoint
*
157 momentary_breakpoint_from_master (struct breakpoint
*orig
,
159 const struct breakpoint_ops
*ops
,
162 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
164 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
168 static void describe_other_breakpoints (struct gdbarch
*,
169 struct program_space
*, CORE_ADDR
,
170 struct obj_section
*, int);
172 static int watchpoint_locations_match (struct bp_location
*loc1
,
173 struct bp_location
*loc2
);
175 static int breakpoint_location_address_match (struct bp_location
*bl
,
176 struct address_space
*aspace
,
179 static int breakpoint_location_address_range_overlap (struct bp_location
*,
180 struct address_space
*,
183 static void breakpoints_info (char *, int);
185 static void watchpoints_info (char *, int);
187 static int breakpoint_1 (char *, int,
188 int (*) (const struct breakpoint
*));
190 static int breakpoint_cond_eval (void *);
192 static void cleanup_executing_breakpoints (void *);
194 static void commands_command (char *, int);
196 static void condition_command (char *, int);
198 static int remove_breakpoint (struct bp_location
*);
199 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
201 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
203 static int watchpoint_check (void *);
205 static void maintenance_info_breakpoints (char *, int);
207 static int hw_breakpoint_used_count (void);
209 static int hw_watchpoint_use_count (struct breakpoint
*);
211 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
213 int *other_type_used
);
215 static void hbreak_command (char *, int);
217 static void thbreak_command (char *, int);
219 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
222 static void stop_command (char *arg
, int from_tty
);
224 static void stopin_command (char *arg
, int from_tty
);
226 static void stopat_command (char *arg
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void free_bp_location (struct bp_location
*loc
);
231 static void incref_bp_location (struct bp_location
*loc
);
232 static void decref_bp_location (struct bp_location
**loc
);
234 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
236 /* update_global_location_list's modes of operation wrt to whether to
237 insert locations now. */
238 enum ugll_insert_mode
240 /* Don't insert any breakpoint locations into the inferior, only
241 remove already-inserted locations that no longer should be
242 inserted. Functions that delete a breakpoint or breakpoints
243 should specify this mode, so that deleting a breakpoint doesn't
244 have the side effect of inserting the locations of other
245 breakpoints that are marked not-inserted, but should_be_inserted
246 returns true on them.
248 This behavior is useful is situations close to tear-down -- e.g.,
249 after an exec, while the target still has execution, but
250 breakpoint shadows of the previous executable image should *NOT*
251 be restored to the new image; or before detaching, where the
252 target still has execution and wants to delete breakpoints from
253 GDB's lists, and all breakpoints had already been removed from
257 /* May insert breakpoints iff breakpoints_should_be_inserted_now
258 claims breakpoints should be inserted now. */
261 /* Insert locations now, irrespective of
262 breakpoints_should_be_inserted_now. E.g., say all threads are
263 stopped right now, and the user did "continue". We need to
264 insert breakpoints _before_ resuming the target, but
265 UGLL_MAY_INSERT wouldn't insert them, because
266 breakpoints_should_be_inserted_now returns false at that point,
267 as no thread is running yet. */
271 static void update_global_location_list (enum ugll_insert_mode
);
273 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
275 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
277 static void insert_breakpoint_locations (void);
279 static void tracepoints_info (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num
);
291 static int is_masked_watchpoint (const struct breakpoint
*b
);
293 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint
*b
);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops
;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops
;
311 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
312 static struct breakpoint_ops longjmp_breakpoint_ops
;
314 /* The breakpoint_ops structure to be used in regular user created
316 struct breakpoint_ops bkpt_breakpoint_ops
;
318 /* Breakpoints set on probes. */
319 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
321 /* Dynamic printf class type. */
322 struct breakpoint_ops dprintf_breakpoint_ops
;
324 /* The style in which to perform a dynamic printf. This is a user
325 option because different output options have different tradeoffs;
326 if GDB does the printing, there is better error handling if there
327 is a problem with any of the arguments, but using an inferior
328 function lets you have special-purpose printers and sending of
329 output to the same place as compiled-in print functions. */
331 static const char dprintf_style_gdb
[] = "gdb";
332 static const char dprintf_style_call
[] = "call";
333 static const char dprintf_style_agent
[] = "agent";
334 static const char *const dprintf_style_enums
[] = {
340 static const char *dprintf_style
= dprintf_style_gdb
;
342 /* The function to use for dynamic printf if the preferred style is to
343 call into the inferior. The value is simply a string that is
344 copied into the command, so it can be anything that GDB can
345 evaluate to a callable address, not necessarily a function name. */
347 static char *dprintf_function
= "";
349 /* The channel to use for dynamic printf if the preferred style is to
350 call into the inferior; if a nonempty string, it will be passed to
351 the call as the first argument, with the format string as the
352 second. As with the dprintf function, this can be anything that
353 GDB knows how to evaluate, so in addition to common choices like
354 "stderr", this could be an app-specific expression like
355 "mystreams[curlogger]". */
357 static char *dprintf_channel
= "";
359 /* True if dprintf commands should continue to operate even if GDB
361 static int disconnected_dprintf
= 1;
363 /* A reference-counted struct command_line. This lets multiple
364 breakpoints share a single command list. */
365 struct counted_command_line
367 /* The reference count. */
370 /* The command list. */
371 struct command_line
*commands
;
374 struct command_line
*
375 breakpoint_commands (struct breakpoint
*b
)
377 return b
->commands
? b
->commands
->commands
: NULL
;
380 /* Flag indicating that a command has proceeded the inferior past the
381 current breakpoint. */
383 static int breakpoint_proceeded
;
386 bpdisp_text (enum bpdisp disp
)
388 /* NOTE: the following values are a part of MI protocol and
389 represent values of 'disp' field returned when inferior stops at
391 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
393 return bpdisps
[(int) disp
];
396 /* Prototypes for exported functions. */
397 /* If FALSE, gdb will not use hardware support for watchpoints, even
398 if such is available. */
399 static int can_use_hw_watchpoints
;
402 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
,
406 fprintf_filtered (file
,
407 _("Debugger's willingness to use "
408 "watchpoint hardware is %s.\n"),
412 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
413 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
414 for unrecognized breakpoint locations.
415 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
416 static enum auto_boolean pending_break_support
;
418 show_pending_break_support (struct ui_file
*file
, int from_tty
,
419 struct cmd_list_element
*c
,
422 fprintf_filtered (file
,
423 _("Debugger's behavior regarding "
424 "pending breakpoints is %s.\n"),
428 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
429 set with "break" but falling in read-only memory.
430 If 0, gdb will warn about such breakpoints, but won't automatically
431 use hardware breakpoints. */
432 static int automatic_hardware_breakpoints
;
434 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
435 struct cmd_list_element
*c
,
438 fprintf_filtered (file
,
439 _("Automatic usage of hardware breakpoints is %s.\n"),
443 /* If on, GDB keeps breakpoints inserted even if the inferior is
444 stopped, and immediately inserts any new breakpoints as soon as
445 they're created. If off (default), GDB keeps breakpoints off of
446 the target as long as possible. That is, it delays inserting
447 breakpoints until the next resume, and removes them again when the
448 target fully stops. This is a bit safer in case GDB crashes while
449 processing user input. */
450 static int always_inserted_mode
= 0;
453 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
, const char *value
)
456 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
460 /* See breakpoint.h. */
463 breakpoints_should_be_inserted_now (void)
465 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
467 /* If breakpoints are global, they should be inserted even if no
468 thread under gdb's control is running, or even if there are
469 no threads under GDB's control yet. */
472 else if (target_has_execution
)
474 struct thread_info
*tp
;
476 if (always_inserted_mode
)
478 /* The user wants breakpoints inserted even if all threads
483 if (threads_are_executing ())
486 /* Don't remove breakpoints yet if, even though all threads are
487 stopped, we still have events to process. */
488 ALL_NON_EXITED_THREADS (tp
)
490 && tp
->suspend
.waitstatus_pending_p
)
496 static const char condition_evaluation_both
[] = "host or target";
498 /* Modes for breakpoint condition evaluation. */
499 static const char condition_evaluation_auto
[] = "auto";
500 static const char condition_evaluation_host
[] = "host";
501 static const char condition_evaluation_target
[] = "target";
502 static const char *const condition_evaluation_enums
[] = {
503 condition_evaluation_auto
,
504 condition_evaluation_host
,
505 condition_evaluation_target
,
509 /* Global that holds the current mode for breakpoint condition evaluation. */
510 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
512 /* Global that we use to display information to the user (gets its value from
513 condition_evaluation_mode_1. */
514 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
516 /* Translate a condition evaluation mode MODE into either "host"
517 or "target". This is used mostly to translate from "auto" to the
518 real setting that is being used. It returns the translated
522 translate_condition_evaluation_mode (const char *mode
)
524 if (mode
== condition_evaluation_auto
)
526 if (target_supports_evaluation_of_breakpoint_conditions ())
527 return condition_evaluation_target
;
529 return condition_evaluation_host
;
535 /* Discovers what condition_evaluation_auto translates to. */
538 breakpoint_condition_evaluation_mode (void)
540 return translate_condition_evaluation_mode (condition_evaluation_mode
);
543 /* Return true if GDB should evaluate breakpoint conditions or false
547 gdb_evaluates_breakpoint_condition_p (void)
549 const char *mode
= breakpoint_condition_evaluation_mode ();
551 return (mode
== condition_evaluation_host
);
554 void _initialize_breakpoint (void);
556 /* Are we executing breakpoint commands? */
557 static int executing_breakpoint_commands
;
559 /* Are overlay event breakpoints enabled? */
560 static int overlay_events_enabled
;
562 /* See description in breakpoint.h. */
563 int target_exact_watchpoints
= 0;
565 /* Walk the following statement or block through all breakpoints.
566 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
567 current breakpoint. */
569 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
571 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
572 for (B = breakpoint_chain; \
573 B ? (TMP=B->next, 1): 0; \
576 /* Similar iterator for the low-level breakpoints. SAFE variant is
577 not provided so update_global_location_list must not be called
578 while executing the block of ALL_BP_LOCATIONS. */
580 #define ALL_BP_LOCATIONS(B,BP_TMP) \
581 for (BP_TMP = bp_location; \
582 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
585 /* Iterates through locations with address ADDRESS for the currently selected
586 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
587 to where the loop should start from.
588 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
589 appropriate location to start with. */
591 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
592 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
593 BP_LOCP_TMP = BP_LOCP_START; \
595 && (BP_LOCP_TMP < bp_location + bp_location_count \
596 && (*BP_LOCP_TMP)->address == ADDRESS); \
599 /* Iterator for tracepoints only. */
601 #define ALL_TRACEPOINTS(B) \
602 for (B = breakpoint_chain; B; B = B->next) \
603 if (is_tracepoint (B))
605 /* Chains of all breakpoints defined. */
607 struct breakpoint
*breakpoint_chain
;
609 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
611 static struct bp_location
**bp_location
;
613 /* Number of elements of BP_LOCATION. */
615 static unsigned bp_location_count
;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATION which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATION to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_location_placed_address_before_address_max
;
625 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
626 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
627 BP_LOCATION which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATION to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_location_shadow_len_after_address_max
;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from bp_location array, but for which a hit may still be reported
636 VEC(bp_location_p
) *moribund_locations
= NULL
;
638 /* Number of last breakpoint made. */
640 static int breakpoint_count
;
642 /* The value of `breakpoint_count' before the last command that
643 created breakpoints. If the last (break-like) command created more
644 than one breakpoint, then the difference between BREAKPOINT_COUNT
645 and PREV_BREAKPOINT_COUNT is more than one. */
646 static int prev_breakpoint_count
;
648 /* Number of last tracepoint made. */
650 static int tracepoint_count
;
652 static struct cmd_list_element
*breakpoint_set_cmdlist
;
653 static struct cmd_list_element
*breakpoint_show_cmdlist
;
654 struct cmd_list_element
*save_cmdlist
;
656 /* See declaration at breakpoint.h. */
659 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
662 struct breakpoint
*b
= NULL
;
666 if (func (b
, user_data
) != 0)
673 /* Return whether a breakpoint is an active enabled breakpoint. */
675 breakpoint_enabled (struct breakpoint
*b
)
677 return (b
->enable_state
== bp_enabled
);
680 /* Set breakpoint count to NUM. */
683 set_breakpoint_count (int num
)
685 prev_breakpoint_count
= breakpoint_count
;
686 breakpoint_count
= num
;
687 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
690 /* Used by `start_rbreak_breakpoints' below, to record the current
691 breakpoint count before "rbreak" creates any breakpoint. */
692 static int rbreak_start_breakpoint_count
;
694 /* Called at the start an "rbreak" command to record the first
698 start_rbreak_breakpoints (void)
700 rbreak_start_breakpoint_count
= breakpoint_count
;
703 /* Called at the end of an "rbreak" command to record the last
707 end_rbreak_breakpoints (void)
709 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
712 /* Used in run_command to zero the hit count when a new run starts. */
715 clear_breakpoint_hit_counts (void)
717 struct breakpoint
*b
;
723 /* Allocate a new counted_command_line with reference count of 1.
724 The new structure owns COMMANDS. */
726 static struct counted_command_line
*
727 alloc_counted_command_line (struct command_line
*commands
)
729 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
732 result
->commands
= commands
;
737 /* Increment reference count. This does nothing if CMD is NULL. */
740 incref_counted_command_line (struct counted_command_line
*cmd
)
746 /* Decrement reference count. If the reference count reaches 0,
747 destroy the counted_command_line. Sets *CMDP to NULL. This does
748 nothing if *CMDP is NULL. */
751 decref_counted_command_line (struct counted_command_line
**cmdp
)
755 if (--(*cmdp
)->refc
== 0)
757 free_command_lines (&(*cmdp
)->commands
);
764 /* A cleanup function that calls decref_counted_command_line. */
767 do_cleanup_counted_command_line (void *arg
)
769 decref_counted_command_line ((struct counted_command_line
**) arg
);
772 /* Create a cleanup that calls decref_counted_command_line on the
775 static struct cleanup
*
776 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
778 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
782 /* Return the breakpoint with the specified number, or NULL
783 if the number does not refer to an existing breakpoint. */
786 get_breakpoint (int num
)
788 struct breakpoint
*b
;
791 if (b
->number
== num
)
799 /* Mark locations as "conditions have changed" in case the target supports
800 evaluating conditions on its side. */
803 mark_breakpoint_modified (struct breakpoint
*b
)
805 struct bp_location
*loc
;
807 /* This is only meaningful if the target is
808 evaluating conditions and if the user has
809 opted for condition evaluation on the target's
811 if (gdb_evaluates_breakpoint_condition_p ()
812 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (b
))
818 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
819 loc
->condition_changed
= condition_modified
;
822 /* Mark location as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_location_modified (struct bp_location
*loc
)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
837 if (!is_breakpoint (loc
->owner
))
840 loc
->condition_changed
= condition_modified
;
843 /* Sets the condition-evaluation mode using the static global
844 condition_evaluation_mode. */
847 set_condition_evaluation_mode (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 const char *old_mode
, *new_mode
;
852 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
853 && !target_supports_evaluation_of_breakpoint_conditions ())
855 condition_evaluation_mode_1
= condition_evaluation_mode
;
856 warning (_("Target does not support breakpoint condition evaluation.\n"
857 "Using host evaluation mode instead."));
861 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
862 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
864 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
865 settings was "auto". */
866 condition_evaluation_mode
= condition_evaluation_mode_1
;
868 /* Only update the mode if the user picked a different one. */
869 if (new_mode
!= old_mode
)
871 struct bp_location
*loc
, **loc_tmp
;
872 /* If the user switched to a different evaluation mode, we
873 need to synch the changes with the target as follows:
875 "host" -> "target": Send all (valid) conditions to the target.
876 "target" -> "host": Remove all the conditions from the target.
879 if (new_mode
== condition_evaluation_target
)
881 /* Mark everything modified and synch conditions with the
883 ALL_BP_LOCATIONS (loc
, loc_tmp
)
884 mark_breakpoint_location_modified (loc
);
888 /* Manually mark non-duplicate locations to synch conditions
889 with the target. We do this to remove all the conditions the
890 target knows about. */
891 ALL_BP_LOCATIONS (loc
, loc_tmp
)
892 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
893 loc
->needs_update
= 1;
897 update_global_location_list (UGLL_MAY_INSERT
);
903 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
904 what "auto" is translating to. */
907 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
908 struct cmd_list_element
*c
, const char *value
)
910 if (condition_evaluation_mode
== condition_evaluation_auto
)
911 fprintf_filtered (file
,
912 _("Breakpoint condition evaluation "
913 "mode is %s (currently %s).\n"),
915 breakpoint_condition_evaluation_mode ());
917 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
921 /* A comparison function for bp_location AP and BP that is used by
922 bsearch. This comparison function only cares about addresses, unlike
923 the more general bp_location_compare function. */
926 bp_location_compare_addrs (const void *ap
, const void *bp
)
928 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
929 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
931 if (a
->address
== b
->address
)
934 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
937 /* Helper function to skip all bp_locations with addresses
938 less than ADDRESS. It returns the first bp_location that
939 is greater than or equal to ADDRESS. If none is found, just
942 static struct bp_location
**
943 get_first_locp_gte_addr (CORE_ADDR address
)
945 struct bp_location dummy_loc
;
946 struct bp_location
*dummy_locp
= &dummy_loc
;
947 struct bp_location
**locp_found
= NULL
;
949 /* Initialize the dummy location's address field. */
950 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
951 dummy_loc
.address
= address
;
953 /* Find a close match to the first location at ADDRESS. */
954 locp_found
= ((struct bp_location
**)
955 bsearch (&dummy_locp
, bp_location
, bp_location_count
,
956 sizeof (struct bp_location
**),
957 bp_location_compare_addrs
));
959 /* Nothing was found, nothing left to do. */
960 if (locp_found
== NULL
)
963 /* We may have found a location that is at ADDRESS but is not the first in the
964 location's list. Go backwards (if possible) and locate the first one. */
965 while ((locp_found
- 1) >= bp_location
966 && (*(locp_found
- 1))->address
== address
)
973 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
976 xfree (b
->cond_string
);
977 b
->cond_string
= NULL
;
979 if (is_watchpoint (b
))
981 struct watchpoint
*w
= (struct watchpoint
*) b
;
988 struct bp_location
*loc
;
990 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
995 /* No need to free the condition agent expression
996 bytecode (if we have one). We will handle this
997 when we go through update_global_location_list. */
1004 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1008 const char *arg
= exp
;
1010 /* I don't know if it matters whether this is the string the user
1011 typed in or the decompiled expression. */
1012 b
->cond_string
= xstrdup (arg
);
1013 b
->condition_not_parsed
= 0;
1015 if (is_watchpoint (b
))
1017 struct watchpoint
*w
= (struct watchpoint
*) b
;
1019 innermost_block
= NULL
;
1021 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1023 error (_("Junk at end of expression"));
1024 w
->cond_exp_valid_block
= innermost_block
;
1028 struct bp_location
*loc
;
1030 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1034 parse_exp_1 (&arg
, loc
->address
,
1035 block_for_pc (loc
->address
), 0);
1037 error (_("Junk at end of expression"));
1041 mark_breakpoint_modified (b
);
1043 observer_notify_breakpoint_modified (b
);
1046 /* Completion for the "condition" command. */
1048 static VEC (char_ptr
) *
1049 condition_completer (struct cmd_list_element
*cmd
,
1050 const char *text
, const char *word
)
1054 text
= skip_spaces_const (text
);
1055 space
= skip_to_space_const (text
);
1059 struct breakpoint
*b
;
1060 VEC (char_ptr
) *result
= NULL
;
1064 /* We don't support completion of history indices. */
1065 if (isdigit (text
[1]))
1067 return complete_internalvar (&text
[1]);
1070 /* We're completing the breakpoint number. */
1071 len
= strlen (text
);
1077 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1079 if (strncmp (number
, text
, len
) == 0)
1080 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1086 /* We're completing the expression part. */
1087 text
= skip_spaces_const (space
);
1088 return expression_completer (cmd
, text
, word
);
1091 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1094 condition_command (char *arg
, int from_tty
)
1096 struct breakpoint
*b
;
1101 error_no_arg (_("breakpoint number"));
1104 bnum
= get_number (&p
);
1106 error (_("Bad breakpoint argument: '%s'"), arg
);
1109 if (b
->number
== bnum
)
1111 /* Check if this breakpoint has a "stop" method implemented in an
1112 extension language. This method and conditions entered into GDB
1113 from the CLI are mutually exclusive. */
1114 const struct extension_language_defn
*extlang
1115 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1117 if (extlang
!= NULL
)
1119 error (_("Only one stop condition allowed. There is currently"
1120 " a %s stop condition defined for this breakpoint."),
1121 ext_lang_capitalized_name (extlang
));
1123 set_breakpoint_condition (b
, p
, from_tty
);
1125 if (is_breakpoint (b
))
1126 update_global_location_list (UGLL_MAY_INSERT
);
1131 error (_("No breakpoint number %d."), bnum
);
1134 /* Check that COMMAND do not contain commands that are suitable
1135 only for tracepoints and not suitable for ordinary breakpoints.
1136 Throw if any such commands is found. */
1139 check_no_tracepoint_commands (struct command_line
*commands
)
1141 struct command_line
*c
;
1143 for (c
= commands
; c
; c
= c
->next
)
1147 if (c
->control_type
== while_stepping_control
)
1148 error (_("The 'while-stepping' command can "
1149 "only be used for tracepoints"));
1151 for (i
= 0; i
< c
->body_count
; ++i
)
1152 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1154 /* Not that command parsing removes leading whitespace and comment
1155 lines and also empty lines. So, we only need to check for
1156 command directly. */
1157 if (strstr (c
->line
, "collect ") == c
->line
)
1158 error (_("The 'collect' command can only be used for tracepoints"));
1160 if (strstr (c
->line
, "teval ") == c
->line
)
1161 error (_("The 'teval' command can only be used for tracepoints"));
1165 /* Encapsulate tests for different types of tracepoints. */
1168 is_tracepoint_type (enum bptype type
)
1170 return (type
== bp_tracepoint
1171 || type
== bp_fast_tracepoint
1172 || type
== bp_static_tracepoint
);
1176 is_tracepoint (const struct breakpoint
*b
)
1178 return is_tracepoint_type (b
->type
);
1181 /* A helper function that validates that COMMANDS are valid for a
1182 breakpoint. This function will throw an exception if a problem is
1186 validate_commands_for_breakpoint (struct breakpoint
*b
,
1187 struct command_line
*commands
)
1189 if (is_tracepoint (b
))
1191 struct tracepoint
*t
= (struct tracepoint
*) b
;
1192 struct command_line
*c
;
1193 struct command_line
*while_stepping
= 0;
1195 /* Reset the while-stepping step count. The previous commands
1196 might have included a while-stepping action, while the new
1200 /* We need to verify that each top-level element of commands is
1201 valid for tracepoints, that there's at most one
1202 while-stepping element, and that the while-stepping's body
1203 has valid tracing commands excluding nested while-stepping.
1204 We also need to validate the tracepoint action line in the
1205 context of the tracepoint --- validate_actionline actually
1206 has side effects, like setting the tracepoint's
1207 while-stepping STEP_COUNT, in addition to checking if the
1208 collect/teval actions parse and make sense in the
1209 tracepoint's context. */
1210 for (c
= commands
; c
; c
= c
->next
)
1212 if (c
->control_type
== while_stepping_control
)
1214 if (b
->type
== bp_fast_tracepoint
)
1215 error (_("The 'while-stepping' command "
1216 "cannot be used for fast tracepoint"));
1217 else if (b
->type
== bp_static_tracepoint
)
1218 error (_("The 'while-stepping' command "
1219 "cannot be used for static tracepoint"));
1222 error (_("The 'while-stepping' command "
1223 "can be used only once"));
1228 validate_actionline (c
->line
, b
);
1232 struct command_line
*c2
;
1234 gdb_assert (while_stepping
->body_count
== 1);
1235 c2
= while_stepping
->body_list
[0];
1236 for (; c2
; c2
= c2
->next
)
1238 if (c2
->control_type
== while_stepping_control
)
1239 error (_("The 'while-stepping' command cannot be nested"));
1245 check_no_tracepoint_commands (commands
);
1249 /* Return a vector of all the static tracepoints set at ADDR. The
1250 caller is responsible for releasing the vector. */
1253 static_tracepoints_here (CORE_ADDR addr
)
1255 struct breakpoint
*b
;
1256 VEC(breakpoint_p
) *found
= 0;
1257 struct bp_location
*loc
;
1260 if (b
->type
== bp_static_tracepoint
)
1262 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1263 if (loc
->address
== addr
)
1264 VEC_safe_push(breakpoint_p
, found
, b
);
1270 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1271 validate that only allowed commands are included. */
1274 breakpoint_set_commands (struct breakpoint
*b
,
1275 struct command_line
*commands
)
1277 validate_commands_for_breakpoint (b
, commands
);
1279 decref_counted_command_line (&b
->commands
);
1280 b
->commands
= alloc_counted_command_line (commands
);
1281 observer_notify_breakpoint_modified (b
);
1284 /* Set the internal `silent' flag on the breakpoint. Note that this
1285 is not the same as the "silent" that may appear in the breakpoint's
1289 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1291 int old_silent
= b
->silent
;
1294 if (old_silent
!= silent
)
1295 observer_notify_breakpoint_modified (b
);
1298 /* Set the thread for this breakpoint. If THREAD is -1, make the
1299 breakpoint work for any thread. */
1302 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1304 int old_thread
= b
->thread
;
1307 if (old_thread
!= thread
)
1308 observer_notify_breakpoint_modified (b
);
1311 /* Set the task for this breakpoint. If TASK is 0, make the
1312 breakpoint work for any task. */
1315 breakpoint_set_task (struct breakpoint
*b
, int task
)
1317 int old_task
= b
->task
;
1320 if (old_task
!= task
)
1321 observer_notify_breakpoint_modified (b
);
1325 check_tracepoint_command (char *line
, void *closure
)
1327 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1329 validate_actionline (line
, b
);
1332 /* A structure used to pass information through
1333 map_breakpoint_numbers. */
1335 struct commands_info
1337 /* True if the command was typed at a tty. */
1340 /* The breakpoint range spec. */
1343 /* Non-NULL if the body of the commands are being read from this
1344 already-parsed command. */
1345 struct command_line
*control
;
1347 /* The command lines read from the user, or NULL if they have not
1349 struct counted_command_line
*cmd
;
1352 /* A callback for map_breakpoint_numbers that sets the commands for
1353 commands_command. */
1356 do_map_commands_command (struct breakpoint
*b
, void *data
)
1358 struct commands_info
*info
= (struct commands_info
*) data
;
1360 if (info
->cmd
== NULL
)
1362 struct command_line
*l
;
1364 if (info
->control
!= NULL
)
1365 l
= copy_command_lines (info
->control
->body_list
[0]);
1368 struct cleanup
*old_chain
;
1371 str
= xstrprintf (_("Type commands for breakpoint(s) "
1372 "%s, one per line."),
1375 old_chain
= make_cleanup (xfree
, str
);
1377 l
= read_command_lines (str
,
1380 ? check_tracepoint_command
: 0),
1383 do_cleanups (old_chain
);
1386 info
->cmd
= alloc_counted_command_line (l
);
1389 /* If a breakpoint was on the list more than once, we don't need to
1391 if (b
->commands
!= info
->cmd
)
1393 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1394 incref_counted_command_line (info
->cmd
);
1395 decref_counted_command_line (&b
->commands
);
1396 b
->commands
= info
->cmd
;
1397 observer_notify_breakpoint_modified (b
);
1402 commands_command_1 (char *arg
, int from_tty
,
1403 struct command_line
*control
)
1405 struct cleanup
*cleanups
;
1406 struct commands_info info
;
1408 info
.from_tty
= from_tty
;
1409 info
.control
= control
;
1411 /* If we read command lines from the user, then `info' will hold an
1412 extra reference to the commands that we must clean up. */
1413 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1415 if (arg
== NULL
|| !*arg
)
1417 if (breakpoint_count
- prev_breakpoint_count
> 1)
1418 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1420 else if (breakpoint_count
> 0)
1421 arg
= xstrprintf ("%d", breakpoint_count
);
1424 /* So that we don't try to free the incoming non-NULL
1425 argument in the cleanup below. Mapping breakpoint
1426 numbers will fail in this case. */
1431 /* The command loop has some static state, so we need to preserve
1433 arg
= xstrdup (arg
);
1436 make_cleanup (xfree
, arg
);
1440 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1442 if (info
.cmd
== NULL
)
1443 error (_("No breakpoints specified."));
1445 do_cleanups (cleanups
);
1449 commands_command (char *arg
, int from_tty
)
1451 commands_command_1 (arg
, from_tty
, NULL
);
1454 /* Like commands_command, but instead of reading the commands from
1455 input stream, takes them from an already parsed command structure.
1457 This is used by cli-script.c to DTRT with breakpoint commands
1458 that are part of if and while bodies. */
1459 enum command_control_type
1460 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1462 commands_command_1 (arg
, 0, cmd
);
1463 return simple_control
;
1466 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1469 bp_location_has_shadow (struct bp_location
*bl
)
1471 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1475 if (bl
->target_info
.shadow_len
== 0)
1476 /* BL isn't valid, or doesn't shadow memory. */
1481 /* Update BUF, which is LEN bytes read from the target address
1482 MEMADDR, by replacing a memory breakpoint with its shadowed
1485 If READBUF is not NULL, this buffer must not overlap with the of
1486 the breakpoint location's shadow_contents buffer. Otherwise, a
1487 failed assertion internal error will be raised. */
1490 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1491 const gdb_byte
*writebuf_org
,
1492 ULONGEST memaddr
, LONGEST len
,
1493 struct bp_target_info
*target_info
,
1494 struct gdbarch
*gdbarch
)
1496 /* Now do full processing of the found relevant range of elements. */
1497 CORE_ADDR bp_addr
= 0;
1501 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1502 current_program_space
->aspace
, 0))
1504 /* The breakpoint is inserted in a different address space. */
1508 /* Addresses and length of the part of the breakpoint that
1510 bp_addr
= target_info
->placed_address
;
1511 bp_size
= target_info
->shadow_len
;
1513 if (bp_addr
+ bp_size
<= memaddr
)
1515 /* The breakpoint is entirely before the chunk of memory we are
1520 if (bp_addr
>= memaddr
+ len
)
1522 /* The breakpoint is entirely after the chunk of memory we are
1527 /* Offset within shadow_contents. */
1528 if (bp_addr
< memaddr
)
1530 /* Only copy the second part of the breakpoint. */
1531 bp_size
-= memaddr
- bp_addr
;
1532 bptoffset
= memaddr
- bp_addr
;
1536 if (bp_addr
+ bp_size
> memaddr
+ len
)
1538 /* Only copy the first part of the breakpoint. */
1539 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1542 if (readbuf
!= NULL
)
1544 /* Verify that the readbuf buffer does not overlap with the
1545 shadow_contents buffer. */
1546 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1547 || readbuf
>= (target_info
->shadow_contents
1548 + target_info
->shadow_len
));
1550 /* Update the read buffer with this inserted breakpoint's
1552 memcpy (readbuf
+ bp_addr
- memaddr
,
1553 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1557 const unsigned char *bp
;
1558 CORE_ADDR addr
= target_info
->reqstd_address
;
1561 /* Update the shadow with what we want to write to memory. */
1562 memcpy (target_info
->shadow_contents
+ bptoffset
,
1563 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1565 /* Determine appropriate breakpoint contents and size for this
1567 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1569 /* Update the final write buffer with this inserted
1570 breakpoint's INSN. */
1571 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1575 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1576 by replacing any memory breakpoints with their shadowed contents.
1578 If READBUF is not NULL, this buffer must not overlap with any of
1579 the breakpoint location's shadow_contents buffers. Otherwise,
1580 a failed assertion internal error will be raised.
1582 The range of shadowed area by each bp_location is:
1583 bl->address - bp_location_placed_address_before_address_max
1584 up to bl->address + bp_location_shadow_len_after_address_max
1585 The range we were requested to resolve shadows for is:
1586 memaddr ... memaddr + len
1587 Thus the safe cutoff boundaries for performance optimization are
1588 memaddr + len <= (bl->address
1589 - bp_location_placed_address_before_address_max)
1591 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1594 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1595 const gdb_byte
*writebuf_org
,
1596 ULONGEST memaddr
, LONGEST len
)
1598 /* Left boundary, right boundary and median element of our binary
1600 unsigned bc_l
, bc_r
, bc
;
1602 /* Find BC_L which is a leftmost element which may affect BUF
1603 content. It is safe to report lower value but a failure to
1604 report higher one. */
1607 bc_r
= bp_location_count
;
1608 while (bc_l
+ 1 < bc_r
)
1610 struct bp_location
*bl
;
1612 bc
= (bc_l
+ bc_r
) / 2;
1613 bl
= bp_location
[bc
];
1615 /* Check first BL->ADDRESS will not overflow due to the added
1616 constant. Then advance the left boundary only if we are sure
1617 the BC element can in no way affect the BUF content (MEMADDR
1618 to MEMADDR + LEN range).
1620 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1621 offset so that we cannot miss a breakpoint with its shadow
1622 range tail still reaching MEMADDR. */
1624 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1626 && (bl
->address
+ bp_location_shadow_len_after_address_max
1633 /* Due to the binary search above, we need to make sure we pick the
1634 first location that's at BC_L's address. E.g., if there are
1635 multiple locations at the same address, BC_L may end up pointing
1636 at a duplicate location, and miss the "master"/"inserted"
1637 location. Say, given locations L1, L2 and L3 at addresses A and
1640 L1@A, L2@A, L3@B, ...
1642 BC_L could end up pointing at location L2, while the "master"
1643 location could be L1. Since the `loc->inserted' flag is only set
1644 on "master" locations, we'd forget to restore the shadow of L1
1647 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1650 /* Now do full processing of the found relevant range of elements. */
1652 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1654 struct bp_location
*bl
= bp_location
[bc
];
1656 /* bp_location array has BL->OWNER always non-NULL. */
1657 if (bl
->owner
->type
== bp_none
)
1658 warning (_("reading through apparently deleted breakpoint #%d?"),
1661 /* Performance optimization: any further element can no longer affect BUF
1664 if (bl
->address
>= bp_location_placed_address_before_address_max
1665 && memaddr
+ len
<= (bl
->address
1666 - bp_location_placed_address_before_address_max
))
1669 if (!bp_location_has_shadow (bl
))
1672 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1673 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1679 /* Return true if BPT is either a software breakpoint or a hardware
1683 is_breakpoint (const struct breakpoint
*bpt
)
1685 return (bpt
->type
== bp_breakpoint
1686 || bpt
->type
== bp_hardware_breakpoint
1687 || bpt
->type
== bp_dprintf
);
1690 /* Return true if BPT is of any hardware watchpoint kind. */
1693 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1695 return (bpt
->type
== bp_hardware_watchpoint
1696 || bpt
->type
== bp_read_watchpoint
1697 || bpt
->type
== bp_access_watchpoint
);
1700 /* Return true if BPT is of any watchpoint kind, hardware or
1704 is_watchpoint (const struct breakpoint
*bpt
)
1706 return (is_hardware_watchpoint (bpt
)
1707 || bpt
->type
== bp_watchpoint
);
1710 /* Returns true if the current thread and its running state are safe
1711 to evaluate or update watchpoint B. Watchpoints on local
1712 expressions need to be evaluated in the context of the thread that
1713 was current when the watchpoint was created, and, that thread needs
1714 to be stopped to be able to select the correct frame context.
1715 Watchpoints on global expressions can be evaluated on any thread,
1716 and in any state. It is presently left to the target allowing
1717 memory accesses when threads are running. */
1720 watchpoint_in_thread_scope (struct watchpoint
*b
)
1722 return (b
->base
.pspace
== current_program_space
1723 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1724 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1725 && !is_executing (inferior_ptid
))));
1728 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1729 associated bp_watchpoint_scope breakpoint. */
1732 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1734 struct breakpoint
*b
= &w
->base
;
1736 if (b
->related_breakpoint
!= b
)
1738 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1739 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1740 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1741 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1742 b
->related_breakpoint
= b
;
1744 b
->disposition
= disp_del_at_next_stop
;
1747 /* Extract a bitfield value from value VAL using the bit parameters contained in
1750 static struct value
*
1751 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1753 struct value
*bit_val
;
1758 bit_val
= allocate_value (value_type (val
));
1760 unpack_value_bitfield (bit_val
,
1763 value_contents_for_printing (val
),
1770 /* Allocate a dummy location and add it to B, which must be a software
1771 watchpoint. This is required because even if a software watchpoint
1772 is not watching any memory, bpstat_stop_status requires a location
1773 to be able to report stops. */
1776 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1777 struct program_space
*pspace
)
1779 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1781 b
->loc
= allocate_bp_location (b
);
1782 b
->loc
->pspace
= pspace
;
1783 b
->loc
->address
= -1;
1784 b
->loc
->length
= -1;
1787 /* Returns true if B is a software watchpoint that is not watching any
1788 memory (e.g., "watch $pc"). */
1791 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1793 return (b
->type
== bp_watchpoint
1795 && b
->loc
->next
== NULL
1796 && b
->loc
->address
== -1
1797 && b
->loc
->length
== -1);
1800 /* Assuming that B is a watchpoint:
1801 - Reparse watchpoint expression, if REPARSE is non-zero
1802 - Evaluate expression and store the result in B->val
1803 - Evaluate the condition if there is one, and store the result
1805 - Update the list of values that must be watched in B->loc.
1807 If the watchpoint disposition is disp_del_at_next_stop, then do
1808 nothing. If this is local watchpoint that is out of scope, delete
1811 Even with `set breakpoint always-inserted on' the watchpoints are
1812 removed + inserted on each stop here. Normal breakpoints must
1813 never be removed because they might be missed by a running thread
1814 when debugging in non-stop mode. On the other hand, hardware
1815 watchpoints (is_hardware_watchpoint; processed here) are specific
1816 to each LWP since they are stored in each LWP's hardware debug
1817 registers. Therefore, such LWP must be stopped first in order to
1818 be able to modify its hardware watchpoints.
1820 Hardware watchpoints must be reset exactly once after being
1821 presented to the user. It cannot be done sooner, because it would
1822 reset the data used to present the watchpoint hit to the user. And
1823 it must not be done later because it could display the same single
1824 watchpoint hit during multiple GDB stops. Note that the latter is
1825 relevant only to the hardware watchpoint types bp_read_watchpoint
1826 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1827 not user-visible - its hit is suppressed if the memory content has
1830 The following constraints influence the location where we can reset
1831 hardware watchpoints:
1833 * target_stopped_by_watchpoint and target_stopped_data_address are
1834 called several times when GDB stops.
1837 * Multiple hardware watchpoints can be hit at the same time,
1838 causing GDB to stop. GDB only presents one hardware watchpoint
1839 hit at a time as the reason for stopping, and all the other hits
1840 are presented later, one after the other, each time the user
1841 requests the execution to be resumed. Execution is not resumed
1842 for the threads still having pending hit event stored in
1843 LWP_INFO->STATUS. While the watchpoint is already removed from
1844 the inferior on the first stop the thread hit event is kept being
1845 reported from its cached value by linux_nat_stopped_data_address
1846 until the real thread resume happens after the watchpoint gets
1847 presented and thus its LWP_INFO->STATUS gets reset.
1849 Therefore the hardware watchpoint hit can get safely reset on the
1850 watchpoint removal from inferior. */
1853 update_watchpoint (struct watchpoint
*b
, int reparse
)
1855 int within_current_scope
;
1856 struct frame_id saved_frame_id
;
1859 /* If this is a local watchpoint, we only want to check if the
1860 watchpoint frame is in scope if the current thread is the thread
1861 that was used to create the watchpoint. */
1862 if (!watchpoint_in_thread_scope (b
))
1865 if (b
->base
.disposition
== disp_del_at_next_stop
)
1870 /* Determine if the watchpoint is within scope. */
1871 if (b
->exp_valid_block
== NULL
)
1872 within_current_scope
= 1;
1875 struct frame_info
*fi
= get_current_frame ();
1876 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1877 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1879 /* If we're at a point where the stack has been destroyed
1880 (e.g. in a function epilogue), unwinding may not work
1881 properly. Do not attempt to recreate locations at this
1882 point. See similar comments in watchpoint_check. */
1883 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1886 /* Save the current frame's ID so we can restore it after
1887 evaluating the watchpoint expression on its own frame. */
1888 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1889 took a frame parameter, so that we didn't have to change the
1892 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1894 fi
= frame_find_by_id (b
->watchpoint_frame
);
1895 within_current_scope
= (fi
!= NULL
);
1896 if (within_current_scope
)
1900 /* We don't free locations. They are stored in the bp_location array
1901 and update_global_location_list will eventually delete them and
1902 remove breakpoints if needed. */
1905 if (within_current_scope
&& reparse
)
1914 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1915 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1916 /* If the meaning of expression itself changed, the old value is
1917 no longer relevant. We don't want to report a watchpoint hit
1918 to the user when the old value and the new value may actually
1919 be completely different objects. */
1920 value_free (b
->val
);
1924 /* Note that unlike with breakpoints, the watchpoint's condition
1925 expression is stored in the breakpoint object, not in the
1926 locations (re)created below. */
1927 if (b
->base
.cond_string
!= NULL
)
1929 if (b
->cond_exp
!= NULL
)
1931 xfree (b
->cond_exp
);
1935 s
= b
->base
.cond_string
;
1936 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1940 /* If we failed to parse the expression, for example because
1941 it refers to a global variable in a not-yet-loaded shared library,
1942 don't try to insert watchpoint. We don't automatically delete
1943 such watchpoint, though, since failure to parse expression
1944 is different from out-of-scope watchpoint. */
1945 if (!target_has_execution
)
1947 /* Without execution, memory can't change. No use to try and
1948 set watchpoint locations. The watchpoint will be reset when
1949 the target gains execution, through breakpoint_re_set. */
1950 if (!can_use_hw_watchpoints
)
1952 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1953 b
->base
.type
= bp_watchpoint
;
1955 error (_("Can't set read/access watchpoint when "
1956 "hardware watchpoints are disabled."));
1959 else if (within_current_scope
&& b
->exp
)
1962 struct value
*val_chain
, *v
, *result
, *next
;
1963 struct program_space
*frame_pspace
;
1965 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1967 /* Avoid setting b->val if it's already set. The meaning of
1968 b->val is 'the last value' user saw, and we should update
1969 it only if we reported that last value to user. As it
1970 happens, the code that reports it updates b->val directly.
1971 We don't keep track of the memory value for masked
1973 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1975 if (b
->val_bitsize
!= 0)
1977 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1985 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1987 /* Look at each value on the value chain. */
1988 for (v
= val_chain
; v
; v
= value_next (v
))
1990 /* If it's a memory location, and GDB actually needed
1991 its contents to evaluate the expression, then we
1992 must watch it. If the first value returned is
1993 still lazy, that means an error occurred reading it;
1994 watch it anyway in case it becomes readable. */
1995 if (VALUE_LVAL (v
) == lval_memory
1996 && (v
== val_chain
|| ! value_lazy (v
)))
1998 struct type
*vtype
= check_typedef (value_type (v
));
2000 /* We only watch structs and arrays if user asked
2001 for it explicitly, never if they just happen to
2002 appear in the middle of some value chain. */
2004 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2005 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2008 enum target_hw_bp_type type
;
2009 struct bp_location
*loc
, **tmp
;
2010 int bitpos
= 0, bitsize
= 0;
2012 if (value_bitsize (v
) != 0)
2014 /* Extract the bit parameters out from the bitfield
2016 bitpos
= value_bitpos (v
);
2017 bitsize
= value_bitsize (v
);
2019 else if (v
== result
&& b
->val_bitsize
!= 0)
2021 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2022 lvalue whose bit parameters are saved in the fields
2023 VAL_BITPOS and VAL_BITSIZE. */
2024 bitpos
= b
->val_bitpos
;
2025 bitsize
= b
->val_bitsize
;
2028 addr
= value_address (v
);
2031 /* Skip the bytes that don't contain the bitfield. */
2036 if (b
->base
.type
== bp_read_watchpoint
)
2038 else if (b
->base
.type
== bp_access_watchpoint
)
2041 loc
= allocate_bp_location (&b
->base
);
2042 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2045 loc
->gdbarch
= get_type_arch (value_type (v
));
2047 loc
->pspace
= frame_pspace
;
2048 loc
->address
= addr
;
2052 /* Just cover the bytes that make up the bitfield. */
2053 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2056 loc
->length
= TYPE_LENGTH (value_type (v
));
2058 loc
->watchpoint_type
= type
;
2063 /* Change the type of breakpoint between hardware assisted or
2064 an ordinary watchpoint depending on the hardware support
2065 and free hardware slots. REPARSE is set when the inferior
2070 enum bp_loc_type loc_type
;
2071 struct bp_location
*bl
;
2073 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2077 int i
, target_resources_ok
, other_type_used
;
2080 /* Use an exact watchpoint when there's only one memory region to be
2081 watched, and only one debug register is needed to watch it. */
2082 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2084 /* We need to determine how many resources are already
2085 used for all other hardware watchpoints plus this one
2086 to see if we still have enough resources to also fit
2087 this watchpoint in as well. */
2089 /* If this is a software watchpoint, we try to turn it
2090 to a hardware one -- count resources as if B was of
2091 hardware watchpoint type. */
2092 type
= b
->base
.type
;
2093 if (type
== bp_watchpoint
)
2094 type
= bp_hardware_watchpoint
;
2096 /* This watchpoint may or may not have been placed on
2097 the list yet at this point (it won't be in the list
2098 if we're trying to create it for the first time,
2099 through watch_command), so always account for it
2102 /* Count resources used by all watchpoints except B. */
2103 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2105 /* Add in the resources needed for B. */
2106 i
+= hw_watchpoint_use_count (&b
->base
);
2109 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2110 if (target_resources_ok
<= 0)
2112 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2114 if (target_resources_ok
== 0 && !sw_mode
)
2115 error (_("Target does not support this type of "
2116 "hardware watchpoint."));
2117 else if (target_resources_ok
< 0 && !sw_mode
)
2118 error (_("There are not enough available hardware "
2119 "resources for this watchpoint."));
2121 /* Downgrade to software watchpoint. */
2122 b
->base
.type
= bp_watchpoint
;
2126 /* If this was a software watchpoint, we've just
2127 found we have enough resources to turn it to a
2128 hardware watchpoint. Otherwise, this is a
2130 b
->base
.type
= type
;
2133 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2135 if (!can_use_hw_watchpoints
)
2136 error (_("Can't set read/access watchpoint when "
2137 "hardware watchpoints are disabled."));
2139 error (_("Expression cannot be implemented with "
2140 "read/access watchpoint."));
2143 b
->base
.type
= bp_watchpoint
;
2145 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2146 : bp_loc_hardware_watchpoint
);
2147 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2148 bl
->loc_type
= loc_type
;
2151 for (v
= val_chain
; v
; v
= next
)
2153 next
= value_next (v
);
2158 /* If a software watchpoint is not watching any memory, then the
2159 above left it without any location set up. But,
2160 bpstat_stop_status requires a location to be able to report
2161 stops, so make sure there's at least a dummy one. */
2162 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2163 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2165 else if (!within_current_scope
)
2167 printf_filtered (_("\
2168 Watchpoint %d deleted because the program has left the block\n\
2169 in which its expression is valid.\n"),
2171 watchpoint_del_at_next_stop (b
);
2174 /* Restore the selected frame. */
2176 select_frame (frame_find_by_id (saved_frame_id
));
2180 /* Returns 1 iff breakpoint location should be
2181 inserted in the inferior. We don't differentiate the type of BL's owner
2182 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2183 breakpoint_ops is not defined, because in insert_bp_location,
2184 tracepoint's insert_location will not be called. */
2186 should_be_inserted (struct bp_location
*bl
)
2188 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2191 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2194 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2197 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2200 /* This is set for example, when we're attached to the parent of a
2201 vfork, and have detached from the child. The child is running
2202 free, and we expect it to do an exec or exit, at which point the
2203 OS makes the parent schedulable again (and the target reports
2204 that the vfork is done). Until the child is done with the shared
2205 memory region, do not insert breakpoints in the parent, otherwise
2206 the child could still trip on the parent's breakpoints. Since
2207 the parent is blocked anyway, it won't miss any breakpoint. */
2208 if (bl
->pspace
->breakpoints_not_allowed
)
2211 /* Don't insert a breakpoint if we're trying to step past its
2212 location, except if the breakpoint is a single-step breakpoint,
2213 and the breakpoint's thread is the thread which is stepping past
2215 if ((bl
->loc_type
== bp_loc_software_breakpoint
2216 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2217 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2219 /* The single-step breakpoint may be inserted at the location
2220 we're trying to step if the instruction branches to itself.
2221 However, the instruction won't be executed at all and it may
2222 break the semantics of the instruction, for example, the
2223 instruction is a conditional branch or updates some flags.
2224 We can't fix it unless GDB is able to emulate the instruction
2225 or switch to displaced stepping. */
2226 && !(bl
->owner
->type
== bp_single_step
2227 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2231 fprintf_unfiltered (gdb_stdlog
,
2232 "infrun: skipping breakpoint: "
2233 "stepping past insn at: %s\n",
2234 paddress (bl
->gdbarch
, bl
->address
));
2239 /* Don't insert watchpoints if we're trying to step past the
2240 instruction that triggered one. */
2241 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2242 && stepping_past_nonsteppable_watchpoint ())
2246 fprintf_unfiltered (gdb_stdlog
,
2247 "infrun: stepping past non-steppable watchpoint. "
2248 "skipping watchpoint at %s:%d\n",
2249 paddress (bl
->gdbarch
, bl
->address
),
2258 /* Same as should_be_inserted but does the check assuming
2259 that the location is not duplicated. */
2262 unduplicated_should_be_inserted (struct bp_location
*bl
)
2265 const int save_duplicate
= bl
->duplicate
;
2268 result
= should_be_inserted (bl
);
2269 bl
->duplicate
= save_duplicate
;
2273 /* Parses a conditional described by an expression COND into an
2274 agent expression bytecode suitable for evaluation
2275 by the bytecode interpreter. Return NULL if there was
2276 any error during parsing. */
2278 static struct agent_expr
*
2279 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2281 struct agent_expr
*aexpr
= NULL
;
2286 /* We don't want to stop processing, so catch any errors
2287 that may show up. */
2290 aexpr
= gen_eval_for_expr (scope
, cond
);
2293 CATCH (ex
, RETURN_MASK_ERROR
)
2295 /* If we got here, it means the condition could not be parsed to a valid
2296 bytecode expression and thus can't be evaluated on the target's side.
2297 It's no use iterating through the conditions. */
2302 /* We have a valid agent expression. */
2306 /* Based on location BL, create a list of breakpoint conditions to be
2307 passed on to the target. If we have duplicated locations with different
2308 conditions, we will add such conditions to the list. The idea is that the
2309 target will evaluate the list of conditions and will only notify GDB when
2310 one of them is true. */
2313 build_target_condition_list (struct bp_location
*bl
)
2315 struct bp_location
**locp
= NULL
, **loc2p
;
2316 int null_condition_or_parse_error
= 0;
2317 int modified
= bl
->needs_update
;
2318 struct bp_location
*loc
;
2320 /* Release conditions left over from a previous insert. */
2321 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2323 /* This is only meaningful if the target is
2324 evaluating conditions and if the user has
2325 opted for condition evaluation on the target's
2327 if (gdb_evaluates_breakpoint_condition_p ()
2328 || !target_supports_evaluation_of_breakpoint_conditions ())
2331 /* Do a first pass to check for locations with no assigned
2332 conditions or conditions that fail to parse to a valid agent expression
2333 bytecode. If any of these happen, then it's no use to send conditions
2334 to the target since this location will always trigger and generate a
2335 response back to GDB. */
2336 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2339 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2343 struct agent_expr
*aexpr
;
2345 /* Re-parse the conditions since something changed. In that
2346 case we already freed the condition bytecodes (see
2347 force_breakpoint_reinsertion). We just
2348 need to parse the condition to bytecodes again. */
2349 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2350 loc
->cond_bytecode
= aexpr
;
2353 /* If we have a NULL bytecode expression, it means something
2354 went wrong or we have a null condition expression. */
2355 if (!loc
->cond_bytecode
)
2357 null_condition_or_parse_error
= 1;
2363 /* If any of these happened, it means we will have to evaluate the conditions
2364 for the location's address on gdb's side. It is no use keeping bytecodes
2365 for all the other duplicate locations, thus we free all of them here.
2367 This is so we have a finer control over which locations' conditions are
2368 being evaluated by GDB or the remote stub. */
2369 if (null_condition_or_parse_error
)
2371 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2374 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2376 /* Only go as far as the first NULL bytecode is
2378 if (!loc
->cond_bytecode
)
2381 free_agent_expr (loc
->cond_bytecode
);
2382 loc
->cond_bytecode
= NULL
;
2387 /* No NULL conditions or failed bytecode generation. Build a condition list
2388 for this location's address. */
2389 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2393 && is_breakpoint (loc
->owner
)
2394 && loc
->pspace
->num
== bl
->pspace
->num
2395 && loc
->owner
->enable_state
== bp_enabled
2397 /* Add the condition to the vector. This will be used later to send the
2398 conditions to the target. */
2399 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2400 loc
->cond_bytecode
);
2406 /* Parses a command described by string CMD into an agent expression
2407 bytecode suitable for evaluation by the bytecode interpreter.
2408 Return NULL if there was any error during parsing. */
2410 static struct agent_expr
*
2411 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2413 struct cleanup
*old_cleanups
= 0;
2414 struct expression
*expr
, **argvec
;
2415 struct agent_expr
*aexpr
= NULL
;
2416 const char *cmdrest
;
2417 const char *format_start
, *format_end
;
2418 struct format_piece
*fpieces
;
2420 struct gdbarch
*gdbarch
= get_current_arch ();
2427 if (*cmdrest
== ',')
2429 cmdrest
= skip_spaces_const (cmdrest
);
2431 if (*cmdrest
++ != '"')
2432 error (_("No format string following the location"));
2434 format_start
= cmdrest
;
2436 fpieces
= parse_format_string (&cmdrest
);
2438 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2440 format_end
= cmdrest
;
2442 if (*cmdrest
++ != '"')
2443 error (_("Bad format string, non-terminated '\"'."));
2445 cmdrest
= skip_spaces_const (cmdrest
);
2447 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2448 error (_("Invalid argument syntax"));
2450 if (*cmdrest
== ',')
2452 cmdrest
= skip_spaces_const (cmdrest
);
2454 /* For each argument, make an expression. */
2456 argvec
= (struct expression
**) alloca (strlen (cmd
)
2457 * sizeof (struct expression
*));
2460 while (*cmdrest
!= '\0')
2465 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2466 argvec
[nargs
++] = expr
;
2468 if (*cmdrest
== ',')
2472 /* We don't want to stop processing, so catch any errors
2473 that may show up. */
2476 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2477 format_start
, format_end
- format_start
,
2478 fpieces
, nargs
, argvec
);
2480 CATCH (ex
, RETURN_MASK_ERROR
)
2482 /* If we got here, it means the command could not be parsed to a valid
2483 bytecode expression and thus can't be evaluated on the target's side.
2484 It's no use iterating through the other commands. */
2489 do_cleanups (old_cleanups
);
2491 /* We have a valid agent expression, return it. */
2495 /* Based on location BL, create a list of breakpoint commands to be
2496 passed on to the target. If we have duplicated locations with
2497 different commands, we will add any such to the list. */
2500 build_target_command_list (struct bp_location
*bl
)
2502 struct bp_location
**locp
= NULL
, **loc2p
;
2503 int null_command_or_parse_error
= 0;
2504 int modified
= bl
->needs_update
;
2505 struct bp_location
*loc
;
2507 /* Release commands left over from a previous insert. */
2508 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2510 if (!target_can_run_breakpoint_commands ())
2513 /* For now, limit to agent-style dprintf breakpoints. */
2514 if (dprintf_style
!= dprintf_style_agent
)
2517 /* For now, if we have any duplicate location that isn't a dprintf,
2518 don't install the target-side commands, as that would make the
2519 breakpoint not be reported to the core, and we'd lose
2521 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2524 if (is_breakpoint (loc
->owner
)
2525 && loc
->pspace
->num
== bl
->pspace
->num
2526 && loc
->owner
->type
!= bp_dprintf
)
2530 /* Do a first pass to check for locations with no assigned
2531 conditions or conditions that fail to parse to a valid agent expression
2532 bytecode. If any of these happen, then it's no use to send conditions
2533 to the target since this location will always trigger and generate a
2534 response back to GDB. */
2535 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2538 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2542 struct agent_expr
*aexpr
;
2544 /* Re-parse the commands since something changed. In that
2545 case we already freed the command bytecodes (see
2546 force_breakpoint_reinsertion). We just
2547 need to parse the command to bytecodes again. */
2548 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2549 loc
->owner
->extra_string
);
2550 loc
->cmd_bytecode
= aexpr
;
2553 /* If we have a NULL bytecode expression, it means something
2554 went wrong or we have a null command expression. */
2555 if (!loc
->cmd_bytecode
)
2557 null_command_or_parse_error
= 1;
2563 /* If anything failed, then we're not doing target-side commands,
2565 if (null_command_or_parse_error
)
2567 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2570 if (is_breakpoint (loc
->owner
)
2571 && loc
->pspace
->num
== bl
->pspace
->num
)
2573 /* Only go as far as the first NULL bytecode is
2575 if (loc
->cmd_bytecode
== NULL
)
2578 free_agent_expr (loc
->cmd_bytecode
);
2579 loc
->cmd_bytecode
= NULL
;
2584 /* No NULL commands or failed bytecode generation. Build a command list
2585 for this location's address. */
2586 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2589 if (loc
->owner
->extra_string
2590 && is_breakpoint (loc
->owner
)
2591 && loc
->pspace
->num
== bl
->pspace
->num
2592 && loc
->owner
->enable_state
== bp_enabled
2594 /* Add the command to the vector. This will be used later
2595 to send the commands to the target. */
2596 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2600 bl
->target_info
.persist
= 0;
2601 /* Maybe flag this location as persistent. */
2602 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2603 bl
->target_info
.persist
= 1;
2606 /* Return the kind of breakpoint on address *ADDR. */
2609 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2611 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2614 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2615 location. Any error messages are printed to TMP_ERROR_STREAM; and
2616 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2617 Returns 0 for success, 1 if the bp_location type is not supported or
2620 NOTE drow/2003-09-09: This routine could be broken down to an
2621 object-style method for each breakpoint or catchpoint type. */
2623 insert_bp_location (struct bp_location
*bl
,
2624 struct ui_file
*tmp_error_stream
,
2625 int *disabled_breaks
,
2626 int *hw_breakpoint_error
,
2627 int *hw_bp_error_explained_already
)
2629 enum errors bp_err
= GDB_NO_ERROR
;
2630 const char *bp_err_message
= NULL
;
2632 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2635 /* Note we don't initialize bl->target_info, as that wipes out
2636 the breakpoint location's shadow_contents if the breakpoint
2637 is still inserted at that location. This in turn breaks
2638 target_read_memory which depends on these buffers when
2639 a memory read is requested at the breakpoint location:
2640 Once the target_info has been wiped, we fail to see that
2641 we have a breakpoint inserted at that address and thus
2642 read the breakpoint instead of returning the data saved in
2643 the breakpoint location's shadow contents. */
2644 bl
->target_info
.reqstd_address
= bl
->address
;
2645 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2646 bl
->target_info
.length
= bl
->length
;
2648 /* When working with target-side conditions, we must pass all the conditions
2649 for the same breakpoint address down to the target since GDB will not
2650 insert those locations. With a list of breakpoint conditions, the target
2651 can decide when to stop and notify GDB. */
2653 if (is_breakpoint (bl
->owner
))
2655 build_target_condition_list (bl
);
2656 build_target_command_list (bl
);
2657 /* Reset the modification marker. */
2658 bl
->needs_update
= 0;
2661 if (bl
->loc_type
== bp_loc_software_breakpoint
2662 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2664 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2666 /* If the explicitly specified breakpoint type
2667 is not hardware breakpoint, check the memory map to see
2668 if the breakpoint address is in read only memory or not.
2670 Two important cases are:
2671 - location type is not hardware breakpoint, memory
2672 is readonly. We change the type of the location to
2673 hardware breakpoint.
2674 - location type is hardware breakpoint, memory is
2675 read-write. This means we've previously made the
2676 location hardware one, but then the memory map changed,
2679 When breakpoints are removed, remove_breakpoints will use
2680 location types we've just set here, the only possible
2681 problem is that memory map has changed during running
2682 program, but it's not going to work anyway with current
2684 struct mem_region
*mr
2685 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2689 if (automatic_hardware_breakpoints
)
2691 enum bp_loc_type new_type
;
2693 if (mr
->attrib
.mode
!= MEM_RW
)
2694 new_type
= bp_loc_hardware_breakpoint
;
2696 new_type
= bp_loc_software_breakpoint
;
2698 if (new_type
!= bl
->loc_type
)
2700 static int said
= 0;
2702 bl
->loc_type
= new_type
;
2705 fprintf_filtered (gdb_stdout
,
2706 _("Note: automatically using "
2707 "hardware breakpoints for "
2708 "read-only addresses.\n"));
2713 else if (bl
->loc_type
== bp_loc_software_breakpoint
2714 && mr
->attrib
.mode
!= MEM_RW
)
2716 fprintf_unfiltered (tmp_error_stream
,
2717 _("Cannot insert breakpoint %d.\n"
2718 "Cannot set software breakpoint "
2719 "at read-only address %s\n"),
2721 paddress (bl
->gdbarch
, bl
->address
));
2727 /* First check to see if we have to handle an overlay. */
2728 if (overlay_debugging
== ovly_off
2729 || bl
->section
== NULL
2730 || !(section_is_overlay (bl
->section
)))
2732 /* No overlay handling: just set the breakpoint. */
2737 val
= bl
->owner
->ops
->insert_location (bl
);
2739 bp_err
= GENERIC_ERROR
;
2741 CATCH (e
, RETURN_MASK_ALL
)
2744 bp_err_message
= e
.message
;
2750 /* This breakpoint is in an overlay section.
2751 Shall we set a breakpoint at the LMA? */
2752 if (!overlay_events_enabled
)
2754 /* Yes -- overlay event support is not active,
2755 so we must try to set a breakpoint at the LMA.
2756 This will not work for a hardware breakpoint. */
2757 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2758 warning (_("hardware breakpoint %d not supported in overlay!"),
2762 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2764 /* Set a software (trap) breakpoint at the LMA. */
2765 bl
->overlay_target_info
= bl
->target_info
;
2766 bl
->overlay_target_info
.reqstd_address
= addr
;
2768 /* No overlay handling: just set the breakpoint. */
2773 bl
->overlay_target_info
.kind
2774 = breakpoint_kind (bl
, &addr
);
2775 bl
->overlay_target_info
.placed_address
= addr
;
2776 val
= target_insert_breakpoint (bl
->gdbarch
,
2777 &bl
->overlay_target_info
);
2779 bp_err
= GENERIC_ERROR
;
2781 CATCH (e
, RETURN_MASK_ALL
)
2784 bp_err_message
= e
.message
;
2788 if (bp_err
!= GDB_NO_ERROR
)
2789 fprintf_unfiltered (tmp_error_stream
,
2790 "Overlay breakpoint %d "
2791 "failed: in ROM?\n",
2795 /* Shall we set a breakpoint at the VMA? */
2796 if (section_is_mapped (bl
->section
))
2798 /* Yes. This overlay section is mapped into memory. */
2803 val
= bl
->owner
->ops
->insert_location (bl
);
2805 bp_err
= GENERIC_ERROR
;
2807 CATCH (e
, RETURN_MASK_ALL
)
2810 bp_err_message
= e
.message
;
2816 /* No. This breakpoint will not be inserted.
2817 No error, but do not mark the bp as 'inserted'. */
2822 if (bp_err
!= GDB_NO_ERROR
)
2824 /* Can't set the breakpoint. */
2826 /* In some cases, we might not be able to insert a
2827 breakpoint in a shared library that has already been
2828 removed, but we have not yet processed the shlib unload
2829 event. Unfortunately, some targets that implement
2830 breakpoint insertion themselves can't tell why the
2831 breakpoint insertion failed (e.g., the remote target
2832 doesn't define error codes), so we must treat generic
2833 errors as memory errors. */
2834 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2835 && bl
->loc_type
== bp_loc_software_breakpoint
2836 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2837 || shared_objfile_contains_address_p (bl
->pspace
,
2840 /* See also: disable_breakpoints_in_shlibs. */
2841 bl
->shlib_disabled
= 1;
2842 observer_notify_breakpoint_modified (bl
->owner
);
2843 if (!*disabled_breaks
)
2845 fprintf_unfiltered (tmp_error_stream
,
2846 "Cannot insert breakpoint %d.\n",
2848 fprintf_unfiltered (tmp_error_stream
,
2849 "Temporarily disabling shared "
2850 "library breakpoints:\n");
2852 *disabled_breaks
= 1;
2853 fprintf_unfiltered (tmp_error_stream
,
2854 "breakpoint #%d\n", bl
->owner
->number
);
2859 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2861 *hw_breakpoint_error
= 1;
2862 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2863 fprintf_unfiltered (tmp_error_stream
,
2864 "Cannot insert hardware breakpoint %d%s",
2865 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2866 if (bp_err_message
!= NULL
)
2867 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2871 if (bp_err_message
== NULL
)
2874 = memory_error_message (TARGET_XFER_E_IO
,
2875 bl
->gdbarch
, bl
->address
);
2876 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2878 fprintf_unfiltered (tmp_error_stream
,
2879 "Cannot insert breakpoint %d.\n"
2881 bl
->owner
->number
, message
);
2882 do_cleanups (old_chain
);
2886 fprintf_unfiltered (tmp_error_stream
,
2887 "Cannot insert breakpoint %d: %s\n",
2902 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2903 /* NOTE drow/2003-09-08: This state only exists for removing
2904 watchpoints. It's not clear that it's necessary... */
2905 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2909 gdb_assert (bl
->owner
->ops
!= NULL
2910 && bl
->owner
->ops
->insert_location
!= NULL
);
2912 val
= bl
->owner
->ops
->insert_location (bl
);
2914 /* If trying to set a read-watchpoint, and it turns out it's not
2915 supported, try emulating one with an access watchpoint. */
2916 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2918 struct bp_location
*loc
, **loc_temp
;
2920 /* But don't try to insert it, if there's already another
2921 hw_access location that would be considered a duplicate
2923 ALL_BP_LOCATIONS (loc
, loc_temp
)
2925 && loc
->watchpoint_type
== hw_access
2926 && watchpoint_locations_match (bl
, loc
))
2930 bl
->target_info
= loc
->target_info
;
2931 bl
->watchpoint_type
= hw_access
;
2938 bl
->watchpoint_type
= hw_access
;
2939 val
= bl
->owner
->ops
->insert_location (bl
);
2942 /* Back to the original value. */
2943 bl
->watchpoint_type
= hw_read
;
2947 bl
->inserted
= (val
== 0);
2950 else if (bl
->owner
->type
== bp_catchpoint
)
2954 gdb_assert (bl
->owner
->ops
!= NULL
2955 && bl
->owner
->ops
->insert_location
!= NULL
);
2957 val
= bl
->owner
->ops
->insert_location (bl
);
2960 bl
->owner
->enable_state
= bp_disabled
;
2964 Error inserting catchpoint %d: Your system does not support this type\n\
2965 of catchpoint."), bl
->owner
->number
);
2967 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2970 bl
->inserted
= (val
== 0);
2972 /* We've already printed an error message if there was a problem
2973 inserting this catchpoint, and we've disabled the catchpoint,
2974 so just return success. */
2981 /* This function is called when program space PSPACE is about to be
2982 deleted. It takes care of updating breakpoints to not reference
2986 breakpoint_program_space_exit (struct program_space
*pspace
)
2988 struct breakpoint
*b
, *b_temp
;
2989 struct bp_location
*loc
, **loc_temp
;
2991 /* Remove any breakpoint that was set through this program space. */
2992 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2994 if (b
->pspace
== pspace
)
2995 delete_breakpoint (b
);
2998 /* Breakpoints set through other program spaces could have locations
2999 bound to PSPACE as well. Remove those. */
3000 ALL_BP_LOCATIONS (loc
, loc_temp
)
3002 struct bp_location
*tmp
;
3004 if (loc
->pspace
== pspace
)
3006 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3007 if (loc
->owner
->loc
== loc
)
3008 loc
->owner
->loc
= loc
->next
;
3010 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3011 if (tmp
->next
== loc
)
3013 tmp
->next
= loc
->next
;
3019 /* Now update the global location list to permanently delete the
3020 removed locations above. */
3021 update_global_location_list (UGLL_DONT_INSERT
);
3024 /* Make sure all breakpoints are inserted in inferior.
3025 Throws exception on any error.
3026 A breakpoint that is already inserted won't be inserted
3027 again, so calling this function twice is safe. */
3029 insert_breakpoints (void)
3031 struct breakpoint
*bpt
;
3033 ALL_BREAKPOINTS (bpt
)
3034 if (is_hardware_watchpoint (bpt
))
3036 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3038 update_watchpoint (w
, 0 /* don't reparse. */);
3041 /* Updating watchpoints creates new locations, so update the global
3042 location list. Explicitly tell ugll to insert locations and
3043 ignore breakpoints_always_inserted_mode. */
3044 update_global_location_list (UGLL_INSERT
);
3047 /* Invoke CALLBACK for each of bp_location. */
3050 iterate_over_bp_locations (walk_bp_location_callback callback
)
3052 struct bp_location
*loc
, **loc_tmp
;
3054 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3056 callback (loc
, NULL
);
3060 /* This is used when we need to synch breakpoint conditions between GDB and the
3061 target. It is the case with deleting and disabling of breakpoints when using
3062 always-inserted mode. */
3065 update_inserted_breakpoint_locations (void)
3067 struct bp_location
*bl
, **blp_tmp
;
3070 int disabled_breaks
= 0;
3071 int hw_breakpoint_error
= 0;
3072 int hw_bp_details_reported
= 0;
3074 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3075 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3077 /* Explicitly mark the warning -- this will only be printed if
3078 there was an error. */
3079 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3081 save_current_space_and_thread ();
3083 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3085 /* We only want to update software breakpoints and hardware
3087 if (!is_breakpoint (bl
->owner
))
3090 /* We only want to update locations that are already inserted
3091 and need updating. This is to avoid unwanted insertion during
3092 deletion of breakpoints. */
3093 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3096 switch_to_program_space_and_thread (bl
->pspace
);
3098 /* For targets that support global breakpoints, there's no need
3099 to select an inferior to insert breakpoint to. In fact, even
3100 if we aren't attached to any process yet, we should still
3101 insert breakpoints. */
3102 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3103 && ptid_equal (inferior_ptid
, null_ptid
))
3106 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3107 &hw_breakpoint_error
, &hw_bp_details_reported
);
3114 target_terminal_ours_for_output ();
3115 error_stream (tmp_error_stream
);
3118 do_cleanups (cleanups
);
3121 /* Used when starting or continuing the program. */
3124 insert_breakpoint_locations (void)
3126 struct breakpoint
*bpt
;
3127 struct bp_location
*bl
, **blp_tmp
;
3130 int disabled_breaks
= 0;
3131 int hw_breakpoint_error
= 0;
3132 int hw_bp_error_explained_already
= 0;
3134 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3135 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3137 /* Explicitly mark the warning -- this will only be printed if
3138 there was an error. */
3139 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3141 save_current_space_and_thread ();
3143 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3145 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3148 /* There is no point inserting thread-specific breakpoints if
3149 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3150 has BL->OWNER always non-NULL. */
3151 if (bl
->owner
->thread
!= -1
3152 && !valid_global_thread_id (bl
->owner
->thread
))
3155 switch_to_program_space_and_thread (bl
->pspace
);
3157 /* For targets that support global breakpoints, there's no need
3158 to select an inferior to insert breakpoint to. In fact, even
3159 if we aren't attached to any process yet, we should still
3160 insert breakpoints. */
3161 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3162 && ptid_equal (inferior_ptid
, null_ptid
))
3165 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3166 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3171 /* If we failed to insert all locations of a watchpoint, remove
3172 them, as half-inserted watchpoint is of limited use. */
3173 ALL_BREAKPOINTS (bpt
)
3175 int some_failed
= 0;
3176 struct bp_location
*loc
;
3178 if (!is_hardware_watchpoint (bpt
))
3181 if (!breakpoint_enabled (bpt
))
3184 if (bpt
->disposition
== disp_del_at_next_stop
)
3187 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3188 if (!loc
->inserted
&& should_be_inserted (loc
))
3195 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3197 remove_breakpoint (loc
);
3199 hw_breakpoint_error
= 1;
3200 fprintf_unfiltered (tmp_error_stream
,
3201 "Could not insert hardware watchpoint %d.\n",
3209 /* If a hardware breakpoint or watchpoint was inserted, add a
3210 message about possibly exhausted resources. */
3211 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3213 fprintf_unfiltered (tmp_error_stream
,
3214 "Could not insert hardware breakpoints:\n\
3215 You may have requested too many hardware breakpoints/watchpoints.\n");
3217 target_terminal_ours_for_output ();
3218 error_stream (tmp_error_stream
);
3221 do_cleanups (cleanups
);
3224 /* Used when the program stops.
3225 Returns zero if successful, or non-zero if there was a problem
3226 removing a breakpoint location. */
3229 remove_breakpoints (void)
3231 struct bp_location
*bl
, **blp_tmp
;
3234 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3236 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3237 val
|= remove_breakpoint (bl
);
3242 /* When a thread exits, remove breakpoints that are related to
3246 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3248 struct breakpoint
*b
, *b_tmp
;
3250 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3252 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3254 b
->disposition
= disp_del_at_next_stop
;
3256 printf_filtered (_("\
3257 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3258 b
->number
, print_thread_id (tp
));
3260 /* Hide it from the user. */
3266 /* Remove breakpoints of process PID. */
3269 remove_breakpoints_pid (int pid
)
3271 struct bp_location
*bl
, **blp_tmp
;
3273 struct inferior
*inf
= find_inferior_pid (pid
);
3275 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3277 if (bl
->pspace
!= inf
->pspace
)
3280 if (bl
->inserted
&& !bl
->target_info
.persist
)
3282 val
= remove_breakpoint (bl
);
3291 reattach_breakpoints (int pid
)
3293 struct cleanup
*old_chain
;
3294 struct bp_location
*bl
, **blp_tmp
;
3296 struct ui_file
*tmp_error_stream
;
3297 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3298 struct inferior
*inf
;
3299 struct thread_info
*tp
;
3301 tp
= any_live_thread_of_process (pid
);
3305 inf
= find_inferior_pid (pid
);
3306 old_chain
= save_inferior_ptid ();
3308 inferior_ptid
= tp
->ptid
;
3310 tmp_error_stream
= mem_fileopen ();
3311 make_cleanup_ui_file_delete (tmp_error_stream
);
3313 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3315 if (bl
->pspace
!= inf
->pspace
)
3321 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3324 do_cleanups (old_chain
);
3329 do_cleanups (old_chain
);
3333 static int internal_breakpoint_number
= -1;
3335 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3336 If INTERNAL is non-zero, the breakpoint number will be populated
3337 from internal_breakpoint_number and that variable decremented.
3338 Otherwise the breakpoint number will be populated from
3339 breakpoint_count and that value incremented. Internal breakpoints
3340 do not set the internal var bpnum. */
3342 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3345 b
->number
= internal_breakpoint_number
--;
3348 set_breakpoint_count (breakpoint_count
+ 1);
3349 b
->number
= breakpoint_count
;
3353 static struct breakpoint
*
3354 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3355 CORE_ADDR address
, enum bptype type
,
3356 const struct breakpoint_ops
*ops
)
3358 struct symtab_and_line sal
;
3359 struct breakpoint
*b
;
3361 init_sal (&sal
); /* Initialize to zeroes. */
3364 sal
.section
= find_pc_overlay (sal
.pc
);
3365 sal
.pspace
= current_program_space
;
3367 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3368 b
->number
= internal_breakpoint_number
--;
3369 b
->disposition
= disp_donttouch
;
3374 static const char *const longjmp_names
[] =
3376 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3378 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3380 /* Per-objfile data private to breakpoint.c. */
3381 struct breakpoint_objfile_data
3383 /* Minimal symbol for "_ovly_debug_event" (if any). */
3384 struct bound_minimal_symbol overlay_msym
;
3386 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3387 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3389 /* True if we have looked for longjmp probes. */
3390 int longjmp_searched
;
3392 /* SystemTap probe points for longjmp (if any). */
3393 VEC (probe_p
) *longjmp_probes
;
3395 /* Minimal symbol for "std::terminate()" (if any). */
3396 struct bound_minimal_symbol terminate_msym
;
3398 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3399 struct bound_minimal_symbol exception_msym
;
3401 /* True if we have looked for exception probes. */
3402 int exception_searched
;
3404 /* SystemTap probe points for unwinding (if any). */
3405 VEC (probe_p
) *exception_probes
;
3408 static const struct objfile_data
*breakpoint_objfile_key
;
3410 /* Minimal symbol not found sentinel. */
3411 static struct minimal_symbol msym_not_found
;
3413 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3416 msym_not_found_p (const struct minimal_symbol
*msym
)
3418 return msym
== &msym_not_found
;
3421 /* Return per-objfile data needed by breakpoint.c.
3422 Allocate the data if necessary. */
3424 static struct breakpoint_objfile_data
*
3425 get_breakpoint_objfile_data (struct objfile
*objfile
)
3427 struct breakpoint_objfile_data
*bp_objfile_data
;
3429 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3430 objfile_data (objfile
, breakpoint_objfile_key
));
3431 if (bp_objfile_data
== NULL
)
3434 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3436 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3437 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3439 return bp_objfile_data
;
3443 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3445 struct breakpoint_objfile_data
*bp_objfile_data
3446 = (struct breakpoint_objfile_data
*) data
;
3448 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3449 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3453 create_overlay_event_breakpoint (void)
3455 struct objfile
*objfile
;
3456 const char *const func_name
= "_ovly_debug_event";
3458 ALL_OBJFILES (objfile
)
3460 struct breakpoint
*b
;
3461 struct breakpoint_objfile_data
*bp_objfile_data
;
3463 struct explicit_location explicit_loc
;
3465 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3467 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3470 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3472 struct bound_minimal_symbol m
;
3474 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3475 if (m
.minsym
== NULL
)
3477 /* Avoid future lookups in this objfile. */
3478 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3481 bp_objfile_data
->overlay_msym
= m
;
3484 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3485 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3487 &internal_breakpoint_ops
);
3488 initialize_explicit_location (&explicit_loc
);
3489 explicit_loc
.function_name
= ASTRDUP (func_name
);
3490 b
->location
= new_explicit_location (&explicit_loc
);
3492 if (overlay_debugging
== ovly_auto
)
3494 b
->enable_state
= bp_enabled
;
3495 overlay_events_enabled
= 1;
3499 b
->enable_state
= bp_disabled
;
3500 overlay_events_enabled
= 0;
3506 create_longjmp_master_breakpoint (void)
3508 struct program_space
*pspace
;
3509 struct cleanup
*old_chain
;
3511 old_chain
= save_current_program_space ();
3513 ALL_PSPACES (pspace
)
3515 struct objfile
*objfile
;
3517 set_current_program_space (pspace
);
3519 ALL_OBJFILES (objfile
)
3522 struct gdbarch
*gdbarch
;
3523 struct breakpoint_objfile_data
*bp_objfile_data
;
3525 gdbarch
= get_objfile_arch (objfile
);
3527 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3529 if (!bp_objfile_data
->longjmp_searched
)
3533 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3536 /* We are only interested in checking one element. */
3537 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3539 if (!can_evaluate_probe_arguments (p
))
3541 /* We cannot use the probe interface here, because it does
3542 not know how to evaluate arguments. */
3543 VEC_free (probe_p
, ret
);
3547 bp_objfile_data
->longjmp_probes
= ret
;
3548 bp_objfile_data
->longjmp_searched
= 1;
3551 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3554 struct probe
*probe
;
3555 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3558 VEC_iterate (probe_p
,
3559 bp_objfile_data
->longjmp_probes
,
3563 struct breakpoint
*b
;
3565 b
= create_internal_breakpoint (gdbarch
,
3566 get_probe_address (probe
,
3569 &internal_breakpoint_ops
);
3571 = new_probe_location ("-probe-stap libc:longjmp");
3572 b
->enable_state
= bp_disabled
;
3578 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3581 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3583 struct breakpoint
*b
;
3584 const char *func_name
;
3586 struct explicit_location explicit_loc
;
3588 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3591 func_name
= longjmp_names
[i
];
3592 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3594 struct bound_minimal_symbol m
;
3596 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3597 if (m
.minsym
== NULL
)
3599 /* Prevent future lookups in this objfile. */
3600 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3603 bp_objfile_data
->longjmp_msym
[i
] = m
;
3606 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3607 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3608 &internal_breakpoint_ops
);
3609 initialize_explicit_location (&explicit_loc
);
3610 explicit_loc
.function_name
= ASTRDUP (func_name
);
3611 b
->location
= new_explicit_location (&explicit_loc
);
3612 b
->enable_state
= bp_disabled
;
3617 do_cleanups (old_chain
);
3620 /* Create a master std::terminate breakpoint. */
3622 create_std_terminate_master_breakpoint (void)
3624 struct program_space
*pspace
;
3625 struct cleanup
*old_chain
;
3626 const char *const func_name
= "std::terminate()";
3628 old_chain
= save_current_program_space ();
3630 ALL_PSPACES (pspace
)
3632 struct objfile
*objfile
;
3635 set_current_program_space (pspace
);
3637 ALL_OBJFILES (objfile
)
3639 struct breakpoint
*b
;
3640 struct breakpoint_objfile_data
*bp_objfile_data
;
3641 struct explicit_location explicit_loc
;
3643 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3645 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3648 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3650 struct bound_minimal_symbol m
;
3652 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3653 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3654 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3656 /* Prevent future lookups in this objfile. */
3657 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3660 bp_objfile_data
->terminate_msym
= m
;
3663 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3664 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3665 bp_std_terminate_master
,
3666 &internal_breakpoint_ops
);
3667 initialize_explicit_location (&explicit_loc
);
3668 explicit_loc
.function_name
= ASTRDUP (func_name
);
3669 b
->location
= new_explicit_location (&explicit_loc
);
3670 b
->enable_state
= bp_disabled
;
3674 do_cleanups (old_chain
);
3677 /* Install a master breakpoint on the unwinder's debug hook. */
3680 create_exception_master_breakpoint (void)
3682 struct objfile
*objfile
;
3683 const char *const func_name
= "_Unwind_DebugHook";
3685 ALL_OBJFILES (objfile
)
3687 struct breakpoint
*b
;
3688 struct gdbarch
*gdbarch
;
3689 struct breakpoint_objfile_data
*bp_objfile_data
;
3691 struct explicit_location explicit_loc
;
3693 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3695 /* We prefer the SystemTap probe point if it exists. */
3696 if (!bp_objfile_data
->exception_searched
)
3700 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3704 /* We are only interested in checking one element. */
3705 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3707 if (!can_evaluate_probe_arguments (p
))
3709 /* We cannot use the probe interface here, because it does
3710 not know how to evaluate arguments. */
3711 VEC_free (probe_p
, ret
);
3715 bp_objfile_data
->exception_probes
= ret
;
3716 bp_objfile_data
->exception_searched
= 1;
3719 if (bp_objfile_data
->exception_probes
!= NULL
)
3721 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3723 struct probe
*probe
;
3726 VEC_iterate (probe_p
,
3727 bp_objfile_data
->exception_probes
,
3731 struct breakpoint
*b
;
3733 b
= create_internal_breakpoint (gdbarch
,
3734 get_probe_address (probe
,
3736 bp_exception_master
,
3737 &internal_breakpoint_ops
);
3739 = new_probe_location ("-probe-stap libgcc:unwind");
3740 b
->enable_state
= bp_disabled
;
3746 /* Otherwise, try the hook function. */
3748 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3751 gdbarch
= get_objfile_arch (objfile
);
3753 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3755 struct bound_minimal_symbol debug_hook
;
3757 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3758 if (debug_hook
.minsym
== NULL
)
3760 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3764 bp_objfile_data
->exception_msym
= debug_hook
;
3767 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3768 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3770 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3771 &internal_breakpoint_ops
);
3772 initialize_explicit_location (&explicit_loc
);
3773 explicit_loc
.function_name
= ASTRDUP (func_name
);
3774 b
->location
= new_explicit_location (&explicit_loc
);
3775 b
->enable_state
= bp_disabled
;
3779 /* Does B have a location spec? */
3782 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3784 return b
->location
!= NULL
&& event_location_empty_p (b
->location
);
3788 update_breakpoints_after_exec (void)
3790 struct breakpoint
*b
, *b_tmp
;
3791 struct bp_location
*bploc
, **bplocp_tmp
;
3793 /* We're about to delete breakpoints from GDB's lists. If the
3794 INSERTED flag is true, GDB will try to lift the breakpoints by
3795 writing the breakpoints' "shadow contents" back into memory. The
3796 "shadow contents" are NOT valid after an exec, so GDB should not
3797 do that. Instead, the target is responsible from marking
3798 breakpoints out as soon as it detects an exec. We don't do that
3799 here instead, because there may be other attempts to delete
3800 breakpoints after detecting an exec and before reaching here. */
3801 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3802 if (bploc
->pspace
== current_program_space
)
3803 gdb_assert (!bploc
->inserted
);
3805 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3807 if (b
->pspace
!= current_program_space
)
3810 /* Solib breakpoints must be explicitly reset after an exec(). */
3811 if (b
->type
== bp_shlib_event
)
3813 delete_breakpoint (b
);
3817 /* JIT breakpoints must be explicitly reset after an exec(). */
3818 if (b
->type
== bp_jit_event
)
3820 delete_breakpoint (b
);
3824 /* Thread event breakpoints must be set anew after an exec(),
3825 as must overlay event and longjmp master breakpoints. */
3826 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3827 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3828 || b
->type
== bp_exception_master
)
3830 delete_breakpoint (b
);
3834 /* Step-resume breakpoints are meaningless after an exec(). */
3835 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3837 delete_breakpoint (b
);
3841 /* Just like single-step breakpoints. */
3842 if (b
->type
== bp_single_step
)
3844 delete_breakpoint (b
);
3848 /* Longjmp and longjmp-resume breakpoints are also meaningless
3850 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3851 || b
->type
== bp_longjmp_call_dummy
3852 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3854 delete_breakpoint (b
);
3858 if (b
->type
== bp_catchpoint
)
3860 /* For now, none of the bp_catchpoint breakpoints need to
3861 do anything at this point. In the future, if some of
3862 the catchpoints need to something, we will need to add
3863 a new method, and call this method from here. */
3867 /* bp_finish is a special case. The only way we ought to be able
3868 to see one of these when an exec() has happened, is if the user
3869 caught a vfork, and then said "finish". Ordinarily a finish just
3870 carries them to the call-site of the current callee, by setting
3871 a temporary bp there and resuming. But in this case, the finish
3872 will carry them entirely through the vfork & exec.
3874 We don't want to allow a bp_finish to remain inserted now. But
3875 we can't safely delete it, 'cause finish_command has a handle to
3876 the bp on a bpstat, and will later want to delete it. There's a
3877 chance (and I've seen it happen) that if we delete the bp_finish
3878 here, that its storage will get reused by the time finish_command
3879 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3880 We really must allow finish_command to delete a bp_finish.
3882 In the absence of a general solution for the "how do we know
3883 it's safe to delete something others may have handles to?"
3884 problem, what we'll do here is just uninsert the bp_finish, and
3885 let finish_command delete it.
3887 (We know the bp_finish is "doomed" in the sense that it's
3888 momentary, and will be deleted as soon as finish_command sees
3889 the inferior stopped. So it doesn't matter that the bp's
3890 address is probably bogus in the new a.out, unlike e.g., the
3891 solib breakpoints.) */
3893 if (b
->type
== bp_finish
)
3898 /* Without a symbolic address, we have little hope of the
3899 pre-exec() address meaning the same thing in the post-exec()
3901 if (breakpoint_event_location_empty_p (b
))
3903 delete_breakpoint (b
);
3910 detach_breakpoints (ptid_t ptid
)
3912 struct bp_location
*bl
, **blp_tmp
;
3914 struct cleanup
*old_chain
= save_inferior_ptid ();
3915 struct inferior
*inf
= current_inferior ();
3917 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3918 error (_("Cannot detach breakpoints of inferior_ptid"));
3920 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3921 inferior_ptid
= ptid
;
3922 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3924 if (bl
->pspace
!= inf
->pspace
)
3927 /* This function must physically remove breakpoints locations
3928 from the specified ptid, without modifying the breakpoint
3929 package's state. Locations of type bp_loc_other are only
3930 maintained at GDB side. So, there is no need to remove
3931 these bp_loc_other locations. Moreover, removing these
3932 would modify the breakpoint package's state. */
3933 if (bl
->loc_type
== bp_loc_other
)
3937 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3940 do_cleanups (old_chain
);
3944 /* Remove the breakpoint location BL from the current address space.
3945 Note that this is used to detach breakpoints from a child fork.
3946 When we get here, the child isn't in the inferior list, and neither
3947 do we have objects to represent its address space --- we should
3948 *not* look at bl->pspace->aspace here. */
3951 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3955 /* BL is never in moribund_locations by our callers. */
3956 gdb_assert (bl
->owner
!= NULL
);
3958 /* The type of none suggests that owner is actually deleted.
3959 This should not ever happen. */
3960 gdb_assert (bl
->owner
->type
!= bp_none
);
3962 if (bl
->loc_type
== bp_loc_software_breakpoint
3963 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3965 /* "Normal" instruction breakpoint: either the standard
3966 trap-instruction bp (bp_breakpoint), or a
3967 bp_hardware_breakpoint. */
3969 /* First check to see if we have to handle an overlay. */
3970 if (overlay_debugging
== ovly_off
3971 || bl
->section
== NULL
3972 || !(section_is_overlay (bl
->section
)))
3974 /* No overlay handling: just remove the breakpoint. */
3976 /* If we're trying to uninsert a memory breakpoint that we
3977 know is set in a dynamic object that is marked
3978 shlib_disabled, then either the dynamic object was
3979 removed with "remove-symbol-file" or with
3980 "nosharedlibrary". In the former case, we don't know
3981 whether another dynamic object might have loaded over the
3982 breakpoint's address -- the user might well let us know
3983 about it next with add-symbol-file (the whole point of
3984 add-symbol-file is letting the user manually maintain a
3985 list of dynamically loaded objects). If we have the
3986 breakpoint's shadow memory, that is, this is a software
3987 breakpoint managed by GDB, check whether the breakpoint
3988 is still inserted in memory, to avoid overwriting wrong
3989 code with stale saved shadow contents. Note that HW
3990 breakpoints don't have shadow memory, as they're
3991 implemented using a mechanism that is not dependent on
3992 being able to modify the target's memory, and as such
3993 they should always be removed. */
3994 if (bl
->shlib_disabled
3995 && bl
->target_info
.shadow_len
!= 0
3996 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3999 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4003 /* This breakpoint is in an overlay section.
4004 Did we set a breakpoint at the LMA? */
4005 if (!overlay_events_enabled
)
4007 /* Yes -- overlay event support is not active, so we
4008 should have set a breakpoint at the LMA. Remove it.
4010 /* Ignore any failures: if the LMA is in ROM, we will
4011 have already warned when we failed to insert it. */
4012 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4013 target_remove_hw_breakpoint (bl
->gdbarch
,
4014 &bl
->overlay_target_info
);
4016 target_remove_breakpoint (bl
->gdbarch
,
4017 &bl
->overlay_target_info
,
4020 /* Did we set a breakpoint at the VMA?
4021 If so, we will have marked the breakpoint 'inserted'. */
4024 /* Yes -- remove it. Previously we did not bother to
4025 remove the breakpoint if the section had been
4026 unmapped, but let's not rely on that being safe. We
4027 don't know what the overlay manager might do. */
4029 /* However, we should remove *software* breakpoints only
4030 if the section is still mapped, or else we overwrite
4031 wrong code with the saved shadow contents. */
4032 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4033 || section_is_mapped (bl
->section
))
4034 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4040 /* No -- not inserted, so no need to remove. No error. */
4045 /* In some cases, we might not be able to remove a breakpoint in
4046 a shared library that has already been removed, but we have
4047 not yet processed the shlib unload event. Similarly for an
4048 unloaded add-symbol-file object - the user might not yet have
4049 had the chance to remove-symbol-file it. shlib_disabled will
4050 be set if the library/object has already been removed, but
4051 the breakpoint hasn't been uninserted yet, e.g., after
4052 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4053 always-inserted mode. */
4055 && (bl
->loc_type
== bp_loc_software_breakpoint
4056 && (bl
->shlib_disabled
4057 || solib_name_from_address (bl
->pspace
, bl
->address
)
4058 || shared_objfile_contains_address_p (bl
->pspace
,
4064 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4066 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4068 gdb_assert (bl
->owner
->ops
!= NULL
4069 && bl
->owner
->ops
->remove_location
!= NULL
);
4071 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4072 bl
->owner
->ops
->remove_location (bl
, reason
);
4074 /* Failure to remove any of the hardware watchpoints comes here. */
4075 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4076 warning (_("Could not remove hardware watchpoint %d."),
4079 else if (bl
->owner
->type
== bp_catchpoint
4080 && breakpoint_enabled (bl
->owner
)
4083 gdb_assert (bl
->owner
->ops
!= NULL
4084 && bl
->owner
->ops
->remove_location
!= NULL
);
4086 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4090 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4097 remove_breakpoint (struct bp_location
*bl
)
4100 struct cleanup
*old_chain
;
4102 /* BL is never in moribund_locations by our callers. */
4103 gdb_assert (bl
->owner
!= NULL
);
4105 /* The type of none suggests that owner is actually deleted.
4106 This should not ever happen. */
4107 gdb_assert (bl
->owner
->type
!= bp_none
);
4109 old_chain
= save_current_space_and_thread ();
4111 switch_to_program_space_and_thread (bl
->pspace
);
4113 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4115 do_cleanups (old_chain
);
4119 /* Clear the "inserted" flag in all breakpoints. */
4122 mark_breakpoints_out (void)
4124 struct bp_location
*bl
, **blp_tmp
;
4126 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4127 if (bl
->pspace
== current_program_space
)
4131 /* Clear the "inserted" flag in all breakpoints and delete any
4132 breakpoints which should go away between runs of the program.
4134 Plus other such housekeeping that has to be done for breakpoints
4137 Note: this function gets called at the end of a run (by
4138 generic_mourn_inferior) and when a run begins (by
4139 init_wait_for_inferior). */
4144 breakpoint_init_inferior (enum inf_context context
)
4146 struct breakpoint
*b
, *b_tmp
;
4147 struct bp_location
*bl
;
4149 struct program_space
*pspace
= current_program_space
;
4151 /* If breakpoint locations are shared across processes, then there's
4153 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4156 mark_breakpoints_out ();
4158 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4160 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4166 case bp_longjmp_call_dummy
:
4168 /* If the call dummy breakpoint is at the entry point it will
4169 cause problems when the inferior is rerun, so we better get
4172 case bp_watchpoint_scope
:
4174 /* Also get rid of scope breakpoints. */
4176 case bp_shlib_event
:
4178 /* Also remove solib event breakpoints. Their addresses may
4179 have changed since the last time we ran the program.
4180 Actually we may now be debugging against different target;
4181 and so the solib backend that installed this breakpoint may
4182 not be used in by the target. E.g.,
4184 (gdb) file prog-linux
4185 (gdb) run # native linux target
4188 (gdb) file prog-win.exe
4189 (gdb) tar rem :9999 # remote Windows gdbserver.
4192 case bp_step_resume
:
4194 /* Also remove step-resume breakpoints. */
4196 case bp_single_step
:
4198 /* Also remove single-step breakpoints. */
4200 delete_breakpoint (b
);
4204 case bp_hardware_watchpoint
:
4205 case bp_read_watchpoint
:
4206 case bp_access_watchpoint
:
4208 struct watchpoint
*w
= (struct watchpoint
*) b
;
4210 /* Likewise for watchpoints on local expressions. */
4211 if (w
->exp_valid_block
!= NULL
)
4212 delete_breakpoint (b
);
4215 /* Get rid of existing locations, which are no longer
4216 valid. New ones will be created in
4217 update_watchpoint, when the inferior is restarted.
4218 The next update_global_location_list call will
4219 garbage collect them. */
4222 if (context
== inf_starting
)
4224 /* Reset val field to force reread of starting value in
4225 insert_breakpoints. */
4227 value_free (w
->val
);
4239 /* Get rid of the moribund locations. */
4240 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4241 decref_bp_location (&bl
);
4242 VEC_free (bp_location_p
, moribund_locations
);
4245 /* These functions concern about actual breakpoints inserted in the
4246 target --- to e.g. check if we need to do decr_pc adjustment or if
4247 we need to hop over the bkpt --- so we check for address space
4248 match, not program space. */
4250 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4251 exists at PC. It returns ordinary_breakpoint_here if it's an
4252 ordinary breakpoint, or permanent_breakpoint_here if it's a
4253 permanent breakpoint.
4254 - When continuing from a location with an ordinary breakpoint, we
4255 actually single step once before calling insert_breakpoints.
4256 - When continuing from a location with a permanent breakpoint, we
4257 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4258 the target, to advance the PC past the breakpoint. */
4260 enum breakpoint_here
4261 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4263 struct bp_location
*bl
, **blp_tmp
;
4264 int any_breakpoint_here
= 0;
4266 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4268 if (bl
->loc_type
!= bp_loc_software_breakpoint
4269 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4272 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4273 if ((breakpoint_enabled (bl
->owner
)
4275 && breakpoint_location_address_match (bl
, aspace
, pc
))
4277 if (overlay_debugging
4278 && section_is_overlay (bl
->section
)
4279 && !section_is_mapped (bl
->section
))
4280 continue; /* unmapped overlay -- can't be a match */
4281 else if (bl
->permanent
)
4282 return permanent_breakpoint_here
;
4284 any_breakpoint_here
= 1;
4288 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4291 /* See breakpoint.h. */
4294 breakpoint_in_range_p (struct address_space
*aspace
,
4295 CORE_ADDR addr
, ULONGEST len
)
4297 struct bp_location
*bl
, **blp_tmp
;
4299 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4301 if (bl
->loc_type
!= bp_loc_software_breakpoint
4302 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4305 if ((breakpoint_enabled (bl
->owner
)
4307 && breakpoint_location_address_range_overlap (bl
, aspace
,
4310 if (overlay_debugging
4311 && section_is_overlay (bl
->section
)
4312 && !section_is_mapped (bl
->section
))
4314 /* Unmapped overlay -- can't be a match. */
4325 /* Return true if there's a moribund breakpoint at PC. */
4328 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4330 struct bp_location
*loc
;
4333 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4334 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4340 /* Returns non-zero iff BL is inserted at PC, in address space
4344 bp_location_inserted_here_p (struct bp_location
*bl
,
4345 struct address_space
*aspace
, CORE_ADDR pc
)
4348 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4351 if (overlay_debugging
4352 && section_is_overlay (bl
->section
)
4353 && !section_is_mapped (bl
->section
))
4354 return 0; /* unmapped overlay -- can't be a match */
4361 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4364 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4366 struct bp_location
**blp
, **blp_tmp
= NULL
;
4368 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4370 struct bp_location
*bl
= *blp
;
4372 if (bl
->loc_type
!= bp_loc_software_breakpoint
4373 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4376 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4382 /* This function returns non-zero iff there is a software breakpoint
4386 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4389 struct bp_location
**blp
, **blp_tmp
= NULL
;
4391 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4393 struct bp_location
*bl
= *blp
;
4395 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4398 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4405 /* See breakpoint.h. */
4408 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4411 struct bp_location
**blp
, **blp_tmp
= NULL
;
4413 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4415 struct bp_location
*bl
= *blp
;
4417 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4420 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4428 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4429 CORE_ADDR addr
, ULONGEST len
)
4431 struct breakpoint
*bpt
;
4433 ALL_BREAKPOINTS (bpt
)
4435 struct bp_location
*loc
;
4437 if (bpt
->type
!= bp_hardware_watchpoint
4438 && bpt
->type
!= bp_access_watchpoint
)
4441 if (!breakpoint_enabled (bpt
))
4444 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4445 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4449 /* Check for intersection. */
4450 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4451 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4460 /* bpstat stuff. External routines' interfaces are documented
4464 is_catchpoint (struct breakpoint
*ep
)
4466 return (ep
->type
== bp_catchpoint
);
4469 /* Frees any storage that is part of a bpstat. Does not walk the
4473 bpstat_free (bpstat bs
)
4475 if (bs
->old_val
!= NULL
)
4476 value_free (bs
->old_val
);
4477 decref_counted_command_line (&bs
->commands
);
4478 decref_bp_location (&bs
->bp_location_at
);
4482 /* Clear a bpstat so that it says we are not at any breakpoint.
4483 Also free any storage that is part of a bpstat. */
4486 bpstat_clear (bpstat
*bsp
)
4503 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4504 is part of the bpstat is copied as well. */
4507 bpstat_copy (bpstat bs
)
4511 bpstat retval
= NULL
;
4516 for (; bs
!= NULL
; bs
= bs
->next
)
4518 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4519 memcpy (tmp
, bs
, sizeof (*tmp
));
4520 incref_counted_command_line (tmp
->commands
);
4521 incref_bp_location (tmp
->bp_location_at
);
4522 if (bs
->old_val
!= NULL
)
4524 tmp
->old_val
= value_copy (bs
->old_val
);
4525 release_value (tmp
->old_val
);
4529 /* This is the first thing in the chain. */
4539 /* Find the bpstat associated with this breakpoint. */
4542 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4547 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4549 if (bsp
->breakpoint_at
== breakpoint
)
4555 /* See breakpoint.h. */
4558 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4560 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4562 if (bsp
->breakpoint_at
== NULL
)
4564 /* A moribund location can never explain a signal other than
4566 if (sig
== GDB_SIGNAL_TRAP
)
4571 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4580 /* Put in *NUM the breakpoint number of the first breakpoint we are
4581 stopped at. *BSP upon return is a bpstat which points to the
4582 remaining breakpoints stopped at (but which is not guaranteed to be
4583 good for anything but further calls to bpstat_num).
4585 Return 0 if passed a bpstat which does not indicate any breakpoints.
4586 Return -1 if stopped at a breakpoint that has been deleted since
4588 Return 1 otherwise. */
4591 bpstat_num (bpstat
*bsp
, int *num
)
4593 struct breakpoint
*b
;
4596 return 0; /* No more breakpoint values */
4598 /* We assume we'll never have several bpstats that correspond to a
4599 single breakpoint -- otherwise, this function might return the
4600 same number more than once and this will look ugly. */
4601 b
= (*bsp
)->breakpoint_at
;
4602 *bsp
= (*bsp
)->next
;
4604 return -1; /* breakpoint that's been deleted since */
4606 *num
= b
->number
; /* We have its number */
4610 /* See breakpoint.h. */
4613 bpstat_clear_actions (void)
4615 struct thread_info
*tp
;
4618 if (ptid_equal (inferior_ptid
, null_ptid
))
4621 tp
= find_thread_ptid (inferior_ptid
);
4625 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4627 decref_counted_command_line (&bs
->commands
);
4629 if (bs
->old_val
!= NULL
)
4631 value_free (bs
->old_val
);
4637 /* Called when a command is about to proceed the inferior. */
4640 breakpoint_about_to_proceed (void)
4642 if (!ptid_equal (inferior_ptid
, null_ptid
))
4644 struct thread_info
*tp
= inferior_thread ();
4646 /* Allow inferior function calls in breakpoint commands to not
4647 interrupt the command list. When the call finishes
4648 successfully, the inferior will be standing at the same
4649 breakpoint as if nothing happened. */
4650 if (tp
->control
.in_infcall
)
4654 breakpoint_proceeded
= 1;
4657 /* Stub for cleaning up our state if we error-out of a breakpoint
4660 cleanup_executing_breakpoints (void *ignore
)
4662 executing_breakpoint_commands
= 0;
4665 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4666 or its equivalent. */
4669 command_line_is_silent (struct command_line
*cmd
)
4671 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4674 /* Execute all the commands associated with all the breakpoints at
4675 this location. Any of these commands could cause the process to
4676 proceed beyond this point, etc. We look out for such changes by
4677 checking the global "breakpoint_proceeded" after each command.
4679 Returns true if a breakpoint command resumed the inferior. In that
4680 case, it is the caller's responsibility to recall it again with the
4681 bpstat of the current thread. */
4684 bpstat_do_actions_1 (bpstat
*bsp
)
4687 struct cleanup
*old_chain
;
4690 /* Avoid endless recursion if a `source' command is contained
4692 if (executing_breakpoint_commands
)
4695 executing_breakpoint_commands
= 1;
4696 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4698 prevent_dont_repeat ();
4700 /* This pointer will iterate over the list of bpstat's. */
4703 breakpoint_proceeded
= 0;
4704 for (; bs
!= NULL
; bs
= bs
->next
)
4706 struct counted_command_line
*ccmd
;
4707 struct command_line
*cmd
;
4708 struct cleanup
*this_cmd_tree_chain
;
4710 /* Take ownership of the BSP's command tree, if it has one.
4712 The command tree could legitimately contain commands like
4713 'step' and 'next', which call clear_proceed_status, which
4714 frees stop_bpstat's command tree. To make sure this doesn't
4715 free the tree we're executing out from under us, we need to
4716 take ownership of the tree ourselves. Since a given bpstat's
4717 commands are only executed once, we don't need to copy it; we
4718 can clear the pointer in the bpstat, and make sure we free
4719 the tree when we're done. */
4720 ccmd
= bs
->commands
;
4721 bs
->commands
= NULL
;
4722 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4723 cmd
= ccmd
? ccmd
->commands
: NULL
;
4724 if (command_line_is_silent (cmd
))
4726 /* The action has been already done by bpstat_stop_status. */
4732 execute_control_command (cmd
);
4734 if (breakpoint_proceeded
)
4740 /* We can free this command tree now. */
4741 do_cleanups (this_cmd_tree_chain
);
4743 if (breakpoint_proceeded
)
4745 if (current_ui
->async
)
4746 /* If we are in async mode, then the target might be still
4747 running, not stopped at any breakpoint, so nothing for
4748 us to do here -- just return to the event loop. */
4751 /* In sync mode, when execute_control_command returns
4752 we're already standing on the next breakpoint.
4753 Breakpoint commands for that stop were not run, since
4754 execute_command does not run breakpoint commands --
4755 only command_line_handler does, but that one is not
4756 involved in execution of breakpoint commands. So, we
4757 can now execute breakpoint commands. It should be
4758 noted that making execute_command do bpstat actions is
4759 not an option -- in this case we'll have recursive
4760 invocation of bpstat for each breakpoint with a
4761 command, and can easily blow up GDB stack. Instead, we
4762 return true, which will trigger the caller to recall us
4763 with the new stop_bpstat. */
4768 do_cleanups (old_chain
);
4773 bpstat_do_actions (void)
4775 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4777 /* Do any commands attached to breakpoint we are stopped at. */
4778 while (!ptid_equal (inferior_ptid
, null_ptid
)
4779 && target_has_execution
4780 && !is_exited (inferior_ptid
)
4781 && !is_executing (inferior_ptid
))
4782 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4783 and only return when it is stopped at the next breakpoint, we
4784 keep doing breakpoint actions until it returns false to
4785 indicate the inferior was not resumed. */
4786 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4789 discard_cleanups (cleanup_if_error
);
4792 /* Print out the (old or new) value associated with a watchpoint. */
4795 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4798 fprintf_unfiltered (stream
, _("<unreadable>"));
4801 struct value_print_options opts
;
4802 get_user_print_options (&opts
);
4803 value_print (val
, stream
, &opts
);
4807 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4808 debugging multiple threads. */
4811 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4813 if (ui_out_is_mi_like_p (uiout
))
4816 ui_out_text (uiout
, "\n");
4818 if (show_thread_that_caused_stop ())
4821 struct thread_info
*thr
= inferior_thread ();
4823 ui_out_text (uiout
, "Thread ");
4824 ui_out_field_fmt (uiout
, "thread-id", "%s", print_thread_id (thr
));
4826 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4829 ui_out_text (uiout
, " \"");
4830 ui_out_field_fmt (uiout
, "name", "%s", name
);
4831 ui_out_text (uiout
, "\"");
4834 ui_out_text (uiout
, " hit ");
4838 /* Generic routine for printing messages indicating why we
4839 stopped. The behavior of this function depends on the value
4840 'print_it' in the bpstat structure. Under some circumstances we
4841 may decide not to print anything here and delegate the task to
4844 static enum print_stop_action
4845 print_bp_stop_message (bpstat bs
)
4847 switch (bs
->print_it
)
4850 /* Nothing should be printed for this bpstat entry. */
4851 return PRINT_UNKNOWN
;
4855 /* We still want to print the frame, but we already printed the
4856 relevant messages. */
4857 return PRINT_SRC_AND_LOC
;
4860 case print_it_normal
:
4862 struct breakpoint
*b
= bs
->breakpoint_at
;
4864 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4865 which has since been deleted. */
4867 return PRINT_UNKNOWN
;
4869 /* Normal case. Call the breakpoint's print_it method. */
4870 return b
->ops
->print_it (bs
);
4875 internal_error (__FILE__
, __LINE__
,
4876 _("print_bp_stop_message: unrecognized enum value"));
4881 /* A helper function that prints a shared library stopped event. */
4884 print_solib_event (int is_catchpoint
)
4887 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4889 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4893 if (any_added
|| any_deleted
)
4894 ui_out_text (current_uiout
,
4895 _("Stopped due to shared library event:\n"));
4897 ui_out_text (current_uiout
,
4898 _("Stopped due to shared library event (no "
4899 "libraries added or removed)\n"));
4902 if (ui_out_is_mi_like_p (current_uiout
))
4903 ui_out_field_string (current_uiout
, "reason",
4904 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4908 struct cleanup
*cleanup
;
4912 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4913 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4916 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4921 ui_out_text (current_uiout
, " ");
4922 ui_out_field_string (current_uiout
, "library", name
);
4923 ui_out_text (current_uiout
, "\n");
4926 do_cleanups (cleanup
);
4931 struct so_list
*iter
;
4933 struct cleanup
*cleanup
;
4935 ui_out_text (current_uiout
, _(" Inferior loaded "));
4936 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4939 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4944 ui_out_text (current_uiout
, " ");
4945 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4946 ui_out_text (current_uiout
, "\n");
4949 do_cleanups (cleanup
);
4953 /* Print a message indicating what happened. This is called from
4954 normal_stop(). The input to this routine is the head of the bpstat
4955 list - a list of the eventpoints that caused this stop. KIND is
4956 the target_waitkind for the stopping event. This
4957 routine calls the generic print routine for printing a message
4958 about reasons for stopping. This will print (for example) the
4959 "Breakpoint n," part of the output. The return value of this
4962 PRINT_UNKNOWN: Means we printed nothing.
4963 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4964 code to print the location. An example is
4965 "Breakpoint 1, " which should be followed by
4967 PRINT_SRC_ONLY: Means we printed something, but there is no need
4968 to also print the location part of the message.
4969 An example is the catch/throw messages, which
4970 don't require a location appended to the end.
4971 PRINT_NOTHING: We have done some printing and we don't need any
4972 further info to be printed. */
4974 enum print_stop_action
4975 bpstat_print (bpstat bs
, int kind
)
4977 enum print_stop_action val
;
4979 /* Maybe another breakpoint in the chain caused us to stop.
4980 (Currently all watchpoints go on the bpstat whether hit or not.
4981 That probably could (should) be changed, provided care is taken
4982 with respect to bpstat_explains_signal). */
4983 for (; bs
; bs
= bs
->next
)
4985 val
= print_bp_stop_message (bs
);
4986 if (val
== PRINT_SRC_ONLY
4987 || val
== PRINT_SRC_AND_LOC
4988 || val
== PRINT_NOTHING
)
4992 /* If we had hit a shared library event breakpoint,
4993 print_bp_stop_message would print out this message. If we hit an
4994 OS-level shared library event, do the same thing. */
4995 if (kind
== TARGET_WAITKIND_LOADED
)
4997 print_solib_event (0);
4998 return PRINT_NOTHING
;
5001 /* We reached the end of the chain, or we got a null BS to start
5002 with and nothing was printed. */
5003 return PRINT_UNKNOWN
;
5006 /* Evaluate the expression EXP and return 1 if value is zero.
5007 This returns the inverse of the condition because it is called
5008 from catch_errors which returns 0 if an exception happened, and if an
5009 exception happens we want execution to stop.
5010 The argument is a "struct expression *" that has been cast to a
5011 "void *" to make it pass through catch_errors. */
5014 breakpoint_cond_eval (void *exp
)
5016 struct value
*mark
= value_mark ();
5017 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
5019 value_free_to_mark (mark
);
5023 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5026 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5030 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5032 **bs_link_pointer
= bs
;
5033 *bs_link_pointer
= &bs
->next
;
5034 bs
->breakpoint_at
= bl
->owner
;
5035 bs
->bp_location_at
= bl
;
5036 incref_bp_location (bl
);
5037 /* If the condition is false, etc., don't do the commands. */
5038 bs
->commands
= NULL
;
5040 bs
->print_it
= print_it_normal
;
5044 /* The target has stopped with waitstatus WS. Check if any hardware
5045 watchpoints have triggered, according to the target. */
5048 watchpoints_triggered (struct target_waitstatus
*ws
)
5050 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5052 struct breakpoint
*b
;
5054 if (!stopped_by_watchpoint
)
5056 /* We were not stopped by a watchpoint. Mark all watchpoints
5057 as not triggered. */
5059 if (is_hardware_watchpoint (b
))
5061 struct watchpoint
*w
= (struct watchpoint
*) b
;
5063 w
->watchpoint_triggered
= watch_triggered_no
;
5069 if (!target_stopped_data_address (¤t_target
, &addr
))
5071 /* We were stopped by a watchpoint, but we don't know where.
5072 Mark all watchpoints as unknown. */
5074 if (is_hardware_watchpoint (b
))
5076 struct watchpoint
*w
= (struct watchpoint
*) b
;
5078 w
->watchpoint_triggered
= watch_triggered_unknown
;
5084 /* The target could report the data address. Mark watchpoints
5085 affected by this data address as triggered, and all others as not
5089 if (is_hardware_watchpoint (b
))
5091 struct watchpoint
*w
= (struct watchpoint
*) b
;
5092 struct bp_location
*loc
;
5094 w
->watchpoint_triggered
= watch_triggered_no
;
5095 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5097 if (is_masked_watchpoint (b
))
5099 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5100 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5102 if (newaddr
== start
)
5104 w
->watchpoint_triggered
= watch_triggered_yes
;
5108 /* Exact match not required. Within range is sufficient. */
5109 else if (target_watchpoint_addr_within_range (¤t_target
,
5113 w
->watchpoint_triggered
= watch_triggered_yes
;
5122 /* Possible return values for watchpoint_check (this can't be an enum
5123 because of check_errors). */
5124 /* The watchpoint has been deleted. */
5125 #define WP_DELETED 1
5126 /* The value has changed. */
5127 #define WP_VALUE_CHANGED 2
5128 /* The value has not changed. */
5129 #define WP_VALUE_NOT_CHANGED 3
5130 /* Ignore this watchpoint, no matter if the value changed or not. */
5133 #define BP_TEMPFLAG 1
5134 #define BP_HARDWAREFLAG 2
5136 /* Evaluate watchpoint condition expression and check if its value
5139 P should be a pointer to struct bpstat, but is defined as a void *
5140 in order for this function to be usable with catch_errors. */
5143 watchpoint_check (void *p
)
5145 bpstat bs
= (bpstat
) p
;
5146 struct watchpoint
*b
;
5147 struct frame_info
*fr
;
5148 int within_current_scope
;
5150 /* BS is built from an existing struct breakpoint. */
5151 gdb_assert (bs
->breakpoint_at
!= NULL
);
5152 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5154 /* If this is a local watchpoint, we only want to check if the
5155 watchpoint frame is in scope if the current thread is the thread
5156 that was used to create the watchpoint. */
5157 if (!watchpoint_in_thread_scope (b
))
5160 if (b
->exp_valid_block
== NULL
)
5161 within_current_scope
= 1;
5164 struct frame_info
*frame
= get_current_frame ();
5165 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5166 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5168 /* stack_frame_destroyed_p() returns a non-zero value if we're
5169 still in the function but the stack frame has already been
5170 invalidated. Since we can't rely on the values of local
5171 variables after the stack has been destroyed, we are treating
5172 the watchpoint in that state as `not changed' without further
5173 checking. Don't mark watchpoints as changed if the current
5174 frame is in an epilogue - even if they are in some other
5175 frame, our view of the stack is likely to be wrong and
5176 frame_find_by_id could error out. */
5177 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5180 fr
= frame_find_by_id (b
->watchpoint_frame
);
5181 within_current_scope
= (fr
!= NULL
);
5183 /* If we've gotten confused in the unwinder, we might have
5184 returned a frame that can't describe this variable. */
5185 if (within_current_scope
)
5187 struct symbol
*function
;
5189 function
= get_frame_function (fr
);
5190 if (function
== NULL
5191 || !contained_in (b
->exp_valid_block
,
5192 SYMBOL_BLOCK_VALUE (function
)))
5193 within_current_scope
= 0;
5196 if (within_current_scope
)
5197 /* If we end up stopping, the current frame will get selected
5198 in normal_stop. So this call to select_frame won't affect
5203 if (within_current_scope
)
5205 /* We use value_{,free_to_}mark because it could be a *long*
5206 time before we return to the command level and call
5207 free_all_values. We can't call free_all_values because we
5208 might be in the middle of evaluating a function call. */
5212 struct value
*new_val
;
5214 if (is_masked_watchpoint (&b
->base
))
5215 /* Since we don't know the exact trigger address (from
5216 stopped_data_address), just tell the user we've triggered
5217 a mask watchpoint. */
5218 return WP_VALUE_CHANGED
;
5220 mark
= value_mark ();
5221 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5223 if (b
->val_bitsize
!= 0)
5224 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5226 /* We use value_equal_contents instead of value_equal because
5227 the latter coerces an array to a pointer, thus comparing just
5228 the address of the array instead of its contents. This is
5229 not what we want. */
5230 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5231 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5233 if (new_val
!= NULL
)
5235 release_value (new_val
);
5236 value_free_to_mark (mark
);
5238 bs
->old_val
= b
->val
;
5241 return WP_VALUE_CHANGED
;
5245 /* Nothing changed. */
5246 value_free_to_mark (mark
);
5247 return WP_VALUE_NOT_CHANGED
;
5252 /* This seems like the only logical thing to do because
5253 if we temporarily ignored the watchpoint, then when
5254 we reenter the block in which it is valid it contains
5255 garbage (in the case of a function, it may have two
5256 garbage values, one before and one after the prologue).
5257 So we can't even detect the first assignment to it and
5258 watch after that (since the garbage may or may not equal
5259 the first value assigned). */
5260 /* We print all the stop information in
5261 breakpoint_ops->print_it, but in this case, by the time we
5262 call breakpoint_ops->print_it this bp will be deleted
5263 already. So we have no choice but print the information
5266 SWITCH_THRU_ALL_UIS ()
5268 struct ui_out
*uiout
= current_uiout
;
5270 if (ui_out_is_mi_like_p (uiout
))
5272 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5273 ui_out_text (uiout
, "\nWatchpoint ");
5274 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5276 " deleted because the program has left the block in\n"
5277 "which its expression is valid.\n");
5280 /* Make sure the watchpoint's commands aren't executed. */
5281 decref_counted_command_line (&b
->base
.commands
);
5282 watchpoint_del_at_next_stop (b
);
5288 /* Return true if it looks like target has stopped due to hitting
5289 breakpoint location BL. This function does not check if we should
5290 stop, only if BL explains the stop. */
5293 bpstat_check_location (const struct bp_location
*bl
,
5294 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5295 const struct target_waitstatus
*ws
)
5297 struct breakpoint
*b
= bl
->owner
;
5299 /* BL is from an existing breakpoint. */
5300 gdb_assert (b
!= NULL
);
5302 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5305 /* Determine if the watched values have actually changed, and we
5306 should stop. If not, set BS->stop to 0. */
5309 bpstat_check_watchpoint (bpstat bs
)
5311 const struct bp_location
*bl
;
5312 struct watchpoint
*b
;
5314 /* BS is built for existing struct breakpoint. */
5315 bl
= bs
->bp_location_at
;
5316 gdb_assert (bl
!= NULL
);
5317 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5318 gdb_assert (b
!= NULL
);
5321 int must_check_value
= 0;
5323 if (b
->base
.type
== bp_watchpoint
)
5324 /* For a software watchpoint, we must always check the
5326 must_check_value
= 1;
5327 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5328 /* We have a hardware watchpoint (read, write, or access)
5329 and the target earlier reported an address watched by
5331 must_check_value
= 1;
5332 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5333 && b
->base
.type
== bp_hardware_watchpoint
)
5334 /* We were stopped by a hardware watchpoint, but the target could
5335 not report the data address. We must check the watchpoint's
5336 value. Access and read watchpoints are out of luck; without
5337 a data address, we can't figure it out. */
5338 must_check_value
= 1;
5340 if (must_check_value
)
5343 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5345 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5346 int e
= catch_errors (watchpoint_check
, bs
, message
,
5348 do_cleanups (cleanups
);
5352 /* We've already printed what needs to be printed. */
5353 bs
->print_it
= print_it_done
;
5357 bs
->print_it
= print_it_noop
;
5360 case WP_VALUE_CHANGED
:
5361 if (b
->base
.type
== bp_read_watchpoint
)
5363 /* There are two cases to consider here:
5365 1. We're watching the triggered memory for reads.
5366 In that case, trust the target, and always report
5367 the watchpoint hit to the user. Even though
5368 reads don't cause value changes, the value may
5369 have changed since the last time it was read, and
5370 since we're not trapping writes, we will not see
5371 those, and as such we should ignore our notion of
5374 2. We're watching the triggered memory for both
5375 reads and writes. There are two ways this may
5378 2.1. This is a target that can't break on data
5379 reads only, but can break on accesses (reads or
5380 writes), such as e.g., x86. We detect this case
5381 at the time we try to insert read watchpoints.
5383 2.2. Otherwise, the target supports read
5384 watchpoints, but, the user set an access or write
5385 watchpoint watching the same memory as this read
5388 If we're watching memory writes as well as reads,
5389 ignore watchpoint hits when we find that the
5390 value hasn't changed, as reads don't cause
5391 changes. This still gives false positives when
5392 the program writes the same value to memory as
5393 what there was already in memory (we will confuse
5394 it for a read), but it's much better than
5397 int other_write_watchpoint
= 0;
5399 if (bl
->watchpoint_type
== hw_read
)
5401 struct breakpoint
*other_b
;
5403 ALL_BREAKPOINTS (other_b
)
5404 if (other_b
->type
== bp_hardware_watchpoint
5405 || other_b
->type
== bp_access_watchpoint
)
5407 struct watchpoint
*other_w
=
5408 (struct watchpoint
*) other_b
;
5410 if (other_w
->watchpoint_triggered
5411 == watch_triggered_yes
)
5413 other_write_watchpoint
= 1;
5419 if (other_write_watchpoint
5420 || bl
->watchpoint_type
== hw_access
)
5422 /* We're watching the same memory for writes,
5423 and the value changed since the last time we
5424 updated it, so this trap must be for a write.
5426 bs
->print_it
= print_it_noop
;
5431 case WP_VALUE_NOT_CHANGED
:
5432 if (b
->base
.type
== bp_hardware_watchpoint
5433 || b
->base
.type
== bp_watchpoint
)
5435 /* Don't stop: write watchpoints shouldn't fire if
5436 the value hasn't changed. */
5437 bs
->print_it
= print_it_noop
;
5445 /* Error from catch_errors. */
5447 SWITCH_THRU_ALL_UIS ()
5449 printf_filtered (_("Watchpoint %d deleted.\n"),
5452 watchpoint_del_at_next_stop (b
);
5453 /* We've already printed what needs to be printed. */
5454 bs
->print_it
= print_it_done
;
5459 else /* must_check_value == 0 */
5461 /* This is a case where some watchpoint(s) triggered, but
5462 not at the address of this watchpoint, or else no
5463 watchpoint triggered after all. So don't print
5464 anything for this watchpoint. */
5465 bs
->print_it
= print_it_noop
;
5471 /* For breakpoints that are currently marked as telling gdb to stop,
5472 check conditions (condition proper, frame, thread and ignore count)
5473 of breakpoint referred to by BS. If we should not stop for this
5474 breakpoint, set BS->stop to 0. */
5477 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5479 const struct bp_location
*bl
;
5480 struct breakpoint
*b
;
5481 int value_is_zero
= 0;
5482 struct expression
*cond
;
5484 gdb_assert (bs
->stop
);
5486 /* BS is built for existing struct breakpoint. */
5487 bl
= bs
->bp_location_at
;
5488 gdb_assert (bl
!= NULL
);
5489 b
= bs
->breakpoint_at
;
5490 gdb_assert (b
!= NULL
);
5492 /* Even if the target evaluated the condition on its end and notified GDB, we
5493 need to do so again since GDB does not know if we stopped due to a
5494 breakpoint or a single step breakpoint. */
5496 if (frame_id_p (b
->frame_id
)
5497 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5503 /* If this is a thread/task-specific breakpoint, don't waste cpu
5504 evaluating the condition if this isn't the specified
5506 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5507 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5514 /* Evaluate extension language breakpoints that have a "stop" method
5516 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5518 if (is_watchpoint (b
))
5520 struct watchpoint
*w
= (struct watchpoint
*) b
;
5527 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5529 int within_current_scope
= 1;
5530 struct watchpoint
* w
;
5532 /* We use value_mark and value_free_to_mark because it could
5533 be a long time before we return to the command level and
5534 call free_all_values. We can't call free_all_values
5535 because we might be in the middle of evaluating a
5537 struct value
*mark
= value_mark ();
5539 if (is_watchpoint (b
))
5540 w
= (struct watchpoint
*) b
;
5544 /* Need to select the frame, with all that implies so that
5545 the conditions will have the right context. Because we
5546 use the frame, we will not see an inlined function's
5547 variables when we arrive at a breakpoint at the start
5548 of the inlined function; the current frame will be the
5550 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5551 select_frame (get_current_frame ());
5554 struct frame_info
*frame
;
5556 /* For local watchpoint expressions, which particular
5557 instance of a local is being watched matters, so we
5558 keep track of the frame to evaluate the expression
5559 in. To evaluate the condition however, it doesn't
5560 really matter which instantiation of the function
5561 where the condition makes sense triggers the
5562 watchpoint. This allows an expression like "watch
5563 global if q > 10" set in `func', catch writes to
5564 global on all threads that call `func', or catch
5565 writes on all recursive calls of `func' by a single
5566 thread. We simply always evaluate the condition in
5567 the innermost frame that's executing where it makes
5568 sense to evaluate the condition. It seems
5570 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5572 select_frame (frame
);
5574 within_current_scope
= 0;
5576 if (within_current_scope
)
5578 = catch_errors (breakpoint_cond_eval
, cond
,
5579 "Error in testing breakpoint condition:\n",
5583 warning (_("Watchpoint condition cannot be tested "
5584 "in the current scope"));
5585 /* If we failed to set the right context for this
5586 watchpoint, unconditionally report it. */
5589 /* FIXME-someday, should give breakpoint #. */
5590 value_free_to_mark (mark
);
5593 if (cond
&& value_is_zero
)
5597 else if (b
->ignore_count
> 0)
5601 /* Increase the hit count even though we don't stop. */
5603 observer_notify_breakpoint_modified (b
);
5607 /* Returns true if we need to track moribund locations of LOC's type
5608 on the current target. */
5611 need_moribund_for_location_type (struct bp_location
*loc
)
5613 return ((loc
->loc_type
== bp_loc_software_breakpoint
5614 && !target_supports_stopped_by_sw_breakpoint ())
5615 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5616 && !target_supports_stopped_by_hw_breakpoint ()));
5620 /* Get a bpstat associated with having just stopped at address
5621 BP_ADDR in thread PTID.
5623 Determine whether we stopped at a breakpoint, etc, or whether we
5624 don't understand this stop. Result is a chain of bpstat's such
5627 if we don't understand the stop, the result is a null pointer.
5629 if we understand why we stopped, the result is not null.
5631 Each element of the chain refers to a particular breakpoint or
5632 watchpoint at which we have stopped. (We may have stopped for
5633 several reasons concurrently.)
5635 Each element of the chain has valid next, breakpoint_at,
5636 commands, FIXME??? fields. */
5639 bpstat_stop_status (struct address_space
*aspace
,
5640 CORE_ADDR bp_addr
, ptid_t ptid
,
5641 const struct target_waitstatus
*ws
)
5643 struct breakpoint
*b
= NULL
;
5644 struct bp_location
*bl
;
5645 struct bp_location
*loc
;
5646 /* First item of allocated bpstat's. */
5647 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5648 /* Pointer to the last thing in the chain currently. */
5651 int need_remove_insert
;
5654 /* First, build the bpstat chain with locations that explain a
5655 target stop, while being careful to not set the target running,
5656 as that may invalidate locations (in particular watchpoint
5657 locations are recreated). Resuming will happen here with
5658 breakpoint conditions or watchpoint expressions that include
5659 inferior function calls. */
5663 if (!breakpoint_enabled (b
))
5666 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5668 /* For hardware watchpoints, we look only at the first
5669 location. The watchpoint_check function will work on the
5670 entire expression, not the individual locations. For
5671 read watchpoints, the watchpoints_triggered function has
5672 checked all locations already. */
5673 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5676 if (!bl
->enabled
|| bl
->shlib_disabled
)
5679 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5682 /* Come here if it's a watchpoint, or if the break address
5685 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5688 /* Assume we stop. Should we find a watchpoint that is not
5689 actually triggered, or if the condition of the breakpoint
5690 evaluates as false, we'll reset 'stop' to 0. */
5694 /* If this is a scope breakpoint, mark the associated
5695 watchpoint as triggered so that we will handle the
5696 out-of-scope event. We'll get to the watchpoint next
5698 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5700 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5702 w
->watchpoint_triggered
= watch_triggered_yes
;
5707 /* Check if a moribund breakpoint explains the stop. */
5708 if (!target_supports_stopped_by_sw_breakpoint ()
5709 || !target_supports_stopped_by_hw_breakpoint ())
5711 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5713 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5714 && need_moribund_for_location_type (loc
))
5716 bs
= bpstat_alloc (loc
, &bs_link
);
5717 /* For hits of moribund locations, we should just proceed. */
5720 bs
->print_it
= print_it_noop
;
5725 /* A bit of special processing for shlib breakpoints. We need to
5726 process solib loading here, so that the lists of loaded and
5727 unloaded libraries are correct before we handle "catch load" and
5729 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5731 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5733 handle_solib_event ();
5738 /* Now go through the locations that caused the target to stop, and
5739 check whether we're interested in reporting this stop to higher
5740 layers, or whether we should resume the target transparently. */
5744 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5749 b
= bs
->breakpoint_at
;
5750 b
->ops
->check_status (bs
);
5753 bpstat_check_breakpoint_conditions (bs
, ptid
);
5758 observer_notify_breakpoint_modified (b
);
5760 /* We will stop here. */
5761 if (b
->disposition
== disp_disable
)
5763 --(b
->enable_count
);
5764 if (b
->enable_count
<= 0)
5765 b
->enable_state
= bp_disabled
;
5770 bs
->commands
= b
->commands
;
5771 incref_counted_command_line (bs
->commands
);
5772 if (command_line_is_silent (bs
->commands
5773 ? bs
->commands
->commands
: NULL
))
5776 b
->ops
->after_condition_true (bs
);
5781 /* Print nothing for this entry if we don't stop or don't
5783 if (!bs
->stop
|| !bs
->print
)
5784 bs
->print_it
= print_it_noop
;
5787 /* If we aren't stopping, the value of some hardware watchpoint may
5788 not have changed, but the intermediate memory locations we are
5789 watching may have. Don't bother if we're stopping; this will get
5791 need_remove_insert
= 0;
5792 if (! bpstat_causes_stop (bs_head
))
5793 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5795 && bs
->breakpoint_at
5796 && is_hardware_watchpoint (bs
->breakpoint_at
))
5798 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5800 update_watchpoint (w
, 0 /* don't reparse. */);
5801 need_remove_insert
= 1;
5804 if (need_remove_insert
)
5805 update_global_location_list (UGLL_MAY_INSERT
);
5806 else if (removed_any
)
5807 update_global_location_list (UGLL_DONT_INSERT
);
5813 handle_jit_event (void)
5815 struct frame_info
*frame
;
5816 struct gdbarch
*gdbarch
;
5819 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5821 /* Switch terminal for any messages produced by
5822 breakpoint_re_set. */
5823 target_terminal_ours_for_output ();
5825 frame
= get_current_frame ();
5826 gdbarch
= get_frame_arch (frame
);
5828 jit_event_handler (gdbarch
);
5830 target_terminal_inferior ();
5833 /* Prepare WHAT final decision for infrun. */
5835 /* Decide what infrun needs to do with this bpstat. */
5838 bpstat_what (bpstat bs_head
)
5840 struct bpstat_what retval
;
5843 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5844 retval
.call_dummy
= STOP_NONE
;
5845 retval
.is_longjmp
= 0;
5847 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5849 /* Extract this BS's action. After processing each BS, we check
5850 if its action overrides all we've seem so far. */
5851 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5854 if (bs
->breakpoint_at
== NULL
)
5856 /* I suspect this can happen if it was a momentary
5857 breakpoint which has since been deleted. */
5861 bptype
= bs
->breakpoint_at
->type
;
5868 case bp_hardware_breakpoint
:
5869 case bp_single_step
:
5872 case bp_shlib_event
:
5876 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5878 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5881 this_action
= BPSTAT_WHAT_SINGLE
;
5884 case bp_hardware_watchpoint
:
5885 case bp_read_watchpoint
:
5886 case bp_access_watchpoint
:
5890 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5892 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5896 /* There was a watchpoint, but we're not stopping.
5897 This requires no further action. */
5901 case bp_longjmp_call_dummy
:
5905 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5906 retval
.is_longjmp
= bptype
!= bp_exception
;
5909 this_action
= BPSTAT_WHAT_SINGLE
;
5911 case bp_longjmp_resume
:
5912 case bp_exception_resume
:
5915 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5916 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5919 this_action
= BPSTAT_WHAT_SINGLE
;
5921 case bp_step_resume
:
5923 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5926 /* It is for the wrong frame. */
5927 this_action
= BPSTAT_WHAT_SINGLE
;
5930 case bp_hp_step_resume
:
5932 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5935 /* It is for the wrong frame. */
5936 this_action
= BPSTAT_WHAT_SINGLE
;
5939 case bp_watchpoint_scope
:
5940 case bp_thread_event
:
5941 case bp_overlay_event
:
5942 case bp_longjmp_master
:
5943 case bp_std_terminate_master
:
5944 case bp_exception_master
:
5945 this_action
= BPSTAT_WHAT_SINGLE
;
5951 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5953 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5957 /* There was a catchpoint, but we're not stopping.
5958 This requires no further action. */
5962 this_action
= BPSTAT_WHAT_SINGLE
;
5965 /* Make sure the action is stop (silent or noisy),
5966 so infrun.c pops the dummy frame. */
5967 retval
.call_dummy
= STOP_STACK_DUMMY
;
5968 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5970 case bp_std_terminate
:
5971 /* Make sure the action is stop (silent or noisy),
5972 so infrun.c pops the dummy frame. */
5973 retval
.call_dummy
= STOP_STD_TERMINATE
;
5974 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5977 case bp_fast_tracepoint
:
5978 case bp_static_tracepoint
:
5979 /* Tracepoint hits should not be reported back to GDB, and
5980 if one got through somehow, it should have been filtered
5982 internal_error (__FILE__
, __LINE__
,
5983 _("bpstat_what: tracepoint encountered"));
5985 case bp_gnu_ifunc_resolver
:
5986 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5987 this_action
= BPSTAT_WHAT_SINGLE
;
5989 case bp_gnu_ifunc_resolver_return
:
5990 /* The breakpoint will be removed, execution will restart from the
5991 PC of the former breakpoint. */
5992 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5997 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5999 this_action
= BPSTAT_WHAT_SINGLE
;
6003 internal_error (__FILE__
, __LINE__
,
6004 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
6007 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6014 bpstat_run_callbacks (bpstat bs_head
)
6018 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6020 struct breakpoint
*b
= bs
->breakpoint_at
;
6027 handle_jit_event ();
6029 case bp_gnu_ifunc_resolver
:
6030 gnu_ifunc_resolver_stop (b
);
6032 case bp_gnu_ifunc_resolver_return
:
6033 gnu_ifunc_resolver_return_stop (b
);
6039 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6040 without hardware support). This isn't related to a specific bpstat,
6041 just to things like whether watchpoints are set. */
6044 bpstat_should_step (void)
6046 struct breakpoint
*b
;
6049 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6055 bpstat_causes_stop (bpstat bs
)
6057 for (; bs
!= NULL
; bs
= bs
->next
)
6066 /* Compute a string of spaces suitable to indent the next line
6067 so it starts at the position corresponding to the table column
6068 named COL_NAME in the currently active table of UIOUT. */
6071 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6073 static char wrap_indent
[80];
6074 int i
, total_width
, width
, align
;
6078 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
6080 if (strcmp (text
, col_name
) == 0)
6082 gdb_assert (total_width
< sizeof wrap_indent
);
6083 memset (wrap_indent
, ' ', total_width
);
6084 wrap_indent
[total_width
] = 0;
6089 total_width
+= width
+ 1;
6095 /* Determine if the locations of this breakpoint will have their conditions
6096 evaluated by the target, host or a mix of both. Returns the following:
6098 "host": Host evals condition.
6099 "host or target": Host or Target evals condition.
6100 "target": Target evals condition.
6104 bp_condition_evaluator (struct breakpoint
*b
)
6106 struct bp_location
*bl
;
6107 char host_evals
= 0;
6108 char target_evals
= 0;
6113 if (!is_breakpoint (b
))
6116 if (gdb_evaluates_breakpoint_condition_p ()
6117 || !target_supports_evaluation_of_breakpoint_conditions ())
6118 return condition_evaluation_host
;
6120 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6122 if (bl
->cond_bytecode
)
6128 if (host_evals
&& target_evals
)
6129 return condition_evaluation_both
;
6130 else if (target_evals
)
6131 return condition_evaluation_target
;
6133 return condition_evaluation_host
;
6136 /* Determine the breakpoint location's condition evaluator. This is
6137 similar to bp_condition_evaluator, but for locations. */
6140 bp_location_condition_evaluator (struct bp_location
*bl
)
6142 if (bl
&& !is_breakpoint (bl
->owner
))
6145 if (gdb_evaluates_breakpoint_condition_p ()
6146 || !target_supports_evaluation_of_breakpoint_conditions ())
6147 return condition_evaluation_host
;
6149 if (bl
&& bl
->cond_bytecode
)
6150 return condition_evaluation_target
;
6152 return condition_evaluation_host
;
6155 /* Print the LOC location out of the list of B->LOC locations. */
6158 print_breakpoint_location (struct breakpoint
*b
,
6159 struct bp_location
*loc
)
6161 struct ui_out
*uiout
= current_uiout
;
6162 struct cleanup
*old_chain
= save_current_program_space ();
6164 if (loc
!= NULL
&& loc
->shlib_disabled
)
6168 set_current_program_space (loc
->pspace
);
6170 if (b
->display_canonical
)
6171 ui_out_field_string (uiout
, "what",
6172 event_location_to_string (b
->location
));
6173 else if (loc
&& loc
->symtab
)
6176 = find_pc_sect_function (loc
->address
, loc
->section
);
6179 ui_out_text (uiout
, "in ");
6180 ui_out_field_string (uiout
, "func",
6181 SYMBOL_PRINT_NAME (sym
));
6182 ui_out_text (uiout
, " ");
6183 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6184 ui_out_text (uiout
, "at ");
6186 ui_out_field_string (uiout
, "file",
6187 symtab_to_filename_for_display (loc
->symtab
));
6188 ui_out_text (uiout
, ":");
6190 if (ui_out_is_mi_like_p (uiout
))
6191 ui_out_field_string (uiout
, "fullname",
6192 symtab_to_fullname (loc
->symtab
));
6194 ui_out_field_int (uiout
, "line", loc
->line_number
);
6198 struct ui_file
*stb
= mem_fileopen ();
6199 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6201 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6203 ui_out_field_stream (uiout
, "at", stb
);
6205 do_cleanups (stb_chain
);
6209 ui_out_field_string (uiout
, "pending",
6210 event_location_to_string (b
->location
));
6211 /* If extra_string is available, it could be holding a condition
6212 or dprintf arguments. In either case, make sure it is printed,
6213 too, but only for non-MI streams. */
6214 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6216 if (b
->type
== bp_dprintf
)
6217 ui_out_text (uiout
, ",");
6219 ui_out_text (uiout
, " ");
6220 ui_out_text (uiout
, b
->extra_string
);
6224 if (loc
&& is_breakpoint (b
)
6225 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6226 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6228 ui_out_text (uiout
, " (");
6229 ui_out_field_string (uiout
, "evaluated-by",
6230 bp_location_condition_evaluator (loc
));
6231 ui_out_text (uiout
, ")");
6234 do_cleanups (old_chain
);
6238 bptype_string (enum bptype type
)
6240 struct ep_type_description
6245 static struct ep_type_description bptypes
[] =
6247 {bp_none
, "?deleted?"},
6248 {bp_breakpoint
, "breakpoint"},
6249 {bp_hardware_breakpoint
, "hw breakpoint"},
6250 {bp_single_step
, "sw single-step"},
6251 {bp_until
, "until"},
6252 {bp_finish
, "finish"},
6253 {bp_watchpoint
, "watchpoint"},
6254 {bp_hardware_watchpoint
, "hw watchpoint"},
6255 {bp_read_watchpoint
, "read watchpoint"},
6256 {bp_access_watchpoint
, "acc watchpoint"},
6257 {bp_longjmp
, "longjmp"},
6258 {bp_longjmp_resume
, "longjmp resume"},
6259 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6260 {bp_exception
, "exception"},
6261 {bp_exception_resume
, "exception resume"},
6262 {bp_step_resume
, "step resume"},
6263 {bp_hp_step_resume
, "high-priority step resume"},
6264 {bp_watchpoint_scope
, "watchpoint scope"},
6265 {bp_call_dummy
, "call dummy"},
6266 {bp_std_terminate
, "std::terminate"},
6267 {bp_shlib_event
, "shlib events"},
6268 {bp_thread_event
, "thread events"},
6269 {bp_overlay_event
, "overlay events"},
6270 {bp_longjmp_master
, "longjmp master"},
6271 {bp_std_terminate_master
, "std::terminate master"},
6272 {bp_exception_master
, "exception master"},
6273 {bp_catchpoint
, "catchpoint"},
6274 {bp_tracepoint
, "tracepoint"},
6275 {bp_fast_tracepoint
, "fast tracepoint"},
6276 {bp_static_tracepoint
, "static tracepoint"},
6277 {bp_dprintf
, "dprintf"},
6278 {bp_jit_event
, "jit events"},
6279 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6280 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6283 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6284 || ((int) type
!= bptypes
[(int) type
].type
))
6285 internal_error (__FILE__
, __LINE__
,
6286 _("bptypes table does not describe type #%d."),
6289 return bptypes
[(int) type
].description
;
6292 /* For MI, output a field named 'thread-groups' with a list as the value.
6293 For CLI, prefix the list with the string 'inf'. */
6296 output_thread_groups (struct ui_out
*uiout
,
6297 const char *field_name
,
6301 struct cleanup
*back_to
;
6302 int is_mi
= ui_out_is_mi_like_p (uiout
);
6306 /* For backward compatibility, don't display inferiors in CLI unless
6307 there are several. Always display them for MI. */
6308 if (!is_mi
&& mi_only
)
6311 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6313 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6319 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6320 ui_out_field_string (uiout
, NULL
, mi_group
);
6325 ui_out_text (uiout
, " inf ");
6327 ui_out_text (uiout
, ", ");
6329 ui_out_text (uiout
, plongest (inf
));
6333 do_cleanups (back_to
);
6336 /* Print B to gdb_stdout. */
6339 print_one_breakpoint_location (struct breakpoint
*b
,
6340 struct bp_location
*loc
,
6342 struct bp_location
**last_loc
,
6345 struct command_line
*l
;
6346 static char bpenables
[] = "nynny";
6348 struct ui_out
*uiout
= current_uiout
;
6349 int header_of_multiple
= 0;
6350 int part_of_multiple
= (loc
!= NULL
);
6351 struct value_print_options opts
;
6353 get_user_print_options (&opts
);
6355 gdb_assert (!loc
|| loc_number
!= 0);
6356 /* See comment in print_one_breakpoint concerning treatment of
6357 breakpoints with single disabled location. */
6360 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6361 header_of_multiple
= 1;
6369 if (part_of_multiple
)
6372 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6373 ui_out_field_string (uiout
, "number", formatted
);
6378 ui_out_field_int (uiout
, "number", b
->number
);
6383 if (part_of_multiple
)
6384 ui_out_field_skip (uiout
, "type");
6386 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6390 if (part_of_multiple
)
6391 ui_out_field_skip (uiout
, "disp");
6393 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6398 if (part_of_multiple
)
6399 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6401 ui_out_field_fmt (uiout
, "enabled", "%c",
6402 bpenables
[(int) b
->enable_state
]);
6403 ui_out_spaces (uiout
, 2);
6407 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6409 /* Although the print_one can possibly print all locations,
6410 calling it here is not likely to get any nice result. So,
6411 make sure there's just one location. */
6412 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6413 b
->ops
->print_one (b
, last_loc
);
6419 internal_error (__FILE__
, __LINE__
,
6420 _("print_one_breakpoint: bp_none encountered\n"));
6424 case bp_hardware_watchpoint
:
6425 case bp_read_watchpoint
:
6426 case bp_access_watchpoint
:
6428 struct watchpoint
*w
= (struct watchpoint
*) b
;
6430 /* Field 4, the address, is omitted (which makes the columns
6431 not line up too nicely with the headers, but the effect
6432 is relatively readable). */
6433 if (opts
.addressprint
)
6434 ui_out_field_skip (uiout
, "addr");
6436 ui_out_field_string (uiout
, "what", w
->exp_string
);
6441 case bp_hardware_breakpoint
:
6442 case bp_single_step
:
6446 case bp_longjmp_resume
:
6447 case bp_longjmp_call_dummy
:
6449 case bp_exception_resume
:
6450 case bp_step_resume
:
6451 case bp_hp_step_resume
:
6452 case bp_watchpoint_scope
:
6454 case bp_std_terminate
:
6455 case bp_shlib_event
:
6456 case bp_thread_event
:
6457 case bp_overlay_event
:
6458 case bp_longjmp_master
:
6459 case bp_std_terminate_master
:
6460 case bp_exception_master
:
6462 case bp_fast_tracepoint
:
6463 case bp_static_tracepoint
:
6466 case bp_gnu_ifunc_resolver
:
6467 case bp_gnu_ifunc_resolver_return
:
6468 if (opts
.addressprint
)
6471 if (header_of_multiple
)
6472 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6473 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6474 ui_out_field_string (uiout
, "addr", "<PENDING>");
6476 ui_out_field_core_addr (uiout
, "addr",
6477 loc
->gdbarch
, loc
->address
);
6480 if (!header_of_multiple
)
6481 print_breakpoint_location (b
, loc
);
6488 if (loc
!= NULL
&& !header_of_multiple
)
6490 struct inferior
*inf
;
6491 VEC(int) *inf_num
= NULL
;
6496 if (inf
->pspace
== loc
->pspace
)
6497 VEC_safe_push (int, inf_num
, inf
->num
);
6500 /* For backward compatibility, don't display inferiors in CLI unless
6501 there are several. Always display for MI. */
6503 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6504 && (number_of_program_spaces () > 1
6505 || number_of_inferiors () > 1)
6506 /* LOC is for existing B, it cannot be in
6507 moribund_locations and thus having NULL OWNER. */
6508 && loc
->owner
->type
!= bp_catchpoint
))
6510 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6511 VEC_free (int, inf_num
);
6514 if (!part_of_multiple
)
6516 if (b
->thread
!= -1)
6518 /* FIXME: This seems to be redundant and lost here; see the
6519 "stop only in" line a little further down. */
6520 ui_out_text (uiout
, " thread ");
6521 ui_out_field_int (uiout
, "thread", b
->thread
);
6523 else if (b
->task
!= 0)
6525 ui_out_text (uiout
, " task ");
6526 ui_out_field_int (uiout
, "task", b
->task
);
6530 ui_out_text (uiout
, "\n");
6532 if (!part_of_multiple
)
6533 b
->ops
->print_one_detail (b
, uiout
);
6535 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6538 ui_out_text (uiout
, "\tstop only in stack frame at ");
6539 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6541 ui_out_field_core_addr (uiout
, "frame",
6542 b
->gdbarch
, b
->frame_id
.stack_addr
);
6543 ui_out_text (uiout
, "\n");
6546 if (!part_of_multiple
&& b
->cond_string
)
6549 if (is_tracepoint (b
))
6550 ui_out_text (uiout
, "\ttrace only if ");
6552 ui_out_text (uiout
, "\tstop only if ");
6553 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6555 /* Print whether the target is doing the breakpoint's condition
6556 evaluation. If GDB is doing the evaluation, don't print anything. */
6557 if (is_breakpoint (b
)
6558 && breakpoint_condition_evaluation_mode ()
6559 == condition_evaluation_target
)
6561 ui_out_text (uiout
, " (");
6562 ui_out_field_string (uiout
, "evaluated-by",
6563 bp_condition_evaluator (b
));
6564 ui_out_text (uiout
, " evals)");
6566 ui_out_text (uiout
, "\n");
6569 if (!part_of_multiple
&& b
->thread
!= -1)
6571 /* FIXME should make an annotation for this. */
6572 ui_out_text (uiout
, "\tstop only in thread ");
6573 if (ui_out_is_mi_like_p (uiout
))
6574 ui_out_field_int (uiout
, "thread", b
->thread
);
6577 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6579 ui_out_field_string (uiout
, "thread", print_thread_id (thr
));
6581 ui_out_text (uiout
, "\n");
6584 if (!part_of_multiple
)
6588 /* FIXME should make an annotation for this. */
6589 if (is_catchpoint (b
))
6590 ui_out_text (uiout
, "\tcatchpoint");
6591 else if (is_tracepoint (b
))
6592 ui_out_text (uiout
, "\ttracepoint");
6594 ui_out_text (uiout
, "\tbreakpoint");
6595 ui_out_text (uiout
, " already hit ");
6596 ui_out_field_int (uiout
, "times", b
->hit_count
);
6597 if (b
->hit_count
== 1)
6598 ui_out_text (uiout
, " time\n");
6600 ui_out_text (uiout
, " times\n");
6604 /* Output the count also if it is zero, but only if this is mi. */
6605 if (ui_out_is_mi_like_p (uiout
))
6606 ui_out_field_int (uiout
, "times", b
->hit_count
);
6610 if (!part_of_multiple
&& b
->ignore_count
)
6613 ui_out_text (uiout
, "\tignore next ");
6614 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6615 ui_out_text (uiout
, " hits\n");
6618 /* Note that an enable count of 1 corresponds to "enable once"
6619 behavior, which is reported by the combination of enablement and
6620 disposition, so we don't need to mention it here. */
6621 if (!part_of_multiple
&& b
->enable_count
> 1)
6624 ui_out_text (uiout
, "\tdisable after ");
6625 /* Tweak the wording to clarify that ignore and enable counts
6626 are distinct, and have additive effect. */
6627 if (b
->ignore_count
)
6628 ui_out_text (uiout
, "additional ");
6630 ui_out_text (uiout
, "next ");
6631 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6632 ui_out_text (uiout
, " hits\n");
6635 if (!part_of_multiple
&& is_tracepoint (b
))
6637 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6639 if (tp
->traceframe_usage
)
6641 ui_out_text (uiout
, "\ttrace buffer usage ");
6642 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6643 ui_out_text (uiout
, " bytes\n");
6647 l
= b
->commands
? b
->commands
->commands
: NULL
;
6648 if (!part_of_multiple
&& l
)
6650 struct cleanup
*script_chain
;
6653 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6654 print_command_lines (uiout
, l
, 4);
6655 do_cleanups (script_chain
);
6658 if (is_tracepoint (b
))
6660 struct tracepoint
*t
= (struct tracepoint
*) b
;
6662 if (!part_of_multiple
&& t
->pass_count
)
6664 annotate_field (10);
6665 ui_out_text (uiout
, "\tpass count ");
6666 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6667 ui_out_text (uiout
, " \n");
6670 /* Don't display it when tracepoint or tracepoint location is
6672 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6674 annotate_field (11);
6676 if (ui_out_is_mi_like_p (uiout
))
6677 ui_out_field_string (uiout
, "installed",
6678 loc
->inserted
? "y" : "n");
6682 ui_out_text (uiout
, "\t");
6684 ui_out_text (uiout
, "\tnot ");
6685 ui_out_text (uiout
, "installed on target\n");
6690 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6692 if (is_watchpoint (b
))
6694 struct watchpoint
*w
= (struct watchpoint
*) b
;
6696 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6698 else if (b
->location
!= NULL
6699 && event_location_to_string (b
->location
) != NULL
)
6700 ui_out_field_string (uiout
, "original-location",
6701 event_location_to_string (b
->location
));
6706 print_one_breakpoint (struct breakpoint
*b
,
6707 struct bp_location
**last_loc
,
6710 struct cleanup
*bkpt_chain
;
6711 struct ui_out
*uiout
= current_uiout
;
6713 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6715 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6716 do_cleanups (bkpt_chain
);
6718 /* If this breakpoint has custom print function,
6719 it's already printed. Otherwise, print individual
6720 locations, if any. */
6721 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6723 /* If breakpoint has a single location that is disabled, we
6724 print it as if it had several locations, since otherwise it's
6725 hard to represent "breakpoint enabled, location disabled"
6728 Note that while hardware watchpoints have several locations
6729 internally, that's not a property exposed to user. */
6731 && !is_hardware_watchpoint (b
)
6732 && (b
->loc
->next
|| !b
->loc
->enabled
))
6734 struct bp_location
*loc
;
6737 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6739 struct cleanup
*inner2
=
6740 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6741 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6742 do_cleanups (inner2
);
6749 breakpoint_address_bits (struct breakpoint
*b
)
6751 int print_address_bits
= 0;
6752 struct bp_location
*loc
;
6754 /* Software watchpoints that aren't watching memory don't have an
6755 address to print. */
6756 if (is_no_memory_software_watchpoint (b
))
6759 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6763 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6764 if (addr_bit
> print_address_bits
)
6765 print_address_bits
= addr_bit
;
6768 return print_address_bits
;
6771 struct captured_breakpoint_query_args
6777 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6779 struct captured_breakpoint_query_args
*args
6780 = (struct captured_breakpoint_query_args
*) data
;
6781 struct breakpoint
*b
;
6782 struct bp_location
*dummy_loc
= NULL
;
6786 if (args
->bnum
== b
->number
)
6788 print_one_breakpoint (b
, &dummy_loc
, 0);
6796 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6797 char **error_message
)
6799 struct captured_breakpoint_query_args args
;
6802 /* For the moment we don't trust print_one_breakpoint() to not throw
6804 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6805 error_message
, RETURN_MASK_ALL
) < 0)
6811 /* Return true if this breakpoint was set by the user, false if it is
6812 internal or momentary. */
6815 user_breakpoint_p (struct breakpoint
*b
)
6817 return b
->number
> 0;
6820 /* See breakpoint.h. */
6823 pending_breakpoint_p (struct breakpoint
*b
)
6825 return b
->loc
== NULL
;
6828 /* Print information on user settable breakpoint (watchpoint, etc)
6829 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6830 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6831 FILTER is non-NULL, call it on each breakpoint and only include the
6832 ones for which it returns non-zero. Return the total number of
6833 breakpoints listed. */
6836 breakpoint_1 (char *args
, int allflag
,
6837 int (*filter
) (const struct breakpoint
*))
6839 struct breakpoint
*b
;
6840 struct bp_location
*last_loc
= NULL
;
6841 int nr_printable_breakpoints
;
6842 struct cleanup
*bkpttbl_chain
;
6843 struct value_print_options opts
;
6844 int print_address_bits
= 0;
6845 int print_type_col_width
= 14;
6846 struct ui_out
*uiout
= current_uiout
;
6848 get_user_print_options (&opts
);
6850 /* Compute the number of rows in the table, as well as the size
6851 required for address fields. */
6852 nr_printable_breakpoints
= 0;
6855 /* If we have a filter, only list the breakpoints it accepts. */
6856 if (filter
&& !filter (b
))
6859 /* If we have an "args" string, it is a list of breakpoints to
6860 accept. Skip the others. */
6861 if (args
!= NULL
&& *args
!= '\0')
6863 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6865 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6869 if (allflag
|| user_breakpoint_p (b
))
6871 int addr_bit
, type_len
;
6873 addr_bit
= breakpoint_address_bits (b
);
6874 if (addr_bit
> print_address_bits
)
6875 print_address_bits
= addr_bit
;
6877 type_len
= strlen (bptype_string (b
->type
));
6878 if (type_len
> print_type_col_width
)
6879 print_type_col_width
= type_len
;
6881 nr_printable_breakpoints
++;
6885 if (opts
.addressprint
)
6887 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6888 nr_printable_breakpoints
,
6892 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6893 nr_printable_breakpoints
,
6896 if (nr_printable_breakpoints
> 0)
6897 annotate_breakpoints_headers ();
6898 if (nr_printable_breakpoints
> 0)
6900 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6901 if (nr_printable_breakpoints
> 0)
6903 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6904 "type", "Type"); /* 2 */
6905 if (nr_printable_breakpoints
> 0)
6907 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6908 if (nr_printable_breakpoints
> 0)
6910 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6911 if (opts
.addressprint
)
6913 if (nr_printable_breakpoints
> 0)
6915 if (print_address_bits
<= 32)
6916 ui_out_table_header (uiout
, 10, ui_left
,
6917 "addr", "Address"); /* 5 */
6919 ui_out_table_header (uiout
, 18, ui_left
,
6920 "addr", "Address"); /* 5 */
6922 if (nr_printable_breakpoints
> 0)
6924 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6925 ui_out_table_body (uiout
);
6926 if (nr_printable_breakpoints
> 0)
6927 annotate_breakpoints_table ();
6932 /* If we have a filter, only list the breakpoints it accepts. */
6933 if (filter
&& !filter (b
))
6936 /* If we have an "args" string, it is a list of breakpoints to
6937 accept. Skip the others. */
6939 if (args
!= NULL
&& *args
!= '\0')
6941 if (allflag
) /* maintenance info breakpoint */
6943 if (parse_and_eval_long (args
) != b
->number
)
6946 else /* all others */
6948 if (!number_is_in_list (args
, b
->number
))
6952 /* We only print out user settable breakpoints unless the
6954 if (allflag
|| user_breakpoint_p (b
))
6955 print_one_breakpoint (b
, &last_loc
, allflag
);
6958 do_cleanups (bkpttbl_chain
);
6960 if (nr_printable_breakpoints
== 0)
6962 /* If there's a filter, let the caller decide how to report
6966 if (args
== NULL
|| *args
== '\0')
6967 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6969 ui_out_message (uiout
, 0,
6970 "No breakpoint or watchpoint matching '%s'.\n",
6976 if (last_loc
&& !server_command
)
6977 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6980 /* FIXME? Should this be moved up so that it is only called when
6981 there have been breakpoints? */
6982 annotate_breakpoints_table_end ();
6984 return nr_printable_breakpoints
;
6987 /* Display the value of default-collect in a way that is generally
6988 compatible with the breakpoint list. */
6991 default_collect_info (void)
6993 struct ui_out
*uiout
= current_uiout
;
6995 /* If it has no value (which is frequently the case), say nothing; a
6996 message like "No default-collect." gets in user's face when it's
6998 if (!*default_collect
)
7001 /* The following phrase lines up nicely with per-tracepoint collect
7003 ui_out_text (uiout
, "default collect ");
7004 ui_out_field_string (uiout
, "default-collect", default_collect
);
7005 ui_out_text (uiout
, " \n");
7009 breakpoints_info (char *args
, int from_tty
)
7011 breakpoint_1 (args
, 0, NULL
);
7013 default_collect_info ();
7017 watchpoints_info (char *args
, int from_tty
)
7019 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
7020 struct ui_out
*uiout
= current_uiout
;
7022 if (num_printed
== 0)
7024 if (args
== NULL
|| *args
== '\0')
7025 ui_out_message (uiout
, 0, "No watchpoints.\n");
7027 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
7032 maintenance_info_breakpoints (char *args
, int from_tty
)
7034 breakpoint_1 (args
, 1, NULL
);
7036 default_collect_info ();
7040 breakpoint_has_pc (struct breakpoint
*b
,
7041 struct program_space
*pspace
,
7042 CORE_ADDR pc
, struct obj_section
*section
)
7044 struct bp_location
*bl
= b
->loc
;
7046 for (; bl
; bl
= bl
->next
)
7048 if (bl
->pspace
== pspace
7049 && bl
->address
== pc
7050 && (!overlay_debugging
|| bl
->section
== section
))
7056 /* Print a message describing any user-breakpoints set at PC. This
7057 concerns with logical breakpoints, so we match program spaces, not
7061 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7062 struct program_space
*pspace
, CORE_ADDR pc
,
7063 struct obj_section
*section
, int thread
)
7066 struct breakpoint
*b
;
7069 others
+= (user_breakpoint_p (b
)
7070 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7074 printf_filtered (_("Note: breakpoint "));
7075 else /* if (others == ???) */
7076 printf_filtered (_("Note: breakpoints "));
7078 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7081 printf_filtered ("%d", b
->number
);
7082 if (b
->thread
== -1 && thread
!= -1)
7083 printf_filtered (" (all threads)");
7084 else if (b
->thread
!= -1)
7085 printf_filtered (" (thread %d)", b
->thread
);
7086 printf_filtered ("%s%s ",
7087 ((b
->enable_state
== bp_disabled
7088 || b
->enable_state
== bp_call_disabled
)
7092 : ((others
== 1) ? " and" : ""));
7094 printf_filtered (_("also set at pc "));
7095 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7096 printf_filtered (".\n");
7101 /* Return true iff it is meaningful to use the address member of
7102 BPT locations. For some breakpoint types, the locations' address members
7103 are irrelevant and it makes no sense to attempt to compare them to other
7104 addresses (or use them for any other purpose either).
7106 More specifically, each of the following breakpoint types will
7107 always have a zero valued location address and we don't want to mark
7108 breakpoints of any of these types to be a duplicate of an actual
7109 breakpoint location at address zero:
7117 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7119 enum bptype type
= bpt
->type
;
7121 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7124 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7125 true if LOC1 and LOC2 represent the same watchpoint location. */
7128 watchpoint_locations_match (struct bp_location
*loc1
,
7129 struct bp_location
*loc2
)
7131 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7132 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7134 /* Both of them must exist. */
7135 gdb_assert (w1
!= NULL
);
7136 gdb_assert (w2
!= NULL
);
7138 /* If the target can evaluate the condition expression in hardware,
7139 then we we need to insert both watchpoints even if they are at
7140 the same place. Otherwise the watchpoint will only trigger when
7141 the condition of whichever watchpoint was inserted evaluates to
7142 true, not giving a chance for GDB to check the condition of the
7143 other watchpoint. */
7145 && target_can_accel_watchpoint_condition (loc1
->address
,
7147 loc1
->watchpoint_type
,
7150 && target_can_accel_watchpoint_condition (loc2
->address
,
7152 loc2
->watchpoint_type
,
7156 /* Note that this checks the owner's type, not the location's. In
7157 case the target does not support read watchpoints, but does
7158 support access watchpoints, we'll have bp_read_watchpoint
7159 watchpoints with hw_access locations. Those should be considered
7160 duplicates of hw_read locations. The hw_read locations will
7161 become hw_access locations later. */
7162 return (loc1
->owner
->type
== loc2
->owner
->type
7163 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7164 && loc1
->address
== loc2
->address
7165 && loc1
->length
== loc2
->length
);
7168 /* See breakpoint.h. */
7171 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7172 struct address_space
*aspace2
, CORE_ADDR addr2
)
7174 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7175 || aspace1
== aspace2
)
7179 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7180 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7181 matches ASPACE2. On targets that have global breakpoints, the address
7182 space doesn't really matter. */
7185 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7186 int len1
, struct address_space
*aspace2
,
7189 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7190 || aspace1
== aspace2
)
7191 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7194 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7195 a ranged breakpoint. In most targets, a match happens only if ASPACE
7196 matches the breakpoint's address space. On targets that have global
7197 breakpoints, the address space doesn't really matter. */
7200 breakpoint_location_address_match (struct bp_location
*bl
,
7201 struct address_space
*aspace
,
7204 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7207 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7208 bl
->address
, bl
->length
,
7212 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7213 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7214 match happens only if ASPACE matches the breakpoint's address
7215 space. On targets that have global breakpoints, the address space
7216 doesn't really matter. */
7219 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7220 struct address_space
*aspace
,
7221 CORE_ADDR addr
, int len
)
7223 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7224 || bl
->pspace
->aspace
== aspace
)
7226 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7228 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7234 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7235 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7236 true, otherwise returns false. */
7239 tracepoint_locations_match (struct bp_location
*loc1
,
7240 struct bp_location
*loc2
)
7242 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7243 /* Since tracepoint locations are never duplicated with others', tracepoint
7244 locations at the same address of different tracepoints are regarded as
7245 different locations. */
7246 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7251 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7252 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7253 represent the same location. */
7256 breakpoint_locations_match (struct bp_location
*loc1
,
7257 struct bp_location
*loc2
)
7259 int hw_point1
, hw_point2
;
7261 /* Both of them must not be in moribund_locations. */
7262 gdb_assert (loc1
->owner
!= NULL
);
7263 gdb_assert (loc2
->owner
!= NULL
);
7265 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7266 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7268 if (hw_point1
!= hw_point2
)
7271 return watchpoint_locations_match (loc1
, loc2
);
7272 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7273 return tracepoint_locations_match (loc1
, loc2
);
7275 /* We compare bp_location.length in order to cover ranged breakpoints. */
7276 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7277 loc2
->pspace
->aspace
, loc2
->address
)
7278 && loc1
->length
== loc2
->length
);
7282 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7283 int bnum
, int have_bnum
)
7285 /* The longest string possibly returned by hex_string_custom
7286 is 50 chars. These must be at least that big for safety. */
7290 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7291 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7293 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7294 bnum
, astr1
, astr2
);
7296 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7299 /* Adjust a breakpoint's address to account for architectural
7300 constraints on breakpoint placement. Return the adjusted address.
7301 Note: Very few targets require this kind of adjustment. For most
7302 targets, this function is simply the identity function. */
7305 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7306 CORE_ADDR bpaddr
, enum bptype bptype
)
7308 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7310 /* Very few targets need any kind of breakpoint adjustment. */
7313 else if (bptype
== bp_watchpoint
7314 || bptype
== bp_hardware_watchpoint
7315 || bptype
== bp_read_watchpoint
7316 || bptype
== bp_access_watchpoint
7317 || bptype
== bp_catchpoint
)
7319 /* Watchpoints and the various bp_catch_* eventpoints should not
7320 have their addresses modified. */
7323 else if (bptype
== bp_single_step
)
7325 /* Single-step breakpoints should not have their addresses
7326 modified. If there's any architectural constrain that
7327 applies to this address, then it should have already been
7328 taken into account when the breakpoint was created in the
7329 first place. If we didn't do this, stepping through e.g.,
7330 Thumb-2 IT blocks would break. */
7335 CORE_ADDR adjusted_bpaddr
;
7337 /* Some targets have architectural constraints on the placement
7338 of breakpoint instructions. Obtain the adjusted address. */
7339 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7341 /* An adjusted breakpoint address can significantly alter
7342 a user's expectations. Print a warning if an adjustment
7344 if (adjusted_bpaddr
!= bpaddr
)
7345 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7347 return adjusted_bpaddr
;
7352 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7353 struct breakpoint
*owner
)
7355 memset (loc
, 0, sizeof (*loc
));
7357 gdb_assert (ops
!= NULL
);
7362 loc
->cond_bytecode
= NULL
;
7363 loc
->shlib_disabled
= 0;
7366 switch (owner
->type
)
7369 case bp_single_step
:
7373 case bp_longjmp_resume
:
7374 case bp_longjmp_call_dummy
:
7376 case bp_exception_resume
:
7377 case bp_step_resume
:
7378 case bp_hp_step_resume
:
7379 case bp_watchpoint_scope
:
7381 case bp_std_terminate
:
7382 case bp_shlib_event
:
7383 case bp_thread_event
:
7384 case bp_overlay_event
:
7386 case bp_longjmp_master
:
7387 case bp_std_terminate_master
:
7388 case bp_exception_master
:
7389 case bp_gnu_ifunc_resolver
:
7390 case bp_gnu_ifunc_resolver_return
:
7392 loc
->loc_type
= bp_loc_software_breakpoint
;
7393 mark_breakpoint_location_modified (loc
);
7395 case bp_hardware_breakpoint
:
7396 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7397 mark_breakpoint_location_modified (loc
);
7399 case bp_hardware_watchpoint
:
7400 case bp_read_watchpoint
:
7401 case bp_access_watchpoint
:
7402 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7407 case bp_fast_tracepoint
:
7408 case bp_static_tracepoint
:
7409 loc
->loc_type
= bp_loc_other
;
7412 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7418 /* Allocate a struct bp_location. */
7420 static struct bp_location
*
7421 allocate_bp_location (struct breakpoint
*bpt
)
7423 return bpt
->ops
->allocate_location (bpt
);
7427 free_bp_location (struct bp_location
*loc
)
7429 loc
->ops
->dtor (loc
);
7433 /* Increment reference count. */
7436 incref_bp_location (struct bp_location
*bl
)
7441 /* Decrement reference count. If the reference count reaches 0,
7442 destroy the bp_location. Sets *BLP to NULL. */
7445 decref_bp_location (struct bp_location
**blp
)
7447 gdb_assert ((*blp
)->refc
> 0);
7449 if (--(*blp
)->refc
== 0)
7450 free_bp_location (*blp
);
7454 /* Add breakpoint B at the end of the global breakpoint chain. */
7457 add_to_breakpoint_chain (struct breakpoint
*b
)
7459 struct breakpoint
*b1
;
7461 /* Add this breakpoint to the end of the chain so that a list of
7462 breakpoints will come out in order of increasing numbers. */
7464 b1
= breakpoint_chain
;
7466 breakpoint_chain
= b
;
7475 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7478 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7479 struct gdbarch
*gdbarch
,
7481 const struct breakpoint_ops
*ops
)
7483 memset (b
, 0, sizeof (*b
));
7485 gdb_assert (ops
!= NULL
);
7489 b
->gdbarch
= gdbarch
;
7490 b
->language
= current_language
->la_language
;
7491 b
->input_radix
= input_radix
;
7493 b
->enable_state
= bp_enabled
;
7496 b
->ignore_count
= 0;
7498 b
->frame_id
= null_frame_id
;
7499 b
->condition_not_parsed
= 0;
7500 b
->py_bp_object
= NULL
;
7501 b
->related_breakpoint
= b
;
7505 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7506 that has type BPTYPE and has no locations as yet. */
7508 static struct breakpoint
*
7509 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7511 const struct breakpoint_ops
*ops
)
7513 struct breakpoint
*b
= XNEW (struct breakpoint
);
7515 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7516 add_to_breakpoint_chain (b
);
7520 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7521 resolutions should be made as the user specified the location explicitly
7525 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7527 gdb_assert (loc
->owner
!= NULL
);
7529 if (loc
->owner
->type
== bp_breakpoint
7530 || loc
->owner
->type
== bp_hardware_breakpoint
7531 || is_tracepoint (loc
->owner
))
7534 const char *function_name
;
7535 CORE_ADDR func_addr
;
7537 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7538 &func_addr
, NULL
, &is_gnu_ifunc
);
7540 if (is_gnu_ifunc
&& !explicit_loc
)
7542 struct breakpoint
*b
= loc
->owner
;
7544 gdb_assert (loc
->pspace
== current_program_space
);
7545 if (gnu_ifunc_resolve_name (function_name
,
7546 &loc
->requested_address
))
7548 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7549 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7550 loc
->requested_address
,
7553 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7554 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7556 /* Create only the whole new breakpoint of this type but do not
7557 mess more complicated breakpoints with multiple locations. */
7558 b
->type
= bp_gnu_ifunc_resolver
;
7559 /* Remember the resolver's address for use by the return
7561 loc
->related_address
= func_addr
;
7566 loc
->function_name
= xstrdup (function_name
);
7570 /* Attempt to determine architecture of location identified by SAL. */
7572 get_sal_arch (struct symtab_and_line sal
)
7575 return get_objfile_arch (sal
.section
->objfile
);
7577 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7582 /* Low level routine for partially initializing a breakpoint of type
7583 BPTYPE. The newly created breakpoint's address, section, source
7584 file name, and line number are provided by SAL.
7586 It is expected that the caller will complete the initialization of
7587 the newly created breakpoint struct as well as output any status
7588 information regarding the creation of a new breakpoint. */
7591 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7592 struct symtab_and_line sal
, enum bptype bptype
,
7593 const struct breakpoint_ops
*ops
)
7595 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7597 add_location_to_breakpoint (b
, &sal
);
7599 if (bptype
!= bp_catchpoint
)
7600 gdb_assert (sal
.pspace
!= NULL
);
7602 /* Store the program space that was used to set the breakpoint,
7603 except for ordinary breakpoints, which are independent of the
7605 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7606 b
->pspace
= sal
.pspace
;
7609 /* set_raw_breakpoint is a low level routine for allocating and
7610 partially initializing a breakpoint of type BPTYPE. The newly
7611 created breakpoint's address, section, source file name, and line
7612 number are provided by SAL. The newly created and partially
7613 initialized breakpoint is added to the breakpoint chain and
7614 is also returned as the value of this function.
7616 It is expected that the caller will complete the initialization of
7617 the newly created breakpoint struct as well as output any status
7618 information regarding the creation of a new breakpoint. In
7619 particular, set_raw_breakpoint does NOT set the breakpoint
7620 number! Care should be taken to not allow an error to occur
7621 prior to completing the initialization of the breakpoint. If this
7622 should happen, a bogus breakpoint will be left on the chain. */
7625 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7626 struct symtab_and_line sal
, enum bptype bptype
,
7627 const struct breakpoint_ops
*ops
)
7629 struct breakpoint
*b
= XNEW (struct breakpoint
);
7631 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7632 add_to_breakpoint_chain (b
);
7636 /* Call this routine when stepping and nexting to enable a breakpoint
7637 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7638 initiated the operation. */
7641 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7643 struct breakpoint
*b
, *b_tmp
;
7644 int thread
= tp
->global_num
;
7646 /* To avoid having to rescan all objfile symbols at every step,
7647 we maintain a list of continually-inserted but always disabled
7648 longjmp "master" breakpoints. Here, we simply create momentary
7649 clones of those and enable them for the requested thread. */
7650 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7651 if (b
->pspace
== current_program_space
7652 && (b
->type
== bp_longjmp_master
7653 || b
->type
== bp_exception_master
))
7655 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7656 struct breakpoint
*clone
;
7658 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7659 after their removal. */
7660 clone
= momentary_breakpoint_from_master (b
, type
,
7661 &longjmp_breakpoint_ops
, 1);
7662 clone
->thread
= thread
;
7665 tp
->initiating_frame
= frame
;
7668 /* Delete all longjmp breakpoints from THREAD. */
7670 delete_longjmp_breakpoint (int thread
)
7672 struct breakpoint
*b
, *b_tmp
;
7674 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7675 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7677 if (b
->thread
== thread
)
7678 delete_breakpoint (b
);
7683 delete_longjmp_breakpoint_at_next_stop (int thread
)
7685 struct breakpoint
*b
, *b_tmp
;
7687 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7688 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7690 if (b
->thread
== thread
)
7691 b
->disposition
= disp_del_at_next_stop
;
7695 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7696 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7697 pointer to any of them. Return NULL if this system cannot place longjmp
7701 set_longjmp_breakpoint_for_call_dummy (void)
7703 struct breakpoint
*b
, *retval
= NULL
;
7706 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7708 struct breakpoint
*new_b
;
7710 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7711 &momentary_breakpoint_ops
,
7713 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7715 /* Link NEW_B into the chain of RETVAL breakpoints. */
7717 gdb_assert (new_b
->related_breakpoint
== new_b
);
7720 new_b
->related_breakpoint
= retval
;
7721 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7722 retval
= retval
->related_breakpoint
;
7723 retval
->related_breakpoint
= new_b
;
7729 /* Verify all existing dummy frames and their associated breakpoints for
7730 TP. Remove those which can no longer be found in the current frame
7733 You should call this function only at places where it is safe to currently
7734 unwind the whole stack. Failed stack unwind would discard live dummy
7738 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7740 struct breakpoint
*b
, *b_tmp
;
7742 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7743 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7745 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7747 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7748 dummy_b
= dummy_b
->related_breakpoint
;
7749 if (dummy_b
->type
!= bp_call_dummy
7750 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7753 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7755 while (b
->related_breakpoint
!= b
)
7757 if (b_tmp
== b
->related_breakpoint
)
7758 b_tmp
= b
->related_breakpoint
->next
;
7759 delete_breakpoint (b
->related_breakpoint
);
7761 delete_breakpoint (b
);
7766 enable_overlay_breakpoints (void)
7768 struct breakpoint
*b
;
7771 if (b
->type
== bp_overlay_event
)
7773 b
->enable_state
= bp_enabled
;
7774 update_global_location_list (UGLL_MAY_INSERT
);
7775 overlay_events_enabled
= 1;
7780 disable_overlay_breakpoints (void)
7782 struct breakpoint
*b
;
7785 if (b
->type
== bp_overlay_event
)
7787 b
->enable_state
= bp_disabled
;
7788 update_global_location_list (UGLL_DONT_INSERT
);
7789 overlay_events_enabled
= 0;
7793 /* Set an active std::terminate breakpoint for each std::terminate
7794 master breakpoint. */
7796 set_std_terminate_breakpoint (void)
7798 struct breakpoint
*b
, *b_tmp
;
7800 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7801 if (b
->pspace
== current_program_space
7802 && b
->type
== bp_std_terminate_master
)
7804 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7805 &momentary_breakpoint_ops
, 1);
7809 /* Delete all the std::terminate breakpoints. */
7811 delete_std_terminate_breakpoint (void)
7813 struct breakpoint
*b
, *b_tmp
;
7815 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7816 if (b
->type
== bp_std_terminate
)
7817 delete_breakpoint (b
);
7821 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7823 struct breakpoint
*b
;
7825 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7826 &internal_breakpoint_ops
);
7828 b
->enable_state
= bp_enabled
;
7829 /* location has to be used or breakpoint_re_set will delete me. */
7830 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7832 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7837 struct lang_and_radix
7843 /* Create a breakpoint for JIT code registration and unregistration. */
7846 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7848 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7849 &internal_breakpoint_ops
);
7852 /* Remove JIT code registration and unregistration breakpoint(s). */
7855 remove_jit_event_breakpoints (void)
7857 struct breakpoint
*b
, *b_tmp
;
7859 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7860 if (b
->type
== bp_jit_event
7861 && b
->loc
->pspace
== current_program_space
)
7862 delete_breakpoint (b
);
7866 remove_solib_event_breakpoints (void)
7868 struct breakpoint
*b
, *b_tmp
;
7870 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7871 if (b
->type
== bp_shlib_event
7872 && b
->loc
->pspace
== current_program_space
)
7873 delete_breakpoint (b
);
7876 /* See breakpoint.h. */
7879 remove_solib_event_breakpoints_at_next_stop (void)
7881 struct breakpoint
*b
, *b_tmp
;
7883 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7884 if (b
->type
== bp_shlib_event
7885 && b
->loc
->pspace
== current_program_space
)
7886 b
->disposition
= disp_del_at_next_stop
;
7889 /* Helper for create_solib_event_breakpoint /
7890 create_and_insert_solib_event_breakpoint. Allows specifying which
7891 INSERT_MODE to pass through to update_global_location_list. */
7893 static struct breakpoint
*
7894 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7895 enum ugll_insert_mode insert_mode
)
7897 struct breakpoint
*b
;
7899 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7900 &internal_breakpoint_ops
);
7901 update_global_location_list_nothrow (insert_mode
);
7906 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7908 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7911 /* See breakpoint.h. */
7914 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7916 struct breakpoint
*b
;
7918 /* Explicitly tell update_global_location_list to insert
7920 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7921 if (!b
->loc
->inserted
)
7923 delete_breakpoint (b
);
7929 /* Disable any breakpoints that are on code in shared libraries. Only
7930 apply to enabled breakpoints, disabled ones can just stay disabled. */
7933 disable_breakpoints_in_shlibs (void)
7935 struct bp_location
*loc
, **locp_tmp
;
7937 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7939 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7940 struct breakpoint
*b
= loc
->owner
;
7942 /* We apply the check to all breakpoints, including disabled for
7943 those with loc->duplicate set. This is so that when breakpoint
7944 becomes enabled, or the duplicate is removed, gdb will try to
7945 insert all breakpoints. If we don't set shlib_disabled here,
7946 we'll try to insert those breakpoints and fail. */
7947 if (((b
->type
== bp_breakpoint
)
7948 || (b
->type
== bp_jit_event
)
7949 || (b
->type
== bp_hardware_breakpoint
)
7950 || (is_tracepoint (b
)))
7951 && loc
->pspace
== current_program_space
7952 && !loc
->shlib_disabled
7953 && solib_name_from_address (loc
->pspace
, loc
->address
)
7956 loc
->shlib_disabled
= 1;
7961 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7962 notification of unloaded_shlib. Only apply to enabled breakpoints,
7963 disabled ones can just stay disabled. */
7966 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7968 struct bp_location
*loc
, **locp_tmp
;
7969 int disabled_shlib_breaks
= 0;
7971 /* SunOS a.out shared libraries are always mapped, so do not
7972 disable breakpoints; they will only be reported as unloaded
7973 through clear_solib when GDB discards its shared library
7974 list. See clear_solib for more information. */
7975 if (exec_bfd
!= NULL
7976 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7979 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7981 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7982 struct breakpoint
*b
= loc
->owner
;
7984 if (solib
->pspace
== loc
->pspace
7985 && !loc
->shlib_disabled
7986 && (((b
->type
== bp_breakpoint
7987 || b
->type
== bp_jit_event
7988 || b
->type
== bp_hardware_breakpoint
)
7989 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7990 || loc
->loc_type
== bp_loc_software_breakpoint
))
7991 || is_tracepoint (b
))
7992 && solib_contains_address_p (solib
, loc
->address
))
7994 loc
->shlib_disabled
= 1;
7995 /* At this point, we cannot rely on remove_breakpoint
7996 succeeding so we must mark the breakpoint as not inserted
7997 to prevent future errors occurring in remove_breakpoints. */
8000 /* This may cause duplicate notifications for the same breakpoint. */
8001 observer_notify_breakpoint_modified (b
);
8003 if (!disabled_shlib_breaks
)
8005 target_terminal_ours_for_output ();
8006 warning (_("Temporarily disabling breakpoints "
8007 "for unloaded shared library \"%s\""),
8010 disabled_shlib_breaks
= 1;
8015 /* Disable any breakpoints and tracepoints in OBJFILE upon
8016 notification of free_objfile. Only apply to enabled breakpoints,
8017 disabled ones can just stay disabled. */
8020 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
8022 struct breakpoint
*b
;
8024 if (objfile
== NULL
)
8027 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8028 managed by the user with add-symbol-file/remove-symbol-file.
8029 Similarly to how breakpoints in shared libraries are handled in
8030 response to "nosharedlibrary", mark breakpoints in such modules
8031 shlib_disabled so they end up uninserted on the next global
8032 location list update. Shared libraries not loaded by the user
8033 aren't handled here -- they're already handled in
8034 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8035 solib_unloaded observer. We skip objfiles that are not
8036 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8038 if ((objfile
->flags
& OBJF_SHARED
) == 0
8039 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8044 struct bp_location
*loc
;
8045 int bp_modified
= 0;
8047 if (!is_breakpoint (b
) && !is_tracepoint (b
))
8050 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
8052 CORE_ADDR loc_addr
= loc
->address
;
8054 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8055 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8058 if (loc
->shlib_disabled
!= 0)
8061 if (objfile
->pspace
!= loc
->pspace
)
8064 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8065 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8068 if (is_addr_in_objfile (loc_addr
, objfile
))
8070 loc
->shlib_disabled
= 1;
8071 /* At this point, we don't know whether the object was
8072 unmapped from the inferior or not, so leave the
8073 inserted flag alone. We'll handle failure to
8074 uninsert quietly, in case the object was indeed
8077 mark_breakpoint_location_modified (loc
);
8084 observer_notify_breakpoint_modified (b
);
8088 /* FORK & VFORK catchpoints. */
8090 /* An instance of this type is used to represent a fork or vfork
8091 catchpoint. It includes a "struct breakpoint" as a kind of base
8092 class; users downcast to "struct breakpoint *" when needed. A
8093 breakpoint is really of this type iff its ops pointer points to
8094 CATCH_FORK_BREAKPOINT_OPS. */
8096 struct fork_catchpoint
8098 /* The base class. */
8099 struct breakpoint base
;
8101 /* Process id of a child process whose forking triggered this
8102 catchpoint. This field is only valid immediately after this
8103 catchpoint has triggered. */
8104 ptid_t forked_inferior_pid
;
8107 /* Implement the "insert" breakpoint_ops method for fork
8111 insert_catch_fork (struct bp_location
*bl
)
8113 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8116 /* Implement the "remove" breakpoint_ops method for fork
8120 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8122 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8125 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8129 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8130 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8131 const struct target_waitstatus
*ws
)
8133 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8135 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8138 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8142 /* Implement the "print_it" breakpoint_ops method for fork
8145 static enum print_stop_action
8146 print_it_catch_fork (bpstat bs
)
8148 struct ui_out
*uiout
= current_uiout
;
8149 struct breakpoint
*b
= bs
->breakpoint_at
;
8150 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8152 annotate_catchpoint (b
->number
);
8153 maybe_print_thread_hit_breakpoint (uiout
);
8154 if (b
->disposition
== disp_del
)
8155 ui_out_text (uiout
, "Temporary catchpoint ");
8157 ui_out_text (uiout
, "Catchpoint ");
8158 if (ui_out_is_mi_like_p (uiout
))
8160 ui_out_field_string (uiout
, "reason",
8161 async_reason_lookup (EXEC_ASYNC_FORK
));
8162 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8164 ui_out_field_int (uiout
, "bkptno", b
->number
);
8165 ui_out_text (uiout
, " (forked process ");
8166 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8167 ui_out_text (uiout
, "), ");
8168 return PRINT_SRC_AND_LOC
;
8171 /* Implement the "print_one" breakpoint_ops method for fork
8175 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8177 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8178 struct value_print_options opts
;
8179 struct ui_out
*uiout
= current_uiout
;
8181 get_user_print_options (&opts
);
8183 /* Field 4, the address, is omitted (which makes the columns not
8184 line up too nicely with the headers, but the effect is relatively
8186 if (opts
.addressprint
)
8187 ui_out_field_skip (uiout
, "addr");
8189 ui_out_text (uiout
, "fork");
8190 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8192 ui_out_text (uiout
, ", process ");
8193 ui_out_field_int (uiout
, "what",
8194 ptid_get_pid (c
->forked_inferior_pid
));
8195 ui_out_spaces (uiout
, 1);
8198 if (ui_out_is_mi_like_p (uiout
))
8199 ui_out_field_string (uiout
, "catch-type", "fork");
8202 /* Implement the "print_mention" breakpoint_ops method for fork
8206 print_mention_catch_fork (struct breakpoint
*b
)
8208 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8211 /* Implement the "print_recreate" breakpoint_ops method for fork
8215 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8217 fprintf_unfiltered (fp
, "catch fork");
8218 print_recreate_thread (b
, fp
);
8221 /* The breakpoint_ops structure to be used in fork catchpoints. */
8223 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8225 /* Implement the "insert" breakpoint_ops method for vfork
8229 insert_catch_vfork (struct bp_location
*bl
)
8231 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8234 /* Implement the "remove" breakpoint_ops method for vfork
8238 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8240 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8243 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8247 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8248 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8249 const struct target_waitstatus
*ws
)
8251 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8253 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8256 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8260 /* Implement the "print_it" breakpoint_ops method for vfork
8263 static enum print_stop_action
8264 print_it_catch_vfork (bpstat bs
)
8266 struct ui_out
*uiout
= current_uiout
;
8267 struct breakpoint
*b
= bs
->breakpoint_at
;
8268 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8270 annotate_catchpoint (b
->number
);
8271 maybe_print_thread_hit_breakpoint (uiout
);
8272 if (b
->disposition
== disp_del
)
8273 ui_out_text (uiout
, "Temporary catchpoint ");
8275 ui_out_text (uiout
, "Catchpoint ");
8276 if (ui_out_is_mi_like_p (uiout
))
8278 ui_out_field_string (uiout
, "reason",
8279 async_reason_lookup (EXEC_ASYNC_VFORK
));
8280 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8282 ui_out_field_int (uiout
, "bkptno", b
->number
);
8283 ui_out_text (uiout
, " (vforked process ");
8284 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8285 ui_out_text (uiout
, "), ");
8286 return PRINT_SRC_AND_LOC
;
8289 /* Implement the "print_one" breakpoint_ops method for vfork
8293 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8295 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8296 struct value_print_options opts
;
8297 struct ui_out
*uiout
= current_uiout
;
8299 get_user_print_options (&opts
);
8300 /* Field 4, the address, is omitted (which makes the columns not
8301 line up too nicely with the headers, but the effect is relatively
8303 if (opts
.addressprint
)
8304 ui_out_field_skip (uiout
, "addr");
8306 ui_out_text (uiout
, "vfork");
8307 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8309 ui_out_text (uiout
, ", process ");
8310 ui_out_field_int (uiout
, "what",
8311 ptid_get_pid (c
->forked_inferior_pid
));
8312 ui_out_spaces (uiout
, 1);
8315 if (ui_out_is_mi_like_p (uiout
))
8316 ui_out_field_string (uiout
, "catch-type", "vfork");
8319 /* Implement the "print_mention" breakpoint_ops method for vfork
8323 print_mention_catch_vfork (struct breakpoint
*b
)
8325 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8328 /* Implement the "print_recreate" breakpoint_ops method for vfork
8332 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8334 fprintf_unfiltered (fp
, "catch vfork");
8335 print_recreate_thread (b
, fp
);
8338 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8340 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8342 /* An instance of this type is used to represent an solib catchpoint.
8343 It includes a "struct breakpoint" as a kind of base class; users
8344 downcast to "struct breakpoint *" when needed. A breakpoint is
8345 really of this type iff its ops pointer points to
8346 CATCH_SOLIB_BREAKPOINT_OPS. */
8348 struct solib_catchpoint
8350 /* The base class. */
8351 struct breakpoint base
;
8353 /* True for "catch load", false for "catch unload". */
8354 unsigned char is_load
;
8356 /* Regular expression to match, if any. COMPILED is only valid when
8357 REGEX is non-NULL. */
8363 dtor_catch_solib (struct breakpoint
*b
)
8365 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8368 regfree (&self
->compiled
);
8369 xfree (self
->regex
);
8371 base_breakpoint_ops
.dtor (b
);
8375 insert_catch_solib (struct bp_location
*ignore
)
8381 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8387 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8388 struct address_space
*aspace
,
8390 const struct target_waitstatus
*ws
)
8392 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8393 struct breakpoint
*other
;
8395 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8398 ALL_BREAKPOINTS (other
)
8400 struct bp_location
*other_bl
;
8402 if (other
== bl
->owner
)
8405 if (other
->type
!= bp_shlib_event
)
8408 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8411 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8413 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8422 check_status_catch_solib (struct bpstats
*bs
)
8424 struct solib_catchpoint
*self
8425 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8430 struct so_list
*iter
;
8433 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8438 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8447 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8452 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8458 bs
->print_it
= print_it_noop
;
8461 static enum print_stop_action
8462 print_it_catch_solib (bpstat bs
)
8464 struct breakpoint
*b
= bs
->breakpoint_at
;
8465 struct ui_out
*uiout
= current_uiout
;
8467 annotate_catchpoint (b
->number
);
8468 maybe_print_thread_hit_breakpoint (uiout
);
8469 if (b
->disposition
== disp_del
)
8470 ui_out_text (uiout
, "Temporary catchpoint ");
8472 ui_out_text (uiout
, "Catchpoint ");
8473 ui_out_field_int (uiout
, "bkptno", b
->number
);
8474 ui_out_text (uiout
, "\n");
8475 if (ui_out_is_mi_like_p (uiout
))
8476 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8477 print_solib_event (1);
8478 return PRINT_SRC_AND_LOC
;
8482 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8484 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8485 struct value_print_options opts
;
8486 struct ui_out
*uiout
= current_uiout
;
8489 get_user_print_options (&opts
);
8490 /* Field 4, the address, is omitted (which makes the columns not
8491 line up too nicely with the headers, but the effect is relatively
8493 if (opts
.addressprint
)
8496 ui_out_field_skip (uiout
, "addr");
8503 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8505 msg
= xstrdup (_("load of library"));
8510 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8512 msg
= xstrdup (_("unload of library"));
8514 ui_out_field_string (uiout
, "what", msg
);
8517 if (ui_out_is_mi_like_p (uiout
))
8518 ui_out_field_string (uiout
, "catch-type",
8519 self
->is_load
? "load" : "unload");
8523 print_mention_catch_solib (struct breakpoint
*b
)
8525 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8527 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8528 self
->is_load
? "load" : "unload");
8532 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8534 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8536 fprintf_unfiltered (fp
, "%s %s",
8537 b
->disposition
== disp_del
? "tcatch" : "catch",
8538 self
->is_load
? "load" : "unload");
8540 fprintf_unfiltered (fp
, " %s", self
->regex
);
8541 fprintf_unfiltered (fp
, "\n");
8544 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8546 /* Shared helper function (MI and CLI) for creating and installing
8547 a shared object event catchpoint. If IS_LOAD is non-zero then
8548 the events to be caught are load events, otherwise they are
8549 unload events. If IS_TEMP is non-zero the catchpoint is a
8550 temporary one. If ENABLED is non-zero the catchpoint is
8551 created in an enabled state. */
8554 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8556 struct solib_catchpoint
*c
;
8557 struct gdbarch
*gdbarch
= get_current_arch ();
8558 struct cleanup
*cleanup
;
8562 arg
= skip_spaces (arg
);
8564 c
= XCNEW (struct solib_catchpoint
);
8565 cleanup
= make_cleanup (xfree
, c
);
8571 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8574 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8576 make_cleanup (xfree
, err
);
8577 error (_("Invalid regexp (%s): %s"), err
, arg
);
8579 c
->regex
= xstrdup (arg
);
8582 c
->is_load
= is_load
;
8583 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8584 &catch_solib_breakpoint_ops
);
8586 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8588 discard_cleanups (cleanup
);
8589 install_breakpoint (0, &c
->base
, 1);
8592 /* A helper function that does all the work for "catch load" and
8596 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8597 struct cmd_list_element
*command
)
8600 const int enabled
= 1;
8602 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8604 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8608 catch_load_command_1 (char *arg
, int from_tty
,
8609 struct cmd_list_element
*command
)
8611 catch_load_or_unload (arg
, from_tty
, 1, command
);
8615 catch_unload_command_1 (char *arg
, int from_tty
,
8616 struct cmd_list_element
*command
)
8618 catch_load_or_unload (arg
, from_tty
, 0, command
);
8621 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8622 is non-zero, then make the breakpoint temporary. If COND_STRING is
8623 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8624 the breakpoint_ops structure associated to the catchpoint. */
8627 init_catchpoint (struct breakpoint
*b
,
8628 struct gdbarch
*gdbarch
, int tempflag
,
8630 const struct breakpoint_ops
*ops
)
8632 struct symtab_and_line sal
;
8635 sal
.pspace
= current_program_space
;
8637 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8639 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8640 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8644 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8646 add_to_breakpoint_chain (b
);
8647 set_breakpoint_number (internal
, b
);
8648 if (is_tracepoint (b
))
8649 set_tracepoint_count (breakpoint_count
);
8652 observer_notify_breakpoint_created (b
);
8655 update_global_location_list (UGLL_MAY_INSERT
);
8659 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8660 int tempflag
, char *cond_string
,
8661 const struct breakpoint_ops
*ops
)
8663 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8665 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8667 c
->forked_inferior_pid
= null_ptid
;
8669 install_breakpoint (0, &c
->base
, 1);
8672 /* Exec catchpoints. */
8674 /* An instance of this type is used to represent an exec catchpoint.
8675 It includes a "struct breakpoint" as a kind of base class; users
8676 downcast to "struct breakpoint *" when needed. A breakpoint is
8677 really of this type iff its ops pointer points to
8678 CATCH_EXEC_BREAKPOINT_OPS. */
8680 struct exec_catchpoint
8682 /* The base class. */
8683 struct breakpoint base
;
8685 /* Filename of a program whose exec triggered this catchpoint.
8686 This field is only valid immediately after this catchpoint has
8688 char *exec_pathname
;
8691 /* Implement the "dtor" breakpoint_ops method for exec
8695 dtor_catch_exec (struct breakpoint
*b
)
8697 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8699 xfree (c
->exec_pathname
);
8701 base_breakpoint_ops
.dtor (b
);
8705 insert_catch_exec (struct bp_location
*bl
)
8707 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8711 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8713 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8717 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8718 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8719 const struct target_waitstatus
*ws
)
8721 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8723 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8726 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8730 static enum print_stop_action
8731 print_it_catch_exec (bpstat bs
)
8733 struct ui_out
*uiout
= current_uiout
;
8734 struct breakpoint
*b
= bs
->breakpoint_at
;
8735 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8737 annotate_catchpoint (b
->number
);
8738 maybe_print_thread_hit_breakpoint (uiout
);
8739 if (b
->disposition
== disp_del
)
8740 ui_out_text (uiout
, "Temporary catchpoint ");
8742 ui_out_text (uiout
, "Catchpoint ");
8743 if (ui_out_is_mi_like_p (uiout
))
8745 ui_out_field_string (uiout
, "reason",
8746 async_reason_lookup (EXEC_ASYNC_EXEC
));
8747 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8749 ui_out_field_int (uiout
, "bkptno", b
->number
);
8750 ui_out_text (uiout
, " (exec'd ");
8751 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8752 ui_out_text (uiout
, "), ");
8754 return PRINT_SRC_AND_LOC
;
8758 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8760 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8761 struct value_print_options opts
;
8762 struct ui_out
*uiout
= current_uiout
;
8764 get_user_print_options (&opts
);
8766 /* Field 4, the address, is omitted (which makes the columns
8767 not line up too nicely with the headers, but the effect
8768 is relatively readable). */
8769 if (opts
.addressprint
)
8770 ui_out_field_skip (uiout
, "addr");
8772 ui_out_text (uiout
, "exec");
8773 if (c
->exec_pathname
!= NULL
)
8775 ui_out_text (uiout
, ", program \"");
8776 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8777 ui_out_text (uiout
, "\" ");
8780 if (ui_out_is_mi_like_p (uiout
))
8781 ui_out_field_string (uiout
, "catch-type", "exec");
8785 print_mention_catch_exec (struct breakpoint
*b
)
8787 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8790 /* Implement the "print_recreate" breakpoint_ops method for exec
8794 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8796 fprintf_unfiltered (fp
, "catch exec");
8797 print_recreate_thread (b
, fp
);
8800 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8803 hw_breakpoint_used_count (void)
8806 struct breakpoint
*b
;
8807 struct bp_location
*bl
;
8811 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8812 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8814 /* Special types of hardware breakpoints may use more than
8816 i
+= b
->ops
->resources_needed (bl
);
8823 /* Returns the resources B would use if it were a hardware
8827 hw_watchpoint_use_count (struct breakpoint
*b
)
8830 struct bp_location
*bl
;
8832 if (!breakpoint_enabled (b
))
8835 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8837 /* Special types of hardware watchpoints may use more than
8839 i
+= b
->ops
->resources_needed (bl
);
8845 /* Returns the sum the used resources of all hardware watchpoints of
8846 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8847 the sum of the used resources of all hardware watchpoints of other
8848 types _not_ TYPE. */
8851 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8852 enum bptype type
, int *other_type_used
)
8855 struct breakpoint
*b
;
8857 *other_type_used
= 0;
8862 if (!breakpoint_enabled (b
))
8865 if (b
->type
== type
)
8866 i
+= hw_watchpoint_use_count (b
);
8867 else if (is_hardware_watchpoint (b
))
8868 *other_type_used
= 1;
8875 disable_watchpoints_before_interactive_call_start (void)
8877 struct breakpoint
*b
;
8881 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8883 b
->enable_state
= bp_call_disabled
;
8884 update_global_location_list (UGLL_DONT_INSERT
);
8890 enable_watchpoints_after_interactive_call_stop (void)
8892 struct breakpoint
*b
;
8896 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8898 b
->enable_state
= bp_enabled
;
8899 update_global_location_list (UGLL_MAY_INSERT
);
8905 disable_breakpoints_before_startup (void)
8907 current_program_space
->executing_startup
= 1;
8908 update_global_location_list (UGLL_DONT_INSERT
);
8912 enable_breakpoints_after_startup (void)
8914 current_program_space
->executing_startup
= 0;
8915 breakpoint_re_set ();
8918 /* Create a new single-step breakpoint for thread THREAD, with no
8921 static struct breakpoint
*
8922 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8924 struct breakpoint
*b
= XNEW (struct breakpoint
);
8926 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8927 &momentary_breakpoint_ops
);
8929 b
->disposition
= disp_donttouch
;
8930 b
->frame_id
= null_frame_id
;
8933 gdb_assert (b
->thread
!= 0);
8935 add_to_breakpoint_chain (b
);
8940 /* Set a momentary breakpoint of type TYPE at address specified by
8941 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8945 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8946 struct frame_id frame_id
, enum bptype type
)
8948 struct breakpoint
*b
;
8950 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8952 gdb_assert (!frame_id_artificial_p (frame_id
));
8954 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8955 b
->enable_state
= bp_enabled
;
8956 b
->disposition
= disp_donttouch
;
8957 b
->frame_id
= frame_id
;
8959 /* If we're debugging a multi-threaded program, then we want
8960 momentary breakpoints to be active in only a single thread of
8962 if (in_thread_list (inferior_ptid
))
8963 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8965 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8970 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8971 The new breakpoint will have type TYPE, use OPS as its
8972 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8974 static struct breakpoint
*
8975 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8977 const struct breakpoint_ops
*ops
,
8980 struct breakpoint
*copy
;
8982 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8983 copy
->loc
= allocate_bp_location (copy
);
8984 set_breakpoint_location_function (copy
->loc
, 1);
8986 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8987 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8988 copy
->loc
->address
= orig
->loc
->address
;
8989 copy
->loc
->section
= orig
->loc
->section
;
8990 copy
->loc
->pspace
= orig
->loc
->pspace
;
8991 copy
->loc
->probe
= orig
->loc
->probe
;
8992 copy
->loc
->line_number
= orig
->loc
->line_number
;
8993 copy
->loc
->symtab
= orig
->loc
->symtab
;
8994 copy
->loc
->enabled
= loc_enabled
;
8995 copy
->frame_id
= orig
->frame_id
;
8996 copy
->thread
= orig
->thread
;
8997 copy
->pspace
= orig
->pspace
;
8999 copy
->enable_state
= bp_enabled
;
9000 copy
->disposition
= disp_donttouch
;
9001 copy
->number
= internal_breakpoint_number
--;
9003 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9007 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9011 clone_momentary_breakpoint (struct breakpoint
*orig
)
9013 /* If there's nothing to clone, then return nothing. */
9017 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9021 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9024 struct symtab_and_line sal
;
9026 sal
= find_pc_line (pc
, 0);
9028 sal
.section
= find_pc_overlay (pc
);
9029 sal
.explicit_pc
= 1;
9031 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9035 /* Tell the user we have just set a breakpoint B. */
9038 mention (struct breakpoint
*b
)
9040 b
->ops
->print_mention (b
);
9041 if (ui_out_is_mi_like_p (current_uiout
))
9043 printf_filtered ("\n");
9047 static int bp_loc_is_permanent (struct bp_location
*loc
);
9049 static struct bp_location
*
9050 add_location_to_breakpoint (struct breakpoint
*b
,
9051 const struct symtab_and_line
*sal
)
9053 struct bp_location
*loc
, **tmp
;
9054 CORE_ADDR adjusted_address
;
9055 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9057 if (loc_gdbarch
== NULL
)
9058 loc_gdbarch
= b
->gdbarch
;
9060 /* Adjust the breakpoint's address prior to allocating a location.
9061 Once we call allocate_bp_location(), that mostly uninitialized
9062 location will be placed on the location chain. Adjustment of the
9063 breakpoint may cause target_read_memory() to be called and we do
9064 not want its scan of the location chain to find a breakpoint and
9065 location that's only been partially initialized. */
9066 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9069 /* Sort the locations by their ADDRESS. */
9070 loc
= allocate_bp_location (b
);
9071 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9072 tmp
= &((*tmp
)->next
))
9077 loc
->requested_address
= sal
->pc
;
9078 loc
->address
= adjusted_address
;
9079 loc
->pspace
= sal
->pspace
;
9080 loc
->probe
.probe
= sal
->probe
;
9081 loc
->probe
.objfile
= sal
->objfile
;
9082 gdb_assert (loc
->pspace
!= NULL
);
9083 loc
->section
= sal
->section
;
9084 loc
->gdbarch
= loc_gdbarch
;
9085 loc
->line_number
= sal
->line
;
9086 loc
->symtab
= sal
->symtab
;
9088 set_breakpoint_location_function (loc
,
9089 sal
->explicit_pc
|| sal
->explicit_line
);
9091 /* While by definition, permanent breakpoints are already present in the
9092 code, we don't mark the location as inserted. Normally one would expect
9093 that GDB could rely on that breakpoint instruction to stop the program,
9094 thus removing the need to insert its own breakpoint, except that executing
9095 the breakpoint instruction can kill the target instead of reporting a
9096 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9097 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9098 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9099 breakpoint be inserted normally results in QEMU knowing about the GDB
9100 breakpoint, and thus trap before the breakpoint instruction is executed.
9101 (If GDB later needs to continue execution past the permanent breakpoint,
9102 it manually increments the PC, thus avoiding executing the breakpoint
9104 if (bp_loc_is_permanent (loc
))
9111 /* See breakpoint.h. */
9114 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9118 const gdb_byte
*bpoint
;
9119 gdb_byte
*target_mem
;
9120 struct cleanup
*cleanup
;
9124 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9126 /* Software breakpoints unsupported? */
9130 target_mem
= (gdb_byte
*) alloca (len
);
9132 /* Enable the automatic memory restoration from breakpoints while
9133 we read the memory. Otherwise we could say about our temporary
9134 breakpoints they are permanent. */
9135 cleanup
= make_show_memory_breakpoints_cleanup (0);
9137 if (target_read_memory (address
, target_mem
, len
) == 0
9138 && memcmp (target_mem
, bpoint
, len
) == 0)
9141 do_cleanups (cleanup
);
9146 /* Return 1 if LOC is pointing to a permanent breakpoint,
9147 return 0 otherwise. */
9150 bp_loc_is_permanent (struct bp_location
*loc
)
9152 struct cleanup
*cleanup
;
9155 gdb_assert (loc
!= NULL
);
9157 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9158 attempt to read from the addresses the locations of these breakpoint types
9159 point to. program_breakpoint_here_p, below, will attempt to read
9161 if (!breakpoint_address_is_meaningful (loc
->owner
))
9164 cleanup
= save_current_space_and_thread ();
9165 switch_to_program_space_and_thread (loc
->pspace
);
9167 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9169 do_cleanups (cleanup
);
9174 /* Build a command list for the dprintf corresponding to the current
9175 settings of the dprintf style options. */
9178 update_dprintf_command_list (struct breakpoint
*b
)
9180 char *dprintf_args
= b
->extra_string
;
9181 char *printf_line
= NULL
;
9186 dprintf_args
= skip_spaces (dprintf_args
);
9188 /* Allow a comma, as it may have terminated a location, but don't
9190 if (*dprintf_args
== ',')
9192 dprintf_args
= skip_spaces (dprintf_args
);
9194 if (*dprintf_args
!= '"')
9195 error (_("Bad format string, missing '\"'."));
9197 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9198 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9199 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9201 if (!dprintf_function
)
9202 error (_("No function supplied for dprintf call"));
9204 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9205 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9210 printf_line
= xstrprintf ("call (void) %s (%s)",
9214 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9216 if (target_can_run_breakpoint_commands ())
9217 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9220 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9221 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9225 internal_error (__FILE__
, __LINE__
,
9226 _("Invalid dprintf style."));
9228 gdb_assert (printf_line
!= NULL
);
9229 /* Manufacture a printf sequence. */
9231 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9233 printf_cmd_line
->control_type
= simple_control
;
9234 printf_cmd_line
->body_count
= 0;
9235 printf_cmd_line
->body_list
= NULL
;
9236 printf_cmd_line
->next
= NULL
;
9237 printf_cmd_line
->line
= printf_line
;
9239 breakpoint_set_commands (b
, printf_cmd_line
);
9243 /* Update all dprintf commands, making their command lists reflect
9244 current style settings. */
9247 update_dprintf_commands (char *args
, int from_tty
,
9248 struct cmd_list_element
*c
)
9250 struct breakpoint
*b
;
9254 if (b
->type
== bp_dprintf
)
9255 update_dprintf_command_list (b
);
9259 /* Create a breakpoint with SAL as location. Use LOCATION
9260 as a description of the location, and COND_STRING
9261 as condition expression. If LOCATION is NULL then create an
9262 "address location" from the address in the SAL. */
9265 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9266 struct symtabs_and_lines sals
,
9267 struct event_location
*location
,
9268 char *filter
, char *cond_string
,
9270 enum bptype type
, enum bpdisp disposition
,
9271 int thread
, int task
, int ignore_count
,
9272 const struct breakpoint_ops
*ops
, int from_tty
,
9273 int enabled
, int internal
, unsigned flags
,
9274 int display_canonical
)
9278 if (type
== bp_hardware_breakpoint
)
9280 int target_resources_ok
;
9282 i
= hw_breakpoint_used_count ();
9283 target_resources_ok
=
9284 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9286 if (target_resources_ok
== 0)
9287 error (_("No hardware breakpoint support in the target."));
9288 else if (target_resources_ok
< 0)
9289 error (_("Hardware breakpoints used exceeds limit."));
9292 gdb_assert (sals
.nelts
> 0);
9294 for (i
= 0; i
< sals
.nelts
; ++i
)
9296 struct symtab_and_line sal
= sals
.sals
[i
];
9297 struct bp_location
*loc
;
9301 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9303 loc_gdbarch
= gdbarch
;
9305 describe_other_breakpoints (loc_gdbarch
,
9306 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9311 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9315 b
->cond_string
= cond_string
;
9316 b
->extra_string
= extra_string
;
9317 b
->ignore_count
= ignore_count
;
9318 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9319 b
->disposition
= disposition
;
9321 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9322 b
->loc
->inserted
= 1;
9324 if (type
== bp_static_tracepoint
)
9326 struct tracepoint
*t
= (struct tracepoint
*) b
;
9327 struct static_tracepoint_marker marker
;
9329 if (strace_marker_p (b
))
9331 /* We already know the marker exists, otherwise, we
9332 wouldn't see a sal for it. */
9333 const char *p
= &event_location_to_string (b
->location
)[3];
9337 p
= skip_spaces_const (p
);
9339 endp
= skip_to_space_const (p
);
9341 marker_str
= savestring (p
, endp
- p
);
9342 t
->static_trace_marker_id
= marker_str
;
9344 printf_filtered (_("Probed static tracepoint "
9346 t
->static_trace_marker_id
);
9348 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9350 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9351 release_static_tracepoint_marker (&marker
);
9353 printf_filtered (_("Probed static tracepoint "
9355 t
->static_trace_marker_id
);
9358 warning (_("Couldn't determine the static "
9359 "tracepoint marker to probe"));
9366 loc
= add_location_to_breakpoint (b
, &sal
);
9367 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9373 const char *arg
= b
->cond_string
;
9375 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9376 block_for_pc (loc
->address
), 0);
9378 error (_("Garbage '%s' follows condition"), arg
);
9381 /* Dynamic printf requires and uses additional arguments on the
9382 command line, otherwise it's an error. */
9383 if (type
== bp_dprintf
)
9385 if (b
->extra_string
)
9386 update_dprintf_command_list (b
);
9388 error (_("Format string required"));
9390 else if (b
->extra_string
)
9391 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9394 b
->display_canonical
= display_canonical
;
9395 if (location
!= NULL
)
9396 b
->location
= location
;
9399 const char *addr_string
= NULL
;
9400 int addr_string_len
= 0;
9402 if (location
!= NULL
)
9403 addr_string
= event_location_to_string (location
);
9404 if (addr_string
!= NULL
)
9405 addr_string_len
= strlen (addr_string
);
9407 b
->location
= new_address_location (b
->loc
->address
,
9408 addr_string
, addr_string_len
);
9414 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9415 struct symtabs_and_lines sals
,
9416 struct event_location
*location
,
9417 char *filter
, char *cond_string
,
9419 enum bptype type
, enum bpdisp disposition
,
9420 int thread
, int task
, int ignore_count
,
9421 const struct breakpoint_ops
*ops
, int from_tty
,
9422 int enabled
, int internal
, unsigned flags
,
9423 int display_canonical
)
9425 struct breakpoint
*b
;
9426 struct cleanup
*old_chain
;
9428 if (is_tracepoint_type (type
))
9430 struct tracepoint
*t
;
9432 t
= XCNEW (struct tracepoint
);
9436 b
= XNEW (struct breakpoint
);
9438 old_chain
= make_cleanup (xfree
, b
);
9440 init_breakpoint_sal (b
, gdbarch
,
9442 filter
, cond_string
, extra_string
,
9444 thread
, task
, ignore_count
,
9446 enabled
, internal
, flags
,
9448 discard_cleanups (old_chain
);
9450 install_breakpoint (internal
, b
, 0);
9453 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9454 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9455 value. COND_STRING, if not NULL, specified the condition to be
9456 used for all breakpoints. Essentially the only case where
9457 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9458 function. In that case, it's still not possible to specify
9459 separate conditions for different overloaded functions, so
9460 we take just a single condition string.
9462 NOTE: If the function succeeds, the caller is expected to cleanup
9463 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9464 array contents). If the function fails (error() is called), the
9465 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9466 COND and SALS arrays and each of those arrays contents. */
9469 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9470 struct linespec_result
*canonical
,
9471 char *cond_string
, char *extra_string
,
9472 enum bptype type
, enum bpdisp disposition
,
9473 int thread
, int task
, int ignore_count
,
9474 const struct breakpoint_ops
*ops
, int from_tty
,
9475 int enabled
, int internal
, unsigned flags
)
9478 struct linespec_sals
*lsal
;
9480 if (canonical
->pre_expanded
)
9481 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9483 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9485 /* Note that 'location' can be NULL in the case of a plain
9486 'break', without arguments. */
9487 struct event_location
*location
9488 = (canonical
->location
!= NULL
9489 ? copy_event_location (canonical
->location
) : NULL
);
9490 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9491 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9493 make_cleanup (xfree
, filter_string
);
9494 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9497 cond_string
, extra_string
,
9499 thread
, task
, ignore_count
, ops
,
9500 from_tty
, enabled
, internal
, flags
,
9501 canonical
->special_display
);
9502 discard_cleanups (inner
);
9506 /* Parse LOCATION which is assumed to be a SAL specification possibly
9507 followed by conditionals. On return, SALS contains an array of SAL
9508 addresses found. LOCATION points to the end of the SAL (for
9509 linespec locations).
9511 The array and the line spec strings are allocated on the heap, it is
9512 the caller's responsibility to free them. */
9515 parse_breakpoint_sals (const struct event_location
*location
,
9516 struct linespec_result
*canonical
)
9518 struct symtab_and_line cursal
;
9520 if (event_location_type (location
) == LINESPEC_LOCATION
)
9522 const char *address
= get_linespec_location (location
);
9524 if (address
== NULL
)
9526 /* The last displayed codepoint, if it's valid, is our default
9527 breakpoint address. */
9528 if (last_displayed_sal_is_valid ())
9530 struct linespec_sals lsal
;
9531 struct symtab_and_line sal
;
9534 init_sal (&sal
); /* Initialize to zeroes. */
9535 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9537 /* Set sal's pspace, pc, symtab, and line to the values
9538 corresponding to the last call to print_frame_info.
9539 Be sure to reinitialize LINE with NOTCURRENT == 0
9540 as the breakpoint line number is inappropriate otherwise.
9541 find_pc_line would adjust PC, re-set it back. */
9542 get_last_displayed_sal (&sal
);
9544 sal
= find_pc_line (pc
, 0);
9546 /* "break" without arguments is equivalent to "break *PC"
9547 where PC is the last displayed codepoint's address. So
9548 make sure to set sal.explicit_pc to prevent GDB from
9549 trying to expand the list of sals to include all other
9550 instances with the same symtab and line. */
9552 sal
.explicit_pc
= 1;
9554 lsal
.sals
.sals
[0] = sal
;
9555 lsal
.sals
.nelts
= 1;
9556 lsal
.canonical
= NULL
;
9558 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9562 error (_("No default breakpoint address now."));
9566 /* Force almost all breakpoints to be in terms of the
9567 current_source_symtab (which is decode_line_1's default).
9568 This should produce the results we want almost all of the
9569 time while leaving default_breakpoint_* alone.
9571 ObjC: However, don't match an Objective-C method name which
9572 may have a '+' or '-' succeeded by a '['. */
9573 cursal
= get_current_source_symtab_and_line ();
9574 if (last_displayed_sal_is_valid ())
9576 const char *address
= NULL
;
9578 if (event_location_type (location
) == LINESPEC_LOCATION
)
9579 address
= get_linespec_location (location
);
9583 && strchr ("+-", address
[0]) != NULL
9584 && address
[1] != '['))
9586 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9587 get_last_displayed_symtab (),
9588 get_last_displayed_line (),
9589 canonical
, NULL
, NULL
);
9594 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9595 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9599 /* Convert each SAL into a real PC. Verify that the PC can be
9600 inserted as a breakpoint. If it can't throw an error. */
9603 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9607 for (i
= 0; i
< sals
->nelts
; i
++)
9608 resolve_sal_pc (&sals
->sals
[i
]);
9611 /* Fast tracepoints may have restrictions on valid locations. For
9612 instance, a fast tracepoint using a jump instead of a trap will
9613 likely have to overwrite more bytes than a trap would, and so can
9614 only be placed where the instruction is longer than the jump, or a
9615 multi-instruction sequence does not have a jump into the middle of
9619 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9620 struct symtabs_and_lines
*sals
)
9623 struct symtab_and_line
*sal
;
9625 struct cleanup
*old_chain
;
9627 for (i
= 0; i
< sals
->nelts
; i
++)
9629 struct gdbarch
*sarch
;
9631 sal
= &sals
->sals
[i
];
9633 sarch
= get_sal_arch (*sal
);
9634 /* We fall back to GDBARCH if there is no architecture
9635 associated with SAL. */
9638 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9639 old_chain
= make_cleanup (xfree
, msg
);
9642 error (_("May not have a fast tracepoint at 0x%s%s"),
9643 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9645 do_cleanups (old_chain
);
9649 /* Given TOK, a string specification of condition and thread, as
9650 accepted by the 'break' command, extract the condition
9651 string and thread number and set *COND_STRING and *THREAD.
9652 PC identifies the context at which the condition should be parsed.
9653 If no condition is found, *COND_STRING is set to NULL.
9654 If no thread is found, *THREAD is set to -1. */
9657 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9658 char **cond_string
, int *thread
, int *task
,
9661 *cond_string
= NULL
;
9668 const char *end_tok
;
9670 const char *cond_start
= NULL
;
9671 const char *cond_end
= NULL
;
9673 tok
= skip_spaces_const (tok
);
9675 if ((*tok
== '"' || *tok
== ',') && rest
)
9677 *rest
= savestring (tok
, strlen (tok
));
9681 end_tok
= skip_to_space_const (tok
);
9683 toklen
= end_tok
- tok
;
9685 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9687 struct expression
*expr
;
9689 tok
= cond_start
= end_tok
+ 1;
9690 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9693 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9695 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9698 struct thread_info
*thr
;
9701 thr
= parse_thread_id (tok
, &tmptok
);
9703 error (_("Junk after thread keyword."));
9704 *thread
= thr
->global_num
;
9707 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9712 *task
= strtol (tok
, &tmptok
, 0);
9714 error (_("Junk after task keyword."));
9715 if (!valid_task_id (*task
))
9716 error (_("Unknown task %d."), *task
);
9721 *rest
= savestring (tok
, strlen (tok
));
9725 error (_("Junk at end of arguments."));
9729 /* Decode a static tracepoint marker spec. */
9731 static struct symtabs_and_lines
9732 decode_static_tracepoint_spec (const char **arg_p
)
9734 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9735 struct symtabs_and_lines sals
;
9736 struct cleanup
*old_chain
;
9737 const char *p
= &(*arg_p
)[3];
9742 p
= skip_spaces_const (p
);
9744 endp
= skip_to_space_const (p
);
9746 marker_str
= savestring (p
, endp
- p
);
9747 old_chain
= make_cleanup (xfree
, marker_str
);
9749 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9750 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9751 error (_("No known static tracepoint marker named %s"), marker_str
);
9753 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9754 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9756 for (i
= 0; i
< sals
.nelts
; i
++)
9758 struct static_tracepoint_marker
*marker
;
9760 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9762 init_sal (&sals
.sals
[i
]);
9764 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9765 sals
.sals
[i
].pc
= marker
->address
;
9767 release_static_tracepoint_marker (marker
);
9770 do_cleanups (old_chain
);
9776 /* See breakpoint.h. */
9779 create_breakpoint (struct gdbarch
*gdbarch
,
9780 const struct event_location
*location
, char *cond_string
,
9781 int thread
, char *extra_string
,
9783 int tempflag
, enum bptype type_wanted
,
9785 enum auto_boolean pending_break_support
,
9786 const struct breakpoint_ops
*ops
,
9787 int from_tty
, int enabled
, int internal
,
9790 struct linespec_result canonical
;
9791 struct cleanup
*old_chain
;
9792 struct cleanup
*bkpt_chain
= NULL
;
9795 int prev_bkpt_count
= breakpoint_count
;
9797 gdb_assert (ops
!= NULL
);
9799 /* If extra_string isn't useful, set it to NULL. */
9800 if (extra_string
!= NULL
&& *extra_string
== '\0')
9801 extra_string
= NULL
;
9803 init_linespec_result (&canonical
);
9807 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9809 CATCH (e
, RETURN_MASK_ERROR
)
9811 /* If caller is interested in rc value from parse, set
9813 if (e
.error
== NOT_FOUND_ERROR
)
9815 /* If pending breakpoint support is turned off, throw
9818 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9819 throw_exception (e
);
9821 exception_print (gdb_stderr
, e
);
9823 /* If pending breakpoint support is auto query and the user
9824 selects no, then simply return the error code. */
9825 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9826 && !nquery (_("Make %s pending on future shared library load? "),
9827 bptype_string (type_wanted
)))
9830 /* At this point, either the user was queried about setting
9831 a pending breakpoint and selected yes, or pending
9832 breakpoint behavior is on and thus a pending breakpoint
9833 is defaulted on behalf of the user. */
9837 throw_exception (e
);
9841 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9844 /* Create a chain of things that always need to be cleaned up. */
9845 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9847 /* ----------------------------- SNIP -----------------------------
9848 Anything added to the cleanup chain beyond this point is assumed
9849 to be part of a breakpoint. If the breakpoint create succeeds
9850 then the memory is not reclaimed. */
9851 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9853 /* Resolve all line numbers to PC's and verify that the addresses
9854 are ok for the target. */
9858 struct linespec_sals
*iter
;
9860 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9861 breakpoint_sals_to_pc (&iter
->sals
);
9864 /* Fast tracepoints may have additional restrictions on location. */
9865 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9868 struct linespec_sals
*iter
;
9870 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9871 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9874 /* Verify that condition can be parsed, before setting any
9875 breakpoints. Allocate a separate condition expression for each
9882 struct linespec_sals
*lsal
;
9884 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9886 /* Here we only parse 'arg' to separate condition
9887 from thread number, so parsing in context of first
9888 sal is OK. When setting the breakpoint we'll
9889 re-parse it in context of each sal. */
9891 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9892 &cond_string
, &thread
, &task
, &rest
);
9894 make_cleanup (xfree
, cond_string
);
9896 make_cleanup (xfree
, rest
);
9898 extra_string
= rest
;
9900 extra_string
= NULL
;
9904 if (type_wanted
!= bp_dprintf
9905 && extra_string
!= NULL
&& *extra_string
!= '\0')
9906 error (_("Garbage '%s' at end of location"), extra_string
);
9908 /* Create a private copy of condition string. */
9911 cond_string
= xstrdup (cond_string
);
9912 make_cleanup (xfree
, cond_string
);
9914 /* Create a private copy of any extra string. */
9917 extra_string
= xstrdup (extra_string
);
9918 make_cleanup (xfree
, extra_string
);
9922 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9923 cond_string
, extra_string
, type_wanted
,
9924 tempflag
? disp_del
: disp_donttouch
,
9925 thread
, task
, ignore_count
, ops
,
9926 from_tty
, enabled
, internal
, flags
);
9930 struct breakpoint
*b
;
9932 if (is_tracepoint_type (type_wanted
))
9934 struct tracepoint
*t
;
9936 t
= XCNEW (struct tracepoint
);
9940 b
= XNEW (struct breakpoint
);
9942 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9943 b
->location
= copy_event_location (location
);
9946 b
->cond_string
= NULL
;
9949 /* Create a private copy of condition string. */
9952 cond_string
= xstrdup (cond_string
);
9953 make_cleanup (xfree
, cond_string
);
9955 b
->cond_string
= cond_string
;
9959 /* Create a private copy of any extra string. */
9960 if (extra_string
!= NULL
)
9962 extra_string
= xstrdup (extra_string
);
9963 make_cleanup (xfree
, extra_string
);
9965 b
->extra_string
= extra_string
;
9966 b
->ignore_count
= ignore_count
;
9967 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9968 b
->condition_not_parsed
= 1;
9969 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9970 if ((type_wanted
!= bp_breakpoint
9971 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9972 b
->pspace
= current_program_space
;
9974 install_breakpoint (internal
, b
, 0);
9977 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9979 warning (_("Multiple breakpoints were set.\nUse the "
9980 "\"delete\" command to delete unwanted breakpoints."));
9981 prev_breakpoint_count
= prev_bkpt_count
;
9984 /* That's it. Discard the cleanups for data inserted into the
9986 discard_cleanups (bkpt_chain
);
9987 /* But cleanup everything else. */
9988 do_cleanups (old_chain
);
9990 /* error call may happen here - have BKPT_CHAIN already discarded. */
9991 update_global_location_list (UGLL_MAY_INSERT
);
9996 /* Set a breakpoint.
9997 ARG is a string describing breakpoint address,
9998 condition, and thread.
9999 FLAG specifies if a breakpoint is hardware on,
10000 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10001 and BP_TEMPFLAG. */
10004 break_command_1 (char *arg
, int flag
, int from_tty
)
10006 int tempflag
= flag
& BP_TEMPFLAG
;
10007 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10008 ? bp_hardware_breakpoint
10010 struct breakpoint_ops
*ops
;
10011 struct event_location
*location
;
10012 struct cleanup
*cleanup
;
10014 location
= string_to_event_location (&arg
, current_language
);
10015 cleanup
= make_cleanup_delete_event_location (location
);
10017 /* Matching breakpoints on probes. */
10018 if (location
!= NULL
10019 && event_location_type (location
) == PROBE_LOCATION
)
10020 ops
= &bkpt_probe_breakpoint_ops
;
10022 ops
= &bkpt_breakpoint_ops
;
10024 create_breakpoint (get_current_arch (),
10026 NULL
, 0, arg
, 1 /* parse arg */,
10027 tempflag
, type_wanted
,
10028 0 /* Ignore count */,
10029 pending_break_support
,
10035 do_cleanups (cleanup
);
10038 /* Helper function for break_command_1 and disassemble_command. */
10041 resolve_sal_pc (struct symtab_and_line
*sal
)
10045 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10047 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10048 error (_("No line %d in file \"%s\"."),
10049 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10052 /* If this SAL corresponds to a breakpoint inserted using a line
10053 number, then skip the function prologue if necessary. */
10054 if (sal
->explicit_line
)
10055 skip_prologue_sal (sal
);
10058 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10060 const struct blockvector
*bv
;
10061 const struct block
*b
;
10062 struct symbol
*sym
;
10064 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10065 SYMTAB_COMPUNIT (sal
->symtab
));
10068 sym
= block_linkage_function (b
);
10071 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10072 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10077 /* It really is worthwhile to have the section, so we'll
10078 just have to look harder. This case can be executed
10079 if we have line numbers but no functions (as can
10080 happen in assembly source). */
10082 struct bound_minimal_symbol msym
;
10083 struct cleanup
*old_chain
= save_current_space_and_thread ();
10085 switch_to_program_space_and_thread (sal
->pspace
);
10087 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10089 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10091 do_cleanups (old_chain
);
10098 break_command (char *arg
, int from_tty
)
10100 break_command_1 (arg
, 0, from_tty
);
10104 tbreak_command (char *arg
, int from_tty
)
10106 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10110 hbreak_command (char *arg
, int from_tty
)
10112 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10116 thbreak_command (char *arg
, int from_tty
)
10118 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10122 stop_command (char *arg
, int from_tty
)
10124 printf_filtered (_("Specify the type of breakpoint to set.\n\
10125 Usage: stop in <function | address>\n\
10126 stop at <line>\n"));
10130 stopin_command (char *arg
, int from_tty
)
10134 if (arg
== (char *) NULL
)
10136 else if (*arg
!= '*')
10138 char *argptr
= arg
;
10141 /* Look for a ':'. If this is a line number specification, then
10142 say it is bad, otherwise, it should be an address or
10143 function/method name. */
10144 while (*argptr
&& !hasColon
)
10146 hasColon
= (*argptr
== ':');
10151 badInput
= (*argptr
!= ':'); /* Not a class::method */
10153 badInput
= isdigit (*arg
); /* a simple line number */
10157 printf_filtered (_("Usage: stop in <function | address>\n"));
10159 break_command_1 (arg
, 0, from_tty
);
10163 stopat_command (char *arg
, int from_tty
)
10167 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10171 char *argptr
= arg
;
10174 /* Look for a ':'. If there is a '::' then get out, otherwise
10175 it is probably a line number. */
10176 while (*argptr
&& !hasColon
)
10178 hasColon
= (*argptr
== ':');
10183 badInput
= (*argptr
== ':'); /* we have class::method */
10185 badInput
= !isdigit (*arg
); /* not a line number */
10189 printf_filtered (_("Usage: stop at <line>\n"));
10191 break_command_1 (arg
, 0, from_tty
);
10194 /* The dynamic printf command is mostly like a regular breakpoint, but
10195 with a prewired command list consisting of a single output command,
10196 built from extra arguments supplied on the dprintf command
10200 dprintf_command (char *arg
, int from_tty
)
10202 struct event_location
*location
;
10203 struct cleanup
*cleanup
;
10205 location
= string_to_event_location (&arg
, current_language
);
10206 cleanup
= make_cleanup_delete_event_location (location
);
10208 /* If non-NULL, ARG should have been advanced past the location;
10209 the next character must be ','. */
10212 if (arg
[0] != ',' || arg
[1] == '\0')
10213 error (_("Format string required"));
10216 /* Skip the comma. */
10221 create_breakpoint (get_current_arch (),
10223 NULL
, 0, arg
, 1 /* parse arg */,
10225 0 /* Ignore count */,
10226 pending_break_support
,
10227 &dprintf_breakpoint_ops
,
10232 do_cleanups (cleanup
);
10236 agent_printf_command (char *arg
, int from_tty
)
10238 error (_("May only run agent-printf on the target"));
10241 /* Implement the "breakpoint_hit" breakpoint_ops method for
10242 ranged breakpoints. */
10245 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10246 struct address_space
*aspace
,
10248 const struct target_waitstatus
*ws
)
10250 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10251 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10254 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10255 bl
->length
, aspace
, bp_addr
);
10258 /* Implement the "resources_needed" breakpoint_ops method for
10259 ranged breakpoints. */
10262 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10264 return target_ranged_break_num_registers ();
10267 /* Implement the "print_it" breakpoint_ops method for
10268 ranged breakpoints. */
10270 static enum print_stop_action
10271 print_it_ranged_breakpoint (bpstat bs
)
10273 struct breakpoint
*b
= bs
->breakpoint_at
;
10274 struct bp_location
*bl
= b
->loc
;
10275 struct ui_out
*uiout
= current_uiout
;
10277 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10279 /* Ranged breakpoints have only one location. */
10280 gdb_assert (bl
&& bl
->next
== NULL
);
10282 annotate_breakpoint (b
->number
);
10284 maybe_print_thread_hit_breakpoint (uiout
);
10286 if (b
->disposition
== disp_del
)
10287 ui_out_text (uiout
, "Temporary ranged breakpoint ");
10289 ui_out_text (uiout
, "Ranged breakpoint ");
10290 if (ui_out_is_mi_like_p (uiout
))
10292 ui_out_field_string (uiout
, "reason",
10293 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10294 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10296 ui_out_field_int (uiout
, "bkptno", b
->number
);
10297 ui_out_text (uiout
, ", ");
10299 return PRINT_SRC_AND_LOC
;
10302 /* Implement the "print_one" breakpoint_ops method for
10303 ranged breakpoints. */
10306 print_one_ranged_breakpoint (struct breakpoint
*b
,
10307 struct bp_location
**last_loc
)
10309 struct bp_location
*bl
= b
->loc
;
10310 struct value_print_options opts
;
10311 struct ui_out
*uiout
= current_uiout
;
10313 /* Ranged breakpoints have only one location. */
10314 gdb_assert (bl
&& bl
->next
== NULL
);
10316 get_user_print_options (&opts
);
10318 if (opts
.addressprint
)
10319 /* We don't print the address range here, it will be printed later
10320 by print_one_detail_ranged_breakpoint. */
10321 ui_out_field_skip (uiout
, "addr");
10322 annotate_field (5);
10323 print_breakpoint_location (b
, bl
);
10327 /* Implement the "print_one_detail" breakpoint_ops method for
10328 ranged breakpoints. */
10331 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10332 struct ui_out
*uiout
)
10334 CORE_ADDR address_start
, address_end
;
10335 struct bp_location
*bl
= b
->loc
;
10336 struct ui_file
*stb
= mem_fileopen ();
10337 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10341 address_start
= bl
->address
;
10342 address_end
= address_start
+ bl
->length
- 1;
10344 ui_out_text (uiout
, "\taddress range: ");
10345 fprintf_unfiltered (stb
, "[%s, %s]",
10346 print_core_address (bl
->gdbarch
, address_start
),
10347 print_core_address (bl
->gdbarch
, address_end
));
10348 ui_out_field_stream (uiout
, "addr", stb
);
10349 ui_out_text (uiout
, "\n");
10351 do_cleanups (cleanup
);
10354 /* Implement the "print_mention" breakpoint_ops method for
10355 ranged breakpoints. */
10358 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10360 struct bp_location
*bl
= b
->loc
;
10361 struct ui_out
*uiout
= current_uiout
;
10364 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10366 if (ui_out_is_mi_like_p (uiout
))
10369 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10370 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10371 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10374 /* Implement the "print_recreate" breakpoint_ops method for
10375 ranged breakpoints. */
10378 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10380 fprintf_unfiltered (fp
, "break-range %s, %s",
10381 event_location_to_string (b
->location
),
10382 event_location_to_string (b
->location_range_end
));
10383 print_recreate_thread (b
, fp
);
10386 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10388 static struct breakpoint_ops ranged_breakpoint_ops
;
10390 /* Find the address where the end of the breakpoint range should be
10391 placed, given the SAL of the end of the range. This is so that if
10392 the user provides a line number, the end of the range is set to the
10393 last instruction of the given line. */
10396 find_breakpoint_range_end (struct symtab_and_line sal
)
10400 /* If the user provided a PC value, use it. Otherwise,
10401 find the address of the end of the given location. */
10402 if (sal
.explicit_pc
)
10409 ret
= find_line_pc_range (sal
, &start
, &end
);
10411 error (_("Could not find location of the end of the range."));
10413 /* find_line_pc_range returns the start of the next line. */
10420 /* Implement the "break-range" CLI command. */
10423 break_range_command (char *arg
, int from_tty
)
10425 char *arg_start
, *addr_string_start
;
10426 struct linespec_result canonical_start
, canonical_end
;
10427 int bp_count
, can_use_bp
, length
;
10429 struct breakpoint
*b
;
10430 struct symtab_and_line sal_start
, sal_end
;
10431 struct cleanup
*cleanup_bkpt
;
10432 struct linespec_sals
*lsal_start
, *lsal_end
;
10433 struct event_location
*start_location
, *end_location
;
10435 /* We don't support software ranged breakpoints. */
10436 if (target_ranged_break_num_registers () < 0)
10437 error (_("This target does not support hardware ranged breakpoints."));
10439 bp_count
= hw_breakpoint_used_count ();
10440 bp_count
+= target_ranged_break_num_registers ();
10441 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10443 if (can_use_bp
< 0)
10444 error (_("Hardware breakpoints used exceeds limit."));
10446 arg
= skip_spaces (arg
);
10447 if (arg
== NULL
|| arg
[0] == '\0')
10448 error(_("No address range specified."));
10450 init_linespec_result (&canonical_start
);
10453 start_location
= string_to_event_location (&arg
, current_language
);
10454 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10455 parse_breakpoint_sals (start_location
, &canonical_start
);
10456 make_cleanup_destroy_linespec_result (&canonical_start
);
10459 error (_("Too few arguments."));
10460 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10461 error (_("Could not find location of the beginning of the range."));
10463 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10465 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10466 || lsal_start
->sals
.nelts
!= 1)
10467 error (_("Cannot create a ranged breakpoint with multiple locations."));
10469 sal_start
= lsal_start
->sals
.sals
[0];
10470 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10471 make_cleanup (xfree
, addr_string_start
);
10473 arg
++; /* Skip the comma. */
10474 arg
= skip_spaces (arg
);
10476 /* Parse the end location. */
10478 init_linespec_result (&canonical_end
);
10481 /* We call decode_line_full directly here instead of using
10482 parse_breakpoint_sals because we need to specify the start location's
10483 symtab and line as the default symtab and line for the end of the
10484 range. This makes it possible to have ranges like "foo.c:27, +14",
10485 where +14 means 14 lines from the start location. */
10486 end_location
= string_to_event_location (&arg
, current_language
);
10487 make_cleanup_delete_event_location (end_location
);
10488 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
10489 sal_start
.symtab
, sal_start
.line
,
10490 &canonical_end
, NULL
, NULL
);
10492 make_cleanup_destroy_linespec_result (&canonical_end
);
10494 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10495 error (_("Could not find location of the end of the range."));
10497 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10498 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10499 || lsal_end
->sals
.nelts
!= 1)
10500 error (_("Cannot create a ranged breakpoint with multiple locations."));
10502 sal_end
= lsal_end
->sals
.sals
[0];
10504 end
= find_breakpoint_range_end (sal_end
);
10505 if (sal_start
.pc
> end
)
10506 error (_("Invalid address range, end precedes start."));
10508 length
= end
- sal_start
.pc
+ 1;
10510 /* Length overflowed. */
10511 error (_("Address range too large."));
10512 else if (length
== 1)
10514 /* This range is simple enough to be handled by
10515 the `hbreak' command. */
10516 hbreak_command (addr_string_start
, 1);
10518 do_cleanups (cleanup_bkpt
);
10523 /* Now set up the breakpoint. */
10524 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10525 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10526 set_breakpoint_count (breakpoint_count
+ 1);
10527 b
->number
= breakpoint_count
;
10528 b
->disposition
= disp_donttouch
;
10529 b
->location
= copy_event_location (start_location
);
10530 b
->location_range_end
= copy_event_location (end_location
);
10531 b
->loc
->length
= length
;
10533 do_cleanups (cleanup_bkpt
);
10536 observer_notify_breakpoint_created (b
);
10537 update_global_location_list (UGLL_MAY_INSERT
);
10540 /* Return non-zero if EXP is verified as constant. Returned zero
10541 means EXP is variable. Also the constant detection may fail for
10542 some constant expressions and in such case still falsely return
10546 watchpoint_exp_is_const (const struct expression
*exp
)
10548 int i
= exp
->nelts
;
10554 /* We are only interested in the descriptor of each element. */
10555 operator_length (exp
, i
, &oplenp
, &argsp
);
10558 switch (exp
->elts
[i
].opcode
)
10568 case BINOP_LOGICAL_AND
:
10569 case BINOP_LOGICAL_OR
:
10570 case BINOP_BITWISE_AND
:
10571 case BINOP_BITWISE_IOR
:
10572 case BINOP_BITWISE_XOR
:
10574 case BINOP_NOTEQUAL
:
10601 case OP_OBJC_NSSTRING
:
10604 case UNOP_LOGICAL_NOT
:
10605 case UNOP_COMPLEMENT
:
10610 case UNOP_CAST_TYPE
:
10611 case UNOP_REINTERPRET_CAST
:
10612 case UNOP_DYNAMIC_CAST
:
10613 /* Unary, binary and ternary operators: We have to check
10614 their operands. If they are constant, then so is the
10615 result of that operation. For instance, if A and B are
10616 determined to be constants, then so is "A + B".
10618 UNOP_IND is one exception to the rule above, because the
10619 value of *ADDR is not necessarily a constant, even when
10624 /* Check whether the associated symbol is a constant.
10626 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10627 possible that a buggy compiler could mark a variable as
10628 constant even when it is not, and TYPE_CONST would return
10629 true in this case, while SYMBOL_CLASS wouldn't.
10631 We also have to check for function symbols because they
10632 are always constant. */
10634 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10636 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10637 && SYMBOL_CLASS (s
) != LOC_CONST
10638 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10643 /* The default action is to return 0 because we are using
10644 the optimistic approach here: If we don't know something,
10645 then it is not a constant. */
10654 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10657 dtor_watchpoint (struct breakpoint
*self
)
10659 struct watchpoint
*w
= (struct watchpoint
*) self
;
10661 xfree (w
->cond_exp
);
10663 xfree (w
->exp_string
);
10664 xfree (w
->exp_string_reparse
);
10665 value_free (w
->val
);
10667 base_breakpoint_ops
.dtor (self
);
10670 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10673 re_set_watchpoint (struct breakpoint
*b
)
10675 struct watchpoint
*w
= (struct watchpoint
*) b
;
10677 /* Watchpoint can be either on expression using entirely global
10678 variables, or it can be on local variables.
10680 Watchpoints of the first kind are never auto-deleted, and even
10681 persist across program restarts. Since they can use variables
10682 from shared libraries, we need to reparse expression as libraries
10683 are loaded and unloaded.
10685 Watchpoints on local variables can also change meaning as result
10686 of solib event. For example, if a watchpoint uses both a local
10687 and a global variables in expression, it's a local watchpoint,
10688 but unloading of a shared library will make the expression
10689 invalid. This is not a very common use case, but we still
10690 re-evaluate expression, to avoid surprises to the user.
10692 Note that for local watchpoints, we re-evaluate it only if
10693 watchpoints frame id is still valid. If it's not, it means the
10694 watchpoint is out of scope and will be deleted soon. In fact,
10695 I'm not sure we'll ever be called in this case.
10697 If a local watchpoint's frame id is still valid, then
10698 w->exp_valid_block is likewise valid, and we can safely use it.
10700 Don't do anything about disabled watchpoints, since they will be
10701 reevaluated again when enabled. */
10702 update_watchpoint (w
, 1 /* reparse */);
10705 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10708 insert_watchpoint (struct bp_location
*bl
)
10710 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10711 int length
= w
->exact
? 1 : bl
->length
;
10713 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10717 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10720 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10722 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10723 int length
= w
->exact
? 1 : bl
->length
;
10725 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10730 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10731 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10732 const struct target_waitstatus
*ws
)
10734 struct breakpoint
*b
= bl
->owner
;
10735 struct watchpoint
*w
= (struct watchpoint
*) b
;
10737 /* Continuable hardware watchpoints are treated as non-existent if the
10738 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10739 some data address). Otherwise gdb won't stop on a break instruction
10740 in the code (not from a breakpoint) when a hardware watchpoint has
10741 been defined. Also skip watchpoints which we know did not trigger
10742 (did not match the data address). */
10743 if (is_hardware_watchpoint (b
)
10744 && w
->watchpoint_triggered
== watch_triggered_no
)
10751 check_status_watchpoint (bpstat bs
)
10753 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10755 bpstat_check_watchpoint (bs
);
10758 /* Implement the "resources_needed" breakpoint_ops method for
10759 hardware watchpoints. */
10762 resources_needed_watchpoint (const struct bp_location
*bl
)
10764 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10765 int length
= w
->exact
? 1 : bl
->length
;
10767 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10770 /* Implement the "works_in_software_mode" breakpoint_ops method for
10771 hardware watchpoints. */
10774 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10776 /* Read and access watchpoints only work with hardware support. */
10777 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10780 static enum print_stop_action
10781 print_it_watchpoint (bpstat bs
)
10783 struct cleanup
*old_chain
;
10784 struct breakpoint
*b
;
10785 struct ui_file
*stb
;
10786 enum print_stop_action result
;
10787 struct watchpoint
*w
;
10788 struct ui_out
*uiout
= current_uiout
;
10790 gdb_assert (bs
->bp_location_at
!= NULL
);
10792 b
= bs
->breakpoint_at
;
10793 w
= (struct watchpoint
*) b
;
10795 stb
= mem_fileopen ();
10796 old_chain
= make_cleanup_ui_file_delete (stb
);
10798 annotate_watchpoint (b
->number
);
10799 maybe_print_thread_hit_breakpoint (uiout
);
10803 case bp_watchpoint
:
10804 case bp_hardware_watchpoint
:
10805 if (ui_out_is_mi_like_p (uiout
))
10806 ui_out_field_string
10808 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10810 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10811 ui_out_text (uiout
, "\nOld value = ");
10812 watchpoint_value_print (bs
->old_val
, stb
);
10813 ui_out_field_stream (uiout
, "old", stb
);
10814 ui_out_text (uiout
, "\nNew value = ");
10815 watchpoint_value_print (w
->val
, stb
);
10816 ui_out_field_stream (uiout
, "new", stb
);
10817 ui_out_text (uiout
, "\n");
10818 /* More than one watchpoint may have been triggered. */
10819 result
= PRINT_UNKNOWN
;
10822 case bp_read_watchpoint
:
10823 if (ui_out_is_mi_like_p (uiout
))
10824 ui_out_field_string
10826 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10828 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10829 ui_out_text (uiout
, "\nValue = ");
10830 watchpoint_value_print (w
->val
, stb
);
10831 ui_out_field_stream (uiout
, "value", stb
);
10832 ui_out_text (uiout
, "\n");
10833 result
= PRINT_UNKNOWN
;
10836 case bp_access_watchpoint
:
10837 if (bs
->old_val
!= NULL
)
10839 if (ui_out_is_mi_like_p (uiout
))
10840 ui_out_field_string
10842 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10844 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10845 ui_out_text (uiout
, "\nOld value = ");
10846 watchpoint_value_print (bs
->old_val
, stb
);
10847 ui_out_field_stream (uiout
, "old", stb
);
10848 ui_out_text (uiout
, "\nNew value = ");
10853 if (ui_out_is_mi_like_p (uiout
))
10854 ui_out_field_string
10856 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10857 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10858 ui_out_text (uiout
, "\nValue = ");
10860 watchpoint_value_print (w
->val
, stb
);
10861 ui_out_field_stream (uiout
, "new", stb
);
10862 ui_out_text (uiout
, "\n");
10863 result
= PRINT_UNKNOWN
;
10866 result
= PRINT_UNKNOWN
;
10869 do_cleanups (old_chain
);
10873 /* Implement the "print_mention" breakpoint_ops method for hardware
10877 print_mention_watchpoint (struct breakpoint
*b
)
10879 struct cleanup
*ui_out_chain
;
10880 struct watchpoint
*w
= (struct watchpoint
*) b
;
10881 struct ui_out
*uiout
= current_uiout
;
10885 case bp_watchpoint
:
10886 ui_out_text (uiout
, "Watchpoint ");
10887 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10889 case bp_hardware_watchpoint
:
10890 ui_out_text (uiout
, "Hardware watchpoint ");
10891 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10893 case bp_read_watchpoint
:
10894 ui_out_text (uiout
, "Hardware read watchpoint ");
10895 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10897 case bp_access_watchpoint
:
10898 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10899 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10902 internal_error (__FILE__
, __LINE__
,
10903 _("Invalid hardware watchpoint type."));
10906 ui_out_field_int (uiout
, "number", b
->number
);
10907 ui_out_text (uiout
, ": ");
10908 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10909 do_cleanups (ui_out_chain
);
10912 /* Implement the "print_recreate" breakpoint_ops method for
10916 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10918 struct watchpoint
*w
= (struct watchpoint
*) b
;
10922 case bp_watchpoint
:
10923 case bp_hardware_watchpoint
:
10924 fprintf_unfiltered (fp
, "watch");
10926 case bp_read_watchpoint
:
10927 fprintf_unfiltered (fp
, "rwatch");
10929 case bp_access_watchpoint
:
10930 fprintf_unfiltered (fp
, "awatch");
10933 internal_error (__FILE__
, __LINE__
,
10934 _("Invalid watchpoint type."));
10937 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10938 print_recreate_thread (b
, fp
);
10941 /* Implement the "explains_signal" breakpoint_ops method for
10945 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10947 /* A software watchpoint cannot cause a signal other than
10948 GDB_SIGNAL_TRAP. */
10949 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10955 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10957 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10959 /* Implement the "insert" breakpoint_ops method for
10960 masked hardware watchpoints. */
10963 insert_masked_watchpoint (struct bp_location
*bl
)
10965 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10967 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10968 bl
->watchpoint_type
);
10971 /* Implement the "remove" breakpoint_ops method for
10972 masked hardware watchpoints. */
10975 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10977 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10979 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10980 bl
->watchpoint_type
);
10983 /* Implement the "resources_needed" breakpoint_ops method for
10984 masked hardware watchpoints. */
10987 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10989 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10991 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10994 /* Implement the "works_in_software_mode" breakpoint_ops method for
10995 masked hardware watchpoints. */
10998 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11003 /* Implement the "print_it" breakpoint_ops method for
11004 masked hardware watchpoints. */
11006 static enum print_stop_action
11007 print_it_masked_watchpoint (bpstat bs
)
11009 struct breakpoint
*b
= bs
->breakpoint_at
;
11010 struct ui_out
*uiout
= current_uiout
;
11012 /* Masked watchpoints have only one location. */
11013 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11015 annotate_watchpoint (b
->number
);
11016 maybe_print_thread_hit_breakpoint (uiout
);
11020 case bp_hardware_watchpoint
:
11021 if (ui_out_is_mi_like_p (uiout
))
11022 ui_out_field_string
11024 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11027 case bp_read_watchpoint
:
11028 if (ui_out_is_mi_like_p (uiout
))
11029 ui_out_field_string
11031 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11034 case bp_access_watchpoint
:
11035 if (ui_out_is_mi_like_p (uiout
))
11036 ui_out_field_string
11038 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11041 internal_error (__FILE__
, __LINE__
,
11042 _("Invalid hardware watchpoint type."));
11046 ui_out_text (uiout
, _("\n\
11047 Check the underlying instruction at PC for the memory\n\
11048 address and value which triggered this watchpoint.\n"));
11049 ui_out_text (uiout
, "\n");
11051 /* More than one watchpoint may have been triggered. */
11052 return PRINT_UNKNOWN
;
11055 /* Implement the "print_one_detail" breakpoint_ops method for
11056 masked hardware watchpoints. */
11059 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11060 struct ui_out
*uiout
)
11062 struct watchpoint
*w
= (struct watchpoint
*) b
;
11064 /* Masked watchpoints have only one location. */
11065 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11067 ui_out_text (uiout
, "\tmask ");
11068 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11069 ui_out_text (uiout
, "\n");
11072 /* Implement the "print_mention" breakpoint_ops method for
11073 masked hardware watchpoints. */
11076 print_mention_masked_watchpoint (struct breakpoint
*b
)
11078 struct watchpoint
*w
= (struct watchpoint
*) b
;
11079 struct ui_out
*uiout
= current_uiout
;
11080 struct cleanup
*ui_out_chain
;
11084 case bp_hardware_watchpoint
:
11085 ui_out_text (uiout
, "Masked hardware watchpoint ");
11086 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11088 case bp_read_watchpoint
:
11089 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11090 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11092 case bp_access_watchpoint
:
11093 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11094 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11097 internal_error (__FILE__
, __LINE__
,
11098 _("Invalid hardware watchpoint type."));
11101 ui_out_field_int (uiout
, "number", b
->number
);
11102 ui_out_text (uiout
, ": ");
11103 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11104 do_cleanups (ui_out_chain
);
11107 /* Implement the "print_recreate" breakpoint_ops method for
11108 masked hardware watchpoints. */
11111 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11113 struct watchpoint
*w
= (struct watchpoint
*) b
;
11118 case bp_hardware_watchpoint
:
11119 fprintf_unfiltered (fp
, "watch");
11121 case bp_read_watchpoint
:
11122 fprintf_unfiltered (fp
, "rwatch");
11124 case bp_access_watchpoint
:
11125 fprintf_unfiltered (fp
, "awatch");
11128 internal_error (__FILE__
, __LINE__
,
11129 _("Invalid hardware watchpoint type."));
11132 sprintf_vma (tmp
, w
->hw_wp_mask
);
11133 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11134 print_recreate_thread (b
, fp
);
11137 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11139 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11141 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11144 is_masked_watchpoint (const struct breakpoint
*b
)
11146 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11149 /* accessflag: hw_write: watch write,
11150 hw_read: watch read,
11151 hw_access: watch access (read or write) */
11153 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11154 int just_location
, int internal
)
11156 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11157 struct expression
*exp
;
11158 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11159 struct value
*val
, *mark
, *result
;
11160 int saved_bitpos
= 0, saved_bitsize
= 0;
11161 struct frame_info
*frame
;
11162 const char *exp_start
= NULL
;
11163 const char *exp_end
= NULL
;
11164 const char *tok
, *end_tok
;
11166 const char *cond_start
= NULL
;
11167 const char *cond_end
= NULL
;
11168 enum bptype bp_type
;
11171 /* Flag to indicate whether we are going to use masks for
11172 the hardware watchpoint. */
11174 CORE_ADDR mask
= 0;
11175 struct watchpoint
*w
;
11177 struct cleanup
*back_to
;
11179 /* Make sure that we actually have parameters to parse. */
11180 if (arg
!= NULL
&& arg
[0] != '\0')
11182 const char *value_start
;
11184 exp_end
= arg
+ strlen (arg
);
11186 /* Look for "parameter value" pairs at the end
11187 of the arguments string. */
11188 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11190 /* Skip whitespace at the end of the argument list. */
11191 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11194 /* Find the beginning of the last token.
11195 This is the value of the parameter. */
11196 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11198 value_start
= tok
+ 1;
11200 /* Skip whitespace. */
11201 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11206 /* Find the beginning of the second to last token.
11207 This is the parameter itself. */
11208 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11211 toklen
= end_tok
- tok
+ 1;
11213 if (toklen
== 6 && startswith (tok
, "thread"))
11215 struct thread_info
*thr
;
11216 /* At this point we've found a "thread" token, which means
11217 the user is trying to set a watchpoint that triggers
11218 only in a specific thread. */
11222 error(_("You can specify only one thread."));
11224 /* Extract the thread ID from the next token. */
11225 thr
= parse_thread_id (value_start
, &endp
);
11227 /* Check if the user provided a valid thread ID. */
11228 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11229 invalid_thread_id_error (value_start
);
11231 thread
= thr
->global_num
;
11233 else if (toklen
== 4 && startswith (tok
, "mask"))
11235 /* We've found a "mask" token, which means the user wants to
11236 create a hardware watchpoint that is going to have the mask
11238 struct value
*mask_value
, *mark
;
11241 error(_("You can specify only one mask."));
11243 use_mask
= just_location
= 1;
11245 mark
= value_mark ();
11246 mask_value
= parse_to_comma_and_eval (&value_start
);
11247 mask
= value_as_address (mask_value
);
11248 value_free_to_mark (mark
);
11251 /* We didn't recognize what we found. We should stop here. */
11254 /* Truncate the string and get rid of the "parameter value" pair before
11255 the arguments string is parsed by the parse_exp_1 function. */
11262 /* Parse the rest of the arguments. From here on out, everything
11263 is in terms of a newly allocated string instead of the original
11265 innermost_block
= NULL
;
11266 expression
= savestring (arg
, exp_end
- arg
);
11267 back_to
= make_cleanup (xfree
, expression
);
11268 exp_start
= arg
= expression
;
11269 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11271 /* Remove trailing whitespace from the expression before saving it.
11272 This makes the eventual display of the expression string a bit
11274 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11277 /* Checking if the expression is not constant. */
11278 if (watchpoint_exp_is_const (exp
))
11282 len
= exp_end
- exp_start
;
11283 while (len
> 0 && isspace (exp_start
[len
- 1]))
11285 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11288 exp_valid_block
= innermost_block
;
11289 mark
= value_mark ();
11290 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11292 if (val
!= NULL
&& just_location
)
11294 saved_bitpos
= value_bitpos (val
);
11295 saved_bitsize
= value_bitsize (val
);
11302 exp_valid_block
= NULL
;
11303 val
= value_addr (result
);
11304 release_value (val
);
11305 value_free_to_mark (mark
);
11309 ret
= target_masked_watch_num_registers (value_as_address (val
),
11312 error (_("This target does not support masked watchpoints."));
11313 else if (ret
== -2)
11314 error (_("Invalid mask or memory region."));
11317 else if (val
!= NULL
)
11318 release_value (val
);
11320 tok
= skip_spaces_const (arg
);
11321 end_tok
= skip_to_space_const (tok
);
11323 toklen
= end_tok
- tok
;
11324 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11326 struct expression
*cond
;
11328 innermost_block
= NULL
;
11329 tok
= cond_start
= end_tok
+ 1;
11330 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11332 /* The watchpoint expression may not be local, but the condition
11333 may still be. E.g.: `watch global if local > 0'. */
11334 cond_exp_valid_block
= innermost_block
;
11340 error (_("Junk at end of command."));
11342 frame
= block_innermost_frame (exp_valid_block
);
11344 /* If the expression is "local", then set up a "watchpoint scope"
11345 breakpoint at the point where we've left the scope of the watchpoint
11346 expression. Create the scope breakpoint before the watchpoint, so
11347 that we will encounter it first in bpstat_stop_status. */
11348 if (exp_valid_block
&& frame
)
11350 if (frame_id_p (frame_unwind_caller_id (frame
)))
11353 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11354 frame_unwind_caller_pc (frame
),
11355 bp_watchpoint_scope
,
11356 &momentary_breakpoint_ops
);
11358 scope_breakpoint
->enable_state
= bp_enabled
;
11360 /* Automatically delete the breakpoint when it hits. */
11361 scope_breakpoint
->disposition
= disp_del
;
11363 /* Only break in the proper frame (help with recursion). */
11364 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11366 /* Set the address at which we will stop. */
11367 scope_breakpoint
->loc
->gdbarch
11368 = frame_unwind_caller_arch (frame
);
11369 scope_breakpoint
->loc
->requested_address
11370 = frame_unwind_caller_pc (frame
);
11371 scope_breakpoint
->loc
->address
11372 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11373 scope_breakpoint
->loc
->requested_address
,
11374 scope_breakpoint
->type
);
11378 /* Now set up the breakpoint. We create all watchpoints as hardware
11379 watchpoints here even if hardware watchpoints are turned off, a call
11380 to update_watchpoint later in this function will cause the type to
11381 drop back to bp_watchpoint (software watchpoint) if required. */
11383 if (accessflag
== hw_read
)
11384 bp_type
= bp_read_watchpoint
;
11385 else if (accessflag
== hw_access
)
11386 bp_type
= bp_access_watchpoint
;
11388 bp_type
= bp_hardware_watchpoint
;
11390 w
= XCNEW (struct watchpoint
);
11393 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11394 &masked_watchpoint_breakpoint_ops
);
11396 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11397 &watchpoint_breakpoint_ops
);
11398 b
->thread
= thread
;
11399 b
->disposition
= disp_donttouch
;
11400 b
->pspace
= current_program_space
;
11402 w
->exp_valid_block
= exp_valid_block
;
11403 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11406 struct type
*t
= value_type (val
);
11407 CORE_ADDR addr
= value_as_address (val
);
11410 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11411 name
= type_to_string (t
);
11413 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11414 core_addr_to_string (addr
));
11417 w
->exp_string
= xstrprintf ("-location %.*s",
11418 (int) (exp_end
- exp_start
), exp_start
);
11420 /* The above expression is in C. */
11421 b
->language
= language_c
;
11424 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11428 w
->hw_wp_mask
= mask
;
11433 w
->val_bitpos
= saved_bitpos
;
11434 w
->val_bitsize
= saved_bitsize
;
11439 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11441 b
->cond_string
= 0;
11445 w
->watchpoint_frame
= get_frame_id (frame
);
11446 w
->watchpoint_thread
= inferior_ptid
;
11450 w
->watchpoint_frame
= null_frame_id
;
11451 w
->watchpoint_thread
= null_ptid
;
11454 if (scope_breakpoint
!= NULL
)
11456 /* The scope breakpoint is related to the watchpoint. We will
11457 need to act on them together. */
11458 b
->related_breakpoint
= scope_breakpoint
;
11459 scope_breakpoint
->related_breakpoint
= b
;
11462 if (!just_location
)
11463 value_free_to_mark (mark
);
11467 /* Finally update the new watchpoint. This creates the locations
11468 that should be inserted. */
11469 update_watchpoint (w
, 1);
11471 CATCH (e
, RETURN_MASK_ALL
)
11473 delete_breakpoint (b
);
11474 throw_exception (e
);
11478 install_breakpoint (internal
, b
, 1);
11479 do_cleanups (back_to
);
11482 /* Return count of debug registers needed to watch the given expression.
11483 If the watchpoint cannot be handled in hardware return zero. */
11486 can_use_hardware_watchpoint (struct value
*v
)
11488 int found_memory_cnt
= 0;
11489 struct value
*head
= v
;
11491 /* Did the user specifically forbid us to use hardware watchpoints? */
11492 if (!can_use_hw_watchpoints
)
11495 /* Make sure that the value of the expression depends only upon
11496 memory contents, and values computed from them within GDB. If we
11497 find any register references or function calls, we can't use a
11498 hardware watchpoint.
11500 The idea here is that evaluating an expression generates a series
11501 of values, one holding the value of every subexpression. (The
11502 expression a*b+c has five subexpressions: a, b, a*b, c, and
11503 a*b+c.) GDB's values hold almost enough information to establish
11504 the criteria given above --- they identify memory lvalues,
11505 register lvalues, computed values, etcetera. So we can evaluate
11506 the expression, and then scan the chain of values that leaves
11507 behind to decide whether we can detect any possible change to the
11508 expression's final value using only hardware watchpoints.
11510 However, I don't think that the values returned by inferior
11511 function calls are special in any way. So this function may not
11512 notice that an expression involving an inferior function call
11513 can't be watched with hardware watchpoints. FIXME. */
11514 for (; v
; v
= value_next (v
))
11516 if (VALUE_LVAL (v
) == lval_memory
)
11518 if (v
!= head
&& value_lazy (v
))
11519 /* A lazy memory lvalue in the chain is one that GDB never
11520 needed to fetch; we either just used its address (e.g.,
11521 `a' in `a.b') or we never needed it at all (e.g., `a'
11522 in `a,b'). This doesn't apply to HEAD; if that is
11523 lazy then it was not readable, but watch it anyway. */
11527 /* Ahh, memory we actually used! Check if we can cover
11528 it with hardware watchpoints. */
11529 struct type
*vtype
= check_typedef (value_type (v
));
11531 /* We only watch structs and arrays if user asked for it
11532 explicitly, never if they just happen to appear in a
11533 middle of some value chain. */
11535 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11536 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11538 CORE_ADDR vaddr
= value_address (v
);
11542 len
= (target_exact_watchpoints
11543 && is_scalar_type_recursive (vtype
))?
11544 1 : TYPE_LENGTH (value_type (v
));
11546 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11550 found_memory_cnt
+= num_regs
;
11554 else if (VALUE_LVAL (v
) != not_lval
11555 && deprecated_value_modifiable (v
) == 0)
11556 return 0; /* These are values from the history (e.g., $1). */
11557 else if (VALUE_LVAL (v
) == lval_register
)
11558 return 0; /* Cannot watch a register with a HW watchpoint. */
11561 /* The expression itself looks suitable for using a hardware
11562 watchpoint, but give the target machine a chance to reject it. */
11563 return found_memory_cnt
;
11567 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11569 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11572 /* A helper function that looks for the "-location" argument and then
11573 calls watch_command_1. */
11576 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11578 int just_location
= 0;
11581 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11582 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11584 arg
= skip_spaces (arg
);
11588 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11592 watch_command (char *arg
, int from_tty
)
11594 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11598 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11600 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11604 rwatch_command (char *arg
, int from_tty
)
11606 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11610 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11612 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11616 awatch_command (char *arg
, int from_tty
)
11618 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11622 /* Data for the FSM that manages the until(location)/advance commands
11623 in infcmd.c. Here because it uses the mechanisms of
11626 struct until_break_fsm
11628 /* The base class. */
11629 struct thread_fsm thread_fsm
;
11631 /* The thread that as current when the command was executed. */
11634 /* The breakpoint set at the destination location. */
11635 struct breakpoint
*location_breakpoint
;
11637 /* Breakpoint set at the return address in the caller frame. May be
11639 struct breakpoint
*caller_breakpoint
;
11642 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11643 struct thread_info
*thread
);
11644 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11645 struct thread_info
*thread
);
11646 static enum async_reply_reason
11647 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11649 /* until_break_fsm's vtable. */
11651 static struct thread_fsm_ops until_break_fsm_ops
=
11654 until_break_fsm_clean_up
,
11655 until_break_fsm_should_stop
,
11656 NULL
, /* return_value */
11657 until_break_fsm_async_reply_reason
,
11660 /* Allocate a new until_break_command_fsm. */
11662 static struct until_break_fsm
*
11663 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11664 struct breakpoint
*location_breakpoint
,
11665 struct breakpoint
*caller_breakpoint
)
11667 struct until_break_fsm
*sm
;
11669 sm
= XCNEW (struct until_break_fsm
);
11670 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11672 sm
->thread
= thread
;
11673 sm
->location_breakpoint
= location_breakpoint
;
11674 sm
->caller_breakpoint
= caller_breakpoint
;
11679 /* Implementation of the 'should_stop' FSM method for the
11680 until(location)/advance commands. */
11683 until_break_fsm_should_stop (struct thread_fsm
*self
,
11684 struct thread_info
*tp
)
11686 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11688 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11689 sm
->location_breakpoint
) != NULL
11690 || (sm
->caller_breakpoint
!= NULL
11691 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11692 sm
->caller_breakpoint
) != NULL
))
11693 thread_fsm_set_finished (self
);
11698 /* Implementation of the 'clean_up' FSM method for the
11699 until(location)/advance commands. */
11702 until_break_fsm_clean_up (struct thread_fsm
*self
,
11703 struct thread_info
*thread
)
11705 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11707 /* Clean up our temporary breakpoints. */
11708 if (sm
->location_breakpoint
!= NULL
)
11710 delete_breakpoint (sm
->location_breakpoint
);
11711 sm
->location_breakpoint
= NULL
;
11713 if (sm
->caller_breakpoint
!= NULL
)
11715 delete_breakpoint (sm
->caller_breakpoint
);
11716 sm
->caller_breakpoint
= NULL
;
11718 delete_longjmp_breakpoint (sm
->thread
);
11721 /* Implementation of the 'async_reply_reason' FSM method for the
11722 until(location)/advance commands. */
11724 static enum async_reply_reason
11725 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11727 return EXEC_ASYNC_LOCATION_REACHED
;
11731 until_break_command (char *arg
, int from_tty
, int anywhere
)
11733 struct symtabs_and_lines sals
;
11734 struct symtab_and_line sal
;
11735 struct frame_info
*frame
;
11736 struct gdbarch
*frame_gdbarch
;
11737 struct frame_id stack_frame_id
;
11738 struct frame_id caller_frame_id
;
11739 struct breakpoint
*location_breakpoint
;
11740 struct breakpoint
*caller_breakpoint
= NULL
;
11741 struct cleanup
*old_chain
, *cleanup
;
11743 struct thread_info
*tp
;
11744 struct event_location
*location
;
11745 struct until_break_fsm
*sm
;
11747 clear_proceed_status (0);
11749 /* Set a breakpoint where the user wants it and at return from
11752 location
= string_to_event_location (&arg
, current_language
);
11753 cleanup
= make_cleanup_delete_event_location (location
);
11755 if (last_displayed_sal_is_valid ())
11756 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
11757 get_last_displayed_symtab (),
11758 get_last_displayed_line ());
11760 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11761 NULL
, (struct symtab
*) NULL
, 0);
11763 if (sals
.nelts
!= 1)
11764 error (_("Couldn't get information on specified line."));
11766 sal
= sals
.sals
[0];
11767 xfree (sals
.sals
); /* malloc'd, so freed. */
11770 error (_("Junk at end of arguments."));
11772 resolve_sal_pc (&sal
);
11774 tp
= inferior_thread ();
11775 thread
= tp
->global_num
;
11777 old_chain
= make_cleanup (null_cleanup
, NULL
);
11779 /* Note linespec handling above invalidates the frame chain.
11780 Installing a breakpoint also invalidates the frame chain (as it
11781 may need to switch threads), so do any frame handling before
11784 frame
= get_selected_frame (NULL
);
11785 frame_gdbarch
= get_frame_arch (frame
);
11786 stack_frame_id
= get_stack_frame_id (frame
);
11787 caller_frame_id
= frame_unwind_caller_id (frame
);
11789 /* Keep within the current frame, or in frames called by the current
11792 if (frame_id_p (caller_frame_id
))
11794 struct symtab_and_line sal2
;
11795 struct gdbarch
*caller_gdbarch
;
11797 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11798 sal2
.pc
= frame_unwind_caller_pc (frame
);
11799 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11800 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11804 make_cleanup_delete_breakpoint (caller_breakpoint
);
11806 set_longjmp_breakpoint (tp
, caller_frame_id
);
11807 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11810 /* set_momentary_breakpoint could invalidate FRAME. */
11814 /* If the user told us to continue until a specified location,
11815 we don't specify a frame at which we need to stop. */
11816 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11817 null_frame_id
, bp_until
);
11819 /* Otherwise, specify the selected frame, because we want to stop
11820 only at the very same frame. */
11821 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11822 stack_frame_id
, bp_until
);
11823 make_cleanup_delete_breakpoint (location_breakpoint
);
11825 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11826 location_breakpoint
, caller_breakpoint
);
11827 tp
->thread_fsm
= &sm
->thread_fsm
;
11829 discard_cleanups (old_chain
);
11831 proceed (-1, GDB_SIGNAL_DEFAULT
);
11833 do_cleanups (cleanup
);
11836 /* This function attempts to parse an optional "if <cond>" clause
11837 from the arg string. If one is not found, it returns NULL.
11839 Else, it returns a pointer to the condition string. (It does not
11840 attempt to evaluate the string against a particular block.) And,
11841 it updates arg to point to the first character following the parsed
11842 if clause in the arg string. */
11845 ep_parse_optional_if_clause (char **arg
)
11849 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11852 /* Skip the "if" keyword. */
11855 /* Skip any extra leading whitespace, and record the start of the
11856 condition string. */
11857 *arg
= skip_spaces (*arg
);
11858 cond_string
= *arg
;
11860 /* Assume that the condition occupies the remainder of the arg
11862 (*arg
) += strlen (cond_string
);
11864 return cond_string
;
11867 /* Commands to deal with catching events, such as signals, exceptions,
11868 process start/exit, etc. */
11872 catch_fork_temporary
, catch_vfork_temporary
,
11873 catch_fork_permanent
, catch_vfork_permanent
11878 catch_fork_command_1 (char *arg
, int from_tty
,
11879 struct cmd_list_element
*command
)
11881 struct gdbarch
*gdbarch
= get_current_arch ();
11882 char *cond_string
= NULL
;
11883 catch_fork_kind fork_kind
;
11886 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11887 tempflag
= (fork_kind
== catch_fork_temporary
11888 || fork_kind
== catch_vfork_temporary
);
11892 arg
= skip_spaces (arg
);
11894 /* The allowed syntax is:
11896 catch [v]fork if <cond>
11898 First, check if there's an if clause. */
11899 cond_string
= ep_parse_optional_if_clause (&arg
);
11901 if ((*arg
!= '\0') && !isspace (*arg
))
11902 error (_("Junk at end of arguments."));
11904 /* If this target supports it, create a fork or vfork catchpoint
11905 and enable reporting of such events. */
11908 case catch_fork_temporary
:
11909 case catch_fork_permanent
:
11910 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11911 &catch_fork_breakpoint_ops
);
11913 case catch_vfork_temporary
:
11914 case catch_vfork_permanent
:
11915 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11916 &catch_vfork_breakpoint_ops
);
11919 error (_("unsupported or unknown fork kind; cannot catch it"));
11925 catch_exec_command_1 (char *arg
, int from_tty
,
11926 struct cmd_list_element
*command
)
11928 struct exec_catchpoint
*c
;
11929 struct gdbarch
*gdbarch
= get_current_arch ();
11931 char *cond_string
= NULL
;
11933 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11937 arg
= skip_spaces (arg
);
11939 /* The allowed syntax is:
11941 catch exec if <cond>
11943 First, check if there's an if clause. */
11944 cond_string
= ep_parse_optional_if_clause (&arg
);
11946 if ((*arg
!= '\0') && !isspace (*arg
))
11947 error (_("Junk at end of arguments."));
11949 c
= XNEW (struct exec_catchpoint
);
11950 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11951 &catch_exec_breakpoint_ops
);
11952 c
->exec_pathname
= NULL
;
11954 install_breakpoint (0, &c
->base
, 1);
11958 init_ada_exception_breakpoint (struct breakpoint
*b
,
11959 struct gdbarch
*gdbarch
,
11960 struct symtab_and_line sal
,
11962 const struct breakpoint_ops
*ops
,
11969 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11971 loc_gdbarch
= gdbarch
;
11973 describe_other_breakpoints (loc_gdbarch
,
11974 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11975 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11976 version for exception catchpoints, because two catchpoints
11977 used for different exception names will use the same address.
11978 In this case, a "breakpoint ... also set at..." warning is
11979 unproductive. Besides, the warning phrasing is also a bit
11980 inappropriate, we should use the word catchpoint, and tell
11981 the user what type of catchpoint it is. The above is good
11982 enough for now, though. */
11985 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11987 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11988 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11989 b
->location
= string_to_event_location (&addr_string
,
11990 language_def (language_ada
));
11991 b
->language
= language_ada
;
11995 catch_command (char *arg
, int from_tty
)
11997 error (_("Catch requires an event name."));
12002 tcatch_command (char *arg
, int from_tty
)
12004 error (_("Catch requires an event name."));
12007 /* A qsort comparison function that sorts breakpoints in order. */
12010 compare_breakpoints (const void *a
, const void *b
)
12012 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
12013 uintptr_t ua
= (uintptr_t) *ba
;
12014 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
12015 uintptr_t ub
= (uintptr_t) *bb
;
12017 if ((*ba
)->number
< (*bb
)->number
)
12019 else if ((*ba
)->number
> (*bb
)->number
)
12022 /* Now sort by address, in case we see, e..g, two breakpoints with
12026 return ua
> ub
? 1 : 0;
12029 /* Delete breakpoints by address or line. */
12032 clear_command (char *arg
, int from_tty
)
12034 struct breakpoint
*b
, *prev
;
12035 VEC(breakpoint_p
) *found
= 0;
12038 struct symtabs_and_lines sals
;
12039 struct symtab_and_line sal
;
12041 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12045 sals
= decode_line_with_current_source (arg
,
12046 (DECODE_LINE_FUNFIRSTLINE
12047 | DECODE_LINE_LIST_MODE
));
12048 make_cleanup (xfree
, sals
.sals
);
12053 sals
.sals
= XNEW (struct symtab_and_line
);
12054 make_cleanup (xfree
, sals
.sals
);
12055 init_sal (&sal
); /* Initialize to zeroes. */
12057 /* Set sal's line, symtab, pc, and pspace to the values
12058 corresponding to the last call to print_frame_info. If the
12059 codepoint is not valid, this will set all the fields to 0. */
12060 get_last_displayed_sal (&sal
);
12061 if (sal
.symtab
== 0)
12062 error (_("No source file specified."));
12064 sals
.sals
[0] = sal
;
12070 /* We don't call resolve_sal_pc here. That's not as bad as it
12071 seems, because all existing breakpoints typically have both
12072 file/line and pc set. So, if clear is given file/line, we can
12073 match this to existing breakpoint without obtaining pc at all.
12075 We only support clearing given the address explicitly
12076 present in breakpoint table. Say, we've set breakpoint
12077 at file:line. There were several PC values for that file:line,
12078 due to optimization, all in one block.
12080 We've picked one PC value. If "clear" is issued with another
12081 PC corresponding to the same file:line, the breakpoint won't
12082 be cleared. We probably can still clear the breakpoint, but
12083 since the other PC value is never presented to user, user
12084 can only find it by guessing, and it does not seem important
12085 to support that. */
12087 /* For each line spec given, delete bps which correspond to it. Do
12088 it in two passes, solely to preserve the current behavior that
12089 from_tty is forced true if we delete more than one
12093 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12094 for (i
= 0; i
< sals
.nelts
; i
++)
12096 const char *sal_fullname
;
12098 /* If exact pc given, clear bpts at that pc.
12099 If line given (pc == 0), clear all bpts on specified line.
12100 If defaulting, clear all bpts on default line
12103 defaulting sal.pc != 0 tests to do
12108 1 0 <can't happen> */
12110 sal
= sals
.sals
[i
];
12111 sal_fullname
= (sal
.symtab
== NULL
12112 ? NULL
: symtab_to_fullname (sal
.symtab
));
12114 /* Find all matching breakpoints and add them to 'found'. */
12115 ALL_BREAKPOINTS (b
)
12118 /* Are we going to delete b? */
12119 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12121 struct bp_location
*loc
= b
->loc
;
12122 for (; loc
; loc
= loc
->next
)
12124 /* If the user specified file:line, don't allow a PC
12125 match. This matches historical gdb behavior. */
12126 int pc_match
= (!sal
.explicit_line
12128 && (loc
->pspace
== sal
.pspace
)
12129 && (loc
->address
== sal
.pc
)
12130 && (!section_is_overlay (loc
->section
)
12131 || loc
->section
== sal
.section
));
12132 int line_match
= 0;
12134 if ((default_match
|| sal
.explicit_line
)
12135 && loc
->symtab
!= NULL
12136 && sal_fullname
!= NULL
12137 && sal
.pspace
== loc
->pspace
12138 && loc
->line_number
== sal
.line
12139 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12140 sal_fullname
) == 0)
12143 if (pc_match
|| line_match
)
12152 VEC_safe_push(breakpoint_p
, found
, b
);
12156 /* Now go thru the 'found' chain and delete them. */
12157 if (VEC_empty(breakpoint_p
, found
))
12160 error (_("No breakpoint at %s."), arg
);
12162 error (_("No breakpoint at this line."));
12165 /* Remove duplicates from the vec. */
12166 qsort (VEC_address (breakpoint_p
, found
),
12167 VEC_length (breakpoint_p
, found
),
12168 sizeof (breakpoint_p
),
12169 compare_breakpoints
);
12170 prev
= VEC_index (breakpoint_p
, found
, 0);
12171 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12175 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12180 if (VEC_length(breakpoint_p
, found
) > 1)
12181 from_tty
= 1; /* Always report if deleted more than one. */
12184 if (VEC_length(breakpoint_p
, found
) == 1)
12185 printf_unfiltered (_("Deleted breakpoint "));
12187 printf_unfiltered (_("Deleted breakpoints "));
12190 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12193 printf_unfiltered ("%d ", b
->number
);
12194 delete_breakpoint (b
);
12197 putchar_unfiltered ('\n');
12199 do_cleanups (cleanups
);
12202 /* Delete breakpoint in BS if they are `delete' breakpoints and
12203 all breakpoints that are marked for deletion, whether hit or not.
12204 This is called after any breakpoint is hit, or after errors. */
12207 breakpoint_auto_delete (bpstat bs
)
12209 struct breakpoint
*b
, *b_tmp
;
12211 for (; bs
; bs
= bs
->next
)
12212 if (bs
->breakpoint_at
12213 && bs
->breakpoint_at
->disposition
== disp_del
12215 delete_breakpoint (bs
->breakpoint_at
);
12217 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12219 if (b
->disposition
== disp_del_at_next_stop
)
12220 delete_breakpoint (b
);
12224 /* A comparison function for bp_location AP and BP being interfaced to
12225 qsort. Sort elements primarily by their ADDRESS (no matter what
12226 does breakpoint_address_is_meaningful say for its OWNER),
12227 secondarily by ordering first permanent elements and
12228 terciarily just ensuring the array is sorted stable way despite
12229 qsort being an unstable algorithm. */
12232 bp_location_compare (const void *ap
, const void *bp
)
12234 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12235 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12237 if (a
->address
!= b
->address
)
12238 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12240 /* Sort locations at the same address by their pspace number, keeping
12241 locations of the same inferior (in a multi-inferior environment)
12244 if (a
->pspace
->num
!= b
->pspace
->num
)
12245 return ((a
->pspace
->num
> b
->pspace
->num
)
12246 - (a
->pspace
->num
< b
->pspace
->num
));
12248 /* Sort permanent breakpoints first. */
12249 if (a
->permanent
!= b
->permanent
)
12250 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12252 /* Make the internal GDB representation stable across GDB runs
12253 where A and B memory inside GDB can differ. Breakpoint locations of
12254 the same type at the same address can be sorted in arbitrary order. */
12256 if (a
->owner
->number
!= b
->owner
->number
)
12257 return ((a
->owner
->number
> b
->owner
->number
)
12258 - (a
->owner
->number
< b
->owner
->number
));
12260 return (a
> b
) - (a
< b
);
12263 /* Set bp_location_placed_address_before_address_max and
12264 bp_location_shadow_len_after_address_max according to the current
12265 content of the bp_location array. */
12268 bp_location_target_extensions_update (void)
12270 struct bp_location
*bl
, **blp_tmp
;
12272 bp_location_placed_address_before_address_max
= 0;
12273 bp_location_shadow_len_after_address_max
= 0;
12275 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12277 CORE_ADDR start
, end
, addr
;
12279 if (!bp_location_has_shadow (bl
))
12282 start
= bl
->target_info
.placed_address
;
12283 end
= start
+ bl
->target_info
.shadow_len
;
12285 gdb_assert (bl
->address
>= start
);
12286 addr
= bl
->address
- start
;
12287 if (addr
> bp_location_placed_address_before_address_max
)
12288 bp_location_placed_address_before_address_max
= addr
;
12290 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12292 gdb_assert (bl
->address
< end
);
12293 addr
= end
- bl
->address
;
12294 if (addr
> bp_location_shadow_len_after_address_max
)
12295 bp_location_shadow_len_after_address_max
= addr
;
12299 /* Download tracepoint locations if they haven't been. */
12302 download_tracepoint_locations (void)
12304 struct breakpoint
*b
;
12305 struct cleanup
*old_chain
;
12306 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12308 old_chain
= save_current_space_and_thread ();
12310 ALL_TRACEPOINTS (b
)
12312 struct bp_location
*bl
;
12313 struct tracepoint
*t
;
12314 int bp_location_downloaded
= 0;
12316 if ((b
->type
== bp_fast_tracepoint
12317 ? !may_insert_fast_tracepoints
12318 : !may_insert_tracepoints
))
12321 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12323 if (target_can_download_tracepoint ())
12324 can_download_tracepoint
= TRIBOOL_TRUE
;
12326 can_download_tracepoint
= TRIBOOL_FALSE
;
12329 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12332 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12334 /* In tracepoint, locations are _never_ duplicated, so
12335 should_be_inserted is equivalent to
12336 unduplicated_should_be_inserted. */
12337 if (!should_be_inserted (bl
) || bl
->inserted
)
12340 switch_to_program_space_and_thread (bl
->pspace
);
12342 target_download_tracepoint (bl
);
12345 bp_location_downloaded
= 1;
12347 t
= (struct tracepoint
*) b
;
12348 t
->number_on_target
= b
->number
;
12349 if (bp_location_downloaded
)
12350 observer_notify_breakpoint_modified (b
);
12353 do_cleanups (old_chain
);
12356 /* Swap the insertion/duplication state between two locations. */
12359 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12361 const int left_inserted
= left
->inserted
;
12362 const int left_duplicate
= left
->duplicate
;
12363 const int left_needs_update
= left
->needs_update
;
12364 const struct bp_target_info left_target_info
= left
->target_info
;
12366 /* Locations of tracepoints can never be duplicated. */
12367 if (is_tracepoint (left
->owner
))
12368 gdb_assert (!left
->duplicate
);
12369 if (is_tracepoint (right
->owner
))
12370 gdb_assert (!right
->duplicate
);
12372 left
->inserted
= right
->inserted
;
12373 left
->duplicate
= right
->duplicate
;
12374 left
->needs_update
= right
->needs_update
;
12375 left
->target_info
= right
->target_info
;
12376 right
->inserted
= left_inserted
;
12377 right
->duplicate
= left_duplicate
;
12378 right
->needs_update
= left_needs_update
;
12379 right
->target_info
= left_target_info
;
12382 /* Force the re-insertion of the locations at ADDRESS. This is called
12383 once a new/deleted/modified duplicate location is found and we are evaluating
12384 conditions on the target's side. Such conditions need to be updated on
12388 force_breakpoint_reinsertion (struct bp_location
*bl
)
12390 struct bp_location
**locp
= NULL
, **loc2p
;
12391 struct bp_location
*loc
;
12392 CORE_ADDR address
= 0;
12395 address
= bl
->address
;
12396 pspace_num
= bl
->pspace
->num
;
12398 /* This is only meaningful if the target is
12399 evaluating conditions and if the user has
12400 opted for condition evaluation on the target's
12402 if (gdb_evaluates_breakpoint_condition_p ()
12403 || !target_supports_evaluation_of_breakpoint_conditions ())
12406 /* Flag all breakpoint locations with this address and
12407 the same program space as the location
12408 as "its condition has changed". We need to
12409 update the conditions on the target's side. */
12410 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12414 if (!is_breakpoint (loc
->owner
)
12415 || pspace_num
!= loc
->pspace
->num
)
12418 /* Flag the location appropriately. We use a different state to
12419 let everyone know that we already updated the set of locations
12420 with addr bl->address and program space bl->pspace. This is so
12421 we don't have to keep calling these functions just to mark locations
12422 that have already been marked. */
12423 loc
->condition_changed
= condition_updated
;
12425 /* Free the agent expression bytecode as well. We will compute
12427 if (loc
->cond_bytecode
)
12429 free_agent_expr (loc
->cond_bytecode
);
12430 loc
->cond_bytecode
= NULL
;
12434 /* Called whether new breakpoints are created, or existing breakpoints
12435 deleted, to update the global location list and recompute which
12436 locations are duplicate of which.
12438 The INSERT_MODE flag determines whether locations may not, may, or
12439 shall be inserted now. See 'enum ugll_insert_mode' for more
12443 update_global_location_list (enum ugll_insert_mode insert_mode
)
12445 struct breakpoint
*b
;
12446 struct bp_location
**locp
, *loc
;
12447 struct cleanup
*cleanups
;
12448 /* Last breakpoint location address that was marked for update. */
12449 CORE_ADDR last_addr
= 0;
12450 /* Last breakpoint location program space that was marked for update. */
12451 int last_pspace_num
= -1;
12453 /* Used in the duplicates detection below. When iterating over all
12454 bp_locations, points to the first bp_location of a given address.
12455 Breakpoints and watchpoints of different types are never
12456 duplicates of each other. Keep one pointer for each type of
12457 breakpoint/watchpoint, so we only need to loop over all locations
12459 struct bp_location
*bp_loc_first
; /* breakpoint */
12460 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12461 struct bp_location
*awp_loc_first
; /* access watchpoint */
12462 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12464 /* Saved former bp_location array which we compare against the newly
12465 built bp_location from the current state of ALL_BREAKPOINTS. */
12466 struct bp_location
**old_location
, **old_locp
;
12467 unsigned old_location_count
;
12469 old_location
= bp_location
;
12470 old_location_count
= bp_location_count
;
12471 bp_location
= NULL
;
12472 bp_location_count
= 0;
12473 cleanups
= make_cleanup (xfree
, old_location
);
12475 ALL_BREAKPOINTS (b
)
12476 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12477 bp_location_count
++;
12479 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12480 locp
= bp_location
;
12481 ALL_BREAKPOINTS (b
)
12482 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12484 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12485 bp_location_compare
);
12487 bp_location_target_extensions_update ();
12489 /* Identify bp_location instances that are no longer present in the
12490 new list, and therefore should be freed. Note that it's not
12491 necessary that those locations should be removed from inferior --
12492 if there's another location at the same address (previously
12493 marked as duplicate), we don't need to remove/insert the
12496 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12497 and former bp_location array state respectively. */
12499 locp
= bp_location
;
12500 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12503 struct bp_location
*old_loc
= *old_locp
;
12504 struct bp_location
**loc2p
;
12506 /* Tells if 'old_loc' is found among the new locations. If
12507 not, we have to free it. */
12508 int found_object
= 0;
12509 /* Tells if the location should remain inserted in the target. */
12510 int keep_in_target
= 0;
12513 /* Skip LOCP entries which will definitely never be needed.
12514 Stop either at or being the one matching OLD_LOC. */
12515 while (locp
< bp_location
+ bp_location_count
12516 && (*locp
)->address
< old_loc
->address
)
12520 (loc2p
< bp_location
+ bp_location_count
12521 && (*loc2p
)->address
== old_loc
->address
);
12524 /* Check if this is a new/duplicated location or a duplicated
12525 location that had its condition modified. If so, we want to send
12526 its condition to the target if evaluation of conditions is taking
12528 if ((*loc2p
)->condition_changed
== condition_modified
12529 && (last_addr
!= old_loc
->address
12530 || last_pspace_num
!= old_loc
->pspace
->num
))
12532 force_breakpoint_reinsertion (*loc2p
);
12533 last_pspace_num
= old_loc
->pspace
->num
;
12536 if (*loc2p
== old_loc
)
12540 /* We have already handled this address, update it so that we don't
12541 have to go through updates again. */
12542 last_addr
= old_loc
->address
;
12544 /* Target-side condition evaluation: Handle deleted locations. */
12546 force_breakpoint_reinsertion (old_loc
);
12548 /* If this location is no longer present, and inserted, look if
12549 there's maybe a new location at the same address. If so,
12550 mark that one inserted, and don't remove this one. This is
12551 needed so that we don't have a time window where a breakpoint
12552 at certain location is not inserted. */
12554 if (old_loc
->inserted
)
12556 /* If the location is inserted now, we might have to remove
12559 if (found_object
&& should_be_inserted (old_loc
))
12561 /* The location is still present in the location list,
12562 and still should be inserted. Don't do anything. */
12563 keep_in_target
= 1;
12567 /* This location still exists, but it won't be kept in the
12568 target since it may have been disabled. We proceed to
12569 remove its target-side condition. */
12571 /* The location is either no longer present, or got
12572 disabled. See if there's another location at the
12573 same address, in which case we don't need to remove
12574 this one from the target. */
12576 /* OLD_LOC comes from existing struct breakpoint. */
12577 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12580 (loc2p
< bp_location
+ bp_location_count
12581 && (*loc2p
)->address
== old_loc
->address
);
12584 struct bp_location
*loc2
= *loc2p
;
12586 if (breakpoint_locations_match (loc2
, old_loc
))
12588 /* Read watchpoint locations are switched to
12589 access watchpoints, if the former are not
12590 supported, but the latter are. */
12591 if (is_hardware_watchpoint (old_loc
->owner
))
12593 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12594 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12597 /* loc2 is a duplicated location. We need to check
12598 if it should be inserted in case it will be
12600 if (loc2
!= old_loc
12601 && unduplicated_should_be_inserted (loc2
))
12603 swap_insertion (old_loc
, loc2
);
12604 keep_in_target
= 1;
12612 if (!keep_in_target
)
12614 if (remove_breakpoint (old_loc
))
12616 /* This is just about all we can do. We could keep
12617 this location on the global list, and try to
12618 remove it next time, but there's no particular
12619 reason why we will succeed next time.
12621 Note that at this point, old_loc->owner is still
12622 valid, as delete_breakpoint frees the breakpoint
12623 only after calling us. */
12624 printf_filtered (_("warning: Error removing "
12625 "breakpoint %d\n"),
12626 old_loc
->owner
->number
);
12634 if (removed
&& target_is_non_stop_p ()
12635 && need_moribund_for_location_type (old_loc
))
12637 /* This location was removed from the target. In
12638 non-stop mode, a race condition is possible where
12639 we've removed a breakpoint, but stop events for that
12640 breakpoint are already queued and will arrive later.
12641 We apply an heuristic to be able to distinguish such
12642 SIGTRAPs from other random SIGTRAPs: we keep this
12643 breakpoint location for a bit, and will retire it
12644 after we see some number of events. The theory here
12645 is that reporting of events should, "on the average",
12646 be fair, so after a while we'll see events from all
12647 threads that have anything of interest, and no longer
12648 need to keep this breakpoint location around. We
12649 don't hold locations forever so to reduce chances of
12650 mistaking a non-breakpoint SIGTRAP for a breakpoint
12653 The heuristic failing can be disastrous on
12654 decr_pc_after_break targets.
12656 On decr_pc_after_break targets, like e.g., x86-linux,
12657 if we fail to recognize a late breakpoint SIGTRAP,
12658 because events_till_retirement has reached 0 too
12659 soon, we'll fail to do the PC adjustment, and report
12660 a random SIGTRAP to the user. When the user resumes
12661 the inferior, it will most likely immediately crash
12662 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12663 corrupted, because of being resumed e.g., in the
12664 middle of a multi-byte instruction, or skipped a
12665 one-byte instruction. This was actually seen happen
12666 on native x86-linux, and should be less rare on
12667 targets that do not support new thread events, like
12668 remote, due to the heuristic depending on
12671 Mistaking a random SIGTRAP for a breakpoint trap
12672 causes similar symptoms (PC adjustment applied when
12673 it shouldn't), but then again, playing with SIGTRAPs
12674 behind the debugger's back is asking for trouble.
12676 Since hardware watchpoint traps are always
12677 distinguishable from other traps, so we don't need to
12678 apply keep hardware watchpoint moribund locations
12679 around. We simply always ignore hardware watchpoint
12680 traps we can no longer explain. */
12682 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12683 old_loc
->owner
= NULL
;
12685 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12689 old_loc
->owner
= NULL
;
12690 decref_bp_location (&old_loc
);
12695 /* Rescan breakpoints at the same address and section, marking the
12696 first one as "first" and any others as "duplicates". This is so
12697 that the bpt instruction is only inserted once. If we have a
12698 permanent breakpoint at the same place as BPT, make that one the
12699 official one, and the rest as duplicates. Permanent breakpoints
12700 are sorted first for the same address.
12702 Do the same for hardware watchpoints, but also considering the
12703 watchpoint's type (regular/access/read) and length. */
12705 bp_loc_first
= NULL
;
12706 wp_loc_first
= NULL
;
12707 awp_loc_first
= NULL
;
12708 rwp_loc_first
= NULL
;
12709 ALL_BP_LOCATIONS (loc
, locp
)
12711 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12713 struct bp_location
**loc_first_p
;
12716 if (!unduplicated_should_be_inserted (loc
)
12717 || !breakpoint_address_is_meaningful (b
)
12718 /* Don't detect duplicate for tracepoint locations because they are
12719 never duplicated. See the comments in field `duplicate' of
12720 `struct bp_location'. */
12721 || is_tracepoint (b
))
12723 /* Clear the condition modification flag. */
12724 loc
->condition_changed
= condition_unchanged
;
12728 if (b
->type
== bp_hardware_watchpoint
)
12729 loc_first_p
= &wp_loc_first
;
12730 else if (b
->type
== bp_read_watchpoint
)
12731 loc_first_p
= &rwp_loc_first
;
12732 else if (b
->type
== bp_access_watchpoint
)
12733 loc_first_p
= &awp_loc_first
;
12735 loc_first_p
= &bp_loc_first
;
12737 if (*loc_first_p
== NULL
12738 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12739 || !breakpoint_locations_match (loc
, *loc_first_p
))
12741 *loc_first_p
= loc
;
12742 loc
->duplicate
= 0;
12744 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12746 loc
->needs_update
= 1;
12747 /* Clear the condition modification flag. */
12748 loc
->condition_changed
= condition_unchanged
;
12754 /* This and the above ensure the invariant that the first location
12755 is not duplicated, and is the inserted one.
12756 All following are marked as duplicated, and are not inserted. */
12758 swap_insertion (loc
, *loc_first_p
);
12759 loc
->duplicate
= 1;
12761 /* Clear the condition modification flag. */
12762 loc
->condition_changed
= condition_unchanged
;
12765 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12767 if (insert_mode
!= UGLL_DONT_INSERT
)
12768 insert_breakpoint_locations ();
12771 /* Even though the caller told us to not insert new
12772 locations, we may still need to update conditions on the
12773 target's side of breakpoints that were already inserted
12774 if the target is evaluating breakpoint conditions. We
12775 only update conditions for locations that are marked
12777 update_inserted_breakpoint_locations ();
12781 if (insert_mode
!= UGLL_DONT_INSERT
)
12782 download_tracepoint_locations ();
12784 do_cleanups (cleanups
);
12788 breakpoint_retire_moribund (void)
12790 struct bp_location
*loc
;
12793 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12794 if (--(loc
->events_till_retirement
) == 0)
12796 decref_bp_location (&loc
);
12797 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12803 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12808 update_global_location_list (insert_mode
);
12810 CATCH (e
, RETURN_MASK_ERROR
)
12816 /* Clear BKP from a BPS. */
12819 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12823 for (bs
= bps
; bs
; bs
= bs
->next
)
12824 if (bs
->breakpoint_at
== bpt
)
12826 bs
->breakpoint_at
= NULL
;
12827 bs
->old_val
= NULL
;
12828 /* bs->commands will be freed later. */
12832 /* Callback for iterate_over_threads. */
12834 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12836 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12838 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12842 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12846 say_where (struct breakpoint
*b
)
12848 struct value_print_options opts
;
12850 get_user_print_options (&opts
);
12852 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12854 if (b
->loc
== NULL
)
12856 /* For pending locations, the output differs slightly based
12857 on b->extra_string. If this is non-NULL, it contains either
12858 a condition or dprintf arguments. */
12859 if (b
->extra_string
== NULL
)
12861 printf_filtered (_(" (%s) pending."),
12862 event_location_to_string (b
->location
));
12864 else if (b
->type
== bp_dprintf
)
12866 printf_filtered (_(" (%s,%s) pending."),
12867 event_location_to_string (b
->location
),
12872 printf_filtered (_(" (%s %s) pending."),
12873 event_location_to_string (b
->location
),
12879 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12881 printf_filtered (" at ");
12882 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12885 if (b
->loc
->symtab
!= NULL
)
12887 /* If there is a single location, we can print the location
12889 if (b
->loc
->next
== NULL
)
12890 printf_filtered (": file %s, line %d.",
12891 symtab_to_filename_for_display (b
->loc
->symtab
),
12892 b
->loc
->line_number
);
12894 /* This is not ideal, but each location may have a
12895 different file name, and this at least reflects the
12896 real situation somewhat. */
12897 printf_filtered (": %s.",
12898 event_location_to_string (b
->location
));
12903 struct bp_location
*loc
= b
->loc
;
12905 for (; loc
; loc
= loc
->next
)
12907 printf_filtered (" (%d locations)", n
);
12912 /* Default bp_location_ops methods. */
12915 bp_location_dtor (struct bp_location
*self
)
12917 xfree (self
->cond
);
12918 if (self
->cond_bytecode
)
12919 free_agent_expr (self
->cond_bytecode
);
12920 xfree (self
->function_name
);
12922 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12923 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12926 static const struct bp_location_ops bp_location_ops
=
12931 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12935 base_breakpoint_dtor (struct breakpoint
*self
)
12937 decref_counted_command_line (&self
->commands
);
12938 xfree (self
->cond_string
);
12939 xfree (self
->extra_string
);
12940 xfree (self
->filter
);
12941 delete_event_location (self
->location
);
12942 delete_event_location (self
->location_range_end
);
12945 static struct bp_location
*
12946 base_breakpoint_allocate_location (struct breakpoint
*self
)
12948 struct bp_location
*loc
;
12950 loc
= XNEW (struct bp_location
);
12951 init_bp_location (loc
, &bp_location_ops
, self
);
12956 base_breakpoint_re_set (struct breakpoint
*b
)
12958 /* Nothing to re-set. */
12961 #define internal_error_pure_virtual_called() \
12962 gdb_assert_not_reached ("pure virtual function called")
12965 base_breakpoint_insert_location (struct bp_location
*bl
)
12967 internal_error_pure_virtual_called ();
12971 base_breakpoint_remove_location (struct bp_location
*bl
,
12972 enum remove_bp_reason reason
)
12974 internal_error_pure_virtual_called ();
12978 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12979 struct address_space
*aspace
,
12981 const struct target_waitstatus
*ws
)
12983 internal_error_pure_virtual_called ();
12987 base_breakpoint_check_status (bpstat bs
)
12992 /* A "works_in_software_mode" breakpoint_ops method that just internal
12996 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12998 internal_error_pure_virtual_called ();
13001 /* A "resources_needed" breakpoint_ops method that just internal
13005 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13007 internal_error_pure_virtual_called ();
13010 static enum print_stop_action
13011 base_breakpoint_print_it (bpstat bs
)
13013 internal_error_pure_virtual_called ();
13017 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13018 struct ui_out
*uiout
)
13024 base_breakpoint_print_mention (struct breakpoint
*b
)
13026 internal_error_pure_virtual_called ();
13030 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13032 internal_error_pure_virtual_called ();
13036 base_breakpoint_create_sals_from_location
13037 (const struct event_location
*location
,
13038 struct linespec_result
*canonical
,
13039 enum bptype type_wanted
)
13041 internal_error_pure_virtual_called ();
13045 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13046 struct linespec_result
*c
,
13048 char *extra_string
,
13049 enum bptype type_wanted
,
13050 enum bpdisp disposition
,
13052 int task
, int ignore_count
,
13053 const struct breakpoint_ops
*o
,
13054 int from_tty
, int enabled
,
13055 int internal
, unsigned flags
)
13057 internal_error_pure_virtual_called ();
13061 base_breakpoint_decode_location (struct breakpoint
*b
,
13062 const struct event_location
*location
,
13063 struct program_space
*search_pspace
,
13064 struct symtabs_and_lines
*sals
)
13066 internal_error_pure_virtual_called ();
13069 /* The default 'explains_signal' method. */
13072 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13077 /* The default "after_condition_true" method. */
13080 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13082 /* Nothing to do. */
13085 struct breakpoint_ops base_breakpoint_ops
=
13087 base_breakpoint_dtor
,
13088 base_breakpoint_allocate_location
,
13089 base_breakpoint_re_set
,
13090 base_breakpoint_insert_location
,
13091 base_breakpoint_remove_location
,
13092 base_breakpoint_breakpoint_hit
,
13093 base_breakpoint_check_status
,
13094 base_breakpoint_resources_needed
,
13095 base_breakpoint_works_in_software_mode
,
13096 base_breakpoint_print_it
,
13098 base_breakpoint_print_one_detail
,
13099 base_breakpoint_print_mention
,
13100 base_breakpoint_print_recreate
,
13101 base_breakpoint_create_sals_from_location
,
13102 base_breakpoint_create_breakpoints_sal
,
13103 base_breakpoint_decode_location
,
13104 base_breakpoint_explains_signal
,
13105 base_breakpoint_after_condition_true
,
13108 /* Default breakpoint_ops methods. */
13111 bkpt_re_set (struct breakpoint
*b
)
13113 /* FIXME: is this still reachable? */
13114 if (breakpoint_event_location_empty_p (b
))
13116 /* Anything without a location can't be re-set. */
13117 delete_breakpoint (b
);
13121 breakpoint_re_set_default (b
);
13125 bkpt_insert_location (struct bp_location
*bl
)
13127 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
13129 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
13130 bl
->target_info
.placed_address
= addr
;
13132 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13133 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13135 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13139 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13141 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13142 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13144 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13148 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13149 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13150 const struct target_waitstatus
*ws
)
13152 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13153 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13156 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13160 if (overlay_debugging
/* unmapped overlay section */
13161 && section_is_overlay (bl
->section
)
13162 && !section_is_mapped (bl
->section
))
13169 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13170 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13171 const struct target_waitstatus
*ws
)
13173 if (dprintf_style
== dprintf_style_agent
13174 && target_can_run_breakpoint_commands ())
13176 /* An agent-style dprintf never causes a stop. If we see a trap
13177 for this address it must be for a breakpoint that happens to
13178 be set at the same address. */
13182 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13186 bkpt_resources_needed (const struct bp_location
*bl
)
13188 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13193 static enum print_stop_action
13194 bkpt_print_it (bpstat bs
)
13196 struct breakpoint
*b
;
13197 const struct bp_location
*bl
;
13199 struct ui_out
*uiout
= current_uiout
;
13201 gdb_assert (bs
->bp_location_at
!= NULL
);
13203 bl
= bs
->bp_location_at
;
13204 b
= bs
->breakpoint_at
;
13206 bp_temp
= b
->disposition
== disp_del
;
13207 if (bl
->address
!= bl
->requested_address
)
13208 breakpoint_adjustment_warning (bl
->requested_address
,
13211 annotate_breakpoint (b
->number
);
13212 maybe_print_thread_hit_breakpoint (uiout
);
13215 ui_out_text (uiout
, "Temporary breakpoint ");
13217 ui_out_text (uiout
, "Breakpoint ");
13218 if (ui_out_is_mi_like_p (uiout
))
13220 ui_out_field_string (uiout
, "reason",
13221 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13222 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13224 ui_out_field_int (uiout
, "bkptno", b
->number
);
13225 ui_out_text (uiout
, ", ");
13227 return PRINT_SRC_AND_LOC
;
13231 bkpt_print_mention (struct breakpoint
*b
)
13233 if (ui_out_is_mi_like_p (current_uiout
))
13238 case bp_breakpoint
:
13239 case bp_gnu_ifunc_resolver
:
13240 if (b
->disposition
== disp_del
)
13241 printf_filtered (_("Temporary breakpoint"));
13243 printf_filtered (_("Breakpoint"));
13244 printf_filtered (_(" %d"), b
->number
);
13245 if (b
->type
== bp_gnu_ifunc_resolver
)
13246 printf_filtered (_(" at gnu-indirect-function resolver"));
13248 case bp_hardware_breakpoint
:
13249 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13252 printf_filtered (_("Dprintf %d"), b
->number
);
13260 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13262 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13263 fprintf_unfiltered (fp
, "tbreak");
13264 else if (tp
->type
== bp_breakpoint
)
13265 fprintf_unfiltered (fp
, "break");
13266 else if (tp
->type
== bp_hardware_breakpoint
13267 && tp
->disposition
== disp_del
)
13268 fprintf_unfiltered (fp
, "thbreak");
13269 else if (tp
->type
== bp_hardware_breakpoint
)
13270 fprintf_unfiltered (fp
, "hbreak");
13272 internal_error (__FILE__
, __LINE__
,
13273 _("unhandled breakpoint type %d"), (int) tp
->type
);
13275 fprintf_unfiltered (fp
, " %s",
13276 event_location_to_string (tp
->location
));
13278 /* Print out extra_string if this breakpoint is pending. It might
13279 contain, for example, conditions that were set by the user. */
13280 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13281 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13283 print_recreate_thread (tp
, fp
);
13287 bkpt_create_sals_from_location (const struct event_location
*location
,
13288 struct linespec_result
*canonical
,
13289 enum bptype type_wanted
)
13291 create_sals_from_location_default (location
, canonical
, type_wanted
);
13295 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13296 struct linespec_result
*canonical
,
13298 char *extra_string
,
13299 enum bptype type_wanted
,
13300 enum bpdisp disposition
,
13302 int task
, int ignore_count
,
13303 const struct breakpoint_ops
*ops
,
13304 int from_tty
, int enabled
,
13305 int internal
, unsigned flags
)
13307 create_breakpoints_sal_default (gdbarch
, canonical
,
13308 cond_string
, extra_string
,
13310 disposition
, thread
, task
,
13311 ignore_count
, ops
, from_tty
,
13312 enabled
, internal
, flags
);
13316 bkpt_decode_location (struct breakpoint
*b
,
13317 const struct event_location
*location
,
13318 struct program_space
*search_pspace
,
13319 struct symtabs_and_lines
*sals
)
13321 decode_location_default (b
, location
, search_pspace
, sals
);
13324 /* Virtual table for internal breakpoints. */
13327 internal_bkpt_re_set (struct breakpoint
*b
)
13331 /* Delete overlay event and longjmp master breakpoints; they
13332 will be reset later by breakpoint_re_set. */
13333 case bp_overlay_event
:
13334 case bp_longjmp_master
:
13335 case bp_std_terminate_master
:
13336 case bp_exception_master
:
13337 delete_breakpoint (b
);
13340 /* This breakpoint is special, it's set up when the inferior
13341 starts and we really don't want to touch it. */
13342 case bp_shlib_event
:
13344 /* Like bp_shlib_event, this breakpoint type is special. Once
13345 it is set up, we do not want to touch it. */
13346 case bp_thread_event
:
13352 internal_bkpt_check_status (bpstat bs
)
13354 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13356 /* If requested, stop when the dynamic linker notifies GDB of
13357 events. This allows the user to get control and place
13358 breakpoints in initializer routines for dynamically loaded
13359 objects (among other things). */
13360 bs
->stop
= stop_on_solib_events
;
13361 bs
->print
= stop_on_solib_events
;
13367 static enum print_stop_action
13368 internal_bkpt_print_it (bpstat bs
)
13370 struct breakpoint
*b
;
13372 b
= bs
->breakpoint_at
;
13376 case bp_shlib_event
:
13377 /* Did we stop because the user set the stop_on_solib_events
13378 variable? (If so, we report this as a generic, "Stopped due
13379 to shlib event" message.) */
13380 print_solib_event (0);
13383 case bp_thread_event
:
13384 /* Not sure how we will get here.
13385 GDB should not stop for these breakpoints. */
13386 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13389 case bp_overlay_event
:
13390 /* By analogy with the thread event, GDB should not stop for these. */
13391 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13394 case bp_longjmp_master
:
13395 /* These should never be enabled. */
13396 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13399 case bp_std_terminate_master
:
13400 /* These should never be enabled. */
13401 printf_filtered (_("std::terminate Master Breakpoint: "
13402 "gdb should not stop!\n"));
13405 case bp_exception_master
:
13406 /* These should never be enabled. */
13407 printf_filtered (_("Exception Master Breakpoint: "
13408 "gdb should not stop!\n"));
13412 return PRINT_NOTHING
;
13416 internal_bkpt_print_mention (struct breakpoint
*b
)
13418 /* Nothing to mention. These breakpoints are internal. */
13421 /* Virtual table for momentary breakpoints */
13424 momentary_bkpt_re_set (struct breakpoint
*b
)
13426 /* Keep temporary breakpoints, which can be encountered when we step
13427 over a dlopen call and solib_add is resetting the breakpoints.
13428 Otherwise these should have been blown away via the cleanup chain
13429 or by breakpoint_init_inferior when we rerun the executable. */
13433 momentary_bkpt_check_status (bpstat bs
)
13435 /* Nothing. The point of these breakpoints is causing a stop. */
13438 static enum print_stop_action
13439 momentary_bkpt_print_it (bpstat bs
)
13441 return PRINT_UNKNOWN
;
13445 momentary_bkpt_print_mention (struct breakpoint
*b
)
13447 /* Nothing to mention. These breakpoints are internal. */
13450 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13452 It gets cleared already on the removal of the first one of such placed
13453 breakpoints. This is OK as they get all removed altogether. */
13456 longjmp_bkpt_dtor (struct breakpoint
*self
)
13458 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13461 tp
->initiating_frame
= null_frame_id
;
13463 momentary_breakpoint_ops
.dtor (self
);
13466 /* Specific methods for probe breakpoints. */
13469 bkpt_probe_insert_location (struct bp_location
*bl
)
13471 int v
= bkpt_insert_location (bl
);
13475 /* The insertion was successful, now let's set the probe's semaphore
13477 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13478 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13487 bkpt_probe_remove_location (struct bp_location
*bl
,
13488 enum remove_bp_reason reason
)
13490 /* Let's clear the semaphore before removing the location. */
13491 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13492 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13496 return bkpt_remove_location (bl
, reason
);
13500 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13501 struct linespec_result
*canonical
,
13502 enum bptype type_wanted
)
13504 struct linespec_sals lsal
;
13506 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13507 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13508 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13512 bkpt_probe_decode_location (struct breakpoint
*b
,
13513 const struct event_location
*location
,
13514 struct program_space
*search_pspace
,
13515 struct symtabs_and_lines
*sals
)
13517 *sals
= parse_probes (location
, search_pspace
, NULL
);
13519 error (_("probe not found"));
13522 /* The breakpoint_ops structure to be used in tracepoints. */
13525 tracepoint_re_set (struct breakpoint
*b
)
13527 breakpoint_re_set_default (b
);
13531 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13532 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13533 const struct target_waitstatus
*ws
)
13535 /* By definition, the inferior does not report stops at
13541 tracepoint_print_one_detail (const struct breakpoint
*self
,
13542 struct ui_out
*uiout
)
13544 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13545 if (tp
->static_trace_marker_id
)
13547 gdb_assert (self
->type
== bp_static_tracepoint
);
13549 ui_out_text (uiout
, "\tmarker id is ");
13550 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13551 tp
->static_trace_marker_id
);
13552 ui_out_text (uiout
, "\n");
13557 tracepoint_print_mention (struct breakpoint
*b
)
13559 if (ui_out_is_mi_like_p (current_uiout
))
13564 case bp_tracepoint
:
13565 printf_filtered (_("Tracepoint"));
13566 printf_filtered (_(" %d"), b
->number
);
13568 case bp_fast_tracepoint
:
13569 printf_filtered (_("Fast tracepoint"));
13570 printf_filtered (_(" %d"), b
->number
);
13572 case bp_static_tracepoint
:
13573 printf_filtered (_("Static tracepoint"));
13574 printf_filtered (_(" %d"), b
->number
);
13577 internal_error (__FILE__
, __LINE__
,
13578 _("unhandled tracepoint type %d"), (int) b
->type
);
13585 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13587 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13589 if (self
->type
== bp_fast_tracepoint
)
13590 fprintf_unfiltered (fp
, "ftrace");
13591 else if (self
->type
== bp_static_tracepoint
)
13592 fprintf_unfiltered (fp
, "strace");
13593 else if (self
->type
== bp_tracepoint
)
13594 fprintf_unfiltered (fp
, "trace");
13596 internal_error (__FILE__
, __LINE__
,
13597 _("unhandled tracepoint type %d"), (int) self
->type
);
13599 fprintf_unfiltered (fp
, " %s",
13600 event_location_to_string (self
->location
));
13601 print_recreate_thread (self
, fp
);
13603 if (tp
->pass_count
)
13604 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13608 tracepoint_create_sals_from_location (const struct event_location
*location
,
13609 struct linespec_result
*canonical
,
13610 enum bptype type_wanted
)
13612 create_sals_from_location_default (location
, canonical
, type_wanted
);
13616 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13617 struct linespec_result
*canonical
,
13619 char *extra_string
,
13620 enum bptype type_wanted
,
13621 enum bpdisp disposition
,
13623 int task
, int ignore_count
,
13624 const struct breakpoint_ops
*ops
,
13625 int from_tty
, int enabled
,
13626 int internal
, unsigned flags
)
13628 create_breakpoints_sal_default (gdbarch
, canonical
,
13629 cond_string
, extra_string
,
13631 disposition
, thread
, task
,
13632 ignore_count
, ops
, from_tty
,
13633 enabled
, internal
, flags
);
13637 tracepoint_decode_location (struct breakpoint
*b
,
13638 const struct event_location
*location
,
13639 struct program_space
*search_pspace
,
13640 struct symtabs_and_lines
*sals
)
13642 decode_location_default (b
, location
, search_pspace
, sals
);
13645 struct breakpoint_ops tracepoint_breakpoint_ops
;
13647 /* The breakpoint_ops structure to be use on tracepoints placed in a
13651 tracepoint_probe_create_sals_from_location
13652 (const struct event_location
*location
,
13653 struct linespec_result
*canonical
,
13654 enum bptype type_wanted
)
13656 /* We use the same method for breakpoint on probes. */
13657 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13661 tracepoint_probe_decode_location (struct breakpoint
*b
,
13662 const struct event_location
*location
,
13663 struct program_space
*search_pspace
,
13664 struct symtabs_and_lines
*sals
)
13666 /* We use the same method for breakpoint on probes. */
13667 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13670 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13672 /* Dprintf breakpoint_ops methods. */
13675 dprintf_re_set (struct breakpoint
*b
)
13677 breakpoint_re_set_default (b
);
13679 /* extra_string should never be non-NULL for dprintf. */
13680 gdb_assert (b
->extra_string
!= NULL
);
13682 /* 1 - connect to target 1, that can run breakpoint commands.
13683 2 - create a dprintf, which resolves fine.
13684 3 - disconnect from target 1
13685 4 - connect to target 2, that can NOT run breakpoint commands.
13687 After steps #3/#4, you'll want the dprintf command list to
13688 be updated, because target 1 and 2 may well return different
13689 answers for target_can_run_breakpoint_commands().
13690 Given absence of finer grained resetting, we get to do
13691 it all the time. */
13692 if (b
->extra_string
!= NULL
)
13693 update_dprintf_command_list (b
);
13696 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13699 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13701 fprintf_unfiltered (fp
, "dprintf %s,%s",
13702 event_location_to_string (tp
->location
),
13704 print_recreate_thread (tp
, fp
);
13707 /* Implement the "after_condition_true" breakpoint_ops method for
13710 dprintf's are implemented with regular commands in their command
13711 list, but we run the commands here instead of before presenting the
13712 stop to the user, as dprintf's don't actually cause a stop. This
13713 also makes it so that the commands of multiple dprintfs at the same
13714 address are all handled. */
13717 dprintf_after_condition_true (struct bpstats
*bs
)
13719 struct cleanup
*old_chain
;
13720 struct bpstats tmp_bs
= { NULL
};
13721 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13723 /* dprintf's never cause a stop. This wasn't set in the
13724 check_status hook instead because that would make the dprintf's
13725 condition not be evaluated. */
13728 /* Run the command list here. Take ownership of it instead of
13729 copying. We never want these commands to run later in
13730 bpstat_do_actions, if a breakpoint that causes a stop happens to
13731 be set at same address as this dprintf, or even if running the
13732 commands here throws. */
13733 tmp_bs
.commands
= bs
->commands
;
13734 bs
->commands
= NULL
;
13735 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13737 bpstat_do_actions_1 (&tmp_bs_p
);
13739 /* 'tmp_bs.commands' will usually be NULL by now, but
13740 bpstat_do_actions_1 may return early without processing the whole
13742 do_cleanups (old_chain
);
13745 /* The breakpoint_ops structure to be used on static tracepoints with
13749 strace_marker_create_sals_from_location (const struct event_location
*location
,
13750 struct linespec_result
*canonical
,
13751 enum bptype type_wanted
)
13753 struct linespec_sals lsal
;
13754 const char *arg_start
, *arg
;
13756 struct cleanup
*cleanup
;
13758 arg
= arg_start
= get_linespec_location (location
);
13759 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13761 str
= savestring (arg_start
, arg
- arg_start
);
13762 cleanup
= make_cleanup (xfree
, str
);
13763 canonical
->location
= new_linespec_location (&str
);
13764 do_cleanups (cleanup
);
13766 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13767 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13771 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13772 struct linespec_result
*canonical
,
13774 char *extra_string
,
13775 enum bptype type_wanted
,
13776 enum bpdisp disposition
,
13778 int task
, int ignore_count
,
13779 const struct breakpoint_ops
*ops
,
13780 int from_tty
, int enabled
,
13781 int internal
, unsigned flags
)
13784 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13785 canonical
->sals
, 0);
13787 /* If the user is creating a static tracepoint by marker id
13788 (strace -m MARKER_ID), then store the sals index, so that
13789 breakpoint_re_set can try to match up which of the newly
13790 found markers corresponds to this one, and, don't try to
13791 expand multiple locations for each sal, given than SALS
13792 already should contain all sals for MARKER_ID. */
13794 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13796 struct symtabs_and_lines expanded
;
13797 struct tracepoint
*tp
;
13798 struct cleanup
*old_chain
;
13799 struct event_location
*location
;
13801 expanded
.nelts
= 1;
13802 expanded
.sals
= &lsal
->sals
.sals
[i
];
13804 location
= copy_event_location (canonical
->location
);
13805 old_chain
= make_cleanup_delete_event_location (location
);
13807 tp
= XCNEW (struct tracepoint
);
13808 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13810 cond_string
, extra_string
,
13811 type_wanted
, disposition
,
13812 thread
, task
, ignore_count
, ops
,
13813 from_tty
, enabled
, internal
, flags
,
13814 canonical
->special_display
);
13815 /* Given that its possible to have multiple markers with
13816 the same string id, if the user is creating a static
13817 tracepoint by marker id ("strace -m MARKER_ID"), then
13818 store the sals index, so that breakpoint_re_set can
13819 try to match up which of the newly found markers
13820 corresponds to this one */
13821 tp
->static_trace_marker_id_idx
= i
;
13823 install_breakpoint (internal
, &tp
->base
, 0);
13825 discard_cleanups (old_chain
);
13830 strace_marker_decode_location (struct breakpoint
*b
,
13831 const struct event_location
*location
,
13832 struct program_space
*search_pspace
,
13833 struct symtabs_and_lines
*sals
)
13835 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13836 const char *s
= get_linespec_location (location
);
13838 *sals
= decode_static_tracepoint_spec (&s
);
13839 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13841 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13845 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13848 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13851 strace_marker_p (struct breakpoint
*b
)
13853 return b
->ops
== &strace_marker_breakpoint_ops
;
13856 /* Delete a breakpoint and clean up all traces of it in the data
13860 delete_breakpoint (struct breakpoint
*bpt
)
13862 struct breakpoint
*b
;
13864 gdb_assert (bpt
!= NULL
);
13866 /* Has this bp already been deleted? This can happen because
13867 multiple lists can hold pointers to bp's. bpstat lists are
13870 One example of this happening is a watchpoint's scope bp. When
13871 the scope bp triggers, we notice that the watchpoint is out of
13872 scope, and delete it. We also delete its scope bp. But the
13873 scope bp is marked "auto-deleting", and is already on a bpstat.
13874 That bpstat is then checked for auto-deleting bp's, which are
13877 A real solution to this problem might involve reference counts in
13878 bp's, and/or giving them pointers back to their referencing
13879 bpstat's, and teaching delete_breakpoint to only free a bp's
13880 storage when no more references were extent. A cheaper bandaid
13882 if (bpt
->type
== bp_none
)
13885 /* At least avoid this stale reference until the reference counting
13886 of breakpoints gets resolved. */
13887 if (bpt
->related_breakpoint
!= bpt
)
13889 struct breakpoint
*related
;
13890 struct watchpoint
*w
;
13892 if (bpt
->type
== bp_watchpoint_scope
)
13893 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13894 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13895 w
= (struct watchpoint
*) bpt
;
13899 watchpoint_del_at_next_stop (w
);
13901 /* Unlink bpt from the bpt->related_breakpoint ring. */
13902 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13903 related
= related
->related_breakpoint
);
13904 related
->related_breakpoint
= bpt
->related_breakpoint
;
13905 bpt
->related_breakpoint
= bpt
;
13908 /* watch_command_1 creates a watchpoint but only sets its number if
13909 update_watchpoint succeeds in creating its bp_locations. If there's
13910 a problem in that process, we'll be asked to delete the half-created
13911 watchpoint. In that case, don't announce the deletion. */
13913 observer_notify_breakpoint_deleted (bpt
);
13915 if (breakpoint_chain
== bpt
)
13916 breakpoint_chain
= bpt
->next
;
13918 ALL_BREAKPOINTS (b
)
13919 if (b
->next
== bpt
)
13921 b
->next
= bpt
->next
;
13925 /* Be sure no bpstat's are pointing at the breakpoint after it's
13927 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13928 in all threads for now. Note that we cannot just remove bpstats
13929 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13930 commands are associated with the bpstat; if we remove it here,
13931 then the later call to bpstat_do_actions (&stop_bpstat); in
13932 event-top.c won't do anything, and temporary breakpoints with
13933 commands won't work. */
13935 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13937 /* Now that breakpoint is removed from breakpoint list, update the
13938 global location list. This will remove locations that used to
13939 belong to this breakpoint. Do this before freeing the breakpoint
13940 itself, since remove_breakpoint looks at location's owner. It
13941 might be better design to have location completely
13942 self-contained, but it's not the case now. */
13943 update_global_location_list (UGLL_DONT_INSERT
);
13945 bpt
->ops
->dtor (bpt
);
13946 /* On the chance that someone will soon try again to delete this
13947 same bp, we mark it as deleted before freeing its storage. */
13948 bpt
->type
= bp_none
;
13953 do_delete_breakpoint_cleanup (void *b
)
13955 delete_breakpoint ((struct breakpoint
*) b
);
13959 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13961 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13964 /* Iterator function to call a user-provided callback function once
13965 for each of B and its related breakpoints. */
13968 iterate_over_related_breakpoints (struct breakpoint
*b
,
13969 void (*function
) (struct breakpoint
*,
13973 struct breakpoint
*related
;
13978 struct breakpoint
*next
;
13980 /* FUNCTION may delete RELATED. */
13981 next
= related
->related_breakpoint
;
13983 if (next
== related
)
13985 /* RELATED is the last ring entry. */
13986 function (related
, data
);
13988 /* FUNCTION may have deleted it, so we'd never reach back to
13989 B. There's nothing left to do anyway, so just break
13994 function (related
, data
);
13998 while (related
!= b
);
14002 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14004 delete_breakpoint (b
);
14007 /* A callback for map_breakpoint_numbers that calls
14008 delete_breakpoint. */
14011 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14013 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14017 delete_command (char *arg
, int from_tty
)
14019 struct breakpoint
*b
, *b_tmp
;
14025 int breaks_to_delete
= 0;
14027 /* Delete all breakpoints if no argument. Do not delete
14028 internal breakpoints, these have to be deleted with an
14029 explicit breakpoint number argument. */
14030 ALL_BREAKPOINTS (b
)
14031 if (user_breakpoint_p (b
))
14033 breaks_to_delete
= 1;
14037 /* Ask user only if there are some breakpoints to delete. */
14039 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14041 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14042 if (user_breakpoint_p (b
))
14043 delete_breakpoint (b
);
14047 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14050 /* Return true if all locations of B bound to PSPACE are pending. If
14051 PSPACE is NULL, all locations of all program spaces are
14055 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
14057 struct bp_location
*loc
;
14059 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14060 if ((pspace
== NULL
14061 || loc
->pspace
== pspace
)
14062 && !loc
->shlib_disabled
14063 && !loc
->pspace
->executing_startup
)
14068 /* Subroutine of update_breakpoint_locations to simplify it.
14069 Return non-zero if multiple fns in list LOC have the same name.
14070 Null names are ignored. */
14073 ambiguous_names_p (struct bp_location
*loc
)
14075 struct bp_location
*l
;
14076 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14077 (int (*) (const void *,
14078 const void *)) streq
,
14079 NULL
, xcalloc
, xfree
);
14081 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14084 const char *name
= l
->function_name
;
14086 /* Allow for some names to be NULL, ignore them. */
14090 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14092 /* NOTE: We can assume slot != NULL here because xcalloc never
14096 htab_delete (htab
);
14102 htab_delete (htab
);
14106 /* When symbols change, it probably means the sources changed as well,
14107 and it might mean the static tracepoint markers are no longer at
14108 the same address or line numbers they used to be at last we
14109 checked. Losing your static tracepoints whenever you rebuild is
14110 undesirable. This function tries to resync/rematch gdb static
14111 tracepoints with the markers on the target, for static tracepoints
14112 that have not been set by marker id. Static tracepoint that have
14113 been set by marker id are reset by marker id in breakpoint_re_set.
14116 1) For a tracepoint set at a specific address, look for a marker at
14117 the old PC. If one is found there, assume to be the same marker.
14118 If the name / string id of the marker found is different from the
14119 previous known name, assume that means the user renamed the marker
14120 in the sources, and output a warning.
14122 2) For a tracepoint set at a given line number, look for a marker
14123 at the new address of the old line number. If one is found there,
14124 assume to be the same marker. If the name / string id of the
14125 marker found is different from the previous known name, assume that
14126 means the user renamed the marker in the sources, and output a
14129 3) If a marker is no longer found at the same address or line, it
14130 may mean the marker no longer exists. But it may also just mean
14131 the code changed a bit. Maybe the user added a few lines of code
14132 that made the marker move up or down (in line number terms). Ask
14133 the target for info about the marker with the string id as we knew
14134 it. If found, update line number and address in the matching
14135 static tracepoint. This will get confused if there's more than one
14136 marker with the same ID (possible in UST, although unadvised
14137 precisely because it confuses tools). */
14139 static struct symtab_and_line
14140 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14142 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14143 struct static_tracepoint_marker marker
;
14148 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14150 if (target_static_tracepoint_marker_at (pc
, &marker
))
14152 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14153 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14155 tp
->static_trace_marker_id
, marker
.str_id
);
14157 xfree (tp
->static_trace_marker_id
);
14158 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14159 release_static_tracepoint_marker (&marker
);
14164 /* Old marker wasn't found on target at lineno. Try looking it up
14166 if (!sal
.explicit_pc
14168 && sal
.symtab
!= NULL
14169 && tp
->static_trace_marker_id
!= NULL
)
14171 VEC(static_tracepoint_marker_p
) *markers
;
14174 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14176 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14178 struct symtab_and_line sal2
;
14179 struct symbol
*sym
;
14180 struct static_tracepoint_marker
*tpmarker
;
14181 struct ui_out
*uiout
= current_uiout
;
14182 struct explicit_location explicit_loc
;
14184 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14186 xfree (tp
->static_trace_marker_id
);
14187 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14189 warning (_("marker for static tracepoint %d (%s) not "
14190 "found at previous line number"),
14191 b
->number
, tp
->static_trace_marker_id
);
14195 sal2
.pc
= tpmarker
->address
;
14197 sal2
= find_pc_line (tpmarker
->address
, 0);
14198 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14199 ui_out_text (uiout
, "Now in ");
14202 ui_out_field_string (uiout
, "func",
14203 SYMBOL_PRINT_NAME (sym
));
14204 ui_out_text (uiout
, " at ");
14206 ui_out_field_string (uiout
, "file",
14207 symtab_to_filename_for_display (sal2
.symtab
));
14208 ui_out_text (uiout
, ":");
14210 if (ui_out_is_mi_like_p (uiout
))
14212 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14214 ui_out_field_string (uiout
, "fullname", fullname
);
14217 ui_out_field_int (uiout
, "line", sal2
.line
);
14218 ui_out_text (uiout
, "\n");
14220 b
->loc
->line_number
= sal2
.line
;
14221 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14223 delete_event_location (b
->location
);
14224 initialize_explicit_location (&explicit_loc
);
14225 explicit_loc
.source_filename
14226 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14227 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14228 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14229 b
->location
= new_explicit_location (&explicit_loc
);
14231 /* Might be nice to check if function changed, and warn if
14234 release_static_tracepoint_marker (tpmarker
);
14240 /* Returns 1 iff locations A and B are sufficiently same that
14241 we don't need to report breakpoint as changed. */
14244 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14248 if (a
->address
!= b
->address
)
14251 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14254 if (a
->enabled
!= b
->enabled
)
14261 if ((a
== NULL
) != (b
== NULL
))
14267 /* Split all locations of B that are bound to PSPACE out of B's
14268 location list to a separate list and return that list's head. If
14269 PSPACE is NULL, hoist out all locations of B. */
14271 static struct bp_location
*
14272 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14274 struct bp_location head
;
14275 struct bp_location
*i
= b
->loc
;
14276 struct bp_location
**i_link
= &b
->loc
;
14277 struct bp_location
*hoisted
= &head
;
14279 if (pspace
== NULL
)
14290 if (i
->pspace
== pspace
)
14305 /* Create new breakpoint locations for B (a hardware or software
14306 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14307 zero, then B is a ranged breakpoint. Only recreates locations for
14308 FILTER_PSPACE. Locations of other program spaces are left
14312 update_breakpoint_locations (struct breakpoint
*b
,
14313 struct program_space
*filter_pspace
,
14314 struct symtabs_and_lines sals
,
14315 struct symtabs_and_lines sals_end
)
14318 struct bp_location
*existing_locations
;
14320 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14322 /* Ranged breakpoints have only one start location and one end
14324 b
->enable_state
= bp_disabled
;
14325 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14326 "multiple locations found\n"),
14331 /* If there's no new locations, and all existing locations are
14332 pending, don't do anything. This optimizes the common case where
14333 all locations are in the same shared library, that was unloaded.
14334 We'd like to retain the location, so that when the library is
14335 loaded again, we don't loose the enabled/disabled status of the
14336 individual locations. */
14337 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14340 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14342 for (i
= 0; i
< sals
.nelts
; ++i
)
14344 struct bp_location
*new_loc
;
14346 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14348 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14350 /* Reparse conditions, they might contain references to the
14352 if (b
->cond_string
!= NULL
)
14356 s
= b
->cond_string
;
14359 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14360 block_for_pc (sals
.sals
[i
].pc
),
14363 CATCH (e
, RETURN_MASK_ERROR
)
14365 warning (_("failed to reevaluate condition "
14366 "for breakpoint %d: %s"),
14367 b
->number
, e
.message
);
14368 new_loc
->enabled
= 0;
14373 if (sals_end
.nelts
)
14375 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14377 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14381 /* If possible, carry over 'disable' status from existing
14384 struct bp_location
*e
= existing_locations
;
14385 /* If there are multiple breakpoints with the same function name,
14386 e.g. for inline functions, comparing function names won't work.
14387 Instead compare pc addresses; this is just a heuristic as things
14388 may have moved, but in practice it gives the correct answer
14389 often enough until a better solution is found. */
14390 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14392 for (; e
; e
= e
->next
)
14394 if (!e
->enabled
&& e
->function_name
)
14396 struct bp_location
*l
= b
->loc
;
14397 if (have_ambiguous_names
)
14399 for (; l
; l
= l
->next
)
14400 if (breakpoint_locations_match (e
, l
))
14408 for (; l
; l
= l
->next
)
14409 if (l
->function_name
14410 && strcmp (e
->function_name
, l
->function_name
) == 0)
14420 if (!locations_are_equal (existing_locations
, b
->loc
))
14421 observer_notify_breakpoint_modified (b
);
14424 /* Find the SaL locations corresponding to the given LOCATION.
14425 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14427 static struct symtabs_and_lines
14428 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14429 struct program_space
*search_pspace
, int *found
)
14431 struct symtabs_and_lines sals
= {0};
14432 struct gdb_exception exception
= exception_none
;
14434 gdb_assert (b
->ops
!= NULL
);
14438 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14440 CATCH (e
, RETURN_MASK_ERROR
)
14442 int not_found_and_ok
= 0;
14446 /* For pending breakpoints, it's expected that parsing will
14447 fail until the right shared library is loaded. User has
14448 already told to create pending breakpoints and don't need
14449 extra messages. If breakpoint is in bp_shlib_disabled
14450 state, then user already saw the message about that
14451 breakpoint being disabled, and don't want to see more
14453 if (e
.error
== NOT_FOUND_ERROR
14454 && (b
->condition_not_parsed
14456 && search_pspace
!= NULL
14457 && b
->loc
->pspace
!= search_pspace
)
14458 || (b
->loc
&& b
->loc
->shlib_disabled
)
14459 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14460 || b
->enable_state
== bp_disabled
))
14461 not_found_and_ok
= 1;
14463 if (!not_found_and_ok
)
14465 /* We surely don't want to warn about the same breakpoint
14466 10 times. One solution, implemented here, is disable
14467 the breakpoint on error. Another solution would be to
14468 have separate 'warning emitted' flag. Since this
14469 happens only when a binary has changed, I don't know
14470 which approach is better. */
14471 b
->enable_state
= bp_disabled
;
14472 throw_exception (e
);
14477 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14481 for (i
= 0; i
< sals
.nelts
; ++i
)
14482 resolve_sal_pc (&sals
.sals
[i
]);
14483 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14485 char *cond_string
, *extra_string
;
14488 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14489 &cond_string
, &thread
, &task
,
14491 gdb_assert (b
->cond_string
== NULL
);
14493 b
->cond_string
= cond_string
;
14494 b
->thread
= thread
;
14498 xfree (b
->extra_string
);
14499 b
->extra_string
= extra_string
;
14501 b
->condition_not_parsed
= 0;
14504 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14505 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14515 /* The default re_set method, for typical hardware or software
14516 breakpoints. Reevaluate the breakpoint and recreate its
14520 breakpoint_re_set_default (struct breakpoint
*b
)
14523 struct symtabs_and_lines sals
, sals_end
;
14524 struct symtabs_and_lines expanded
= {0};
14525 struct symtabs_and_lines expanded_end
= {0};
14526 struct program_space
*filter_pspace
= current_program_space
;
14528 sals
= location_to_sals (b
, b
->location
, filter_pspace
, &found
);
14531 make_cleanup (xfree
, sals
.sals
);
14535 if (b
->location_range_end
!= NULL
)
14537 sals_end
= location_to_sals (b
, b
->location_range_end
,
14538 filter_pspace
, &found
);
14541 make_cleanup (xfree
, sals_end
.sals
);
14542 expanded_end
= sals_end
;
14546 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14549 /* Default method for creating SALs from an address string. It basically
14550 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14553 create_sals_from_location_default (const struct event_location
*location
,
14554 struct linespec_result
*canonical
,
14555 enum bptype type_wanted
)
14557 parse_breakpoint_sals (location
, canonical
);
14560 /* Call create_breakpoints_sal for the given arguments. This is the default
14561 function for the `create_breakpoints_sal' method of
14565 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14566 struct linespec_result
*canonical
,
14568 char *extra_string
,
14569 enum bptype type_wanted
,
14570 enum bpdisp disposition
,
14572 int task
, int ignore_count
,
14573 const struct breakpoint_ops
*ops
,
14574 int from_tty
, int enabled
,
14575 int internal
, unsigned flags
)
14577 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14579 type_wanted
, disposition
,
14580 thread
, task
, ignore_count
, ops
, from_tty
,
14581 enabled
, internal
, flags
);
14584 /* Decode the line represented by S by calling decode_line_full. This is the
14585 default function for the `decode_location' method of breakpoint_ops. */
14588 decode_location_default (struct breakpoint
*b
,
14589 const struct event_location
*location
,
14590 struct program_space
*search_pspace
,
14591 struct symtabs_and_lines
*sals
)
14593 struct linespec_result canonical
;
14595 init_linespec_result (&canonical
);
14596 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14597 (struct symtab
*) NULL
, 0,
14598 &canonical
, multiple_symbols_all
,
14601 /* We should get 0 or 1 resulting SALs. */
14602 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14604 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14606 struct linespec_sals
*lsal
;
14608 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14609 *sals
= lsal
->sals
;
14610 /* Arrange it so the destructor does not free the
14612 lsal
->sals
.sals
= NULL
;
14615 destroy_linespec_result (&canonical
);
14618 /* Prepare the global context for a re-set of breakpoint B. */
14620 static struct cleanup
*
14621 prepare_re_set_context (struct breakpoint
*b
)
14623 input_radix
= b
->input_radix
;
14624 set_language (b
->language
);
14626 return make_cleanup (null_cleanup
, NULL
);
14629 /* Reset a breakpoint given it's struct breakpoint * BINT.
14630 The value we return ends up being the return value from catch_errors.
14631 Unused in this case. */
14634 breakpoint_re_set_one (void *bint
)
14636 /* Get past catch_errs. */
14637 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14638 struct cleanup
*cleanups
;
14640 cleanups
= prepare_re_set_context (b
);
14641 b
->ops
->re_set (b
);
14642 do_cleanups (cleanups
);
14646 /* Re-set breakpoint locations for the current program space.
14647 Locations bound to other program spaces are left untouched. */
14650 breakpoint_re_set (void)
14652 struct breakpoint
*b
, *b_tmp
;
14653 enum language save_language
;
14654 int save_input_radix
;
14655 struct cleanup
*old_chain
;
14657 save_language
= current_language
->la_language
;
14658 save_input_radix
= input_radix
;
14659 old_chain
= save_current_space_and_thread ();
14661 /* Note: we must not try to insert locations until after all
14662 breakpoints have been re-set. Otherwise, e.g., when re-setting
14663 breakpoint 1, we'd insert the locations of breakpoint 2, which
14664 hadn't been re-set yet, and thus may have stale locations. */
14666 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14668 /* Format possible error msg. */
14669 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14671 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14672 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14673 do_cleanups (cleanups
);
14675 set_language (save_language
);
14676 input_radix
= save_input_radix
;
14678 jit_breakpoint_re_set ();
14680 do_cleanups (old_chain
);
14682 create_overlay_event_breakpoint ();
14683 create_longjmp_master_breakpoint ();
14684 create_std_terminate_master_breakpoint ();
14685 create_exception_master_breakpoint ();
14687 /* Now we can insert. */
14688 update_global_location_list (UGLL_MAY_INSERT
);
14691 /* Reset the thread number of this breakpoint:
14693 - If the breakpoint is for all threads, leave it as-is.
14694 - Else, reset it to the current thread for inferior_ptid. */
14696 breakpoint_re_set_thread (struct breakpoint
*b
)
14698 if (b
->thread
!= -1)
14700 if (in_thread_list (inferior_ptid
))
14701 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14703 /* We're being called after following a fork. The new fork is
14704 selected as current, and unless this was a vfork will have a
14705 different program space from the original thread. Reset that
14707 b
->loc
->pspace
= current_program_space
;
14711 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14712 If from_tty is nonzero, it prints a message to that effect,
14713 which ends with a period (no newline). */
14716 set_ignore_count (int bptnum
, int count
, int from_tty
)
14718 struct breakpoint
*b
;
14723 ALL_BREAKPOINTS (b
)
14724 if (b
->number
== bptnum
)
14726 if (is_tracepoint (b
))
14728 if (from_tty
&& count
!= 0)
14729 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14734 b
->ignore_count
= count
;
14738 printf_filtered (_("Will stop next time "
14739 "breakpoint %d is reached."),
14741 else if (count
== 1)
14742 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14745 printf_filtered (_("Will ignore next %d "
14746 "crossings of breakpoint %d."),
14749 observer_notify_breakpoint_modified (b
);
14753 error (_("No breakpoint number %d."), bptnum
);
14756 /* Command to set ignore-count of breakpoint N to COUNT. */
14759 ignore_command (char *args
, int from_tty
)
14765 error_no_arg (_("a breakpoint number"));
14767 num
= get_number (&p
);
14769 error (_("bad breakpoint number: '%s'"), args
);
14771 error (_("Second argument (specified ignore-count) is missing."));
14773 set_ignore_count (num
,
14774 longest_to_int (value_as_long (parse_and_eval (p
))),
14777 printf_filtered ("\n");
14780 /* Call FUNCTION on each of the breakpoints
14781 whose numbers are given in ARGS. */
14784 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14789 struct breakpoint
*b
, *tmp
;
14791 if (args
== 0 || *args
== '\0')
14792 error_no_arg (_("one or more breakpoint numbers"));
14794 number_or_range_parser
parser (args
);
14796 while (!parser
.finished ())
14798 const char *p
= parser
.cur_tok ();
14799 bool match
= false;
14801 num
= parser
.get_number ();
14804 warning (_("bad breakpoint number at or near '%s'"), p
);
14808 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14809 if (b
->number
== num
)
14812 function (b
, data
);
14816 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14821 static struct bp_location
*
14822 find_location_by_number (char *number
)
14824 char *dot
= strchr (number
, '.');
14828 struct breakpoint
*b
;
14829 struct bp_location
*loc
;
14834 bp_num
= get_number (&p1
);
14836 error (_("Bad breakpoint number '%s'"), number
);
14838 ALL_BREAKPOINTS (b
)
14839 if (b
->number
== bp_num
)
14844 if (!b
|| b
->number
!= bp_num
)
14845 error (_("Bad breakpoint number '%s'"), number
);
14848 loc_num
= get_number (&p1
);
14850 error (_("Bad breakpoint location number '%s'"), number
);
14854 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14857 error (_("Bad breakpoint location number '%s'"), dot
+1);
14863 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14864 If from_tty is nonzero, it prints a message to that effect,
14865 which ends with a period (no newline). */
14868 disable_breakpoint (struct breakpoint
*bpt
)
14870 /* Never disable a watchpoint scope breakpoint; we want to
14871 hit them when we leave scope so we can delete both the
14872 watchpoint and its scope breakpoint at that time. */
14873 if (bpt
->type
== bp_watchpoint_scope
)
14876 bpt
->enable_state
= bp_disabled
;
14878 /* Mark breakpoint locations modified. */
14879 mark_breakpoint_modified (bpt
);
14881 if (target_supports_enable_disable_tracepoint ()
14882 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14884 struct bp_location
*location
;
14886 for (location
= bpt
->loc
; location
; location
= location
->next
)
14887 target_disable_tracepoint (location
);
14890 update_global_location_list (UGLL_DONT_INSERT
);
14892 observer_notify_breakpoint_modified (bpt
);
14895 /* A callback for iterate_over_related_breakpoints. */
14898 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14900 disable_breakpoint (b
);
14903 /* A callback for map_breakpoint_numbers that calls
14904 disable_breakpoint. */
14907 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14909 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14913 disable_command (char *args
, int from_tty
)
14917 struct breakpoint
*bpt
;
14919 ALL_BREAKPOINTS (bpt
)
14920 if (user_breakpoint_p (bpt
))
14921 disable_breakpoint (bpt
);
14925 char *num
= extract_arg (&args
);
14929 if (strchr (num
, '.'))
14931 struct bp_location
*loc
= find_location_by_number (num
);
14938 mark_breakpoint_location_modified (loc
);
14940 if (target_supports_enable_disable_tracepoint ()
14941 && current_trace_status ()->running
&& loc
->owner
14942 && is_tracepoint (loc
->owner
))
14943 target_disable_tracepoint (loc
);
14945 update_global_location_list (UGLL_DONT_INSERT
);
14948 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14949 num
= extract_arg (&args
);
14955 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14958 int target_resources_ok
;
14960 if (bpt
->type
== bp_hardware_breakpoint
)
14963 i
= hw_breakpoint_used_count ();
14964 target_resources_ok
=
14965 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14967 if (target_resources_ok
== 0)
14968 error (_("No hardware breakpoint support in the target."));
14969 else if (target_resources_ok
< 0)
14970 error (_("Hardware breakpoints used exceeds limit."));
14973 if (is_watchpoint (bpt
))
14975 /* Initialize it just to avoid a GCC false warning. */
14976 enum enable_state orig_enable_state
= bp_disabled
;
14980 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14982 orig_enable_state
= bpt
->enable_state
;
14983 bpt
->enable_state
= bp_enabled
;
14984 update_watchpoint (w
, 1 /* reparse */);
14986 CATCH (e
, RETURN_MASK_ALL
)
14988 bpt
->enable_state
= orig_enable_state
;
14989 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14996 bpt
->enable_state
= bp_enabled
;
14998 /* Mark breakpoint locations modified. */
14999 mark_breakpoint_modified (bpt
);
15001 if (target_supports_enable_disable_tracepoint ()
15002 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15004 struct bp_location
*location
;
15006 for (location
= bpt
->loc
; location
; location
= location
->next
)
15007 target_enable_tracepoint (location
);
15010 bpt
->disposition
= disposition
;
15011 bpt
->enable_count
= count
;
15012 update_global_location_list (UGLL_MAY_INSERT
);
15014 observer_notify_breakpoint_modified (bpt
);
15019 enable_breakpoint (struct breakpoint
*bpt
)
15021 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15025 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15027 enable_breakpoint (bpt
);
15030 /* A callback for map_breakpoint_numbers that calls
15031 enable_breakpoint. */
15034 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15036 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15039 /* The enable command enables the specified breakpoints (or all defined
15040 breakpoints) so they once again become (or continue to be) effective
15041 in stopping the inferior. */
15044 enable_command (char *args
, int from_tty
)
15048 struct breakpoint
*bpt
;
15050 ALL_BREAKPOINTS (bpt
)
15051 if (user_breakpoint_p (bpt
))
15052 enable_breakpoint (bpt
);
15056 char *num
= extract_arg (&args
);
15060 if (strchr (num
, '.'))
15062 struct bp_location
*loc
= find_location_by_number (num
);
15069 mark_breakpoint_location_modified (loc
);
15071 if (target_supports_enable_disable_tracepoint ()
15072 && current_trace_status ()->running
&& loc
->owner
15073 && is_tracepoint (loc
->owner
))
15074 target_enable_tracepoint (loc
);
15076 update_global_location_list (UGLL_MAY_INSERT
);
15079 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15080 num
= extract_arg (&args
);
15085 /* This struct packages up disposition data for application to multiple
15095 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15097 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15099 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15103 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15105 struct disp_data disp
= { disp_disable
, 1 };
15107 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15111 enable_once_command (char *args
, int from_tty
)
15113 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15117 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15119 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15121 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15125 enable_count_command (char *args
, int from_tty
)
15130 error_no_arg (_("hit count"));
15132 count
= get_number (&args
);
15134 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15138 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15140 struct disp_data disp
= { disp_del
, 1 };
15142 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15146 enable_delete_command (char *args
, int from_tty
)
15148 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15152 set_breakpoint_cmd (char *args
, int from_tty
)
15157 show_breakpoint_cmd (char *args
, int from_tty
)
15161 /* Invalidate last known value of any hardware watchpoint if
15162 the memory which that value represents has been written to by
15166 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15167 CORE_ADDR addr
, ssize_t len
,
15168 const bfd_byte
*data
)
15170 struct breakpoint
*bp
;
15172 ALL_BREAKPOINTS (bp
)
15173 if (bp
->enable_state
== bp_enabled
15174 && bp
->type
== bp_hardware_watchpoint
)
15176 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15178 if (wp
->val_valid
&& wp
->val
)
15180 struct bp_location
*loc
;
15182 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15183 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15184 && loc
->address
+ loc
->length
> addr
15185 && addr
+ len
> loc
->address
)
15187 value_free (wp
->val
);
15195 /* Create and insert a breakpoint for software single step. */
15198 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15199 struct address_space
*aspace
,
15202 struct thread_info
*tp
= inferior_thread ();
15203 struct symtab_and_line sal
;
15204 CORE_ADDR pc
= next_pc
;
15206 if (tp
->control
.single_step_breakpoints
== NULL
)
15208 tp
->control
.single_step_breakpoints
15209 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15212 sal
= find_pc_line (pc
, 0);
15214 sal
.section
= find_pc_overlay (pc
);
15215 sal
.explicit_pc
= 1;
15216 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15218 update_global_location_list (UGLL_INSERT
);
15221 /* See breakpoint.h. */
15224 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15225 struct address_space
*aspace
,
15228 struct bp_location
*loc
;
15230 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15232 && breakpoint_location_address_match (loc
, aspace
, pc
))
15238 /* Check whether a software single-step breakpoint is inserted at
15242 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15245 struct breakpoint
*bpt
;
15247 ALL_BREAKPOINTS (bpt
)
15249 if (bpt
->type
== bp_single_step
15250 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15256 /* Tracepoint-specific operations. */
15258 /* Set tracepoint count to NUM. */
15260 set_tracepoint_count (int num
)
15262 tracepoint_count
= num
;
15263 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15267 trace_command (char *arg
, int from_tty
)
15269 struct breakpoint_ops
*ops
;
15270 struct event_location
*location
;
15271 struct cleanup
*back_to
;
15273 location
= string_to_event_location (&arg
, current_language
);
15274 back_to
= make_cleanup_delete_event_location (location
);
15275 if (location
!= NULL
15276 && event_location_type (location
) == PROBE_LOCATION
)
15277 ops
= &tracepoint_probe_breakpoint_ops
;
15279 ops
= &tracepoint_breakpoint_ops
;
15281 create_breakpoint (get_current_arch (),
15283 NULL
, 0, arg
, 1 /* parse arg */,
15285 bp_tracepoint
/* type_wanted */,
15286 0 /* Ignore count */,
15287 pending_break_support
,
15291 0 /* internal */, 0);
15292 do_cleanups (back_to
);
15296 ftrace_command (char *arg
, int from_tty
)
15298 struct event_location
*location
;
15299 struct cleanup
*back_to
;
15301 location
= string_to_event_location (&arg
, current_language
);
15302 back_to
= make_cleanup_delete_event_location (location
);
15303 create_breakpoint (get_current_arch (),
15305 NULL
, 0, arg
, 1 /* parse arg */,
15307 bp_fast_tracepoint
/* type_wanted */,
15308 0 /* Ignore count */,
15309 pending_break_support
,
15310 &tracepoint_breakpoint_ops
,
15313 0 /* internal */, 0);
15314 do_cleanups (back_to
);
15317 /* strace command implementation. Creates a static tracepoint. */
15320 strace_command (char *arg
, int from_tty
)
15322 struct breakpoint_ops
*ops
;
15323 struct event_location
*location
;
15324 struct cleanup
*back_to
;
15326 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15327 or with a normal static tracepoint. */
15328 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15330 ops
= &strace_marker_breakpoint_ops
;
15331 location
= new_linespec_location (&arg
);
15335 ops
= &tracepoint_breakpoint_ops
;
15336 location
= string_to_event_location (&arg
, current_language
);
15339 back_to
= make_cleanup_delete_event_location (location
);
15340 create_breakpoint (get_current_arch (),
15342 NULL
, 0, arg
, 1 /* parse arg */,
15344 bp_static_tracepoint
/* type_wanted */,
15345 0 /* Ignore count */,
15346 pending_break_support
,
15350 0 /* internal */, 0);
15351 do_cleanups (back_to
);
15354 /* Set up a fake reader function that gets command lines from a linked
15355 list that was acquired during tracepoint uploading. */
15357 static struct uploaded_tp
*this_utp
;
15358 static int next_cmd
;
15361 read_uploaded_action (void)
15365 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15372 /* Given information about a tracepoint as recorded on a target (which
15373 can be either a live system or a trace file), attempt to create an
15374 equivalent GDB tracepoint. This is not a reliable process, since
15375 the target does not necessarily have all the information used when
15376 the tracepoint was originally defined. */
15378 struct tracepoint
*
15379 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15381 char *addr_str
, small_buf
[100];
15382 struct tracepoint
*tp
;
15383 struct event_location
*location
;
15384 struct cleanup
*cleanup
;
15386 if (utp
->at_string
)
15387 addr_str
= utp
->at_string
;
15390 /* In the absence of a source location, fall back to raw
15391 address. Since there is no way to confirm that the address
15392 means the same thing as when the trace was started, warn the
15394 warning (_("Uploaded tracepoint %d has no "
15395 "source location, using raw address"),
15397 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15398 addr_str
= small_buf
;
15401 /* There's not much we can do with a sequence of bytecodes. */
15402 if (utp
->cond
&& !utp
->cond_string
)
15403 warning (_("Uploaded tracepoint %d condition "
15404 "has no source form, ignoring it"),
15407 location
= string_to_event_location (&addr_str
, current_language
);
15408 cleanup
= make_cleanup_delete_event_location (location
);
15409 if (!create_breakpoint (get_current_arch (),
15411 utp
->cond_string
, -1, addr_str
,
15412 0 /* parse cond/thread */,
15414 utp
->type
/* type_wanted */,
15415 0 /* Ignore count */,
15416 pending_break_support
,
15417 &tracepoint_breakpoint_ops
,
15419 utp
->enabled
/* enabled */,
15421 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15423 do_cleanups (cleanup
);
15427 do_cleanups (cleanup
);
15429 /* Get the tracepoint we just created. */
15430 tp
= get_tracepoint (tracepoint_count
);
15431 gdb_assert (tp
!= NULL
);
15435 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15438 trace_pass_command (small_buf
, 0);
15441 /* If we have uploaded versions of the original commands, set up a
15442 special-purpose "reader" function and call the usual command line
15443 reader, then pass the result to the breakpoint command-setting
15445 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15447 struct command_line
*cmd_list
;
15452 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15454 breakpoint_set_commands (&tp
->base
, cmd_list
);
15456 else if (!VEC_empty (char_ptr
, utp
->actions
)
15457 || !VEC_empty (char_ptr
, utp
->step_actions
))
15458 warning (_("Uploaded tracepoint %d actions "
15459 "have no source form, ignoring them"),
15462 /* Copy any status information that might be available. */
15463 tp
->base
.hit_count
= utp
->hit_count
;
15464 tp
->traceframe_usage
= utp
->traceframe_usage
;
15469 /* Print information on tracepoint number TPNUM_EXP, or all if
15473 tracepoints_info (char *args
, int from_tty
)
15475 struct ui_out
*uiout
= current_uiout
;
15478 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15480 if (num_printed
== 0)
15482 if (args
== NULL
|| *args
== '\0')
15483 ui_out_message (uiout
, 0, "No tracepoints.\n");
15485 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15488 default_collect_info ();
15491 /* The 'enable trace' command enables tracepoints.
15492 Not supported by all targets. */
15494 enable_trace_command (char *args
, int from_tty
)
15496 enable_command (args
, from_tty
);
15499 /* The 'disable trace' command disables tracepoints.
15500 Not supported by all targets. */
15502 disable_trace_command (char *args
, int from_tty
)
15504 disable_command (args
, from_tty
);
15507 /* Remove a tracepoint (or all if no argument). */
15509 delete_trace_command (char *arg
, int from_tty
)
15511 struct breakpoint
*b
, *b_tmp
;
15517 int breaks_to_delete
= 0;
15519 /* Delete all breakpoints if no argument.
15520 Do not delete internal or call-dummy breakpoints, these
15521 have to be deleted with an explicit breakpoint number
15523 ALL_TRACEPOINTS (b
)
15524 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15526 breaks_to_delete
= 1;
15530 /* Ask user only if there are some breakpoints to delete. */
15532 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15534 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15535 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15536 delete_breakpoint (b
);
15540 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15543 /* Helper function for trace_pass_command. */
15546 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15548 tp
->pass_count
= count
;
15549 observer_notify_breakpoint_modified (&tp
->base
);
15551 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15552 tp
->base
.number
, count
);
15555 /* Set passcount for tracepoint.
15557 First command argument is passcount, second is tracepoint number.
15558 If tracepoint number omitted, apply to most recently defined.
15559 Also accepts special argument "all". */
15562 trace_pass_command (char *args
, int from_tty
)
15564 struct tracepoint
*t1
;
15565 unsigned int count
;
15567 if (args
== 0 || *args
== 0)
15568 error (_("passcount command requires an "
15569 "argument (count + optional TP num)"));
15571 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15573 args
= skip_spaces (args
);
15574 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15576 struct breakpoint
*b
;
15578 args
+= 3; /* Skip special argument "all". */
15580 error (_("Junk at end of arguments."));
15582 ALL_TRACEPOINTS (b
)
15584 t1
= (struct tracepoint
*) b
;
15585 trace_pass_set_count (t1
, count
, from_tty
);
15588 else if (*args
== '\0')
15590 t1
= get_tracepoint_by_number (&args
, NULL
);
15592 trace_pass_set_count (t1
, count
, from_tty
);
15596 number_or_range_parser
parser (args
);
15597 while (!parser
.finished ())
15599 t1
= get_tracepoint_by_number (&args
, &parser
);
15601 trace_pass_set_count (t1
, count
, from_tty
);
15606 struct tracepoint
*
15607 get_tracepoint (int num
)
15609 struct breakpoint
*t
;
15611 ALL_TRACEPOINTS (t
)
15612 if (t
->number
== num
)
15613 return (struct tracepoint
*) t
;
15618 /* Find the tracepoint with the given target-side number (which may be
15619 different from the tracepoint number after disconnecting and
15622 struct tracepoint
*
15623 get_tracepoint_by_number_on_target (int num
)
15625 struct breakpoint
*b
;
15627 ALL_TRACEPOINTS (b
)
15629 struct tracepoint
*t
= (struct tracepoint
*) b
;
15631 if (t
->number_on_target
== num
)
15638 /* Utility: parse a tracepoint number and look it up in the list.
15639 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15640 If the argument is missing, the most recent tracepoint
15641 (tracepoint_count) is returned. */
15643 struct tracepoint
*
15644 get_tracepoint_by_number (char **arg
,
15645 number_or_range_parser
*parser
)
15647 struct breakpoint
*t
;
15649 char *instring
= arg
== NULL
? NULL
: *arg
;
15651 if (parser
!= NULL
)
15653 gdb_assert (!parser
->finished ());
15654 tpnum
= parser
->get_number ();
15656 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15657 tpnum
= tracepoint_count
;
15659 tpnum
= get_number (arg
);
15663 if (instring
&& *instring
)
15664 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15667 printf_filtered (_("No previous tracepoint\n"));
15671 ALL_TRACEPOINTS (t
)
15672 if (t
->number
== tpnum
)
15674 return (struct tracepoint
*) t
;
15677 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15682 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15684 if (b
->thread
!= -1)
15685 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15688 fprintf_unfiltered (fp
, " task %d", b
->task
);
15690 fprintf_unfiltered (fp
, "\n");
15693 /* Save information on user settable breakpoints (watchpoints, etc) to
15694 a new script file named FILENAME. If FILTER is non-NULL, call it
15695 on each breakpoint and only include the ones for which it returns
15699 save_breakpoints (char *filename
, int from_tty
,
15700 int (*filter
) (const struct breakpoint
*))
15702 struct breakpoint
*tp
;
15704 struct cleanup
*cleanup
;
15705 struct ui_file
*fp
;
15706 int extra_trace_bits
= 0;
15708 if (filename
== 0 || *filename
== 0)
15709 error (_("Argument required (file name in which to save)"));
15711 /* See if we have anything to save. */
15712 ALL_BREAKPOINTS (tp
)
15714 /* Skip internal and momentary breakpoints. */
15715 if (!user_breakpoint_p (tp
))
15718 /* If we have a filter, only save the breakpoints it accepts. */
15719 if (filter
&& !filter (tp
))
15724 if (is_tracepoint (tp
))
15726 extra_trace_bits
= 1;
15728 /* We can stop searching. */
15735 warning (_("Nothing to save."));
15739 filename
= tilde_expand (filename
);
15740 cleanup
= make_cleanup (xfree
, filename
);
15741 fp
= gdb_fopen (filename
, "w");
15743 error (_("Unable to open file '%s' for saving (%s)"),
15744 filename
, safe_strerror (errno
));
15745 make_cleanup_ui_file_delete (fp
);
15747 if (extra_trace_bits
)
15748 save_trace_state_variables (fp
);
15750 ALL_BREAKPOINTS (tp
)
15752 /* Skip internal and momentary breakpoints. */
15753 if (!user_breakpoint_p (tp
))
15756 /* If we have a filter, only save the breakpoints it accepts. */
15757 if (filter
&& !filter (tp
))
15760 tp
->ops
->print_recreate (tp
, fp
);
15762 /* Note, we can't rely on tp->number for anything, as we can't
15763 assume the recreated breakpoint numbers will match. Use $bpnum
15766 if (tp
->cond_string
)
15767 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15769 if (tp
->ignore_count
)
15770 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15772 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15774 fprintf_unfiltered (fp
, " commands\n");
15776 ui_out_redirect (current_uiout
, fp
);
15779 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15781 CATCH (ex
, RETURN_MASK_ALL
)
15783 ui_out_redirect (current_uiout
, NULL
);
15784 throw_exception (ex
);
15788 ui_out_redirect (current_uiout
, NULL
);
15789 fprintf_unfiltered (fp
, " end\n");
15792 if (tp
->enable_state
== bp_disabled
)
15793 fprintf_unfiltered (fp
, "disable $bpnum\n");
15795 /* If this is a multi-location breakpoint, check if the locations
15796 should be individually disabled. Watchpoint locations are
15797 special, and not user visible. */
15798 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15800 struct bp_location
*loc
;
15803 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15805 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15809 if (extra_trace_bits
&& *default_collect
)
15810 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15813 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15814 do_cleanups (cleanup
);
15817 /* The `save breakpoints' command. */
15820 save_breakpoints_command (char *args
, int from_tty
)
15822 save_breakpoints (args
, from_tty
, NULL
);
15825 /* The `save tracepoints' command. */
15828 save_tracepoints_command (char *args
, int from_tty
)
15830 save_breakpoints (args
, from_tty
, is_tracepoint
);
15833 /* Create a vector of all tracepoints. */
15835 VEC(breakpoint_p
) *
15836 all_tracepoints (void)
15838 VEC(breakpoint_p
) *tp_vec
= 0;
15839 struct breakpoint
*tp
;
15841 ALL_TRACEPOINTS (tp
)
15843 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15850 /* This help string is used to consolidate all the help string for specifying
15851 locations used by several commands. */
15853 #define LOCATION_HELP_STRING \
15854 "Linespecs are colon-separated lists of location parameters, such as\n\
15855 source filename, function name, label name, and line number.\n\
15856 Example: To specify the start of a label named \"the_top\" in the\n\
15857 function \"fact\" in the file \"factorial.c\", use\n\
15858 \"factorial.c:fact:the_top\".\n\
15860 Address locations begin with \"*\" and specify an exact address in the\n\
15861 program. Example: To specify the fourth byte past the start function\n\
15862 \"main\", use \"*main + 4\".\n\
15864 Explicit locations are similar to linespecs but use an option/argument\n\
15865 syntax to specify location parameters.\n\
15866 Example: To specify the start of the label named \"the_top\" in the\n\
15867 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15868 -function fact -label the_top\".\n"
15870 /* This help string is used for the break, hbreak, tbreak and thbreak
15871 commands. It is defined as a macro to prevent duplication.
15872 COMMAND should be a string constant containing the name of the
15875 #define BREAK_ARGS_HELP(command) \
15876 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15877 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15878 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15879 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15880 `-probe-dtrace' (for a DTrace probe).\n\
15881 LOCATION may be a linespec, address, or explicit location as described\n\
15884 With no LOCATION, uses current execution address of the selected\n\
15885 stack frame. This is useful for breaking on return to a stack frame.\n\
15887 THREADNUM is the number from \"info threads\".\n\
15888 CONDITION is a boolean expression.\n\
15889 \n" LOCATION_HELP_STRING "\n\
15890 Multiple breakpoints at one place are permitted, and useful if their\n\
15891 conditions are different.\n\
15893 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15895 /* List of subcommands for "catch". */
15896 static struct cmd_list_element
*catch_cmdlist
;
15898 /* List of subcommands for "tcatch". */
15899 static struct cmd_list_element
*tcatch_cmdlist
;
15902 add_catch_command (char *name
, char *docstring
,
15903 cmd_sfunc_ftype
*sfunc
,
15904 completer_ftype
*completer
,
15905 void *user_data_catch
,
15906 void *user_data_tcatch
)
15908 struct cmd_list_element
*command
;
15910 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15912 set_cmd_sfunc (command
, sfunc
);
15913 set_cmd_context (command
, user_data_catch
);
15914 set_cmd_completer (command
, completer
);
15916 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15918 set_cmd_sfunc (command
, sfunc
);
15919 set_cmd_context (command
, user_data_tcatch
);
15920 set_cmd_completer (command
, completer
);
15924 save_command (char *arg
, int from_tty
)
15926 printf_unfiltered (_("\"save\" must be followed by "
15927 "the name of a save subcommand.\n"));
15928 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15931 struct breakpoint
*
15932 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15935 struct breakpoint
*b
, *b_tmp
;
15937 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15939 if ((*callback
) (b
, data
))
15946 /* Zero if any of the breakpoint's locations could be a location where
15947 functions have been inlined, nonzero otherwise. */
15950 is_non_inline_function (struct breakpoint
*b
)
15952 /* The shared library event breakpoint is set on the address of a
15953 non-inline function. */
15954 if (b
->type
== bp_shlib_event
)
15960 /* Nonzero if the specified PC cannot be a location where functions
15961 have been inlined. */
15964 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15965 const struct target_waitstatus
*ws
)
15967 struct breakpoint
*b
;
15968 struct bp_location
*bl
;
15970 ALL_BREAKPOINTS (b
)
15972 if (!is_non_inline_function (b
))
15975 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15977 if (!bl
->shlib_disabled
15978 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15986 /* Remove any references to OBJFILE which is going to be freed. */
15989 breakpoint_free_objfile (struct objfile
*objfile
)
15991 struct bp_location
**locp
, *loc
;
15993 ALL_BP_LOCATIONS (loc
, locp
)
15994 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15995 loc
->symtab
= NULL
;
15999 initialize_breakpoint_ops (void)
16001 static int initialized
= 0;
16003 struct breakpoint_ops
*ops
;
16009 /* The breakpoint_ops structure to be inherit by all kinds of
16010 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16011 internal and momentary breakpoints, etc.). */
16012 ops
= &bkpt_base_breakpoint_ops
;
16013 *ops
= base_breakpoint_ops
;
16014 ops
->re_set
= bkpt_re_set
;
16015 ops
->insert_location
= bkpt_insert_location
;
16016 ops
->remove_location
= bkpt_remove_location
;
16017 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16018 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
16019 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16020 ops
->decode_location
= bkpt_decode_location
;
16022 /* The breakpoint_ops structure to be used in regular breakpoints. */
16023 ops
= &bkpt_breakpoint_ops
;
16024 *ops
= bkpt_base_breakpoint_ops
;
16025 ops
->re_set
= bkpt_re_set
;
16026 ops
->resources_needed
= bkpt_resources_needed
;
16027 ops
->print_it
= bkpt_print_it
;
16028 ops
->print_mention
= bkpt_print_mention
;
16029 ops
->print_recreate
= bkpt_print_recreate
;
16031 /* Ranged breakpoints. */
16032 ops
= &ranged_breakpoint_ops
;
16033 *ops
= bkpt_breakpoint_ops
;
16034 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16035 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16036 ops
->print_it
= print_it_ranged_breakpoint
;
16037 ops
->print_one
= print_one_ranged_breakpoint
;
16038 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16039 ops
->print_mention
= print_mention_ranged_breakpoint
;
16040 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16042 /* Internal breakpoints. */
16043 ops
= &internal_breakpoint_ops
;
16044 *ops
= bkpt_base_breakpoint_ops
;
16045 ops
->re_set
= internal_bkpt_re_set
;
16046 ops
->check_status
= internal_bkpt_check_status
;
16047 ops
->print_it
= internal_bkpt_print_it
;
16048 ops
->print_mention
= internal_bkpt_print_mention
;
16050 /* Momentary breakpoints. */
16051 ops
= &momentary_breakpoint_ops
;
16052 *ops
= bkpt_base_breakpoint_ops
;
16053 ops
->re_set
= momentary_bkpt_re_set
;
16054 ops
->check_status
= momentary_bkpt_check_status
;
16055 ops
->print_it
= momentary_bkpt_print_it
;
16056 ops
->print_mention
= momentary_bkpt_print_mention
;
16058 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16059 ops
= &longjmp_breakpoint_ops
;
16060 *ops
= momentary_breakpoint_ops
;
16061 ops
->dtor
= longjmp_bkpt_dtor
;
16063 /* Probe breakpoints. */
16064 ops
= &bkpt_probe_breakpoint_ops
;
16065 *ops
= bkpt_breakpoint_ops
;
16066 ops
->insert_location
= bkpt_probe_insert_location
;
16067 ops
->remove_location
= bkpt_probe_remove_location
;
16068 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
16069 ops
->decode_location
= bkpt_probe_decode_location
;
16072 ops
= &watchpoint_breakpoint_ops
;
16073 *ops
= base_breakpoint_ops
;
16074 ops
->dtor
= dtor_watchpoint
;
16075 ops
->re_set
= re_set_watchpoint
;
16076 ops
->insert_location
= insert_watchpoint
;
16077 ops
->remove_location
= remove_watchpoint
;
16078 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16079 ops
->check_status
= check_status_watchpoint
;
16080 ops
->resources_needed
= resources_needed_watchpoint
;
16081 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16082 ops
->print_it
= print_it_watchpoint
;
16083 ops
->print_mention
= print_mention_watchpoint
;
16084 ops
->print_recreate
= print_recreate_watchpoint
;
16085 ops
->explains_signal
= explains_signal_watchpoint
;
16087 /* Masked watchpoints. */
16088 ops
= &masked_watchpoint_breakpoint_ops
;
16089 *ops
= watchpoint_breakpoint_ops
;
16090 ops
->insert_location
= insert_masked_watchpoint
;
16091 ops
->remove_location
= remove_masked_watchpoint
;
16092 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16093 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16094 ops
->print_it
= print_it_masked_watchpoint
;
16095 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16096 ops
->print_mention
= print_mention_masked_watchpoint
;
16097 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16100 ops
= &tracepoint_breakpoint_ops
;
16101 *ops
= base_breakpoint_ops
;
16102 ops
->re_set
= tracepoint_re_set
;
16103 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16104 ops
->print_one_detail
= tracepoint_print_one_detail
;
16105 ops
->print_mention
= tracepoint_print_mention
;
16106 ops
->print_recreate
= tracepoint_print_recreate
;
16107 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
16108 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16109 ops
->decode_location
= tracepoint_decode_location
;
16111 /* Probe tracepoints. */
16112 ops
= &tracepoint_probe_breakpoint_ops
;
16113 *ops
= tracepoint_breakpoint_ops
;
16114 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
16115 ops
->decode_location
= tracepoint_probe_decode_location
;
16117 /* Static tracepoints with marker (`-m'). */
16118 ops
= &strace_marker_breakpoint_ops
;
16119 *ops
= tracepoint_breakpoint_ops
;
16120 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16121 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16122 ops
->decode_location
= strace_marker_decode_location
;
16124 /* Fork catchpoints. */
16125 ops
= &catch_fork_breakpoint_ops
;
16126 *ops
= base_breakpoint_ops
;
16127 ops
->insert_location
= insert_catch_fork
;
16128 ops
->remove_location
= remove_catch_fork
;
16129 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16130 ops
->print_it
= print_it_catch_fork
;
16131 ops
->print_one
= print_one_catch_fork
;
16132 ops
->print_mention
= print_mention_catch_fork
;
16133 ops
->print_recreate
= print_recreate_catch_fork
;
16135 /* Vfork catchpoints. */
16136 ops
= &catch_vfork_breakpoint_ops
;
16137 *ops
= base_breakpoint_ops
;
16138 ops
->insert_location
= insert_catch_vfork
;
16139 ops
->remove_location
= remove_catch_vfork
;
16140 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16141 ops
->print_it
= print_it_catch_vfork
;
16142 ops
->print_one
= print_one_catch_vfork
;
16143 ops
->print_mention
= print_mention_catch_vfork
;
16144 ops
->print_recreate
= print_recreate_catch_vfork
;
16146 /* Exec catchpoints. */
16147 ops
= &catch_exec_breakpoint_ops
;
16148 *ops
= base_breakpoint_ops
;
16149 ops
->dtor
= dtor_catch_exec
;
16150 ops
->insert_location
= insert_catch_exec
;
16151 ops
->remove_location
= remove_catch_exec
;
16152 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16153 ops
->print_it
= print_it_catch_exec
;
16154 ops
->print_one
= print_one_catch_exec
;
16155 ops
->print_mention
= print_mention_catch_exec
;
16156 ops
->print_recreate
= print_recreate_catch_exec
;
16158 /* Solib-related catchpoints. */
16159 ops
= &catch_solib_breakpoint_ops
;
16160 *ops
= base_breakpoint_ops
;
16161 ops
->dtor
= dtor_catch_solib
;
16162 ops
->insert_location
= insert_catch_solib
;
16163 ops
->remove_location
= remove_catch_solib
;
16164 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16165 ops
->check_status
= check_status_catch_solib
;
16166 ops
->print_it
= print_it_catch_solib
;
16167 ops
->print_one
= print_one_catch_solib
;
16168 ops
->print_mention
= print_mention_catch_solib
;
16169 ops
->print_recreate
= print_recreate_catch_solib
;
16171 ops
= &dprintf_breakpoint_ops
;
16172 *ops
= bkpt_base_breakpoint_ops
;
16173 ops
->re_set
= dprintf_re_set
;
16174 ops
->resources_needed
= bkpt_resources_needed
;
16175 ops
->print_it
= bkpt_print_it
;
16176 ops
->print_mention
= bkpt_print_mention
;
16177 ops
->print_recreate
= dprintf_print_recreate
;
16178 ops
->after_condition_true
= dprintf_after_condition_true
;
16179 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16182 /* Chain containing all defined "enable breakpoint" subcommands. */
16184 static struct cmd_list_element
*enablebreaklist
= NULL
;
16187 _initialize_breakpoint (void)
16189 struct cmd_list_element
*c
;
16191 initialize_breakpoint_ops ();
16193 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16194 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16195 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16197 breakpoint_objfile_key
16198 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16200 breakpoint_chain
= 0;
16201 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16202 before a breakpoint is set. */
16203 breakpoint_count
= 0;
16205 tracepoint_count
= 0;
16207 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16208 Set ignore-count of breakpoint number N to COUNT.\n\
16209 Usage is `ignore N COUNT'."));
16211 add_com ("commands", class_breakpoint
, commands_command
, _("\
16212 Set commands to be executed when a breakpoint is hit.\n\
16213 Give breakpoint number as argument after \"commands\".\n\
16214 With no argument, the targeted breakpoint is the last one set.\n\
16215 The commands themselves follow starting on the next line.\n\
16216 Type a line containing \"end\" to indicate the end of them.\n\
16217 Give \"silent\" as the first line to make the breakpoint silent;\n\
16218 then no output is printed when it is hit, except what the commands print."));
16220 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16221 Specify breakpoint number N to break only if COND is true.\n\
16222 Usage is `condition N COND', where N is an integer and COND is an\n\
16223 expression to be evaluated whenever breakpoint N is reached."));
16224 set_cmd_completer (c
, condition_completer
);
16226 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16227 Set a temporary breakpoint.\n\
16228 Like \"break\" except the breakpoint is only temporary,\n\
16229 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16230 by using \"enable delete\" on the breakpoint number.\n\
16232 BREAK_ARGS_HELP ("tbreak")));
16233 set_cmd_completer (c
, location_completer
);
16235 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16236 Set a hardware assisted breakpoint.\n\
16237 Like \"break\" except the breakpoint requires hardware support,\n\
16238 some target hardware may not have this support.\n\
16240 BREAK_ARGS_HELP ("hbreak")));
16241 set_cmd_completer (c
, location_completer
);
16243 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16244 Set a temporary hardware assisted breakpoint.\n\
16245 Like \"hbreak\" except the breakpoint is only temporary,\n\
16246 so it will be deleted when hit.\n\
16248 BREAK_ARGS_HELP ("thbreak")));
16249 set_cmd_completer (c
, location_completer
);
16251 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16252 Enable some breakpoints.\n\
16253 Give breakpoint numbers (separated by spaces) as arguments.\n\
16254 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16255 This is used to cancel the effect of the \"disable\" command.\n\
16256 With a subcommand you can enable temporarily."),
16257 &enablelist
, "enable ", 1, &cmdlist
);
16259 add_com_alias ("en", "enable", class_breakpoint
, 1);
16261 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16262 Enable some breakpoints.\n\
16263 Give breakpoint numbers (separated by spaces) as arguments.\n\
16264 This is used to cancel the effect of the \"disable\" command.\n\
16265 May be abbreviated to simply \"enable\".\n"),
16266 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16268 add_cmd ("once", no_class
, enable_once_command
, _("\
16269 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16270 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16273 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16274 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16275 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16278 add_cmd ("count", no_class
, enable_count_command
, _("\
16279 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16280 If a breakpoint is hit while enabled in this fashion,\n\
16281 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16284 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16285 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16286 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16289 add_cmd ("once", no_class
, enable_once_command
, _("\
16290 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16291 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16294 add_cmd ("count", no_class
, enable_count_command
, _("\
16295 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16296 If a breakpoint is hit while enabled in this fashion,\n\
16297 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16300 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16301 Disable some breakpoints.\n\
16302 Arguments are breakpoint numbers with spaces in between.\n\
16303 To disable all breakpoints, give no argument.\n\
16304 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16305 &disablelist
, "disable ", 1, &cmdlist
);
16306 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16307 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16309 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16310 Disable some breakpoints.\n\
16311 Arguments are breakpoint numbers with spaces in between.\n\
16312 To disable all breakpoints, give no argument.\n\
16313 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16314 This command may be abbreviated \"disable\"."),
16317 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16318 Delete some breakpoints or auto-display expressions.\n\
16319 Arguments are breakpoint numbers with spaces in between.\n\
16320 To delete all breakpoints, give no argument.\n\
16322 Also a prefix command for deletion of other GDB objects.\n\
16323 The \"unset\" command is also an alias for \"delete\"."),
16324 &deletelist
, "delete ", 1, &cmdlist
);
16325 add_com_alias ("d", "delete", class_breakpoint
, 1);
16326 add_com_alias ("del", "delete", class_breakpoint
, 1);
16328 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16329 Delete some breakpoints or auto-display expressions.\n\
16330 Arguments are breakpoint numbers with spaces in between.\n\
16331 To delete all breakpoints, give no argument.\n\
16332 This command may be abbreviated \"delete\"."),
16335 add_com ("clear", class_breakpoint
, clear_command
, _("\
16336 Clear breakpoint at specified location.\n\
16337 Argument may be a linespec, explicit, or address location as described below.\n\
16339 With no argument, clears all breakpoints in the line that the selected frame\n\
16340 is executing in.\n"
16341 "\n" LOCATION_HELP_STRING
"\n\
16342 See also the \"delete\" command which clears breakpoints by number."));
16343 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16345 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16346 Set breakpoint at specified location.\n"
16347 BREAK_ARGS_HELP ("break")));
16348 set_cmd_completer (c
, location_completer
);
16350 add_com_alias ("b", "break", class_run
, 1);
16351 add_com_alias ("br", "break", class_run
, 1);
16352 add_com_alias ("bre", "break", class_run
, 1);
16353 add_com_alias ("brea", "break", class_run
, 1);
16357 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16358 Break in function/address or break at a line in the current file."),
16359 &stoplist
, "stop ", 1, &cmdlist
);
16360 add_cmd ("in", class_breakpoint
, stopin_command
,
16361 _("Break in function or address."), &stoplist
);
16362 add_cmd ("at", class_breakpoint
, stopat_command
,
16363 _("Break at a line in the current file."), &stoplist
);
16364 add_com ("status", class_info
, breakpoints_info
, _("\
16365 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16366 The \"Type\" column indicates one of:\n\
16367 \tbreakpoint - normal breakpoint\n\
16368 \twatchpoint - watchpoint\n\
16369 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16370 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16371 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16372 address and file/line number respectively.\n\
16374 Convenience variable \"$_\" and default examine address for \"x\"\n\
16375 are set to the address of the last breakpoint listed unless the command\n\
16376 is prefixed with \"server \".\n\n\
16377 Convenience variable \"$bpnum\" contains the number of the last\n\
16378 breakpoint set."));
16381 add_info ("breakpoints", breakpoints_info
, _("\
16382 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16383 The \"Type\" column indicates one of:\n\
16384 \tbreakpoint - normal breakpoint\n\
16385 \twatchpoint - watchpoint\n\
16386 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16387 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16388 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16389 address and file/line number respectively.\n\
16391 Convenience variable \"$_\" and default examine address for \"x\"\n\
16392 are set to the address of the last breakpoint listed unless the command\n\
16393 is prefixed with \"server \".\n\n\
16394 Convenience variable \"$bpnum\" contains the number of the last\n\
16395 breakpoint set."));
16397 add_info_alias ("b", "breakpoints", 1);
16399 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16400 Status of all breakpoints, or breakpoint number NUMBER.\n\
16401 The \"Type\" column indicates one of:\n\
16402 \tbreakpoint - normal breakpoint\n\
16403 \twatchpoint - watchpoint\n\
16404 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16405 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16406 \tuntil - internal breakpoint used by the \"until\" command\n\
16407 \tfinish - internal breakpoint used by the \"finish\" command\n\
16408 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16409 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16410 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16411 address and file/line number respectively.\n\
16413 Convenience variable \"$_\" and default examine address for \"x\"\n\
16414 are set to the address of the last breakpoint listed unless the command\n\
16415 is prefixed with \"server \".\n\n\
16416 Convenience variable \"$bpnum\" contains the number of the last\n\
16418 &maintenanceinfolist
);
16420 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16421 Set catchpoints to catch events."),
16422 &catch_cmdlist
, "catch ",
16423 0/*allow-unknown*/, &cmdlist
);
16425 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16426 Set temporary catchpoints to catch events."),
16427 &tcatch_cmdlist
, "tcatch ",
16428 0/*allow-unknown*/, &cmdlist
);
16430 add_catch_command ("fork", _("Catch calls to fork."),
16431 catch_fork_command_1
,
16433 (void *) (uintptr_t) catch_fork_permanent
,
16434 (void *) (uintptr_t) catch_fork_temporary
);
16435 add_catch_command ("vfork", _("Catch calls to vfork."),
16436 catch_fork_command_1
,
16438 (void *) (uintptr_t) catch_vfork_permanent
,
16439 (void *) (uintptr_t) catch_vfork_temporary
);
16440 add_catch_command ("exec", _("Catch calls to exec."),
16441 catch_exec_command_1
,
16445 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16446 Usage: catch load [REGEX]\n\
16447 If REGEX is given, only stop for libraries matching the regular expression."),
16448 catch_load_command_1
,
16452 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16453 Usage: catch unload [REGEX]\n\
16454 If REGEX is given, only stop for libraries matching the regular expression."),
16455 catch_unload_command_1
,
16460 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16461 Set a watchpoint for an expression.\n\
16462 Usage: watch [-l|-location] EXPRESSION\n\
16463 A watchpoint stops execution of your program whenever the value of\n\
16464 an expression changes.\n\
16465 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16466 the memory to which it refers."));
16467 set_cmd_completer (c
, expression_completer
);
16469 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16470 Set a read watchpoint for an expression.\n\
16471 Usage: rwatch [-l|-location] EXPRESSION\n\
16472 A watchpoint stops execution of your program whenever the value of\n\
16473 an expression is read.\n\
16474 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16475 the memory to which it refers."));
16476 set_cmd_completer (c
, expression_completer
);
16478 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16479 Set a watchpoint for an expression.\n\
16480 Usage: awatch [-l|-location] EXPRESSION\n\
16481 A watchpoint stops execution of your program whenever the value of\n\
16482 an expression is either read or written.\n\
16483 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16484 the memory to which it refers."));
16485 set_cmd_completer (c
, expression_completer
);
16487 add_info ("watchpoints", watchpoints_info
, _("\
16488 Status of specified watchpoints (all watchpoints if no argument)."));
16490 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16491 respond to changes - contrary to the description. */
16492 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16493 &can_use_hw_watchpoints
, _("\
16494 Set debugger's willingness to use watchpoint hardware."), _("\
16495 Show debugger's willingness to use watchpoint hardware."), _("\
16496 If zero, gdb will not use hardware for new watchpoints, even if\n\
16497 such is available. (However, any hardware watchpoints that were\n\
16498 created before setting this to nonzero, will continue to use watchpoint\n\
16501 show_can_use_hw_watchpoints
,
16502 &setlist
, &showlist
);
16504 can_use_hw_watchpoints
= 1;
16506 /* Tracepoint manipulation commands. */
16508 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16509 Set a tracepoint at specified location.\n\
16511 BREAK_ARGS_HELP ("trace") "\n\
16512 Do \"help tracepoints\" for info on other tracepoint commands."));
16513 set_cmd_completer (c
, location_completer
);
16515 add_com_alias ("tp", "trace", class_alias
, 0);
16516 add_com_alias ("tr", "trace", class_alias
, 1);
16517 add_com_alias ("tra", "trace", class_alias
, 1);
16518 add_com_alias ("trac", "trace", class_alias
, 1);
16520 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16521 Set a fast tracepoint at specified location.\n\
16523 BREAK_ARGS_HELP ("ftrace") "\n\
16524 Do \"help tracepoints\" for info on other tracepoint commands."));
16525 set_cmd_completer (c
, location_completer
);
16527 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16528 Set a static tracepoint at location or marker.\n\
16530 strace [LOCATION] [if CONDITION]\n\
16531 LOCATION may be a linespec, explicit, or address location (described below) \n\
16532 or -m MARKER_ID.\n\n\
16533 If a marker id is specified, probe the marker with that name. With\n\
16534 no LOCATION, uses current execution address of the selected stack frame.\n\
16535 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16536 This collects arbitrary user data passed in the probe point call to the\n\
16537 tracing library. You can inspect it when analyzing the trace buffer,\n\
16538 by printing the $_sdata variable like any other convenience variable.\n\
16540 CONDITION is a boolean expression.\n\
16541 \n" LOCATION_HELP_STRING
"\n\
16542 Multiple tracepoints at one place are permitted, and useful if their\n\
16543 conditions are different.\n\
16545 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16546 Do \"help tracepoints\" for info on other tracepoint commands."));
16547 set_cmd_completer (c
, location_completer
);
16549 add_info ("tracepoints", tracepoints_info
, _("\
16550 Status of specified tracepoints (all tracepoints if no argument).\n\
16551 Convenience variable \"$tpnum\" contains the number of the\n\
16552 last tracepoint set."));
16554 add_info_alias ("tp", "tracepoints", 1);
16556 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16557 Delete specified tracepoints.\n\
16558 Arguments are tracepoint numbers, separated by spaces.\n\
16559 No argument means delete all tracepoints."),
16561 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16563 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16564 Disable specified tracepoints.\n\
16565 Arguments are tracepoint numbers, separated by spaces.\n\
16566 No argument means disable all tracepoints."),
16568 deprecate_cmd (c
, "disable");
16570 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16571 Enable specified tracepoints.\n\
16572 Arguments are tracepoint numbers, separated by spaces.\n\
16573 No argument means enable all tracepoints."),
16575 deprecate_cmd (c
, "enable");
16577 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16578 Set the passcount for a tracepoint.\n\
16579 The trace will end when the tracepoint has been passed 'count' times.\n\
16580 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16581 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16583 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16584 _("Save breakpoint definitions as a script."),
16585 &save_cmdlist
, "save ",
16586 0/*allow-unknown*/, &cmdlist
);
16588 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16589 Save current breakpoint definitions as a script.\n\
16590 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16591 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16592 session to restore them."),
16594 set_cmd_completer (c
, filename_completer
);
16596 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16597 Save current tracepoint definitions as a script.\n\
16598 Use the 'source' command in another debug session to restore them."),
16600 set_cmd_completer (c
, filename_completer
);
16602 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16603 deprecate_cmd (c
, "save tracepoints");
16605 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16606 Breakpoint specific settings\n\
16607 Configure various breakpoint-specific variables such as\n\
16608 pending breakpoint behavior"),
16609 &breakpoint_set_cmdlist
, "set breakpoint ",
16610 0/*allow-unknown*/, &setlist
);
16611 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16612 Breakpoint specific settings\n\
16613 Configure various breakpoint-specific variables such as\n\
16614 pending breakpoint behavior"),
16615 &breakpoint_show_cmdlist
, "show breakpoint ",
16616 0/*allow-unknown*/, &showlist
);
16618 add_setshow_auto_boolean_cmd ("pending", no_class
,
16619 &pending_break_support
, _("\
16620 Set debugger's behavior regarding pending breakpoints."), _("\
16621 Show debugger's behavior regarding pending breakpoints."), _("\
16622 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16623 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16624 an error. If auto, an unrecognized breakpoint location results in a\n\
16625 user-query to see if a pending breakpoint should be created."),
16627 show_pending_break_support
,
16628 &breakpoint_set_cmdlist
,
16629 &breakpoint_show_cmdlist
);
16631 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16633 add_setshow_boolean_cmd ("auto-hw", no_class
,
16634 &automatic_hardware_breakpoints
, _("\
16635 Set automatic usage of hardware breakpoints."), _("\
16636 Show automatic usage of hardware breakpoints."), _("\
16637 If set, the debugger will automatically use hardware breakpoints for\n\
16638 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16639 a warning will be emitted for such breakpoints."),
16641 show_automatic_hardware_breakpoints
,
16642 &breakpoint_set_cmdlist
,
16643 &breakpoint_show_cmdlist
);
16645 add_setshow_boolean_cmd ("always-inserted", class_support
,
16646 &always_inserted_mode
, _("\
16647 Set mode for inserting breakpoints."), _("\
16648 Show mode for inserting breakpoints."), _("\
16649 When this mode is on, breakpoints are inserted immediately as soon as\n\
16650 they're created, kept inserted even when execution stops, and removed\n\
16651 only when the user deletes them. When this mode is off (the default),\n\
16652 breakpoints are inserted only when execution continues, and removed\n\
16653 when execution stops."),
16655 &show_always_inserted_mode
,
16656 &breakpoint_set_cmdlist
,
16657 &breakpoint_show_cmdlist
);
16659 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16660 condition_evaluation_enums
,
16661 &condition_evaluation_mode_1
, _("\
16662 Set mode of breakpoint condition evaluation."), _("\
16663 Show mode of breakpoint condition evaluation."), _("\
16664 When this is set to \"host\", breakpoint conditions will be\n\
16665 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16666 breakpoint conditions will be downloaded to the target (if the target\n\
16667 supports such feature) and conditions will be evaluated on the target's side.\n\
16668 If this is set to \"auto\" (default), this will be automatically set to\n\
16669 \"target\" if it supports condition evaluation, otherwise it will\n\
16670 be set to \"gdb\""),
16671 &set_condition_evaluation_mode
,
16672 &show_condition_evaluation_mode
,
16673 &breakpoint_set_cmdlist
,
16674 &breakpoint_show_cmdlist
);
16676 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16677 Set a breakpoint for an address range.\n\
16678 break-range START-LOCATION, END-LOCATION\n\
16679 where START-LOCATION and END-LOCATION can be one of the following:\n\
16680 LINENUM, for that line in the current file,\n\
16681 FILE:LINENUM, for that line in that file,\n\
16682 +OFFSET, for that number of lines after the current line\n\
16683 or the start of the range\n\
16684 FUNCTION, for the first line in that function,\n\
16685 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16686 *ADDRESS, for the instruction at that address.\n\
16688 The breakpoint will stop execution of the inferior whenever it executes\n\
16689 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16690 range (including START-LOCATION and END-LOCATION)."));
16692 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16693 Set a dynamic printf at specified location.\n\
16694 dprintf location,format string,arg1,arg2,...\n\
16695 location may be a linespec, explicit, or address location.\n"
16696 "\n" LOCATION_HELP_STRING
));
16697 set_cmd_completer (c
, location_completer
);
16699 add_setshow_enum_cmd ("dprintf-style", class_support
,
16700 dprintf_style_enums
, &dprintf_style
, _("\
16701 Set the style of usage for dynamic printf."), _("\
16702 Show the style of usage for dynamic printf."), _("\
16703 This setting chooses how GDB will do a dynamic printf.\n\
16704 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16705 console, as with the \"printf\" command.\n\
16706 If the value is \"call\", the print is done by calling a function in your\n\
16707 program; by default printf(), but you can choose a different function or\n\
16708 output stream by setting dprintf-function and dprintf-channel."),
16709 update_dprintf_commands
, NULL
,
16710 &setlist
, &showlist
);
16712 dprintf_function
= xstrdup ("printf");
16713 add_setshow_string_cmd ("dprintf-function", class_support
,
16714 &dprintf_function
, _("\
16715 Set the function to use for dynamic printf"), _("\
16716 Show the function to use for dynamic printf"), NULL
,
16717 update_dprintf_commands
, NULL
,
16718 &setlist
, &showlist
);
16720 dprintf_channel
= xstrdup ("");
16721 add_setshow_string_cmd ("dprintf-channel", class_support
,
16722 &dprintf_channel
, _("\
16723 Set the channel to use for dynamic printf"), _("\
16724 Show the channel to use for dynamic printf"), NULL
,
16725 update_dprintf_commands
, NULL
,
16726 &setlist
, &showlist
);
16728 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16729 &disconnected_dprintf
, _("\
16730 Set whether dprintf continues after GDB disconnects."), _("\
16731 Show whether dprintf continues after GDB disconnects."), _("\
16732 Use this to let dprintf commands continue to hit and produce output\n\
16733 even if GDB disconnects or detaches from the target."),
16736 &setlist
, &showlist
);
16738 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16739 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16740 (target agent only) This is useful for formatted output in user-defined commands."));
16742 automatic_hardware_breakpoints
= 1;
16744 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16745 observer_attach_thread_exit (remove_threaded_breakpoints
);