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. Get the kind
2607 of breakpoint according to ADDR except single-step breakpoint.
2608 Get the kind of single-step breakpoint according to the current
2612 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2614 if (bl
->owner
->type
== bp_single_step
)
2616 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2617 struct regcache
*regcache
;
2619 regcache
= get_thread_regcache (thr
->ptid
);
2621 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2625 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2628 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2629 location. Any error messages are printed to TMP_ERROR_STREAM; and
2630 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2631 Returns 0 for success, 1 if the bp_location type is not supported or
2634 NOTE drow/2003-09-09: This routine could be broken down to an
2635 object-style method for each breakpoint or catchpoint type. */
2637 insert_bp_location (struct bp_location
*bl
,
2638 struct ui_file
*tmp_error_stream
,
2639 int *disabled_breaks
,
2640 int *hw_breakpoint_error
,
2641 int *hw_bp_error_explained_already
)
2643 enum errors bp_err
= GDB_NO_ERROR
;
2644 const char *bp_err_message
= NULL
;
2646 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2649 /* Note we don't initialize bl->target_info, as that wipes out
2650 the breakpoint location's shadow_contents if the breakpoint
2651 is still inserted at that location. This in turn breaks
2652 target_read_memory which depends on these buffers when
2653 a memory read is requested at the breakpoint location:
2654 Once the target_info has been wiped, we fail to see that
2655 we have a breakpoint inserted at that address and thus
2656 read the breakpoint instead of returning the data saved in
2657 the breakpoint location's shadow contents. */
2658 bl
->target_info
.reqstd_address
= bl
->address
;
2659 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2660 bl
->target_info
.length
= bl
->length
;
2662 /* When working with target-side conditions, we must pass all the conditions
2663 for the same breakpoint address down to the target since GDB will not
2664 insert those locations. With a list of breakpoint conditions, the target
2665 can decide when to stop and notify GDB. */
2667 if (is_breakpoint (bl
->owner
))
2669 build_target_condition_list (bl
);
2670 build_target_command_list (bl
);
2671 /* Reset the modification marker. */
2672 bl
->needs_update
= 0;
2675 if (bl
->loc_type
== bp_loc_software_breakpoint
2676 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2678 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2680 /* If the explicitly specified breakpoint type
2681 is not hardware breakpoint, check the memory map to see
2682 if the breakpoint address is in read only memory or not.
2684 Two important cases are:
2685 - location type is not hardware breakpoint, memory
2686 is readonly. We change the type of the location to
2687 hardware breakpoint.
2688 - location type is hardware breakpoint, memory is
2689 read-write. This means we've previously made the
2690 location hardware one, but then the memory map changed,
2693 When breakpoints are removed, remove_breakpoints will use
2694 location types we've just set here, the only possible
2695 problem is that memory map has changed during running
2696 program, but it's not going to work anyway with current
2698 struct mem_region
*mr
2699 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2703 if (automatic_hardware_breakpoints
)
2705 enum bp_loc_type new_type
;
2707 if (mr
->attrib
.mode
!= MEM_RW
)
2708 new_type
= bp_loc_hardware_breakpoint
;
2710 new_type
= bp_loc_software_breakpoint
;
2712 if (new_type
!= bl
->loc_type
)
2714 static int said
= 0;
2716 bl
->loc_type
= new_type
;
2719 fprintf_filtered (gdb_stdout
,
2720 _("Note: automatically using "
2721 "hardware breakpoints for "
2722 "read-only addresses.\n"));
2727 else if (bl
->loc_type
== bp_loc_software_breakpoint
2728 && mr
->attrib
.mode
!= MEM_RW
)
2730 fprintf_unfiltered (tmp_error_stream
,
2731 _("Cannot insert breakpoint %d.\n"
2732 "Cannot set software breakpoint "
2733 "at read-only address %s\n"),
2735 paddress (bl
->gdbarch
, bl
->address
));
2741 /* First check to see if we have to handle an overlay. */
2742 if (overlay_debugging
== ovly_off
2743 || bl
->section
== NULL
2744 || !(section_is_overlay (bl
->section
)))
2746 /* No overlay handling: just set the breakpoint. */
2751 val
= bl
->owner
->ops
->insert_location (bl
);
2753 bp_err
= GENERIC_ERROR
;
2755 CATCH (e
, RETURN_MASK_ALL
)
2758 bp_err_message
= e
.message
;
2764 /* This breakpoint is in an overlay section.
2765 Shall we set a breakpoint at the LMA? */
2766 if (!overlay_events_enabled
)
2768 /* Yes -- overlay event support is not active,
2769 so we must try to set a breakpoint at the LMA.
2770 This will not work for a hardware breakpoint. */
2771 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2772 warning (_("hardware breakpoint %d not supported in overlay!"),
2776 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2778 /* Set a software (trap) breakpoint at the LMA. */
2779 bl
->overlay_target_info
= bl
->target_info
;
2780 bl
->overlay_target_info
.reqstd_address
= addr
;
2782 /* No overlay handling: just set the breakpoint. */
2787 bl
->overlay_target_info
.kind
2788 = breakpoint_kind (bl
, &addr
);
2789 bl
->overlay_target_info
.placed_address
= addr
;
2790 val
= target_insert_breakpoint (bl
->gdbarch
,
2791 &bl
->overlay_target_info
);
2793 bp_err
= GENERIC_ERROR
;
2795 CATCH (e
, RETURN_MASK_ALL
)
2798 bp_err_message
= e
.message
;
2802 if (bp_err
!= GDB_NO_ERROR
)
2803 fprintf_unfiltered (tmp_error_stream
,
2804 "Overlay breakpoint %d "
2805 "failed: in ROM?\n",
2809 /* Shall we set a breakpoint at the VMA? */
2810 if (section_is_mapped (bl
->section
))
2812 /* Yes. This overlay section is mapped into memory. */
2817 val
= bl
->owner
->ops
->insert_location (bl
);
2819 bp_err
= GENERIC_ERROR
;
2821 CATCH (e
, RETURN_MASK_ALL
)
2824 bp_err_message
= e
.message
;
2830 /* No. This breakpoint will not be inserted.
2831 No error, but do not mark the bp as 'inserted'. */
2836 if (bp_err
!= GDB_NO_ERROR
)
2838 /* Can't set the breakpoint. */
2840 /* In some cases, we might not be able to insert a
2841 breakpoint in a shared library that has already been
2842 removed, but we have not yet processed the shlib unload
2843 event. Unfortunately, some targets that implement
2844 breakpoint insertion themselves can't tell why the
2845 breakpoint insertion failed (e.g., the remote target
2846 doesn't define error codes), so we must treat generic
2847 errors as memory errors. */
2848 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2849 && bl
->loc_type
== bp_loc_software_breakpoint
2850 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2851 || shared_objfile_contains_address_p (bl
->pspace
,
2854 /* See also: disable_breakpoints_in_shlibs. */
2855 bl
->shlib_disabled
= 1;
2856 observer_notify_breakpoint_modified (bl
->owner
);
2857 if (!*disabled_breaks
)
2859 fprintf_unfiltered (tmp_error_stream
,
2860 "Cannot insert breakpoint %d.\n",
2862 fprintf_unfiltered (tmp_error_stream
,
2863 "Temporarily disabling shared "
2864 "library breakpoints:\n");
2866 *disabled_breaks
= 1;
2867 fprintf_unfiltered (tmp_error_stream
,
2868 "breakpoint #%d\n", bl
->owner
->number
);
2873 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2875 *hw_breakpoint_error
= 1;
2876 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2877 fprintf_unfiltered (tmp_error_stream
,
2878 "Cannot insert hardware breakpoint %d%s",
2879 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2880 if (bp_err_message
!= NULL
)
2881 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2885 if (bp_err_message
== NULL
)
2888 = memory_error_message (TARGET_XFER_E_IO
,
2889 bl
->gdbarch
, bl
->address
);
2890 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2892 fprintf_unfiltered (tmp_error_stream
,
2893 "Cannot insert breakpoint %d.\n"
2895 bl
->owner
->number
, message
);
2896 do_cleanups (old_chain
);
2900 fprintf_unfiltered (tmp_error_stream
,
2901 "Cannot insert breakpoint %d: %s\n",
2916 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2917 /* NOTE drow/2003-09-08: This state only exists for removing
2918 watchpoints. It's not clear that it's necessary... */
2919 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2923 gdb_assert (bl
->owner
->ops
!= NULL
2924 && bl
->owner
->ops
->insert_location
!= NULL
);
2926 val
= bl
->owner
->ops
->insert_location (bl
);
2928 /* If trying to set a read-watchpoint, and it turns out it's not
2929 supported, try emulating one with an access watchpoint. */
2930 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2932 struct bp_location
*loc
, **loc_temp
;
2934 /* But don't try to insert it, if there's already another
2935 hw_access location that would be considered a duplicate
2937 ALL_BP_LOCATIONS (loc
, loc_temp
)
2939 && loc
->watchpoint_type
== hw_access
2940 && watchpoint_locations_match (bl
, loc
))
2944 bl
->target_info
= loc
->target_info
;
2945 bl
->watchpoint_type
= hw_access
;
2952 bl
->watchpoint_type
= hw_access
;
2953 val
= bl
->owner
->ops
->insert_location (bl
);
2956 /* Back to the original value. */
2957 bl
->watchpoint_type
= hw_read
;
2961 bl
->inserted
= (val
== 0);
2964 else if (bl
->owner
->type
== bp_catchpoint
)
2968 gdb_assert (bl
->owner
->ops
!= NULL
2969 && bl
->owner
->ops
->insert_location
!= NULL
);
2971 val
= bl
->owner
->ops
->insert_location (bl
);
2974 bl
->owner
->enable_state
= bp_disabled
;
2978 Error inserting catchpoint %d: Your system does not support this type\n\
2979 of catchpoint."), bl
->owner
->number
);
2981 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2984 bl
->inserted
= (val
== 0);
2986 /* We've already printed an error message if there was a problem
2987 inserting this catchpoint, and we've disabled the catchpoint,
2988 so just return success. */
2995 /* This function is called when program space PSPACE is about to be
2996 deleted. It takes care of updating breakpoints to not reference
3000 breakpoint_program_space_exit (struct program_space
*pspace
)
3002 struct breakpoint
*b
, *b_temp
;
3003 struct bp_location
*loc
, **loc_temp
;
3005 /* Remove any breakpoint that was set through this program space. */
3006 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
3008 if (b
->pspace
== pspace
)
3009 delete_breakpoint (b
);
3012 /* Breakpoints set through other program spaces could have locations
3013 bound to PSPACE as well. Remove those. */
3014 ALL_BP_LOCATIONS (loc
, loc_temp
)
3016 struct bp_location
*tmp
;
3018 if (loc
->pspace
== pspace
)
3020 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3021 if (loc
->owner
->loc
== loc
)
3022 loc
->owner
->loc
= loc
->next
;
3024 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3025 if (tmp
->next
== loc
)
3027 tmp
->next
= loc
->next
;
3033 /* Now update the global location list to permanently delete the
3034 removed locations above. */
3035 update_global_location_list (UGLL_DONT_INSERT
);
3038 /* Make sure all breakpoints are inserted in inferior.
3039 Throws exception on any error.
3040 A breakpoint that is already inserted won't be inserted
3041 again, so calling this function twice is safe. */
3043 insert_breakpoints (void)
3045 struct breakpoint
*bpt
;
3047 ALL_BREAKPOINTS (bpt
)
3048 if (is_hardware_watchpoint (bpt
))
3050 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3052 update_watchpoint (w
, 0 /* don't reparse. */);
3055 /* Updating watchpoints creates new locations, so update the global
3056 location list. Explicitly tell ugll to insert locations and
3057 ignore breakpoints_always_inserted_mode. */
3058 update_global_location_list (UGLL_INSERT
);
3061 /* Invoke CALLBACK for each of bp_location. */
3064 iterate_over_bp_locations (walk_bp_location_callback callback
)
3066 struct bp_location
*loc
, **loc_tmp
;
3068 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3070 callback (loc
, NULL
);
3074 /* This is used when we need to synch breakpoint conditions between GDB and the
3075 target. It is the case with deleting and disabling of breakpoints when using
3076 always-inserted mode. */
3079 update_inserted_breakpoint_locations (void)
3081 struct bp_location
*bl
, **blp_tmp
;
3084 int disabled_breaks
= 0;
3085 int hw_breakpoint_error
= 0;
3086 int hw_bp_details_reported
= 0;
3088 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3089 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3091 /* Explicitly mark the warning -- this will only be printed if
3092 there was an error. */
3093 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3095 save_current_space_and_thread ();
3097 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3099 /* We only want to update software breakpoints and hardware
3101 if (!is_breakpoint (bl
->owner
))
3104 /* We only want to update locations that are already inserted
3105 and need updating. This is to avoid unwanted insertion during
3106 deletion of breakpoints. */
3107 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3110 switch_to_program_space_and_thread (bl
->pspace
);
3112 /* For targets that support global breakpoints, there's no need
3113 to select an inferior to insert breakpoint to. In fact, even
3114 if we aren't attached to any process yet, we should still
3115 insert breakpoints. */
3116 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3117 && ptid_equal (inferior_ptid
, null_ptid
))
3120 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3121 &hw_breakpoint_error
, &hw_bp_details_reported
);
3128 target_terminal_ours_for_output ();
3129 error_stream (tmp_error_stream
);
3132 do_cleanups (cleanups
);
3135 /* Used when starting or continuing the program. */
3138 insert_breakpoint_locations (void)
3140 struct breakpoint
*bpt
;
3141 struct bp_location
*bl
, **blp_tmp
;
3144 int disabled_breaks
= 0;
3145 int hw_breakpoint_error
= 0;
3146 int hw_bp_error_explained_already
= 0;
3148 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3149 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3151 /* Explicitly mark the warning -- this will only be printed if
3152 there was an error. */
3153 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3155 save_current_space_and_thread ();
3157 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3159 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3162 /* There is no point inserting thread-specific breakpoints if
3163 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3164 has BL->OWNER always non-NULL. */
3165 if (bl
->owner
->thread
!= -1
3166 && !valid_global_thread_id (bl
->owner
->thread
))
3169 switch_to_program_space_and_thread (bl
->pspace
);
3171 /* For targets that support global breakpoints, there's no need
3172 to select an inferior to insert breakpoint to. In fact, even
3173 if we aren't attached to any process yet, we should still
3174 insert breakpoints. */
3175 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3176 && ptid_equal (inferior_ptid
, null_ptid
))
3179 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3180 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3185 /* If we failed to insert all locations of a watchpoint, remove
3186 them, as half-inserted watchpoint is of limited use. */
3187 ALL_BREAKPOINTS (bpt
)
3189 int some_failed
= 0;
3190 struct bp_location
*loc
;
3192 if (!is_hardware_watchpoint (bpt
))
3195 if (!breakpoint_enabled (bpt
))
3198 if (bpt
->disposition
== disp_del_at_next_stop
)
3201 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3202 if (!loc
->inserted
&& should_be_inserted (loc
))
3209 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3211 remove_breakpoint (loc
);
3213 hw_breakpoint_error
= 1;
3214 fprintf_unfiltered (tmp_error_stream
,
3215 "Could not insert hardware watchpoint %d.\n",
3223 /* If a hardware breakpoint or watchpoint was inserted, add a
3224 message about possibly exhausted resources. */
3225 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3227 fprintf_unfiltered (tmp_error_stream
,
3228 "Could not insert hardware breakpoints:\n\
3229 You may have requested too many hardware breakpoints/watchpoints.\n");
3231 target_terminal_ours_for_output ();
3232 error_stream (tmp_error_stream
);
3235 do_cleanups (cleanups
);
3238 /* Used when the program stops.
3239 Returns zero if successful, or non-zero if there was a problem
3240 removing a breakpoint location. */
3243 remove_breakpoints (void)
3245 struct bp_location
*bl
, **blp_tmp
;
3248 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3250 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3251 val
|= remove_breakpoint (bl
);
3256 /* When a thread exits, remove breakpoints that are related to
3260 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3262 struct breakpoint
*b
, *b_tmp
;
3264 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3266 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3268 b
->disposition
= disp_del_at_next_stop
;
3270 printf_filtered (_("\
3271 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3272 b
->number
, print_thread_id (tp
));
3274 /* Hide it from the user. */
3280 /* Remove breakpoints of process PID. */
3283 remove_breakpoints_pid (int pid
)
3285 struct bp_location
*bl
, **blp_tmp
;
3287 struct inferior
*inf
= find_inferior_pid (pid
);
3289 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3291 if (bl
->pspace
!= inf
->pspace
)
3294 if (bl
->inserted
&& !bl
->target_info
.persist
)
3296 val
= remove_breakpoint (bl
);
3305 reattach_breakpoints (int pid
)
3307 struct cleanup
*old_chain
;
3308 struct bp_location
*bl
, **blp_tmp
;
3310 struct ui_file
*tmp_error_stream
;
3311 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3312 struct inferior
*inf
;
3313 struct thread_info
*tp
;
3315 tp
= any_live_thread_of_process (pid
);
3319 inf
= find_inferior_pid (pid
);
3320 old_chain
= save_inferior_ptid ();
3322 inferior_ptid
= tp
->ptid
;
3324 tmp_error_stream
= mem_fileopen ();
3325 make_cleanup_ui_file_delete (tmp_error_stream
);
3327 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3329 if (bl
->pspace
!= inf
->pspace
)
3335 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3338 do_cleanups (old_chain
);
3343 do_cleanups (old_chain
);
3347 static int internal_breakpoint_number
= -1;
3349 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3350 If INTERNAL is non-zero, the breakpoint number will be populated
3351 from internal_breakpoint_number and that variable decremented.
3352 Otherwise the breakpoint number will be populated from
3353 breakpoint_count and that value incremented. Internal breakpoints
3354 do not set the internal var bpnum. */
3356 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3359 b
->number
= internal_breakpoint_number
--;
3362 set_breakpoint_count (breakpoint_count
+ 1);
3363 b
->number
= breakpoint_count
;
3367 static struct breakpoint
*
3368 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3369 CORE_ADDR address
, enum bptype type
,
3370 const struct breakpoint_ops
*ops
)
3372 struct symtab_and_line sal
;
3373 struct breakpoint
*b
;
3375 init_sal (&sal
); /* Initialize to zeroes. */
3378 sal
.section
= find_pc_overlay (sal
.pc
);
3379 sal
.pspace
= current_program_space
;
3381 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3382 b
->number
= internal_breakpoint_number
--;
3383 b
->disposition
= disp_donttouch
;
3388 static const char *const longjmp_names
[] =
3390 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3392 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3394 /* Per-objfile data private to breakpoint.c. */
3395 struct breakpoint_objfile_data
3397 /* Minimal symbol for "_ovly_debug_event" (if any). */
3398 struct bound_minimal_symbol overlay_msym
;
3400 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3401 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3403 /* True if we have looked for longjmp probes. */
3404 int longjmp_searched
;
3406 /* SystemTap probe points for longjmp (if any). */
3407 VEC (probe_p
) *longjmp_probes
;
3409 /* Minimal symbol for "std::terminate()" (if any). */
3410 struct bound_minimal_symbol terminate_msym
;
3412 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3413 struct bound_minimal_symbol exception_msym
;
3415 /* True if we have looked for exception probes. */
3416 int exception_searched
;
3418 /* SystemTap probe points for unwinding (if any). */
3419 VEC (probe_p
) *exception_probes
;
3422 static const struct objfile_data
*breakpoint_objfile_key
;
3424 /* Minimal symbol not found sentinel. */
3425 static struct minimal_symbol msym_not_found
;
3427 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3430 msym_not_found_p (const struct minimal_symbol
*msym
)
3432 return msym
== &msym_not_found
;
3435 /* Return per-objfile data needed by breakpoint.c.
3436 Allocate the data if necessary. */
3438 static struct breakpoint_objfile_data
*
3439 get_breakpoint_objfile_data (struct objfile
*objfile
)
3441 struct breakpoint_objfile_data
*bp_objfile_data
;
3443 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3444 objfile_data (objfile
, breakpoint_objfile_key
));
3445 if (bp_objfile_data
== NULL
)
3448 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3450 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3451 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3453 return bp_objfile_data
;
3457 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3459 struct breakpoint_objfile_data
*bp_objfile_data
3460 = (struct breakpoint_objfile_data
*) data
;
3462 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3463 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3467 create_overlay_event_breakpoint (void)
3469 struct objfile
*objfile
;
3470 const char *const func_name
= "_ovly_debug_event";
3472 ALL_OBJFILES (objfile
)
3474 struct breakpoint
*b
;
3475 struct breakpoint_objfile_data
*bp_objfile_data
;
3477 struct explicit_location explicit_loc
;
3479 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3481 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3484 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3486 struct bound_minimal_symbol m
;
3488 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3489 if (m
.minsym
== NULL
)
3491 /* Avoid future lookups in this objfile. */
3492 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3495 bp_objfile_data
->overlay_msym
= m
;
3498 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3499 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3501 &internal_breakpoint_ops
);
3502 initialize_explicit_location (&explicit_loc
);
3503 explicit_loc
.function_name
= ASTRDUP (func_name
);
3504 b
->location
= new_explicit_location (&explicit_loc
);
3506 if (overlay_debugging
== ovly_auto
)
3508 b
->enable_state
= bp_enabled
;
3509 overlay_events_enabled
= 1;
3513 b
->enable_state
= bp_disabled
;
3514 overlay_events_enabled
= 0;
3520 create_longjmp_master_breakpoint (void)
3522 struct program_space
*pspace
;
3523 struct cleanup
*old_chain
;
3525 old_chain
= save_current_program_space ();
3527 ALL_PSPACES (pspace
)
3529 struct objfile
*objfile
;
3531 set_current_program_space (pspace
);
3533 ALL_OBJFILES (objfile
)
3536 struct gdbarch
*gdbarch
;
3537 struct breakpoint_objfile_data
*bp_objfile_data
;
3539 gdbarch
= get_objfile_arch (objfile
);
3541 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3543 if (!bp_objfile_data
->longjmp_searched
)
3547 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3550 /* We are only interested in checking one element. */
3551 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3553 if (!can_evaluate_probe_arguments (p
))
3555 /* We cannot use the probe interface here, because it does
3556 not know how to evaluate arguments. */
3557 VEC_free (probe_p
, ret
);
3561 bp_objfile_data
->longjmp_probes
= ret
;
3562 bp_objfile_data
->longjmp_searched
= 1;
3565 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3568 struct probe
*probe
;
3569 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3572 VEC_iterate (probe_p
,
3573 bp_objfile_data
->longjmp_probes
,
3577 struct breakpoint
*b
;
3579 b
= create_internal_breakpoint (gdbarch
,
3580 get_probe_address (probe
,
3583 &internal_breakpoint_ops
);
3585 = new_probe_location ("-probe-stap libc:longjmp");
3586 b
->enable_state
= bp_disabled
;
3592 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3595 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3597 struct breakpoint
*b
;
3598 const char *func_name
;
3600 struct explicit_location explicit_loc
;
3602 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3605 func_name
= longjmp_names
[i
];
3606 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3608 struct bound_minimal_symbol m
;
3610 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3611 if (m
.minsym
== NULL
)
3613 /* Prevent future lookups in this objfile. */
3614 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3617 bp_objfile_data
->longjmp_msym
[i
] = m
;
3620 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3621 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3622 &internal_breakpoint_ops
);
3623 initialize_explicit_location (&explicit_loc
);
3624 explicit_loc
.function_name
= ASTRDUP (func_name
);
3625 b
->location
= new_explicit_location (&explicit_loc
);
3626 b
->enable_state
= bp_disabled
;
3631 do_cleanups (old_chain
);
3634 /* Create a master std::terminate breakpoint. */
3636 create_std_terminate_master_breakpoint (void)
3638 struct program_space
*pspace
;
3639 struct cleanup
*old_chain
;
3640 const char *const func_name
= "std::terminate()";
3642 old_chain
= save_current_program_space ();
3644 ALL_PSPACES (pspace
)
3646 struct objfile
*objfile
;
3649 set_current_program_space (pspace
);
3651 ALL_OBJFILES (objfile
)
3653 struct breakpoint
*b
;
3654 struct breakpoint_objfile_data
*bp_objfile_data
;
3655 struct explicit_location explicit_loc
;
3657 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3659 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3662 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3664 struct bound_minimal_symbol m
;
3666 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3667 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3668 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3670 /* Prevent future lookups in this objfile. */
3671 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3674 bp_objfile_data
->terminate_msym
= m
;
3677 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3678 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3679 bp_std_terminate_master
,
3680 &internal_breakpoint_ops
);
3681 initialize_explicit_location (&explicit_loc
);
3682 explicit_loc
.function_name
= ASTRDUP (func_name
);
3683 b
->location
= new_explicit_location (&explicit_loc
);
3684 b
->enable_state
= bp_disabled
;
3688 do_cleanups (old_chain
);
3691 /* Install a master breakpoint on the unwinder's debug hook. */
3694 create_exception_master_breakpoint (void)
3696 struct objfile
*objfile
;
3697 const char *const func_name
= "_Unwind_DebugHook";
3699 ALL_OBJFILES (objfile
)
3701 struct breakpoint
*b
;
3702 struct gdbarch
*gdbarch
;
3703 struct breakpoint_objfile_data
*bp_objfile_data
;
3705 struct explicit_location explicit_loc
;
3707 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3709 /* We prefer the SystemTap probe point if it exists. */
3710 if (!bp_objfile_data
->exception_searched
)
3714 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3718 /* We are only interested in checking one element. */
3719 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3721 if (!can_evaluate_probe_arguments (p
))
3723 /* We cannot use the probe interface here, because it does
3724 not know how to evaluate arguments. */
3725 VEC_free (probe_p
, ret
);
3729 bp_objfile_data
->exception_probes
= ret
;
3730 bp_objfile_data
->exception_searched
= 1;
3733 if (bp_objfile_data
->exception_probes
!= NULL
)
3735 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3737 struct probe
*probe
;
3740 VEC_iterate (probe_p
,
3741 bp_objfile_data
->exception_probes
,
3745 struct breakpoint
*b
;
3747 b
= create_internal_breakpoint (gdbarch
,
3748 get_probe_address (probe
,
3750 bp_exception_master
,
3751 &internal_breakpoint_ops
);
3753 = new_probe_location ("-probe-stap libgcc:unwind");
3754 b
->enable_state
= bp_disabled
;
3760 /* Otherwise, try the hook function. */
3762 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3765 gdbarch
= get_objfile_arch (objfile
);
3767 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3769 struct bound_minimal_symbol debug_hook
;
3771 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3772 if (debug_hook
.minsym
== NULL
)
3774 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3778 bp_objfile_data
->exception_msym
= debug_hook
;
3781 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3782 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3784 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3785 &internal_breakpoint_ops
);
3786 initialize_explicit_location (&explicit_loc
);
3787 explicit_loc
.function_name
= ASTRDUP (func_name
);
3788 b
->location
= new_explicit_location (&explicit_loc
);
3789 b
->enable_state
= bp_disabled
;
3793 /* Does B have a location spec? */
3796 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3798 return b
->location
!= NULL
&& event_location_empty_p (b
->location
);
3802 update_breakpoints_after_exec (void)
3804 struct breakpoint
*b
, *b_tmp
;
3805 struct bp_location
*bploc
, **bplocp_tmp
;
3807 /* We're about to delete breakpoints from GDB's lists. If the
3808 INSERTED flag is true, GDB will try to lift the breakpoints by
3809 writing the breakpoints' "shadow contents" back into memory. The
3810 "shadow contents" are NOT valid after an exec, so GDB should not
3811 do that. Instead, the target is responsible from marking
3812 breakpoints out as soon as it detects an exec. We don't do that
3813 here instead, because there may be other attempts to delete
3814 breakpoints after detecting an exec and before reaching here. */
3815 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3816 if (bploc
->pspace
== current_program_space
)
3817 gdb_assert (!bploc
->inserted
);
3819 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3821 if (b
->pspace
!= current_program_space
)
3824 /* Solib breakpoints must be explicitly reset after an exec(). */
3825 if (b
->type
== bp_shlib_event
)
3827 delete_breakpoint (b
);
3831 /* JIT breakpoints must be explicitly reset after an exec(). */
3832 if (b
->type
== bp_jit_event
)
3834 delete_breakpoint (b
);
3838 /* Thread event breakpoints must be set anew after an exec(),
3839 as must overlay event and longjmp master breakpoints. */
3840 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3841 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3842 || b
->type
== bp_exception_master
)
3844 delete_breakpoint (b
);
3848 /* Step-resume breakpoints are meaningless after an exec(). */
3849 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3851 delete_breakpoint (b
);
3855 /* Just like single-step breakpoints. */
3856 if (b
->type
== bp_single_step
)
3858 delete_breakpoint (b
);
3862 /* Longjmp and longjmp-resume breakpoints are also meaningless
3864 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3865 || b
->type
== bp_longjmp_call_dummy
3866 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3868 delete_breakpoint (b
);
3872 if (b
->type
== bp_catchpoint
)
3874 /* For now, none of the bp_catchpoint breakpoints need to
3875 do anything at this point. In the future, if some of
3876 the catchpoints need to something, we will need to add
3877 a new method, and call this method from here. */
3881 /* bp_finish is a special case. The only way we ought to be able
3882 to see one of these when an exec() has happened, is if the user
3883 caught a vfork, and then said "finish". Ordinarily a finish just
3884 carries them to the call-site of the current callee, by setting
3885 a temporary bp there and resuming. But in this case, the finish
3886 will carry them entirely through the vfork & exec.
3888 We don't want to allow a bp_finish to remain inserted now. But
3889 we can't safely delete it, 'cause finish_command has a handle to
3890 the bp on a bpstat, and will later want to delete it. There's a
3891 chance (and I've seen it happen) that if we delete the bp_finish
3892 here, that its storage will get reused by the time finish_command
3893 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3894 We really must allow finish_command to delete a bp_finish.
3896 In the absence of a general solution for the "how do we know
3897 it's safe to delete something others may have handles to?"
3898 problem, what we'll do here is just uninsert the bp_finish, and
3899 let finish_command delete it.
3901 (We know the bp_finish is "doomed" in the sense that it's
3902 momentary, and will be deleted as soon as finish_command sees
3903 the inferior stopped. So it doesn't matter that the bp's
3904 address is probably bogus in the new a.out, unlike e.g., the
3905 solib breakpoints.) */
3907 if (b
->type
== bp_finish
)
3912 /* Without a symbolic address, we have little hope of the
3913 pre-exec() address meaning the same thing in the post-exec()
3915 if (breakpoint_event_location_empty_p (b
))
3917 delete_breakpoint (b
);
3924 detach_breakpoints (ptid_t ptid
)
3926 struct bp_location
*bl
, **blp_tmp
;
3928 struct cleanup
*old_chain
= save_inferior_ptid ();
3929 struct inferior
*inf
= current_inferior ();
3931 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3932 error (_("Cannot detach breakpoints of inferior_ptid"));
3934 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3935 inferior_ptid
= ptid
;
3936 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3938 if (bl
->pspace
!= inf
->pspace
)
3941 /* This function must physically remove breakpoints locations
3942 from the specified ptid, without modifying the breakpoint
3943 package's state. Locations of type bp_loc_other are only
3944 maintained at GDB side. So, there is no need to remove
3945 these bp_loc_other locations. Moreover, removing these
3946 would modify the breakpoint package's state. */
3947 if (bl
->loc_type
== bp_loc_other
)
3951 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3954 do_cleanups (old_chain
);
3958 /* Remove the breakpoint location BL from the current address space.
3959 Note that this is used to detach breakpoints from a child fork.
3960 When we get here, the child isn't in the inferior list, and neither
3961 do we have objects to represent its address space --- we should
3962 *not* look at bl->pspace->aspace here. */
3965 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3969 /* BL is never in moribund_locations by our callers. */
3970 gdb_assert (bl
->owner
!= NULL
);
3972 /* The type of none suggests that owner is actually deleted.
3973 This should not ever happen. */
3974 gdb_assert (bl
->owner
->type
!= bp_none
);
3976 if (bl
->loc_type
== bp_loc_software_breakpoint
3977 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3979 /* "Normal" instruction breakpoint: either the standard
3980 trap-instruction bp (bp_breakpoint), or a
3981 bp_hardware_breakpoint. */
3983 /* First check to see if we have to handle an overlay. */
3984 if (overlay_debugging
== ovly_off
3985 || bl
->section
== NULL
3986 || !(section_is_overlay (bl
->section
)))
3988 /* No overlay handling: just remove the breakpoint. */
3990 /* If we're trying to uninsert a memory breakpoint that we
3991 know is set in a dynamic object that is marked
3992 shlib_disabled, then either the dynamic object was
3993 removed with "remove-symbol-file" or with
3994 "nosharedlibrary". In the former case, we don't know
3995 whether another dynamic object might have loaded over the
3996 breakpoint's address -- the user might well let us know
3997 about it next with add-symbol-file (the whole point of
3998 add-symbol-file is letting the user manually maintain a
3999 list of dynamically loaded objects). If we have the
4000 breakpoint's shadow memory, that is, this is a software
4001 breakpoint managed by GDB, check whether the breakpoint
4002 is still inserted in memory, to avoid overwriting wrong
4003 code with stale saved shadow contents. Note that HW
4004 breakpoints don't have shadow memory, as they're
4005 implemented using a mechanism that is not dependent on
4006 being able to modify the target's memory, and as such
4007 they should always be removed. */
4008 if (bl
->shlib_disabled
4009 && bl
->target_info
.shadow_len
!= 0
4010 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
4013 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4017 /* This breakpoint is in an overlay section.
4018 Did we set a breakpoint at the LMA? */
4019 if (!overlay_events_enabled
)
4021 /* Yes -- overlay event support is not active, so we
4022 should have set a breakpoint at the LMA. Remove it.
4024 /* Ignore any failures: if the LMA is in ROM, we will
4025 have already warned when we failed to insert it. */
4026 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4027 target_remove_hw_breakpoint (bl
->gdbarch
,
4028 &bl
->overlay_target_info
);
4030 target_remove_breakpoint (bl
->gdbarch
,
4031 &bl
->overlay_target_info
,
4034 /* Did we set a breakpoint at the VMA?
4035 If so, we will have marked the breakpoint 'inserted'. */
4038 /* Yes -- remove it. Previously we did not bother to
4039 remove the breakpoint if the section had been
4040 unmapped, but let's not rely on that being safe. We
4041 don't know what the overlay manager might do. */
4043 /* However, we should remove *software* breakpoints only
4044 if the section is still mapped, or else we overwrite
4045 wrong code with the saved shadow contents. */
4046 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4047 || section_is_mapped (bl
->section
))
4048 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4054 /* No -- not inserted, so no need to remove. No error. */
4059 /* In some cases, we might not be able to remove a breakpoint in
4060 a shared library that has already been removed, but we have
4061 not yet processed the shlib unload event. Similarly for an
4062 unloaded add-symbol-file object - the user might not yet have
4063 had the chance to remove-symbol-file it. shlib_disabled will
4064 be set if the library/object has already been removed, but
4065 the breakpoint hasn't been uninserted yet, e.g., after
4066 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4067 always-inserted mode. */
4069 && (bl
->loc_type
== bp_loc_software_breakpoint
4070 && (bl
->shlib_disabled
4071 || solib_name_from_address (bl
->pspace
, bl
->address
)
4072 || shared_objfile_contains_address_p (bl
->pspace
,
4078 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4080 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4082 gdb_assert (bl
->owner
->ops
!= NULL
4083 && bl
->owner
->ops
->remove_location
!= NULL
);
4085 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4086 bl
->owner
->ops
->remove_location (bl
, reason
);
4088 /* Failure to remove any of the hardware watchpoints comes here. */
4089 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4090 warning (_("Could not remove hardware watchpoint %d."),
4093 else if (bl
->owner
->type
== bp_catchpoint
4094 && breakpoint_enabled (bl
->owner
)
4097 gdb_assert (bl
->owner
->ops
!= NULL
4098 && bl
->owner
->ops
->remove_location
!= NULL
);
4100 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4104 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4111 remove_breakpoint (struct bp_location
*bl
)
4114 struct cleanup
*old_chain
;
4116 /* BL is never in moribund_locations by our callers. */
4117 gdb_assert (bl
->owner
!= NULL
);
4119 /* The type of none suggests that owner is actually deleted.
4120 This should not ever happen. */
4121 gdb_assert (bl
->owner
->type
!= bp_none
);
4123 old_chain
= save_current_space_and_thread ();
4125 switch_to_program_space_and_thread (bl
->pspace
);
4127 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4129 do_cleanups (old_chain
);
4133 /* Clear the "inserted" flag in all breakpoints. */
4136 mark_breakpoints_out (void)
4138 struct bp_location
*bl
, **blp_tmp
;
4140 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4141 if (bl
->pspace
== current_program_space
)
4145 /* Clear the "inserted" flag in all breakpoints and delete any
4146 breakpoints which should go away between runs of the program.
4148 Plus other such housekeeping that has to be done for breakpoints
4151 Note: this function gets called at the end of a run (by
4152 generic_mourn_inferior) and when a run begins (by
4153 init_wait_for_inferior). */
4158 breakpoint_init_inferior (enum inf_context context
)
4160 struct breakpoint
*b
, *b_tmp
;
4161 struct bp_location
*bl
;
4163 struct program_space
*pspace
= current_program_space
;
4165 /* If breakpoint locations are shared across processes, then there's
4167 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4170 mark_breakpoints_out ();
4172 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4174 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4180 case bp_longjmp_call_dummy
:
4182 /* If the call dummy breakpoint is at the entry point it will
4183 cause problems when the inferior is rerun, so we better get
4186 case bp_watchpoint_scope
:
4188 /* Also get rid of scope breakpoints. */
4190 case bp_shlib_event
:
4192 /* Also remove solib event breakpoints. Their addresses may
4193 have changed since the last time we ran the program.
4194 Actually we may now be debugging against different target;
4195 and so the solib backend that installed this breakpoint may
4196 not be used in by the target. E.g.,
4198 (gdb) file prog-linux
4199 (gdb) run # native linux target
4202 (gdb) file prog-win.exe
4203 (gdb) tar rem :9999 # remote Windows gdbserver.
4206 case bp_step_resume
:
4208 /* Also remove step-resume breakpoints. */
4210 case bp_single_step
:
4212 /* Also remove single-step breakpoints. */
4214 delete_breakpoint (b
);
4218 case bp_hardware_watchpoint
:
4219 case bp_read_watchpoint
:
4220 case bp_access_watchpoint
:
4222 struct watchpoint
*w
= (struct watchpoint
*) b
;
4224 /* Likewise for watchpoints on local expressions. */
4225 if (w
->exp_valid_block
!= NULL
)
4226 delete_breakpoint (b
);
4229 /* Get rid of existing locations, which are no longer
4230 valid. New ones will be created in
4231 update_watchpoint, when the inferior is restarted.
4232 The next update_global_location_list call will
4233 garbage collect them. */
4236 if (context
== inf_starting
)
4238 /* Reset val field to force reread of starting value in
4239 insert_breakpoints. */
4241 value_free (w
->val
);
4253 /* Get rid of the moribund locations. */
4254 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4255 decref_bp_location (&bl
);
4256 VEC_free (bp_location_p
, moribund_locations
);
4259 /* These functions concern about actual breakpoints inserted in the
4260 target --- to e.g. check if we need to do decr_pc adjustment or if
4261 we need to hop over the bkpt --- so we check for address space
4262 match, not program space. */
4264 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4265 exists at PC. It returns ordinary_breakpoint_here if it's an
4266 ordinary breakpoint, or permanent_breakpoint_here if it's a
4267 permanent breakpoint.
4268 - When continuing from a location with an ordinary breakpoint, we
4269 actually single step once before calling insert_breakpoints.
4270 - When continuing from a location with a permanent breakpoint, we
4271 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4272 the target, to advance the PC past the breakpoint. */
4274 enum breakpoint_here
4275 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4277 struct bp_location
*bl
, **blp_tmp
;
4278 int any_breakpoint_here
= 0;
4280 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4282 if (bl
->loc_type
!= bp_loc_software_breakpoint
4283 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4286 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4287 if ((breakpoint_enabled (bl
->owner
)
4289 && breakpoint_location_address_match (bl
, aspace
, pc
))
4291 if (overlay_debugging
4292 && section_is_overlay (bl
->section
)
4293 && !section_is_mapped (bl
->section
))
4294 continue; /* unmapped overlay -- can't be a match */
4295 else if (bl
->permanent
)
4296 return permanent_breakpoint_here
;
4298 any_breakpoint_here
= 1;
4302 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4305 /* See breakpoint.h. */
4308 breakpoint_in_range_p (struct address_space
*aspace
,
4309 CORE_ADDR addr
, ULONGEST len
)
4311 struct bp_location
*bl
, **blp_tmp
;
4313 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4315 if (bl
->loc_type
!= bp_loc_software_breakpoint
4316 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4319 if ((breakpoint_enabled (bl
->owner
)
4321 && breakpoint_location_address_range_overlap (bl
, aspace
,
4324 if (overlay_debugging
4325 && section_is_overlay (bl
->section
)
4326 && !section_is_mapped (bl
->section
))
4328 /* Unmapped overlay -- can't be a match. */
4339 /* Return true if there's a moribund breakpoint at PC. */
4342 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4344 struct bp_location
*loc
;
4347 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4348 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4354 /* Returns non-zero iff BL is inserted at PC, in address space
4358 bp_location_inserted_here_p (struct bp_location
*bl
,
4359 struct address_space
*aspace
, CORE_ADDR pc
)
4362 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4365 if (overlay_debugging
4366 && section_is_overlay (bl
->section
)
4367 && !section_is_mapped (bl
->section
))
4368 return 0; /* unmapped overlay -- can't be a match */
4375 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4378 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4380 struct bp_location
**blp
, **blp_tmp
= NULL
;
4382 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4384 struct bp_location
*bl
= *blp
;
4386 if (bl
->loc_type
!= bp_loc_software_breakpoint
4387 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4390 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4396 /* This function returns non-zero iff there is a software breakpoint
4400 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4403 struct bp_location
**blp
, **blp_tmp
= NULL
;
4405 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4407 struct bp_location
*bl
= *blp
;
4409 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4412 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4419 /* See breakpoint.h. */
4422 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4425 struct bp_location
**blp
, **blp_tmp
= NULL
;
4427 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4429 struct bp_location
*bl
= *blp
;
4431 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4434 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4442 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4443 CORE_ADDR addr
, ULONGEST len
)
4445 struct breakpoint
*bpt
;
4447 ALL_BREAKPOINTS (bpt
)
4449 struct bp_location
*loc
;
4451 if (bpt
->type
!= bp_hardware_watchpoint
4452 && bpt
->type
!= bp_access_watchpoint
)
4455 if (!breakpoint_enabled (bpt
))
4458 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4459 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4463 /* Check for intersection. */
4464 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4465 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4474 /* bpstat stuff. External routines' interfaces are documented
4478 is_catchpoint (struct breakpoint
*ep
)
4480 return (ep
->type
== bp_catchpoint
);
4483 /* Frees any storage that is part of a bpstat. Does not walk the
4487 bpstat_free (bpstat bs
)
4489 if (bs
->old_val
!= NULL
)
4490 value_free (bs
->old_val
);
4491 decref_counted_command_line (&bs
->commands
);
4492 decref_bp_location (&bs
->bp_location_at
);
4496 /* Clear a bpstat so that it says we are not at any breakpoint.
4497 Also free any storage that is part of a bpstat. */
4500 bpstat_clear (bpstat
*bsp
)
4517 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4518 is part of the bpstat is copied as well. */
4521 bpstat_copy (bpstat bs
)
4525 bpstat retval
= NULL
;
4530 for (; bs
!= NULL
; bs
= bs
->next
)
4532 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4533 memcpy (tmp
, bs
, sizeof (*tmp
));
4534 incref_counted_command_line (tmp
->commands
);
4535 incref_bp_location (tmp
->bp_location_at
);
4536 if (bs
->old_val
!= NULL
)
4538 tmp
->old_val
= value_copy (bs
->old_val
);
4539 release_value (tmp
->old_val
);
4543 /* This is the first thing in the chain. */
4553 /* Find the bpstat associated with this breakpoint. */
4556 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4561 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4563 if (bsp
->breakpoint_at
== breakpoint
)
4569 /* See breakpoint.h. */
4572 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4574 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4576 if (bsp
->breakpoint_at
== NULL
)
4578 /* A moribund location can never explain a signal other than
4580 if (sig
== GDB_SIGNAL_TRAP
)
4585 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4594 /* Put in *NUM the breakpoint number of the first breakpoint we are
4595 stopped at. *BSP upon return is a bpstat which points to the
4596 remaining breakpoints stopped at (but which is not guaranteed to be
4597 good for anything but further calls to bpstat_num).
4599 Return 0 if passed a bpstat which does not indicate any breakpoints.
4600 Return -1 if stopped at a breakpoint that has been deleted since
4602 Return 1 otherwise. */
4605 bpstat_num (bpstat
*bsp
, int *num
)
4607 struct breakpoint
*b
;
4610 return 0; /* No more breakpoint values */
4612 /* We assume we'll never have several bpstats that correspond to a
4613 single breakpoint -- otherwise, this function might return the
4614 same number more than once and this will look ugly. */
4615 b
= (*bsp
)->breakpoint_at
;
4616 *bsp
= (*bsp
)->next
;
4618 return -1; /* breakpoint that's been deleted since */
4620 *num
= b
->number
; /* We have its number */
4624 /* See breakpoint.h. */
4627 bpstat_clear_actions (void)
4629 struct thread_info
*tp
;
4632 if (ptid_equal (inferior_ptid
, null_ptid
))
4635 tp
= find_thread_ptid (inferior_ptid
);
4639 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4641 decref_counted_command_line (&bs
->commands
);
4643 if (bs
->old_val
!= NULL
)
4645 value_free (bs
->old_val
);
4651 /* Called when a command is about to proceed the inferior. */
4654 breakpoint_about_to_proceed (void)
4656 if (!ptid_equal (inferior_ptid
, null_ptid
))
4658 struct thread_info
*tp
= inferior_thread ();
4660 /* Allow inferior function calls in breakpoint commands to not
4661 interrupt the command list. When the call finishes
4662 successfully, the inferior will be standing at the same
4663 breakpoint as if nothing happened. */
4664 if (tp
->control
.in_infcall
)
4668 breakpoint_proceeded
= 1;
4671 /* Stub for cleaning up our state if we error-out of a breakpoint
4674 cleanup_executing_breakpoints (void *ignore
)
4676 executing_breakpoint_commands
= 0;
4679 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4680 or its equivalent. */
4683 command_line_is_silent (struct command_line
*cmd
)
4685 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4688 /* Execute all the commands associated with all the breakpoints at
4689 this location. Any of these commands could cause the process to
4690 proceed beyond this point, etc. We look out for such changes by
4691 checking the global "breakpoint_proceeded" after each command.
4693 Returns true if a breakpoint command resumed the inferior. In that
4694 case, it is the caller's responsibility to recall it again with the
4695 bpstat of the current thread. */
4698 bpstat_do_actions_1 (bpstat
*bsp
)
4701 struct cleanup
*old_chain
;
4704 /* Avoid endless recursion if a `source' command is contained
4706 if (executing_breakpoint_commands
)
4709 executing_breakpoint_commands
= 1;
4710 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4712 prevent_dont_repeat ();
4714 /* This pointer will iterate over the list of bpstat's. */
4717 breakpoint_proceeded
= 0;
4718 for (; bs
!= NULL
; bs
= bs
->next
)
4720 struct counted_command_line
*ccmd
;
4721 struct command_line
*cmd
;
4722 struct cleanup
*this_cmd_tree_chain
;
4724 /* Take ownership of the BSP's command tree, if it has one.
4726 The command tree could legitimately contain commands like
4727 'step' and 'next', which call clear_proceed_status, which
4728 frees stop_bpstat's command tree. To make sure this doesn't
4729 free the tree we're executing out from under us, we need to
4730 take ownership of the tree ourselves. Since a given bpstat's
4731 commands are only executed once, we don't need to copy it; we
4732 can clear the pointer in the bpstat, and make sure we free
4733 the tree when we're done. */
4734 ccmd
= bs
->commands
;
4735 bs
->commands
= NULL
;
4736 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4737 cmd
= ccmd
? ccmd
->commands
: NULL
;
4738 if (command_line_is_silent (cmd
))
4740 /* The action has been already done by bpstat_stop_status. */
4746 execute_control_command (cmd
);
4748 if (breakpoint_proceeded
)
4754 /* We can free this command tree now. */
4755 do_cleanups (this_cmd_tree_chain
);
4757 if (breakpoint_proceeded
)
4759 if (current_ui
->async
)
4760 /* If we are in async mode, then the target might be still
4761 running, not stopped at any breakpoint, so nothing for
4762 us to do here -- just return to the event loop. */
4765 /* In sync mode, when execute_control_command returns
4766 we're already standing on the next breakpoint.
4767 Breakpoint commands for that stop were not run, since
4768 execute_command does not run breakpoint commands --
4769 only command_line_handler does, but that one is not
4770 involved in execution of breakpoint commands. So, we
4771 can now execute breakpoint commands. It should be
4772 noted that making execute_command do bpstat actions is
4773 not an option -- in this case we'll have recursive
4774 invocation of bpstat for each breakpoint with a
4775 command, and can easily blow up GDB stack. Instead, we
4776 return true, which will trigger the caller to recall us
4777 with the new stop_bpstat. */
4782 do_cleanups (old_chain
);
4787 bpstat_do_actions (void)
4789 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4791 /* Do any commands attached to breakpoint we are stopped at. */
4792 while (!ptid_equal (inferior_ptid
, null_ptid
)
4793 && target_has_execution
4794 && !is_exited (inferior_ptid
)
4795 && !is_executing (inferior_ptid
))
4796 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4797 and only return when it is stopped at the next breakpoint, we
4798 keep doing breakpoint actions until it returns false to
4799 indicate the inferior was not resumed. */
4800 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4803 discard_cleanups (cleanup_if_error
);
4806 /* Print out the (old or new) value associated with a watchpoint. */
4809 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4812 fprintf_unfiltered (stream
, _("<unreadable>"));
4815 struct value_print_options opts
;
4816 get_user_print_options (&opts
);
4817 value_print (val
, stream
, &opts
);
4821 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4822 debugging multiple threads. */
4825 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4827 if (ui_out_is_mi_like_p (uiout
))
4830 ui_out_text (uiout
, "\n");
4832 if (show_thread_that_caused_stop ())
4835 struct thread_info
*thr
= inferior_thread ();
4837 ui_out_text (uiout
, "Thread ");
4838 ui_out_field_fmt (uiout
, "thread-id", "%s", print_thread_id (thr
));
4840 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4843 ui_out_text (uiout
, " \"");
4844 ui_out_field_fmt (uiout
, "name", "%s", name
);
4845 ui_out_text (uiout
, "\"");
4848 ui_out_text (uiout
, " hit ");
4852 /* Generic routine for printing messages indicating why we
4853 stopped. The behavior of this function depends on the value
4854 'print_it' in the bpstat structure. Under some circumstances we
4855 may decide not to print anything here and delegate the task to
4858 static enum print_stop_action
4859 print_bp_stop_message (bpstat bs
)
4861 switch (bs
->print_it
)
4864 /* Nothing should be printed for this bpstat entry. */
4865 return PRINT_UNKNOWN
;
4869 /* We still want to print the frame, but we already printed the
4870 relevant messages. */
4871 return PRINT_SRC_AND_LOC
;
4874 case print_it_normal
:
4876 struct breakpoint
*b
= bs
->breakpoint_at
;
4878 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4879 which has since been deleted. */
4881 return PRINT_UNKNOWN
;
4883 /* Normal case. Call the breakpoint's print_it method. */
4884 return b
->ops
->print_it (bs
);
4889 internal_error (__FILE__
, __LINE__
,
4890 _("print_bp_stop_message: unrecognized enum value"));
4895 /* A helper function that prints a shared library stopped event. */
4898 print_solib_event (int is_catchpoint
)
4901 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4903 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4907 if (any_added
|| any_deleted
)
4908 ui_out_text (current_uiout
,
4909 _("Stopped due to shared library event:\n"));
4911 ui_out_text (current_uiout
,
4912 _("Stopped due to shared library event (no "
4913 "libraries added or removed)\n"));
4916 if (ui_out_is_mi_like_p (current_uiout
))
4917 ui_out_field_string (current_uiout
, "reason",
4918 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4922 struct cleanup
*cleanup
;
4926 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4927 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4930 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4935 ui_out_text (current_uiout
, " ");
4936 ui_out_field_string (current_uiout
, "library", name
);
4937 ui_out_text (current_uiout
, "\n");
4940 do_cleanups (cleanup
);
4945 struct so_list
*iter
;
4947 struct cleanup
*cleanup
;
4949 ui_out_text (current_uiout
, _(" Inferior loaded "));
4950 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4953 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4958 ui_out_text (current_uiout
, " ");
4959 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4960 ui_out_text (current_uiout
, "\n");
4963 do_cleanups (cleanup
);
4967 /* Print a message indicating what happened. This is called from
4968 normal_stop(). The input to this routine is the head of the bpstat
4969 list - a list of the eventpoints that caused this stop. KIND is
4970 the target_waitkind for the stopping event. This
4971 routine calls the generic print routine for printing a message
4972 about reasons for stopping. This will print (for example) the
4973 "Breakpoint n," part of the output. The return value of this
4976 PRINT_UNKNOWN: Means we printed nothing.
4977 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4978 code to print the location. An example is
4979 "Breakpoint 1, " which should be followed by
4981 PRINT_SRC_ONLY: Means we printed something, but there is no need
4982 to also print the location part of the message.
4983 An example is the catch/throw messages, which
4984 don't require a location appended to the end.
4985 PRINT_NOTHING: We have done some printing and we don't need any
4986 further info to be printed. */
4988 enum print_stop_action
4989 bpstat_print (bpstat bs
, int kind
)
4991 enum print_stop_action val
;
4993 /* Maybe another breakpoint in the chain caused us to stop.
4994 (Currently all watchpoints go on the bpstat whether hit or not.
4995 That probably could (should) be changed, provided care is taken
4996 with respect to bpstat_explains_signal). */
4997 for (; bs
; bs
= bs
->next
)
4999 val
= print_bp_stop_message (bs
);
5000 if (val
== PRINT_SRC_ONLY
5001 || val
== PRINT_SRC_AND_LOC
5002 || val
== PRINT_NOTHING
)
5006 /* If we had hit a shared library event breakpoint,
5007 print_bp_stop_message would print out this message. If we hit an
5008 OS-level shared library event, do the same thing. */
5009 if (kind
== TARGET_WAITKIND_LOADED
)
5011 print_solib_event (0);
5012 return PRINT_NOTHING
;
5015 /* We reached the end of the chain, or we got a null BS to start
5016 with and nothing was printed. */
5017 return PRINT_UNKNOWN
;
5020 /* Evaluate the expression EXP and return 1 if value is zero.
5021 This returns the inverse of the condition because it is called
5022 from catch_errors which returns 0 if an exception happened, and if an
5023 exception happens we want execution to stop.
5024 The argument is a "struct expression *" that has been cast to a
5025 "void *" to make it pass through catch_errors. */
5028 breakpoint_cond_eval (void *exp
)
5030 struct value
*mark
= value_mark ();
5031 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
5033 value_free_to_mark (mark
);
5037 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5040 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5044 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5046 **bs_link_pointer
= bs
;
5047 *bs_link_pointer
= &bs
->next
;
5048 bs
->breakpoint_at
= bl
->owner
;
5049 bs
->bp_location_at
= bl
;
5050 incref_bp_location (bl
);
5051 /* If the condition is false, etc., don't do the commands. */
5052 bs
->commands
= NULL
;
5054 bs
->print_it
= print_it_normal
;
5058 /* The target has stopped with waitstatus WS. Check if any hardware
5059 watchpoints have triggered, according to the target. */
5062 watchpoints_triggered (struct target_waitstatus
*ws
)
5064 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5066 struct breakpoint
*b
;
5068 if (!stopped_by_watchpoint
)
5070 /* We were not stopped by a watchpoint. Mark all watchpoints
5071 as not triggered. */
5073 if (is_hardware_watchpoint (b
))
5075 struct watchpoint
*w
= (struct watchpoint
*) b
;
5077 w
->watchpoint_triggered
= watch_triggered_no
;
5083 if (!target_stopped_data_address (¤t_target
, &addr
))
5085 /* We were stopped by a watchpoint, but we don't know where.
5086 Mark all watchpoints as unknown. */
5088 if (is_hardware_watchpoint (b
))
5090 struct watchpoint
*w
= (struct watchpoint
*) b
;
5092 w
->watchpoint_triggered
= watch_triggered_unknown
;
5098 /* The target could report the data address. Mark watchpoints
5099 affected by this data address as triggered, and all others as not
5103 if (is_hardware_watchpoint (b
))
5105 struct watchpoint
*w
= (struct watchpoint
*) b
;
5106 struct bp_location
*loc
;
5108 w
->watchpoint_triggered
= watch_triggered_no
;
5109 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5111 if (is_masked_watchpoint (b
))
5113 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5114 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5116 if (newaddr
== start
)
5118 w
->watchpoint_triggered
= watch_triggered_yes
;
5122 /* Exact match not required. Within range is sufficient. */
5123 else if (target_watchpoint_addr_within_range (¤t_target
,
5127 w
->watchpoint_triggered
= watch_triggered_yes
;
5136 /* Possible return values for watchpoint_check (this can't be an enum
5137 because of check_errors). */
5138 /* The watchpoint has been deleted. */
5139 #define WP_DELETED 1
5140 /* The value has changed. */
5141 #define WP_VALUE_CHANGED 2
5142 /* The value has not changed. */
5143 #define WP_VALUE_NOT_CHANGED 3
5144 /* Ignore this watchpoint, no matter if the value changed or not. */
5147 #define BP_TEMPFLAG 1
5148 #define BP_HARDWAREFLAG 2
5150 /* Evaluate watchpoint condition expression and check if its value
5153 P should be a pointer to struct bpstat, but is defined as a void *
5154 in order for this function to be usable with catch_errors. */
5157 watchpoint_check (void *p
)
5159 bpstat bs
= (bpstat
) p
;
5160 struct watchpoint
*b
;
5161 struct frame_info
*fr
;
5162 int within_current_scope
;
5164 /* BS is built from an existing struct breakpoint. */
5165 gdb_assert (bs
->breakpoint_at
!= NULL
);
5166 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5168 /* If this is a local watchpoint, we only want to check if the
5169 watchpoint frame is in scope if the current thread is the thread
5170 that was used to create the watchpoint. */
5171 if (!watchpoint_in_thread_scope (b
))
5174 if (b
->exp_valid_block
== NULL
)
5175 within_current_scope
= 1;
5178 struct frame_info
*frame
= get_current_frame ();
5179 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5180 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5182 /* stack_frame_destroyed_p() returns a non-zero value if we're
5183 still in the function but the stack frame has already been
5184 invalidated. Since we can't rely on the values of local
5185 variables after the stack has been destroyed, we are treating
5186 the watchpoint in that state as `not changed' without further
5187 checking. Don't mark watchpoints as changed if the current
5188 frame is in an epilogue - even if they are in some other
5189 frame, our view of the stack is likely to be wrong and
5190 frame_find_by_id could error out. */
5191 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5194 fr
= frame_find_by_id (b
->watchpoint_frame
);
5195 within_current_scope
= (fr
!= NULL
);
5197 /* If we've gotten confused in the unwinder, we might have
5198 returned a frame that can't describe this variable. */
5199 if (within_current_scope
)
5201 struct symbol
*function
;
5203 function
= get_frame_function (fr
);
5204 if (function
== NULL
5205 || !contained_in (b
->exp_valid_block
,
5206 SYMBOL_BLOCK_VALUE (function
)))
5207 within_current_scope
= 0;
5210 if (within_current_scope
)
5211 /* If we end up stopping, the current frame will get selected
5212 in normal_stop. So this call to select_frame won't affect
5217 if (within_current_scope
)
5219 /* We use value_{,free_to_}mark because it could be a *long*
5220 time before we return to the command level and call
5221 free_all_values. We can't call free_all_values because we
5222 might be in the middle of evaluating a function call. */
5226 struct value
*new_val
;
5228 if (is_masked_watchpoint (&b
->base
))
5229 /* Since we don't know the exact trigger address (from
5230 stopped_data_address), just tell the user we've triggered
5231 a mask watchpoint. */
5232 return WP_VALUE_CHANGED
;
5234 mark
= value_mark ();
5235 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5237 if (b
->val_bitsize
!= 0)
5238 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5240 /* We use value_equal_contents instead of value_equal because
5241 the latter coerces an array to a pointer, thus comparing just
5242 the address of the array instead of its contents. This is
5243 not what we want. */
5244 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5245 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5247 if (new_val
!= NULL
)
5249 release_value (new_val
);
5250 value_free_to_mark (mark
);
5252 bs
->old_val
= b
->val
;
5255 return WP_VALUE_CHANGED
;
5259 /* Nothing changed. */
5260 value_free_to_mark (mark
);
5261 return WP_VALUE_NOT_CHANGED
;
5266 /* This seems like the only logical thing to do because
5267 if we temporarily ignored the watchpoint, then when
5268 we reenter the block in which it is valid it contains
5269 garbage (in the case of a function, it may have two
5270 garbage values, one before and one after the prologue).
5271 So we can't even detect the first assignment to it and
5272 watch after that (since the garbage may or may not equal
5273 the first value assigned). */
5274 /* We print all the stop information in
5275 breakpoint_ops->print_it, but in this case, by the time we
5276 call breakpoint_ops->print_it this bp will be deleted
5277 already. So we have no choice but print the information
5280 SWITCH_THRU_ALL_UIS ()
5282 struct ui_out
*uiout
= current_uiout
;
5284 if (ui_out_is_mi_like_p (uiout
))
5286 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5287 ui_out_text (uiout
, "\nWatchpoint ");
5288 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5290 " deleted because the program has left the block in\n"
5291 "which its expression is valid.\n");
5294 /* Make sure the watchpoint's commands aren't executed. */
5295 decref_counted_command_line (&b
->base
.commands
);
5296 watchpoint_del_at_next_stop (b
);
5302 /* Return true if it looks like target has stopped due to hitting
5303 breakpoint location BL. This function does not check if we should
5304 stop, only if BL explains the stop. */
5307 bpstat_check_location (const struct bp_location
*bl
,
5308 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5309 const struct target_waitstatus
*ws
)
5311 struct breakpoint
*b
= bl
->owner
;
5313 /* BL is from an existing breakpoint. */
5314 gdb_assert (b
!= NULL
);
5316 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5319 /* Determine if the watched values have actually changed, and we
5320 should stop. If not, set BS->stop to 0. */
5323 bpstat_check_watchpoint (bpstat bs
)
5325 const struct bp_location
*bl
;
5326 struct watchpoint
*b
;
5328 /* BS is built for existing struct breakpoint. */
5329 bl
= bs
->bp_location_at
;
5330 gdb_assert (bl
!= NULL
);
5331 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5332 gdb_assert (b
!= NULL
);
5335 int must_check_value
= 0;
5337 if (b
->base
.type
== bp_watchpoint
)
5338 /* For a software watchpoint, we must always check the
5340 must_check_value
= 1;
5341 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5342 /* We have a hardware watchpoint (read, write, or access)
5343 and the target earlier reported an address watched by
5345 must_check_value
= 1;
5346 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5347 && b
->base
.type
== bp_hardware_watchpoint
)
5348 /* We were stopped by a hardware watchpoint, but the target could
5349 not report the data address. We must check the watchpoint's
5350 value. Access and read watchpoints are out of luck; without
5351 a data address, we can't figure it out. */
5352 must_check_value
= 1;
5354 if (must_check_value
)
5357 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5359 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5360 int e
= catch_errors (watchpoint_check
, bs
, message
,
5362 do_cleanups (cleanups
);
5366 /* We've already printed what needs to be printed. */
5367 bs
->print_it
= print_it_done
;
5371 bs
->print_it
= print_it_noop
;
5374 case WP_VALUE_CHANGED
:
5375 if (b
->base
.type
== bp_read_watchpoint
)
5377 /* There are two cases to consider here:
5379 1. We're watching the triggered memory for reads.
5380 In that case, trust the target, and always report
5381 the watchpoint hit to the user. Even though
5382 reads don't cause value changes, the value may
5383 have changed since the last time it was read, and
5384 since we're not trapping writes, we will not see
5385 those, and as such we should ignore our notion of
5388 2. We're watching the triggered memory for both
5389 reads and writes. There are two ways this may
5392 2.1. This is a target that can't break on data
5393 reads only, but can break on accesses (reads or
5394 writes), such as e.g., x86. We detect this case
5395 at the time we try to insert read watchpoints.
5397 2.2. Otherwise, the target supports read
5398 watchpoints, but, the user set an access or write
5399 watchpoint watching the same memory as this read
5402 If we're watching memory writes as well as reads,
5403 ignore watchpoint hits when we find that the
5404 value hasn't changed, as reads don't cause
5405 changes. This still gives false positives when
5406 the program writes the same value to memory as
5407 what there was already in memory (we will confuse
5408 it for a read), but it's much better than
5411 int other_write_watchpoint
= 0;
5413 if (bl
->watchpoint_type
== hw_read
)
5415 struct breakpoint
*other_b
;
5417 ALL_BREAKPOINTS (other_b
)
5418 if (other_b
->type
== bp_hardware_watchpoint
5419 || other_b
->type
== bp_access_watchpoint
)
5421 struct watchpoint
*other_w
=
5422 (struct watchpoint
*) other_b
;
5424 if (other_w
->watchpoint_triggered
5425 == watch_triggered_yes
)
5427 other_write_watchpoint
= 1;
5433 if (other_write_watchpoint
5434 || bl
->watchpoint_type
== hw_access
)
5436 /* We're watching the same memory for writes,
5437 and the value changed since the last time we
5438 updated it, so this trap must be for a write.
5440 bs
->print_it
= print_it_noop
;
5445 case WP_VALUE_NOT_CHANGED
:
5446 if (b
->base
.type
== bp_hardware_watchpoint
5447 || b
->base
.type
== bp_watchpoint
)
5449 /* Don't stop: write watchpoints shouldn't fire if
5450 the value hasn't changed. */
5451 bs
->print_it
= print_it_noop
;
5459 /* Error from catch_errors. */
5461 SWITCH_THRU_ALL_UIS ()
5463 printf_filtered (_("Watchpoint %d deleted.\n"),
5466 watchpoint_del_at_next_stop (b
);
5467 /* We've already printed what needs to be printed. */
5468 bs
->print_it
= print_it_done
;
5473 else /* must_check_value == 0 */
5475 /* This is a case where some watchpoint(s) triggered, but
5476 not at the address of this watchpoint, or else no
5477 watchpoint triggered after all. So don't print
5478 anything for this watchpoint. */
5479 bs
->print_it
= print_it_noop
;
5485 /* For breakpoints that are currently marked as telling gdb to stop,
5486 check conditions (condition proper, frame, thread and ignore count)
5487 of breakpoint referred to by BS. If we should not stop for this
5488 breakpoint, set BS->stop to 0. */
5491 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5493 const struct bp_location
*bl
;
5494 struct breakpoint
*b
;
5495 int value_is_zero
= 0;
5496 struct expression
*cond
;
5498 gdb_assert (bs
->stop
);
5500 /* BS is built for existing struct breakpoint. */
5501 bl
= bs
->bp_location_at
;
5502 gdb_assert (bl
!= NULL
);
5503 b
= bs
->breakpoint_at
;
5504 gdb_assert (b
!= NULL
);
5506 /* Even if the target evaluated the condition on its end and notified GDB, we
5507 need to do so again since GDB does not know if we stopped due to a
5508 breakpoint or a single step breakpoint. */
5510 if (frame_id_p (b
->frame_id
)
5511 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5517 /* If this is a thread/task-specific breakpoint, don't waste cpu
5518 evaluating the condition if this isn't the specified
5520 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5521 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5528 /* Evaluate extension language breakpoints that have a "stop" method
5530 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5532 if (is_watchpoint (b
))
5534 struct watchpoint
*w
= (struct watchpoint
*) b
;
5541 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5543 int within_current_scope
= 1;
5544 struct watchpoint
* w
;
5546 /* We use value_mark and value_free_to_mark because it could
5547 be a long time before we return to the command level and
5548 call free_all_values. We can't call free_all_values
5549 because we might be in the middle of evaluating a
5551 struct value
*mark
= value_mark ();
5553 if (is_watchpoint (b
))
5554 w
= (struct watchpoint
*) b
;
5558 /* Need to select the frame, with all that implies so that
5559 the conditions will have the right context. Because we
5560 use the frame, we will not see an inlined function's
5561 variables when we arrive at a breakpoint at the start
5562 of the inlined function; the current frame will be the
5564 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5565 select_frame (get_current_frame ());
5568 struct frame_info
*frame
;
5570 /* For local watchpoint expressions, which particular
5571 instance of a local is being watched matters, so we
5572 keep track of the frame to evaluate the expression
5573 in. To evaluate the condition however, it doesn't
5574 really matter which instantiation of the function
5575 where the condition makes sense triggers the
5576 watchpoint. This allows an expression like "watch
5577 global if q > 10" set in `func', catch writes to
5578 global on all threads that call `func', or catch
5579 writes on all recursive calls of `func' by a single
5580 thread. We simply always evaluate the condition in
5581 the innermost frame that's executing where it makes
5582 sense to evaluate the condition. It seems
5584 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5586 select_frame (frame
);
5588 within_current_scope
= 0;
5590 if (within_current_scope
)
5592 = catch_errors (breakpoint_cond_eval
, cond
,
5593 "Error in testing breakpoint condition:\n",
5597 warning (_("Watchpoint condition cannot be tested "
5598 "in the current scope"));
5599 /* If we failed to set the right context for this
5600 watchpoint, unconditionally report it. */
5603 /* FIXME-someday, should give breakpoint #. */
5604 value_free_to_mark (mark
);
5607 if (cond
&& value_is_zero
)
5611 else if (b
->ignore_count
> 0)
5615 /* Increase the hit count even though we don't stop. */
5617 observer_notify_breakpoint_modified (b
);
5621 /* Returns true if we need to track moribund locations of LOC's type
5622 on the current target. */
5625 need_moribund_for_location_type (struct bp_location
*loc
)
5627 return ((loc
->loc_type
== bp_loc_software_breakpoint
5628 && !target_supports_stopped_by_sw_breakpoint ())
5629 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5630 && !target_supports_stopped_by_hw_breakpoint ()));
5634 /* Get a bpstat associated with having just stopped at address
5635 BP_ADDR in thread PTID.
5637 Determine whether we stopped at a breakpoint, etc, or whether we
5638 don't understand this stop. Result is a chain of bpstat's such
5641 if we don't understand the stop, the result is a null pointer.
5643 if we understand why we stopped, the result is not null.
5645 Each element of the chain refers to a particular breakpoint or
5646 watchpoint at which we have stopped. (We may have stopped for
5647 several reasons concurrently.)
5649 Each element of the chain has valid next, breakpoint_at,
5650 commands, FIXME??? fields. */
5653 bpstat_stop_status (struct address_space
*aspace
,
5654 CORE_ADDR bp_addr
, ptid_t ptid
,
5655 const struct target_waitstatus
*ws
)
5657 struct breakpoint
*b
= NULL
;
5658 struct bp_location
*bl
;
5659 struct bp_location
*loc
;
5660 /* First item of allocated bpstat's. */
5661 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5662 /* Pointer to the last thing in the chain currently. */
5665 int need_remove_insert
;
5668 /* First, build the bpstat chain with locations that explain a
5669 target stop, while being careful to not set the target running,
5670 as that may invalidate locations (in particular watchpoint
5671 locations are recreated). Resuming will happen here with
5672 breakpoint conditions or watchpoint expressions that include
5673 inferior function calls. */
5677 if (!breakpoint_enabled (b
))
5680 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5682 /* For hardware watchpoints, we look only at the first
5683 location. The watchpoint_check function will work on the
5684 entire expression, not the individual locations. For
5685 read watchpoints, the watchpoints_triggered function has
5686 checked all locations already. */
5687 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5690 if (!bl
->enabled
|| bl
->shlib_disabled
)
5693 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5696 /* Come here if it's a watchpoint, or if the break address
5699 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5702 /* Assume we stop. Should we find a watchpoint that is not
5703 actually triggered, or if the condition of the breakpoint
5704 evaluates as false, we'll reset 'stop' to 0. */
5708 /* If this is a scope breakpoint, mark the associated
5709 watchpoint as triggered so that we will handle the
5710 out-of-scope event. We'll get to the watchpoint next
5712 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5714 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5716 w
->watchpoint_triggered
= watch_triggered_yes
;
5721 /* Check if a moribund breakpoint explains the stop. */
5722 if (!target_supports_stopped_by_sw_breakpoint ()
5723 || !target_supports_stopped_by_hw_breakpoint ())
5725 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5727 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5728 && need_moribund_for_location_type (loc
))
5730 bs
= bpstat_alloc (loc
, &bs_link
);
5731 /* For hits of moribund locations, we should just proceed. */
5734 bs
->print_it
= print_it_noop
;
5739 /* A bit of special processing for shlib breakpoints. We need to
5740 process solib loading here, so that the lists of loaded and
5741 unloaded libraries are correct before we handle "catch load" and
5743 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5745 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5747 handle_solib_event ();
5752 /* Now go through the locations that caused the target to stop, and
5753 check whether we're interested in reporting this stop to higher
5754 layers, or whether we should resume the target transparently. */
5758 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5763 b
= bs
->breakpoint_at
;
5764 b
->ops
->check_status (bs
);
5767 bpstat_check_breakpoint_conditions (bs
, ptid
);
5772 observer_notify_breakpoint_modified (b
);
5774 /* We will stop here. */
5775 if (b
->disposition
== disp_disable
)
5777 --(b
->enable_count
);
5778 if (b
->enable_count
<= 0)
5779 b
->enable_state
= bp_disabled
;
5784 bs
->commands
= b
->commands
;
5785 incref_counted_command_line (bs
->commands
);
5786 if (command_line_is_silent (bs
->commands
5787 ? bs
->commands
->commands
: NULL
))
5790 b
->ops
->after_condition_true (bs
);
5795 /* Print nothing for this entry if we don't stop or don't
5797 if (!bs
->stop
|| !bs
->print
)
5798 bs
->print_it
= print_it_noop
;
5801 /* If we aren't stopping, the value of some hardware watchpoint may
5802 not have changed, but the intermediate memory locations we are
5803 watching may have. Don't bother if we're stopping; this will get
5805 need_remove_insert
= 0;
5806 if (! bpstat_causes_stop (bs_head
))
5807 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5809 && bs
->breakpoint_at
5810 && is_hardware_watchpoint (bs
->breakpoint_at
))
5812 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5814 update_watchpoint (w
, 0 /* don't reparse. */);
5815 need_remove_insert
= 1;
5818 if (need_remove_insert
)
5819 update_global_location_list (UGLL_MAY_INSERT
);
5820 else if (removed_any
)
5821 update_global_location_list (UGLL_DONT_INSERT
);
5827 handle_jit_event (void)
5829 struct frame_info
*frame
;
5830 struct gdbarch
*gdbarch
;
5833 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5835 /* Switch terminal for any messages produced by
5836 breakpoint_re_set. */
5837 target_terminal_ours_for_output ();
5839 frame
= get_current_frame ();
5840 gdbarch
= get_frame_arch (frame
);
5842 jit_event_handler (gdbarch
);
5844 target_terminal_inferior ();
5847 /* Prepare WHAT final decision for infrun. */
5849 /* Decide what infrun needs to do with this bpstat. */
5852 bpstat_what (bpstat bs_head
)
5854 struct bpstat_what retval
;
5857 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5858 retval
.call_dummy
= STOP_NONE
;
5859 retval
.is_longjmp
= 0;
5861 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5863 /* Extract this BS's action. After processing each BS, we check
5864 if its action overrides all we've seem so far. */
5865 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5868 if (bs
->breakpoint_at
== NULL
)
5870 /* I suspect this can happen if it was a momentary
5871 breakpoint which has since been deleted. */
5875 bptype
= bs
->breakpoint_at
->type
;
5882 case bp_hardware_breakpoint
:
5883 case bp_single_step
:
5886 case bp_shlib_event
:
5890 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5892 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5895 this_action
= BPSTAT_WHAT_SINGLE
;
5898 case bp_hardware_watchpoint
:
5899 case bp_read_watchpoint
:
5900 case bp_access_watchpoint
:
5904 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5906 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5910 /* There was a watchpoint, but we're not stopping.
5911 This requires no further action. */
5915 case bp_longjmp_call_dummy
:
5919 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5920 retval
.is_longjmp
= bptype
!= bp_exception
;
5923 this_action
= BPSTAT_WHAT_SINGLE
;
5925 case bp_longjmp_resume
:
5926 case bp_exception_resume
:
5929 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5930 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5933 this_action
= BPSTAT_WHAT_SINGLE
;
5935 case bp_step_resume
:
5937 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5940 /* It is for the wrong frame. */
5941 this_action
= BPSTAT_WHAT_SINGLE
;
5944 case bp_hp_step_resume
:
5946 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5949 /* It is for the wrong frame. */
5950 this_action
= BPSTAT_WHAT_SINGLE
;
5953 case bp_watchpoint_scope
:
5954 case bp_thread_event
:
5955 case bp_overlay_event
:
5956 case bp_longjmp_master
:
5957 case bp_std_terminate_master
:
5958 case bp_exception_master
:
5959 this_action
= BPSTAT_WHAT_SINGLE
;
5965 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5967 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5971 /* There was a catchpoint, but we're not stopping.
5972 This requires no further action. */
5976 this_action
= BPSTAT_WHAT_SINGLE
;
5979 /* Make sure the action is stop (silent or noisy),
5980 so infrun.c pops the dummy frame. */
5981 retval
.call_dummy
= STOP_STACK_DUMMY
;
5982 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5984 case bp_std_terminate
:
5985 /* Make sure the action is stop (silent or noisy),
5986 so infrun.c pops the dummy frame. */
5987 retval
.call_dummy
= STOP_STD_TERMINATE
;
5988 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5991 case bp_fast_tracepoint
:
5992 case bp_static_tracepoint
:
5993 /* Tracepoint hits should not be reported back to GDB, and
5994 if one got through somehow, it should have been filtered
5996 internal_error (__FILE__
, __LINE__
,
5997 _("bpstat_what: tracepoint encountered"));
5999 case bp_gnu_ifunc_resolver
:
6000 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6001 this_action
= BPSTAT_WHAT_SINGLE
;
6003 case bp_gnu_ifunc_resolver_return
:
6004 /* The breakpoint will be removed, execution will restart from the
6005 PC of the former breakpoint. */
6006 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6011 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6013 this_action
= BPSTAT_WHAT_SINGLE
;
6017 internal_error (__FILE__
, __LINE__
,
6018 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
6021 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6028 bpstat_run_callbacks (bpstat bs_head
)
6032 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6034 struct breakpoint
*b
= bs
->breakpoint_at
;
6041 handle_jit_event ();
6043 case bp_gnu_ifunc_resolver
:
6044 gnu_ifunc_resolver_stop (b
);
6046 case bp_gnu_ifunc_resolver_return
:
6047 gnu_ifunc_resolver_return_stop (b
);
6053 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6054 without hardware support). This isn't related to a specific bpstat,
6055 just to things like whether watchpoints are set. */
6058 bpstat_should_step (void)
6060 struct breakpoint
*b
;
6063 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6069 bpstat_causes_stop (bpstat bs
)
6071 for (; bs
!= NULL
; bs
= bs
->next
)
6080 /* Compute a string of spaces suitable to indent the next line
6081 so it starts at the position corresponding to the table column
6082 named COL_NAME in the currently active table of UIOUT. */
6085 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6087 static char wrap_indent
[80];
6088 int i
, total_width
, width
, align
;
6092 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
6094 if (strcmp (text
, col_name
) == 0)
6096 gdb_assert (total_width
< sizeof wrap_indent
);
6097 memset (wrap_indent
, ' ', total_width
);
6098 wrap_indent
[total_width
] = 0;
6103 total_width
+= width
+ 1;
6109 /* Determine if the locations of this breakpoint will have their conditions
6110 evaluated by the target, host or a mix of both. Returns the following:
6112 "host": Host evals condition.
6113 "host or target": Host or Target evals condition.
6114 "target": Target evals condition.
6118 bp_condition_evaluator (struct breakpoint
*b
)
6120 struct bp_location
*bl
;
6121 char host_evals
= 0;
6122 char target_evals
= 0;
6127 if (!is_breakpoint (b
))
6130 if (gdb_evaluates_breakpoint_condition_p ()
6131 || !target_supports_evaluation_of_breakpoint_conditions ())
6132 return condition_evaluation_host
;
6134 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6136 if (bl
->cond_bytecode
)
6142 if (host_evals
&& target_evals
)
6143 return condition_evaluation_both
;
6144 else if (target_evals
)
6145 return condition_evaluation_target
;
6147 return condition_evaluation_host
;
6150 /* Determine the breakpoint location's condition evaluator. This is
6151 similar to bp_condition_evaluator, but for locations. */
6154 bp_location_condition_evaluator (struct bp_location
*bl
)
6156 if (bl
&& !is_breakpoint (bl
->owner
))
6159 if (gdb_evaluates_breakpoint_condition_p ()
6160 || !target_supports_evaluation_of_breakpoint_conditions ())
6161 return condition_evaluation_host
;
6163 if (bl
&& bl
->cond_bytecode
)
6164 return condition_evaluation_target
;
6166 return condition_evaluation_host
;
6169 /* Print the LOC location out of the list of B->LOC locations. */
6172 print_breakpoint_location (struct breakpoint
*b
,
6173 struct bp_location
*loc
)
6175 struct ui_out
*uiout
= current_uiout
;
6176 struct cleanup
*old_chain
= save_current_program_space ();
6178 if (loc
!= NULL
&& loc
->shlib_disabled
)
6182 set_current_program_space (loc
->pspace
);
6184 if (b
->display_canonical
)
6185 ui_out_field_string (uiout
, "what",
6186 event_location_to_string (b
->location
));
6187 else if (loc
&& loc
->symtab
)
6190 = find_pc_sect_function (loc
->address
, loc
->section
);
6193 ui_out_text (uiout
, "in ");
6194 ui_out_field_string (uiout
, "func",
6195 SYMBOL_PRINT_NAME (sym
));
6196 ui_out_text (uiout
, " ");
6197 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6198 ui_out_text (uiout
, "at ");
6200 ui_out_field_string (uiout
, "file",
6201 symtab_to_filename_for_display (loc
->symtab
));
6202 ui_out_text (uiout
, ":");
6204 if (ui_out_is_mi_like_p (uiout
))
6205 ui_out_field_string (uiout
, "fullname",
6206 symtab_to_fullname (loc
->symtab
));
6208 ui_out_field_int (uiout
, "line", loc
->line_number
);
6212 struct ui_file
*stb
= mem_fileopen ();
6213 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6215 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6217 ui_out_field_stream (uiout
, "at", stb
);
6219 do_cleanups (stb_chain
);
6223 ui_out_field_string (uiout
, "pending",
6224 event_location_to_string (b
->location
));
6225 /* If extra_string is available, it could be holding a condition
6226 or dprintf arguments. In either case, make sure it is printed,
6227 too, but only for non-MI streams. */
6228 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6230 if (b
->type
== bp_dprintf
)
6231 ui_out_text (uiout
, ",");
6233 ui_out_text (uiout
, " ");
6234 ui_out_text (uiout
, b
->extra_string
);
6238 if (loc
&& is_breakpoint (b
)
6239 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6240 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6242 ui_out_text (uiout
, " (");
6243 ui_out_field_string (uiout
, "evaluated-by",
6244 bp_location_condition_evaluator (loc
));
6245 ui_out_text (uiout
, ")");
6248 do_cleanups (old_chain
);
6252 bptype_string (enum bptype type
)
6254 struct ep_type_description
6259 static struct ep_type_description bptypes
[] =
6261 {bp_none
, "?deleted?"},
6262 {bp_breakpoint
, "breakpoint"},
6263 {bp_hardware_breakpoint
, "hw breakpoint"},
6264 {bp_single_step
, "sw single-step"},
6265 {bp_until
, "until"},
6266 {bp_finish
, "finish"},
6267 {bp_watchpoint
, "watchpoint"},
6268 {bp_hardware_watchpoint
, "hw watchpoint"},
6269 {bp_read_watchpoint
, "read watchpoint"},
6270 {bp_access_watchpoint
, "acc watchpoint"},
6271 {bp_longjmp
, "longjmp"},
6272 {bp_longjmp_resume
, "longjmp resume"},
6273 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6274 {bp_exception
, "exception"},
6275 {bp_exception_resume
, "exception resume"},
6276 {bp_step_resume
, "step resume"},
6277 {bp_hp_step_resume
, "high-priority step resume"},
6278 {bp_watchpoint_scope
, "watchpoint scope"},
6279 {bp_call_dummy
, "call dummy"},
6280 {bp_std_terminate
, "std::terminate"},
6281 {bp_shlib_event
, "shlib events"},
6282 {bp_thread_event
, "thread events"},
6283 {bp_overlay_event
, "overlay events"},
6284 {bp_longjmp_master
, "longjmp master"},
6285 {bp_std_terminate_master
, "std::terminate master"},
6286 {bp_exception_master
, "exception master"},
6287 {bp_catchpoint
, "catchpoint"},
6288 {bp_tracepoint
, "tracepoint"},
6289 {bp_fast_tracepoint
, "fast tracepoint"},
6290 {bp_static_tracepoint
, "static tracepoint"},
6291 {bp_dprintf
, "dprintf"},
6292 {bp_jit_event
, "jit events"},
6293 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6294 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6297 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6298 || ((int) type
!= bptypes
[(int) type
].type
))
6299 internal_error (__FILE__
, __LINE__
,
6300 _("bptypes table does not describe type #%d."),
6303 return bptypes
[(int) type
].description
;
6306 /* For MI, output a field named 'thread-groups' with a list as the value.
6307 For CLI, prefix the list with the string 'inf'. */
6310 output_thread_groups (struct ui_out
*uiout
,
6311 const char *field_name
,
6315 struct cleanup
*back_to
;
6316 int is_mi
= ui_out_is_mi_like_p (uiout
);
6320 /* For backward compatibility, don't display inferiors in CLI unless
6321 there are several. Always display them for MI. */
6322 if (!is_mi
&& mi_only
)
6325 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6327 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6333 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6334 ui_out_field_string (uiout
, NULL
, mi_group
);
6339 ui_out_text (uiout
, " inf ");
6341 ui_out_text (uiout
, ", ");
6343 ui_out_text (uiout
, plongest (inf
));
6347 do_cleanups (back_to
);
6350 /* Print B to gdb_stdout. */
6353 print_one_breakpoint_location (struct breakpoint
*b
,
6354 struct bp_location
*loc
,
6356 struct bp_location
**last_loc
,
6359 struct command_line
*l
;
6360 static char bpenables
[] = "nynny";
6362 struct ui_out
*uiout
= current_uiout
;
6363 int header_of_multiple
= 0;
6364 int part_of_multiple
= (loc
!= NULL
);
6365 struct value_print_options opts
;
6367 get_user_print_options (&opts
);
6369 gdb_assert (!loc
|| loc_number
!= 0);
6370 /* See comment in print_one_breakpoint concerning treatment of
6371 breakpoints with single disabled location. */
6374 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6375 header_of_multiple
= 1;
6383 if (part_of_multiple
)
6386 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6387 ui_out_field_string (uiout
, "number", formatted
);
6392 ui_out_field_int (uiout
, "number", b
->number
);
6397 if (part_of_multiple
)
6398 ui_out_field_skip (uiout
, "type");
6400 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6404 if (part_of_multiple
)
6405 ui_out_field_skip (uiout
, "disp");
6407 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6412 if (part_of_multiple
)
6413 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6415 ui_out_field_fmt (uiout
, "enabled", "%c",
6416 bpenables
[(int) b
->enable_state
]);
6417 ui_out_spaces (uiout
, 2);
6421 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6423 /* Although the print_one can possibly print all locations,
6424 calling it here is not likely to get any nice result. So,
6425 make sure there's just one location. */
6426 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6427 b
->ops
->print_one (b
, last_loc
);
6433 internal_error (__FILE__
, __LINE__
,
6434 _("print_one_breakpoint: bp_none encountered\n"));
6438 case bp_hardware_watchpoint
:
6439 case bp_read_watchpoint
:
6440 case bp_access_watchpoint
:
6442 struct watchpoint
*w
= (struct watchpoint
*) b
;
6444 /* Field 4, the address, is omitted (which makes the columns
6445 not line up too nicely with the headers, but the effect
6446 is relatively readable). */
6447 if (opts
.addressprint
)
6448 ui_out_field_skip (uiout
, "addr");
6450 ui_out_field_string (uiout
, "what", w
->exp_string
);
6455 case bp_hardware_breakpoint
:
6456 case bp_single_step
:
6460 case bp_longjmp_resume
:
6461 case bp_longjmp_call_dummy
:
6463 case bp_exception_resume
:
6464 case bp_step_resume
:
6465 case bp_hp_step_resume
:
6466 case bp_watchpoint_scope
:
6468 case bp_std_terminate
:
6469 case bp_shlib_event
:
6470 case bp_thread_event
:
6471 case bp_overlay_event
:
6472 case bp_longjmp_master
:
6473 case bp_std_terminate_master
:
6474 case bp_exception_master
:
6476 case bp_fast_tracepoint
:
6477 case bp_static_tracepoint
:
6480 case bp_gnu_ifunc_resolver
:
6481 case bp_gnu_ifunc_resolver_return
:
6482 if (opts
.addressprint
)
6485 if (header_of_multiple
)
6486 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6487 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6488 ui_out_field_string (uiout
, "addr", "<PENDING>");
6490 ui_out_field_core_addr (uiout
, "addr",
6491 loc
->gdbarch
, loc
->address
);
6494 if (!header_of_multiple
)
6495 print_breakpoint_location (b
, loc
);
6502 if (loc
!= NULL
&& !header_of_multiple
)
6504 struct inferior
*inf
;
6505 VEC(int) *inf_num
= NULL
;
6510 if (inf
->pspace
== loc
->pspace
)
6511 VEC_safe_push (int, inf_num
, inf
->num
);
6514 /* For backward compatibility, don't display inferiors in CLI unless
6515 there are several. Always display for MI. */
6517 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6518 && (number_of_program_spaces () > 1
6519 || number_of_inferiors () > 1)
6520 /* LOC is for existing B, it cannot be in
6521 moribund_locations and thus having NULL OWNER. */
6522 && loc
->owner
->type
!= bp_catchpoint
))
6524 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6525 VEC_free (int, inf_num
);
6528 if (!part_of_multiple
)
6530 if (b
->thread
!= -1)
6532 /* FIXME: This seems to be redundant and lost here; see the
6533 "stop only in" line a little further down. */
6534 ui_out_text (uiout
, " thread ");
6535 ui_out_field_int (uiout
, "thread", b
->thread
);
6537 else if (b
->task
!= 0)
6539 ui_out_text (uiout
, " task ");
6540 ui_out_field_int (uiout
, "task", b
->task
);
6544 ui_out_text (uiout
, "\n");
6546 if (!part_of_multiple
)
6547 b
->ops
->print_one_detail (b
, uiout
);
6549 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6552 ui_out_text (uiout
, "\tstop only in stack frame at ");
6553 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6555 ui_out_field_core_addr (uiout
, "frame",
6556 b
->gdbarch
, b
->frame_id
.stack_addr
);
6557 ui_out_text (uiout
, "\n");
6560 if (!part_of_multiple
&& b
->cond_string
)
6563 if (is_tracepoint (b
))
6564 ui_out_text (uiout
, "\ttrace only if ");
6566 ui_out_text (uiout
, "\tstop only if ");
6567 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6569 /* Print whether the target is doing the breakpoint's condition
6570 evaluation. If GDB is doing the evaluation, don't print anything. */
6571 if (is_breakpoint (b
)
6572 && breakpoint_condition_evaluation_mode ()
6573 == condition_evaluation_target
)
6575 ui_out_text (uiout
, " (");
6576 ui_out_field_string (uiout
, "evaluated-by",
6577 bp_condition_evaluator (b
));
6578 ui_out_text (uiout
, " evals)");
6580 ui_out_text (uiout
, "\n");
6583 if (!part_of_multiple
&& b
->thread
!= -1)
6585 /* FIXME should make an annotation for this. */
6586 ui_out_text (uiout
, "\tstop only in thread ");
6587 if (ui_out_is_mi_like_p (uiout
))
6588 ui_out_field_int (uiout
, "thread", b
->thread
);
6591 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6593 ui_out_field_string (uiout
, "thread", print_thread_id (thr
));
6595 ui_out_text (uiout
, "\n");
6598 if (!part_of_multiple
)
6602 /* FIXME should make an annotation for this. */
6603 if (is_catchpoint (b
))
6604 ui_out_text (uiout
, "\tcatchpoint");
6605 else if (is_tracepoint (b
))
6606 ui_out_text (uiout
, "\ttracepoint");
6608 ui_out_text (uiout
, "\tbreakpoint");
6609 ui_out_text (uiout
, " already hit ");
6610 ui_out_field_int (uiout
, "times", b
->hit_count
);
6611 if (b
->hit_count
== 1)
6612 ui_out_text (uiout
, " time\n");
6614 ui_out_text (uiout
, " times\n");
6618 /* Output the count also if it is zero, but only if this is mi. */
6619 if (ui_out_is_mi_like_p (uiout
))
6620 ui_out_field_int (uiout
, "times", b
->hit_count
);
6624 if (!part_of_multiple
&& b
->ignore_count
)
6627 ui_out_text (uiout
, "\tignore next ");
6628 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6629 ui_out_text (uiout
, " hits\n");
6632 /* Note that an enable count of 1 corresponds to "enable once"
6633 behavior, which is reported by the combination of enablement and
6634 disposition, so we don't need to mention it here. */
6635 if (!part_of_multiple
&& b
->enable_count
> 1)
6638 ui_out_text (uiout
, "\tdisable after ");
6639 /* Tweak the wording to clarify that ignore and enable counts
6640 are distinct, and have additive effect. */
6641 if (b
->ignore_count
)
6642 ui_out_text (uiout
, "additional ");
6644 ui_out_text (uiout
, "next ");
6645 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6646 ui_out_text (uiout
, " hits\n");
6649 if (!part_of_multiple
&& is_tracepoint (b
))
6651 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6653 if (tp
->traceframe_usage
)
6655 ui_out_text (uiout
, "\ttrace buffer usage ");
6656 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6657 ui_out_text (uiout
, " bytes\n");
6661 l
= b
->commands
? b
->commands
->commands
: NULL
;
6662 if (!part_of_multiple
&& l
)
6664 struct cleanup
*script_chain
;
6667 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6668 print_command_lines (uiout
, l
, 4);
6669 do_cleanups (script_chain
);
6672 if (is_tracepoint (b
))
6674 struct tracepoint
*t
= (struct tracepoint
*) b
;
6676 if (!part_of_multiple
&& t
->pass_count
)
6678 annotate_field (10);
6679 ui_out_text (uiout
, "\tpass count ");
6680 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6681 ui_out_text (uiout
, " \n");
6684 /* Don't display it when tracepoint or tracepoint location is
6686 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6688 annotate_field (11);
6690 if (ui_out_is_mi_like_p (uiout
))
6691 ui_out_field_string (uiout
, "installed",
6692 loc
->inserted
? "y" : "n");
6696 ui_out_text (uiout
, "\t");
6698 ui_out_text (uiout
, "\tnot ");
6699 ui_out_text (uiout
, "installed on target\n");
6704 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6706 if (is_watchpoint (b
))
6708 struct watchpoint
*w
= (struct watchpoint
*) b
;
6710 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6712 else if (b
->location
!= NULL
6713 && event_location_to_string (b
->location
) != NULL
)
6714 ui_out_field_string (uiout
, "original-location",
6715 event_location_to_string (b
->location
));
6720 print_one_breakpoint (struct breakpoint
*b
,
6721 struct bp_location
**last_loc
,
6724 struct cleanup
*bkpt_chain
;
6725 struct ui_out
*uiout
= current_uiout
;
6727 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6729 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6730 do_cleanups (bkpt_chain
);
6732 /* If this breakpoint has custom print function,
6733 it's already printed. Otherwise, print individual
6734 locations, if any. */
6735 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6737 /* If breakpoint has a single location that is disabled, we
6738 print it as if it had several locations, since otherwise it's
6739 hard to represent "breakpoint enabled, location disabled"
6742 Note that while hardware watchpoints have several locations
6743 internally, that's not a property exposed to user. */
6745 && !is_hardware_watchpoint (b
)
6746 && (b
->loc
->next
|| !b
->loc
->enabled
))
6748 struct bp_location
*loc
;
6751 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6753 struct cleanup
*inner2
=
6754 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6755 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6756 do_cleanups (inner2
);
6763 breakpoint_address_bits (struct breakpoint
*b
)
6765 int print_address_bits
= 0;
6766 struct bp_location
*loc
;
6768 /* Software watchpoints that aren't watching memory don't have an
6769 address to print. */
6770 if (is_no_memory_software_watchpoint (b
))
6773 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6777 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6778 if (addr_bit
> print_address_bits
)
6779 print_address_bits
= addr_bit
;
6782 return print_address_bits
;
6785 struct captured_breakpoint_query_args
6791 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6793 struct captured_breakpoint_query_args
*args
6794 = (struct captured_breakpoint_query_args
*) data
;
6795 struct breakpoint
*b
;
6796 struct bp_location
*dummy_loc
= NULL
;
6800 if (args
->bnum
== b
->number
)
6802 print_one_breakpoint (b
, &dummy_loc
, 0);
6810 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6811 char **error_message
)
6813 struct captured_breakpoint_query_args args
;
6816 /* For the moment we don't trust print_one_breakpoint() to not throw
6818 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6819 error_message
, RETURN_MASK_ALL
) < 0)
6825 /* Return true if this breakpoint was set by the user, false if it is
6826 internal or momentary. */
6829 user_breakpoint_p (struct breakpoint
*b
)
6831 return b
->number
> 0;
6834 /* See breakpoint.h. */
6837 pending_breakpoint_p (struct breakpoint
*b
)
6839 return b
->loc
== NULL
;
6842 /* Print information on user settable breakpoint (watchpoint, etc)
6843 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6844 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6845 FILTER is non-NULL, call it on each breakpoint and only include the
6846 ones for which it returns non-zero. Return the total number of
6847 breakpoints listed. */
6850 breakpoint_1 (char *args
, int allflag
,
6851 int (*filter
) (const struct breakpoint
*))
6853 struct breakpoint
*b
;
6854 struct bp_location
*last_loc
= NULL
;
6855 int nr_printable_breakpoints
;
6856 struct cleanup
*bkpttbl_chain
;
6857 struct value_print_options opts
;
6858 int print_address_bits
= 0;
6859 int print_type_col_width
= 14;
6860 struct ui_out
*uiout
= current_uiout
;
6862 get_user_print_options (&opts
);
6864 /* Compute the number of rows in the table, as well as the size
6865 required for address fields. */
6866 nr_printable_breakpoints
= 0;
6869 /* If we have a filter, only list the breakpoints it accepts. */
6870 if (filter
&& !filter (b
))
6873 /* If we have an "args" string, it is a list of breakpoints to
6874 accept. Skip the others. */
6875 if (args
!= NULL
&& *args
!= '\0')
6877 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6879 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6883 if (allflag
|| user_breakpoint_p (b
))
6885 int addr_bit
, type_len
;
6887 addr_bit
= breakpoint_address_bits (b
);
6888 if (addr_bit
> print_address_bits
)
6889 print_address_bits
= addr_bit
;
6891 type_len
= strlen (bptype_string (b
->type
));
6892 if (type_len
> print_type_col_width
)
6893 print_type_col_width
= type_len
;
6895 nr_printable_breakpoints
++;
6899 if (opts
.addressprint
)
6901 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6902 nr_printable_breakpoints
,
6906 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6907 nr_printable_breakpoints
,
6910 if (nr_printable_breakpoints
> 0)
6911 annotate_breakpoints_headers ();
6912 if (nr_printable_breakpoints
> 0)
6914 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6915 if (nr_printable_breakpoints
> 0)
6917 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6918 "type", "Type"); /* 2 */
6919 if (nr_printable_breakpoints
> 0)
6921 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6922 if (nr_printable_breakpoints
> 0)
6924 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6925 if (opts
.addressprint
)
6927 if (nr_printable_breakpoints
> 0)
6929 if (print_address_bits
<= 32)
6930 ui_out_table_header (uiout
, 10, ui_left
,
6931 "addr", "Address"); /* 5 */
6933 ui_out_table_header (uiout
, 18, ui_left
,
6934 "addr", "Address"); /* 5 */
6936 if (nr_printable_breakpoints
> 0)
6938 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6939 ui_out_table_body (uiout
);
6940 if (nr_printable_breakpoints
> 0)
6941 annotate_breakpoints_table ();
6946 /* If we have a filter, only list the breakpoints it accepts. */
6947 if (filter
&& !filter (b
))
6950 /* If we have an "args" string, it is a list of breakpoints to
6951 accept. Skip the others. */
6953 if (args
!= NULL
&& *args
!= '\0')
6955 if (allflag
) /* maintenance info breakpoint */
6957 if (parse_and_eval_long (args
) != b
->number
)
6960 else /* all others */
6962 if (!number_is_in_list (args
, b
->number
))
6966 /* We only print out user settable breakpoints unless the
6968 if (allflag
|| user_breakpoint_p (b
))
6969 print_one_breakpoint (b
, &last_loc
, allflag
);
6972 do_cleanups (bkpttbl_chain
);
6974 if (nr_printable_breakpoints
== 0)
6976 /* If there's a filter, let the caller decide how to report
6980 if (args
== NULL
|| *args
== '\0')
6981 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6983 ui_out_message (uiout
, 0,
6984 "No breakpoint or watchpoint matching '%s'.\n",
6990 if (last_loc
&& !server_command
)
6991 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6994 /* FIXME? Should this be moved up so that it is only called when
6995 there have been breakpoints? */
6996 annotate_breakpoints_table_end ();
6998 return nr_printable_breakpoints
;
7001 /* Display the value of default-collect in a way that is generally
7002 compatible with the breakpoint list. */
7005 default_collect_info (void)
7007 struct ui_out
*uiout
= current_uiout
;
7009 /* If it has no value (which is frequently the case), say nothing; a
7010 message like "No default-collect." gets in user's face when it's
7012 if (!*default_collect
)
7015 /* The following phrase lines up nicely with per-tracepoint collect
7017 ui_out_text (uiout
, "default collect ");
7018 ui_out_field_string (uiout
, "default-collect", default_collect
);
7019 ui_out_text (uiout
, " \n");
7023 breakpoints_info (char *args
, int from_tty
)
7025 breakpoint_1 (args
, 0, NULL
);
7027 default_collect_info ();
7031 watchpoints_info (char *args
, int from_tty
)
7033 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
7034 struct ui_out
*uiout
= current_uiout
;
7036 if (num_printed
== 0)
7038 if (args
== NULL
|| *args
== '\0')
7039 ui_out_message (uiout
, 0, "No watchpoints.\n");
7041 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
7046 maintenance_info_breakpoints (char *args
, int from_tty
)
7048 breakpoint_1 (args
, 1, NULL
);
7050 default_collect_info ();
7054 breakpoint_has_pc (struct breakpoint
*b
,
7055 struct program_space
*pspace
,
7056 CORE_ADDR pc
, struct obj_section
*section
)
7058 struct bp_location
*bl
= b
->loc
;
7060 for (; bl
; bl
= bl
->next
)
7062 if (bl
->pspace
== pspace
7063 && bl
->address
== pc
7064 && (!overlay_debugging
|| bl
->section
== section
))
7070 /* Print a message describing any user-breakpoints set at PC. This
7071 concerns with logical breakpoints, so we match program spaces, not
7075 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7076 struct program_space
*pspace
, CORE_ADDR pc
,
7077 struct obj_section
*section
, int thread
)
7080 struct breakpoint
*b
;
7083 others
+= (user_breakpoint_p (b
)
7084 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7088 printf_filtered (_("Note: breakpoint "));
7089 else /* if (others == ???) */
7090 printf_filtered (_("Note: breakpoints "));
7092 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7095 printf_filtered ("%d", b
->number
);
7096 if (b
->thread
== -1 && thread
!= -1)
7097 printf_filtered (" (all threads)");
7098 else if (b
->thread
!= -1)
7099 printf_filtered (" (thread %d)", b
->thread
);
7100 printf_filtered ("%s%s ",
7101 ((b
->enable_state
== bp_disabled
7102 || b
->enable_state
== bp_call_disabled
)
7106 : ((others
== 1) ? " and" : ""));
7108 printf_filtered (_("also set at pc "));
7109 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7110 printf_filtered (".\n");
7115 /* Return true iff it is meaningful to use the address member of
7116 BPT locations. For some breakpoint types, the locations' address members
7117 are irrelevant and it makes no sense to attempt to compare them to other
7118 addresses (or use them for any other purpose either).
7120 More specifically, each of the following breakpoint types will
7121 always have a zero valued location address and we don't want to mark
7122 breakpoints of any of these types to be a duplicate of an actual
7123 breakpoint location at address zero:
7131 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7133 enum bptype type
= bpt
->type
;
7135 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7138 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7139 true if LOC1 and LOC2 represent the same watchpoint location. */
7142 watchpoint_locations_match (struct bp_location
*loc1
,
7143 struct bp_location
*loc2
)
7145 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7146 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7148 /* Both of them must exist. */
7149 gdb_assert (w1
!= NULL
);
7150 gdb_assert (w2
!= NULL
);
7152 /* If the target can evaluate the condition expression in hardware,
7153 then we we need to insert both watchpoints even if they are at
7154 the same place. Otherwise the watchpoint will only trigger when
7155 the condition of whichever watchpoint was inserted evaluates to
7156 true, not giving a chance for GDB to check the condition of the
7157 other watchpoint. */
7159 && target_can_accel_watchpoint_condition (loc1
->address
,
7161 loc1
->watchpoint_type
,
7164 && target_can_accel_watchpoint_condition (loc2
->address
,
7166 loc2
->watchpoint_type
,
7170 /* Note that this checks the owner's type, not the location's. In
7171 case the target does not support read watchpoints, but does
7172 support access watchpoints, we'll have bp_read_watchpoint
7173 watchpoints with hw_access locations. Those should be considered
7174 duplicates of hw_read locations. The hw_read locations will
7175 become hw_access locations later. */
7176 return (loc1
->owner
->type
== loc2
->owner
->type
7177 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7178 && loc1
->address
== loc2
->address
7179 && loc1
->length
== loc2
->length
);
7182 /* See breakpoint.h. */
7185 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7186 struct address_space
*aspace2
, CORE_ADDR addr2
)
7188 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7189 || aspace1
== aspace2
)
7193 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7194 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7195 matches ASPACE2. On targets that have global breakpoints, the address
7196 space doesn't really matter. */
7199 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7200 int len1
, struct address_space
*aspace2
,
7203 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7204 || aspace1
== aspace2
)
7205 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7208 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7209 a ranged breakpoint. In most targets, a match happens only if ASPACE
7210 matches the breakpoint's address space. On targets that have global
7211 breakpoints, the address space doesn't really matter. */
7214 breakpoint_location_address_match (struct bp_location
*bl
,
7215 struct address_space
*aspace
,
7218 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7221 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7222 bl
->address
, bl
->length
,
7226 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7227 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7228 match happens only if ASPACE matches the breakpoint's address
7229 space. On targets that have global breakpoints, the address space
7230 doesn't really matter. */
7233 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7234 struct address_space
*aspace
,
7235 CORE_ADDR addr
, int len
)
7237 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7238 || bl
->pspace
->aspace
== aspace
)
7240 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7242 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7248 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7249 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7250 true, otherwise returns false. */
7253 tracepoint_locations_match (struct bp_location
*loc1
,
7254 struct bp_location
*loc2
)
7256 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7257 /* Since tracepoint locations are never duplicated with others', tracepoint
7258 locations at the same address of different tracepoints are regarded as
7259 different locations. */
7260 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7265 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7266 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7267 represent the same location. */
7270 breakpoint_locations_match (struct bp_location
*loc1
,
7271 struct bp_location
*loc2
)
7273 int hw_point1
, hw_point2
;
7275 /* Both of them must not be in moribund_locations. */
7276 gdb_assert (loc1
->owner
!= NULL
);
7277 gdb_assert (loc2
->owner
!= NULL
);
7279 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7280 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7282 if (hw_point1
!= hw_point2
)
7285 return watchpoint_locations_match (loc1
, loc2
);
7286 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7287 return tracepoint_locations_match (loc1
, loc2
);
7289 /* We compare bp_location.length in order to cover ranged breakpoints. */
7290 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7291 loc2
->pspace
->aspace
, loc2
->address
)
7292 && loc1
->length
== loc2
->length
);
7296 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7297 int bnum
, int have_bnum
)
7299 /* The longest string possibly returned by hex_string_custom
7300 is 50 chars. These must be at least that big for safety. */
7304 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7305 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7307 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7308 bnum
, astr1
, astr2
);
7310 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7313 /* Adjust a breakpoint's address to account for architectural
7314 constraints on breakpoint placement. Return the adjusted address.
7315 Note: Very few targets require this kind of adjustment. For most
7316 targets, this function is simply the identity function. */
7319 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7320 CORE_ADDR bpaddr
, enum bptype bptype
)
7322 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7324 /* Very few targets need any kind of breakpoint adjustment. */
7327 else if (bptype
== bp_watchpoint
7328 || bptype
== bp_hardware_watchpoint
7329 || bptype
== bp_read_watchpoint
7330 || bptype
== bp_access_watchpoint
7331 || bptype
== bp_catchpoint
)
7333 /* Watchpoints and the various bp_catch_* eventpoints should not
7334 have their addresses modified. */
7337 else if (bptype
== bp_single_step
)
7339 /* Single-step breakpoints should not have their addresses
7340 modified. If there's any architectural constrain that
7341 applies to this address, then it should have already been
7342 taken into account when the breakpoint was created in the
7343 first place. If we didn't do this, stepping through e.g.,
7344 Thumb-2 IT blocks would break. */
7349 CORE_ADDR adjusted_bpaddr
;
7351 /* Some targets have architectural constraints on the placement
7352 of breakpoint instructions. Obtain the adjusted address. */
7353 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7355 /* An adjusted breakpoint address can significantly alter
7356 a user's expectations. Print a warning if an adjustment
7358 if (adjusted_bpaddr
!= bpaddr
)
7359 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7361 return adjusted_bpaddr
;
7366 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7367 struct breakpoint
*owner
)
7369 memset (loc
, 0, sizeof (*loc
));
7371 gdb_assert (ops
!= NULL
);
7376 loc
->cond_bytecode
= NULL
;
7377 loc
->shlib_disabled
= 0;
7380 switch (owner
->type
)
7383 case bp_single_step
:
7387 case bp_longjmp_resume
:
7388 case bp_longjmp_call_dummy
:
7390 case bp_exception_resume
:
7391 case bp_step_resume
:
7392 case bp_hp_step_resume
:
7393 case bp_watchpoint_scope
:
7395 case bp_std_terminate
:
7396 case bp_shlib_event
:
7397 case bp_thread_event
:
7398 case bp_overlay_event
:
7400 case bp_longjmp_master
:
7401 case bp_std_terminate_master
:
7402 case bp_exception_master
:
7403 case bp_gnu_ifunc_resolver
:
7404 case bp_gnu_ifunc_resolver_return
:
7406 loc
->loc_type
= bp_loc_software_breakpoint
;
7407 mark_breakpoint_location_modified (loc
);
7409 case bp_hardware_breakpoint
:
7410 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7411 mark_breakpoint_location_modified (loc
);
7413 case bp_hardware_watchpoint
:
7414 case bp_read_watchpoint
:
7415 case bp_access_watchpoint
:
7416 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7421 case bp_fast_tracepoint
:
7422 case bp_static_tracepoint
:
7423 loc
->loc_type
= bp_loc_other
;
7426 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7432 /* Allocate a struct bp_location. */
7434 static struct bp_location
*
7435 allocate_bp_location (struct breakpoint
*bpt
)
7437 return bpt
->ops
->allocate_location (bpt
);
7441 free_bp_location (struct bp_location
*loc
)
7443 loc
->ops
->dtor (loc
);
7447 /* Increment reference count. */
7450 incref_bp_location (struct bp_location
*bl
)
7455 /* Decrement reference count. If the reference count reaches 0,
7456 destroy the bp_location. Sets *BLP to NULL. */
7459 decref_bp_location (struct bp_location
**blp
)
7461 gdb_assert ((*blp
)->refc
> 0);
7463 if (--(*blp
)->refc
== 0)
7464 free_bp_location (*blp
);
7468 /* Add breakpoint B at the end of the global breakpoint chain. */
7471 add_to_breakpoint_chain (struct breakpoint
*b
)
7473 struct breakpoint
*b1
;
7475 /* Add this breakpoint to the end of the chain so that a list of
7476 breakpoints will come out in order of increasing numbers. */
7478 b1
= breakpoint_chain
;
7480 breakpoint_chain
= b
;
7489 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7492 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7493 struct gdbarch
*gdbarch
,
7495 const struct breakpoint_ops
*ops
)
7497 memset (b
, 0, sizeof (*b
));
7499 gdb_assert (ops
!= NULL
);
7503 b
->gdbarch
= gdbarch
;
7504 b
->language
= current_language
->la_language
;
7505 b
->input_radix
= input_radix
;
7507 b
->enable_state
= bp_enabled
;
7510 b
->ignore_count
= 0;
7512 b
->frame_id
= null_frame_id
;
7513 b
->condition_not_parsed
= 0;
7514 b
->py_bp_object
= NULL
;
7515 b
->related_breakpoint
= b
;
7519 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7520 that has type BPTYPE and has no locations as yet. */
7522 static struct breakpoint
*
7523 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7525 const struct breakpoint_ops
*ops
)
7527 struct breakpoint
*b
= XNEW (struct breakpoint
);
7529 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7530 add_to_breakpoint_chain (b
);
7534 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7535 resolutions should be made as the user specified the location explicitly
7539 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7541 gdb_assert (loc
->owner
!= NULL
);
7543 if (loc
->owner
->type
== bp_breakpoint
7544 || loc
->owner
->type
== bp_hardware_breakpoint
7545 || is_tracepoint (loc
->owner
))
7548 const char *function_name
;
7549 CORE_ADDR func_addr
;
7551 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7552 &func_addr
, NULL
, &is_gnu_ifunc
);
7554 if (is_gnu_ifunc
&& !explicit_loc
)
7556 struct breakpoint
*b
= loc
->owner
;
7558 gdb_assert (loc
->pspace
== current_program_space
);
7559 if (gnu_ifunc_resolve_name (function_name
,
7560 &loc
->requested_address
))
7562 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7563 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7564 loc
->requested_address
,
7567 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7568 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7570 /* Create only the whole new breakpoint of this type but do not
7571 mess more complicated breakpoints with multiple locations. */
7572 b
->type
= bp_gnu_ifunc_resolver
;
7573 /* Remember the resolver's address for use by the return
7575 loc
->related_address
= func_addr
;
7580 loc
->function_name
= xstrdup (function_name
);
7584 /* Attempt to determine architecture of location identified by SAL. */
7586 get_sal_arch (struct symtab_and_line sal
)
7589 return get_objfile_arch (sal
.section
->objfile
);
7591 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7596 /* Low level routine for partially initializing a breakpoint of type
7597 BPTYPE. The newly created breakpoint's address, section, source
7598 file name, and line number are provided by SAL.
7600 It is expected that the caller will complete the initialization of
7601 the newly created breakpoint struct as well as output any status
7602 information regarding the creation of a new breakpoint. */
7605 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7606 struct symtab_and_line sal
, enum bptype bptype
,
7607 const struct breakpoint_ops
*ops
)
7609 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7611 add_location_to_breakpoint (b
, &sal
);
7613 if (bptype
!= bp_catchpoint
)
7614 gdb_assert (sal
.pspace
!= NULL
);
7616 /* Store the program space that was used to set the breakpoint,
7617 except for ordinary breakpoints, which are independent of the
7619 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7620 b
->pspace
= sal
.pspace
;
7623 /* set_raw_breakpoint is a low level routine for allocating and
7624 partially initializing a breakpoint of type BPTYPE. The newly
7625 created breakpoint's address, section, source file name, and line
7626 number are provided by SAL. The newly created and partially
7627 initialized breakpoint is added to the breakpoint chain and
7628 is also returned as the value of this function.
7630 It is expected that the caller will complete the initialization of
7631 the newly created breakpoint struct as well as output any status
7632 information regarding the creation of a new breakpoint. In
7633 particular, set_raw_breakpoint does NOT set the breakpoint
7634 number! Care should be taken to not allow an error to occur
7635 prior to completing the initialization of the breakpoint. If this
7636 should happen, a bogus breakpoint will be left on the chain. */
7639 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7640 struct symtab_and_line sal
, enum bptype bptype
,
7641 const struct breakpoint_ops
*ops
)
7643 struct breakpoint
*b
= XNEW (struct breakpoint
);
7645 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7646 add_to_breakpoint_chain (b
);
7650 /* Call this routine when stepping and nexting to enable a breakpoint
7651 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7652 initiated the operation. */
7655 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7657 struct breakpoint
*b
, *b_tmp
;
7658 int thread
= tp
->global_num
;
7660 /* To avoid having to rescan all objfile symbols at every step,
7661 we maintain a list of continually-inserted but always disabled
7662 longjmp "master" breakpoints. Here, we simply create momentary
7663 clones of those and enable them for the requested thread. */
7664 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7665 if (b
->pspace
== current_program_space
7666 && (b
->type
== bp_longjmp_master
7667 || b
->type
== bp_exception_master
))
7669 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7670 struct breakpoint
*clone
;
7672 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7673 after their removal. */
7674 clone
= momentary_breakpoint_from_master (b
, type
,
7675 &longjmp_breakpoint_ops
, 1);
7676 clone
->thread
= thread
;
7679 tp
->initiating_frame
= frame
;
7682 /* Delete all longjmp breakpoints from THREAD. */
7684 delete_longjmp_breakpoint (int thread
)
7686 struct breakpoint
*b
, *b_tmp
;
7688 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7689 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7691 if (b
->thread
== thread
)
7692 delete_breakpoint (b
);
7697 delete_longjmp_breakpoint_at_next_stop (int thread
)
7699 struct breakpoint
*b
, *b_tmp
;
7701 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7702 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7704 if (b
->thread
== thread
)
7705 b
->disposition
= disp_del_at_next_stop
;
7709 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7710 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7711 pointer to any of them. Return NULL if this system cannot place longjmp
7715 set_longjmp_breakpoint_for_call_dummy (void)
7717 struct breakpoint
*b
, *retval
= NULL
;
7720 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7722 struct breakpoint
*new_b
;
7724 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7725 &momentary_breakpoint_ops
,
7727 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7729 /* Link NEW_B into the chain of RETVAL breakpoints. */
7731 gdb_assert (new_b
->related_breakpoint
== new_b
);
7734 new_b
->related_breakpoint
= retval
;
7735 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7736 retval
= retval
->related_breakpoint
;
7737 retval
->related_breakpoint
= new_b
;
7743 /* Verify all existing dummy frames and their associated breakpoints for
7744 TP. Remove those which can no longer be found in the current frame
7747 You should call this function only at places where it is safe to currently
7748 unwind the whole stack. Failed stack unwind would discard live dummy
7752 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7754 struct breakpoint
*b
, *b_tmp
;
7756 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7757 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7759 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7761 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7762 dummy_b
= dummy_b
->related_breakpoint
;
7763 if (dummy_b
->type
!= bp_call_dummy
7764 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7767 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7769 while (b
->related_breakpoint
!= b
)
7771 if (b_tmp
== b
->related_breakpoint
)
7772 b_tmp
= b
->related_breakpoint
->next
;
7773 delete_breakpoint (b
->related_breakpoint
);
7775 delete_breakpoint (b
);
7780 enable_overlay_breakpoints (void)
7782 struct breakpoint
*b
;
7785 if (b
->type
== bp_overlay_event
)
7787 b
->enable_state
= bp_enabled
;
7788 update_global_location_list (UGLL_MAY_INSERT
);
7789 overlay_events_enabled
= 1;
7794 disable_overlay_breakpoints (void)
7796 struct breakpoint
*b
;
7799 if (b
->type
== bp_overlay_event
)
7801 b
->enable_state
= bp_disabled
;
7802 update_global_location_list (UGLL_DONT_INSERT
);
7803 overlay_events_enabled
= 0;
7807 /* Set an active std::terminate breakpoint for each std::terminate
7808 master breakpoint. */
7810 set_std_terminate_breakpoint (void)
7812 struct breakpoint
*b
, *b_tmp
;
7814 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7815 if (b
->pspace
== current_program_space
7816 && b
->type
== bp_std_terminate_master
)
7818 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7819 &momentary_breakpoint_ops
, 1);
7823 /* Delete all the std::terminate breakpoints. */
7825 delete_std_terminate_breakpoint (void)
7827 struct breakpoint
*b
, *b_tmp
;
7829 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7830 if (b
->type
== bp_std_terminate
)
7831 delete_breakpoint (b
);
7835 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7837 struct breakpoint
*b
;
7839 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7840 &internal_breakpoint_ops
);
7842 b
->enable_state
= bp_enabled
;
7843 /* location has to be used or breakpoint_re_set will delete me. */
7844 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7846 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7851 struct lang_and_radix
7857 /* Create a breakpoint for JIT code registration and unregistration. */
7860 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7862 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7863 &internal_breakpoint_ops
);
7866 /* Remove JIT code registration and unregistration breakpoint(s). */
7869 remove_jit_event_breakpoints (void)
7871 struct breakpoint
*b
, *b_tmp
;
7873 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7874 if (b
->type
== bp_jit_event
7875 && b
->loc
->pspace
== current_program_space
)
7876 delete_breakpoint (b
);
7880 remove_solib_event_breakpoints (void)
7882 struct breakpoint
*b
, *b_tmp
;
7884 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7885 if (b
->type
== bp_shlib_event
7886 && b
->loc
->pspace
== current_program_space
)
7887 delete_breakpoint (b
);
7890 /* See breakpoint.h. */
7893 remove_solib_event_breakpoints_at_next_stop (void)
7895 struct breakpoint
*b
, *b_tmp
;
7897 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7898 if (b
->type
== bp_shlib_event
7899 && b
->loc
->pspace
== current_program_space
)
7900 b
->disposition
= disp_del_at_next_stop
;
7903 /* Helper for create_solib_event_breakpoint /
7904 create_and_insert_solib_event_breakpoint. Allows specifying which
7905 INSERT_MODE to pass through to update_global_location_list. */
7907 static struct breakpoint
*
7908 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7909 enum ugll_insert_mode insert_mode
)
7911 struct breakpoint
*b
;
7913 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7914 &internal_breakpoint_ops
);
7915 update_global_location_list_nothrow (insert_mode
);
7920 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7922 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7925 /* See breakpoint.h. */
7928 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7930 struct breakpoint
*b
;
7932 /* Explicitly tell update_global_location_list to insert
7934 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7935 if (!b
->loc
->inserted
)
7937 delete_breakpoint (b
);
7943 /* Disable any breakpoints that are on code in shared libraries. Only
7944 apply to enabled breakpoints, disabled ones can just stay disabled. */
7947 disable_breakpoints_in_shlibs (void)
7949 struct bp_location
*loc
, **locp_tmp
;
7951 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7953 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7954 struct breakpoint
*b
= loc
->owner
;
7956 /* We apply the check to all breakpoints, including disabled for
7957 those with loc->duplicate set. This is so that when breakpoint
7958 becomes enabled, or the duplicate is removed, gdb will try to
7959 insert all breakpoints. If we don't set shlib_disabled here,
7960 we'll try to insert those breakpoints and fail. */
7961 if (((b
->type
== bp_breakpoint
)
7962 || (b
->type
== bp_jit_event
)
7963 || (b
->type
== bp_hardware_breakpoint
)
7964 || (is_tracepoint (b
)))
7965 && loc
->pspace
== current_program_space
7966 && !loc
->shlib_disabled
7967 && solib_name_from_address (loc
->pspace
, loc
->address
)
7970 loc
->shlib_disabled
= 1;
7975 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7976 notification of unloaded_shlib. Only apply to enabled breakpoints,
7977 disabled ones can just stay disabled. */
7980 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7982 struct bp_location
*loc
, **locp_tmp
;
7983 int disabled_shlib_breaks
= 0;
7985 /* SunOS a.out shared libraries are always mapped, so do not
7986 disable breakpoints; they will only be reported as unloaded
7987 through clear_solib when GDB discards its shared library
7988 list. See clear_solib for more information. */
7989 if (exec_bfd
!= NULL
7990 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7993 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7995 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7996 struct breakpoint
*b
= loc
->owner
;
7998 if (solib
->pspace
== loc
->pspace
7999 && !loc
->shlib_disabled
8000 && (((b
->type
== bp_breakpoint
8001 || b
->type
== bp_jit_event
8002 || b
->type
== bp_hardware_breakpoint
)
8003 && (loc
->loc_type
== bp_loc_hardware_breakpoint
8004 || loc
->loc_type
== bp_loc_software_breakpoint
))
8005 || is_tracepoint (b
))
8006 && solib_contains_address_p (solib
, loc
->address
))
8008 loc
->shlib_disabled
= 1;
8009 /* At this point, we cannot rely on remove_breakpoint
8010 succeeding so we must mark the breakpoint as not inserted
8011 to prevent future errors occurring in remove_breakpoints. */
8014 /* This may cause duplicate notifications for the same breakpoint. */
8015 observer_notify_breakpoint_modified (b
);
8017 if (!disabled_shlib_breaks
)
8019 target_terminal_ours_for_output ();
8020 warning (_("Temporarily disabling breakpoints "
8021 "for unloaded shared library \"%s\""),
8024 disabled_shlib_breaks
= 1;
8029 /* Disable any breakpoints and tracepoints in OBJFILE upon
8030 notification of free_objfile. Only apply to enabled breakpoints,
8031 disabled ones can just stay disabled. */
8034 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
8036 struct breakpoint
*b
;
8038 if (objfile
== NULL
)
8041 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8042 managed by the user with add-symbol-file/remove-symbol-file.
8043 Similarly to how breakpoints in shared libraries are handled in
8044 response to "nosharedlibrary", mark breakpoints in such modules
8045 shlib_disabled so they end up uninserted on the next global
8046 location list update. Shared libraries not loaded by the user
8047 aren't handled here -- they're already handled in
8048 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8049 solib_unloaded observer. We skip objfiles that are not
8050 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8052 if ((objfile
->flags
& OBJF_SHARED
) == 0
8053 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8058 struct bp_location
*loc
;
8059 int bp_modified
= 0;
8061 if (!is_breakpoint (b
) && !is_tracepoint (b
))
8064 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
8066 CORE_ADDR loc_addr
= loc
->address
;
8068 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8069 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8072 if (loc
->shlib_disabled
!= 0)
8075 if (objfile
->pspace
!= loc
->pspace
)
8078 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8079 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8082 if (is_addr_in_objfile (loc_addr
, objfile
))
8084 loc
->shlib_disabled
= 1;
8085 /* At this point, we don't know whether the object was
8086 unmapped from the inferior or not, so leave the
8087 inserted flag alone. We'll handle failure to
8088 uninsert quietly, in case the object was indeed
8091 mark_breakpoint_location_modified (loc
);
8098 observer_notify_breakpoint_modified (b
);
8102 /* FORK & VFORK catchpoints. */
8104 /* An instance of this type is used to represent a fork or vfork
8105 catchpoint. It includes a "struct breakpoint" as a kind of base
8106 class; users downcast to "struct breakpoint *" when needed. A
8107 breakpoint is really of this type iff its ops pointer points to
8108 CATCH_FORK_BREAKPOINT_OPS. */
8110 struct fork_catchpoint
8112 /* The base class. */
8113 struct breakpoint base
;
8115 /* Process id of a child process whose forking triggered this
8116 catchpoint. This field is only valid immediately after this
8117 catchpoint has triggered. */
8118 ptid_t forked_inferior_pid
;
8121 /* Implement the "insert" breakpoint_ops method for fork
8125 insert_catch_fork (struct bp_location
*bl
)
8127 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8130 /* Implement the "remove" breakpoint_ops method for fork
8134 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8136 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8139 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8143 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8144 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8145 const struct target_waitstatus
*ws
)
8147 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8149 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8152 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8156 /* Implement the "print_it" breakpoint_ops method for fork
8159 static enum print_stop_action
8160 print_it_catch_fork (bpstat bs
)
8162 struct ui_out
*uiout
= current_uiout
;
8163 struct breakpoint
*b
= bs
->breakpoint_at
;
8164 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8166 annotate_catchpoint (b
->number
);
8167 maybe_print_thread_hit_breakpoint (uiout
);
8168 if (b
->disposition
== disp_del
)
8169 ui_out_text (uiout
, "Temporary catchpoint ");
8171 ui_out_text (uiout
, "Catchpoint ");
8172 if (ui_out_is_mi_like_p (uiout
))
8174 ui_out_field_string (uiout
, "reason",
8175 async_reason_lookup (EXEC_ASYNC_FORK
));
8176 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8178 ui_out_field_int (uiout
, "bkptno", b
->number
);
8179 ui_out_text (uiout
, " (forked process ");
8180 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8181 ui_out_text (uiout
, "), ");
8182 return PRINT_SRC_AND_LOC
;
8185 /* Implement the "print_one" breakpoint_ops method for fork
8189 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8191 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8192 struct value_print_options opts
;
8193 struct ui_out
*uiout
= current_uiout
;
8195 get_user_print_options (&opts
);
8197 /* Field 4, the address, is omitted (which makes the columns not
8198 line up too nicely with the headers, but the effect is relatively
8200 if (opts
.addressprint
)
8201 ui_out_field_skip (uiout
, "addr");
8203 ui_out_text (uiout
, "fork");
8204 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8206 ui_out_text (uiout
, ", process ");
8207 ui_out_field_int (uiout
, "what",
8208 ptid_get_pid (c
->forked_inferior_pid
));
8209 ui_out_spaces (uiout
, 1);
8212 if (ui_out_is_mi_like_p (uiout
))
8213 ui_out_field_string (uiout
, "catch-type", "fork");
8216 /* Implement the "print_mention" breakpoint_ops method for fork
8220 print_mention_catch_fork (struct breakpoint
*b
)
8222 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8225 /* Implement the "print_recreate" breakpoint_ops method for fork
8229 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8231 fprintf_unfiltered (fp
, "catch fork");
8232 print_recreate_thread (b
, fp
);
8235 /* The breakpoint_ops structure to be used in fork catchpoints. */
8237 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8239 /* Implement the "insert" breakpoint_ops method for vfork
8243 insert_catch_vfork (struct bp_location
*bl
)
8245 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8248 /* Implement the "remove" breakpoint_ops method for vfork
8252 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8254 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8257 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8261 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8262 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8263 const struct target_waitstatus
*ws
)
8265 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8267 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8270 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8274 /* Implement the "print_it" breakpoint_ops method for vfork
8277 static enum print_stop_action
8278 print_it_catch_vfork (bpstat bs
)
8280 struct ui_out
*uiout
= current_uiout
;
8281 struct breakpoint
*b
= bs
->breakpoint_at
;
8282 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8284 annotate_catchpoint (b
->number
);
8285 maybe_print_thread_hit_breakpoint (uiout
);
8286 if (b
->disposition
== disp_del
)
8287 ui_out_text (uiout
, "Temporary catchpoint ");
8289 ui_out_text (uiout
, "Catchpoint ");
8290 if (ui_out_is_mi_like_p (uiout
))
8292 ui_out_field_string (uiout
, "reason",
8293 async_reason_lookup (EXEC_ASYNC_VFORK
));
8294 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8296 ui_out_field_int (uiout
, "bkptno", b
->number
);
8297 ui_out_text (uiout
, " (vforked process ");
8298 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8299 ui_out_text (uiout
, "), ");
8300 return PRINT_SRC_AND_LOC
;
8303 /* Implement the "print_one" breakpoint_ops method for vfork
8307 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8309 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8310 struct value_print_options opts
;
8311 struct ui_out
*uiout
= current_uiout
;
8313 get_user_print_options (&opts
);
8314 /* Field 4, the address, is omitted (which makes the columns not
8315 line up too nicely with the headers, but the effect is relatively
8317 if (opts
.addressprint
)
8318 ui_out_field_skip (uiout
, "addr");
8320 ui_out_text (uiout
, "vfork");
8321 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8323 ui_out_text (uiout
, ", process ");
8324 ui_out_field_int (uiout
, "what",
8325 ptid_get_pid (c
->forked_inferior_pid
));
8326 ui_out_spaces (uiout
, 1);
8329 if (ui_out_is_mi_like_p (uiout
))
8330 ui_out_field_string (uiout
, "catch-type", "vfork");
8333 /* Implement the "print_mention" breakpoint_ops method for vfork
8337 print_mention_catch_vfork (struct breakpoint
*b
)
8339 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8342 /* Implement the "print_recreate" breakpoint_ops method for vfork
8346 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8348 fprintf_unfiltered (fp
, "catch vfork");
8349 print_recreate_thread (b
, fp
);
8352 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8354 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8356 /* An instance of this type is used to represent an solib catchpoint.
8357 It includes a "struct breakpoint" as a kind of base class; users
8358 downcast to "struct breakpoint *" when needed. A breakpoint is
8359 really of this type iff its ops pointer points to
8360 CATCH_SOLIB_BREAKPOINT_OPS. */
8362 struct solib_catchpoint
8364 /* The base class. */
8365 struct breakpoint base
;
8367 /* True for "catch load", false for "catch unload". */
8368 unsigned char is_load
;
8370 /* Regular expression to match, if any. COMPILED is only valid when
8371 REGEX is non-NULL. */
8377 dtor_catch_solib (struct breakpoint
*b
)
8379 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8382 regfree (&self
->compiled
);
8383 xfree (self
->regex
);
8385 base_breakpoint_ops
.dtor (b
);
8389 insert_catch_solib (struct bp_location
*ignore
)
8395 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8401 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8402 struct address_space
*aspace
,
8404 const struct target_waitstatus
*ws
)
8406 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8407 struct breakpoint
*other
;
8409 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8412 ALL_BREAKPOINTS (other
)
8414 struct bp_location
*other_bl
;
8416 if (other
== bl
->owner
)
8419 if (other
->type
!= bp_shlib_event
)
8422 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8425 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8427 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8436 check_status_catch_solib (struct bpstats
*bs
)
8438 struct solib_catchpoint
*self
8439 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8444 struct so_list
*iter
;
8447 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8452 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8461 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8466 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8472 bs
->print_it
= print_it_noop
;
8475 static enum print_stop_action
8476 print_it_catch_solib (bpstat bs
)
8478 struct breakpoint
*b
= bs
->breakpoint_at
;
8479 struct ui_out
*uiout
= current_uiout
;
8481 annotate_catchpoint (b
->number
);
8482 maybe_print_thread_hit_breakpoint (uiout
);
8483 if (b
->disposition
== disp_del
)
8484 ui_out_text (uiout
, "Temporary catchpoint ");
8486 ui_out_text (uiout
, "Catchpoint ");
8487 ui_out_field_int (uiout
, "bkptno", b
->number
);
8488 ui_out_text (uiout
, "\n");
8489 if (ui_out_is_mi_like_p (uiout
))
8490 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8491 print_solib_event (1);
8492 return PRINT_SRC_AND_LOC
;
8496 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8498 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8499 struct value_print_options opts
;
8500 struct ui_out
*uiout
= current_uiout
;
8503 get_user_print_options (&opts
);
8504 /* Field 4, the address, is omitted (which makes the columns not
8505 line up too nicely with the headers, but the effect is relatively
8507 if (opts
.addressprint
)
8510 ui_out_field_skip (uiout
, "addr");
8517 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8519 msg
= xstrdup (_("load of library"));
8524 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8526 msg
= xstrdup (_("unload of library"));
8528 ui_out_field_string (uiout
, "what", msg
);
8531 if (ui_out_is_mi_like_p (uiout
))
8532 ui_out_field_string (uiout
, "catch-type",
8533 self
->is_load
? "load" : "unload");
8537 print_mention_catch_solib (struct breakpoint
*b
)
8539 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8541 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8542 self
->is_load
? "load" : "unload");
8546 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8548 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8550 fprintf_unfiltered (fp
, "%s %s",
8551 b
->disposition
== disp_del
? "tcatch" : "catch",
8552 self
->is_load
? "load" : "unload");
8554 fprintf_unfiltered (fp
, " %s", self
->regex
);
8555 fprintf_unfiltered (fp
, "\n");
8558 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8560 /* Shared helper function (MI and CLI) for creating and installing
8561 a shared object event catchpoint. If IS_LOAD is non-zero then
8562 the events to be caught are load events, otherwise they are
8563 unload events. If IS_TEMP is non-zero the catchpoint is a
8564 temporary one. If ENABLED is non-zero the catchpoint is
8565 created in an enabled state. */
8568 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8570 struct solib_catchpoint
*c
;
8571 struct gdbarch
*gdbarch
= get_current_arch ();
8572 struct cleanup
*cleanup
;
8576 arg
= skip_spaces (arg
);
8578 c
= XCNEW (struct solib_catchpoint
);
8579 cleanup
= make_cleanup (xfree
, c
);
8585 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8588 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8590 make_cleanup (xfree
, err
);
8591 error (_("Invalid regexp (%s): %s"), err
, arg
);
8593 c
->regex
= xstrdup (arg
);
8596 c
->is_load
= is_load
;
8597 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8598 &catch_solib_breakpoint_ops
);
8600 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8602 discard_cleanups (cleanup
);
8603 install_breakpoint (0, &c
->base
, 1);
8606 /* A helper function that does all the work for "catch load" and
8610 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8611 struct cmd_list_element
*command
)
8614 const int enabled
= 1;
8616 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8618 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8622 catch_load_command_1 (char *arg
, int from_tty
,
8623 struct cmd_list_element
*command
)
8625 catch_load_or_unload (arg
, from_tty
, 1, command
);
8629 catch_unload_command_1 (char *arg
, int from_tty
,
8630 struct cmd_list_element
*command
)
8632 catch_load_or_unload (arg
, from_tty
, 0, command
);
8635 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8636 is non-zero, then make the breakpoint temporary. If COND_STRING is
8637 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8638 the breakpoint_ops structure associated to the catchpoint. */
8641 init_catchpoint (struct breakpoint
*b
,
8642 struct gdbarch
*gdbarch
, int tempflag
,
8644 const struct breakpoint_ops
*ops
)
8646 struct symtab_and_line sal
;
8649 sal
.pspace
= current_program_space
;
8651 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8653 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8654 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8658 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8660 add_to_breakpoint_chain (b
);
8661 set_breakpoint_number (internal
, b
);
8662 if (is_tracepoint (b
))
8663 set_tracepoint_count (breakpoint_count
);
8666 observer_notify_breakpoint_created (b
);
8669 update_global_location_list (UGLL_MAY_INSERT
);
8673 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8674 int tempflag
, char *cond_string
,
8675 const struct breakpoint_ops
*ops
)
8677 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8679 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8681 c
->forked_inferior_pid
= null_ptid
;
8683 install_breakpoint (0, &c
->base
, 1);
8686 /* Exec catchpoints. */
8688 /* An instance of this type is used to represent an exec catchpoint.
8689 It includes a "struct breakpoint" as a kind of base class; users
8690 downcast to "struct breakpoint *" when needed. A breakpoint is
8691 really of this type iff its ops pointer points to
8692 CATCH_EXEC_BREAKPOINT_OPS. */
8694 struct exec_catchpoint
8696 /* The base class. */
8697 struct breakpoint base
;
8699 /* Filename of a program whose exec triggered this catchpoint.
8700 This field is only valid immediately after this catchpoint has
8702 char *exec_pathname
;
8705 /* Implement the "dtor" breakpoint_ops method for exec
8709 dtor_catch_exec (struct breakpoint
*b
)
8711 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8713 xfree (c
->exec_pathname
);
8715 base_breakpoint_ops
.dtor (b
);
8719 insert_catch_exec (struct bp_location
*bl
)
8721 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8725 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8727 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8731 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8732 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8733 const struct target_waitstatus
*ws
)
8735 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8737 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8740 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8744 static enum print_stop_action
8745 print_it_catch_exec (bpstat bs
)
8747 struct ui_out
*uiout
= current_uiout
;
8748 struct breakpoint
*b
= bs
->breakpoint_at
;
8749 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8751 annotate_catchpoint (b
->number
);
8752 maybe_print_thread_hit_breakpoint (uiout
);
8753 if (b
->disposition
== disp_del
)
8754 ui_out_text (uiout
, "Temporary catchpoint ");
8756 ui_out_text (uiout
, "Catchpoint ");
8757 if (ui_out_is_mi_like_p (uiout
))
8759 ui_out_field_string (uiout
, "reason",
8760 async_reason_lookup (EXEC_ASYNC_EXEC
));
8761 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8763 ui_out_field_int (uiout
, "bkptno", b
->number
);
8764 ui_out_text (uiout
, " (exec'd ");
8765 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8766 ui_out_text (uiout
, "), ");
8768 return PRINT_SRC_AND_LOC
;
8772 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8774 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8775 struct value_print_options opts
;
8776 struct ui_out
*uiout
= current_uiout
;
8778 get_user_print_options (&opts
);
8780 /* Field 4, the address, is omitted (which makes the columns
8781 not line up too nicely with the headers, but the effect
8782 is relatively readable). */
8783 if (opts
.addressprint
)
8784 ui_out_field_skip (uiout
, "addr");
8786 ui_out_text (uiout
, "exec");
8787 if (c
->exec_pathname
!= NULL
)
8789 ui_out_text (uiout
, ", program \"");
8790 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8791 ui_out_text (uiout
, "\" ");
8794 if (ui_out_is_mi_like_p (uiout
))
8795 ui_out_field_string (uiout
, "catch-type", "exec");
8799 print_mention_catch_exec (struct breakpoint
*b
)
8801 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8804 /* Implement the "print_recreate" breakpoint_ops method for exec
8808 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8810 fprintf_unfiltered (fp
, "catch exec");
8811 print_recreate_thread (b
, fp
);
8814 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8817 hw_breakpoint_used_count (void)
8820 struct breakpoint
*b
;
8821 struct bp_location
*bl
;
8825 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8826 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8828 /* Special types of hardware breakpoints may use more than
8830 i
+= b
->ops
->resources_needed (bl
);
8837 /* Returns the resources B would use if it were a hardware
8841 hw_watchpoint_use_count (struct breakpoint
*b
)
8844 struct bp_location
*bl
;
8846 if (!breakpoint_enabled (b
))
8849 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8851 /* Special types of hardware watchpoints may use more than
8853 i
+= b
->ops
->resources_needed (bl
);
8859 /* Returns the sum the used resources of all hardware watchpoints of
8860 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8861 the sum of the used resources of all hardware watchpoints of other
8862 types _not_ TYPE. */
8865 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8866 enum bptype type
, int *other_type_used
)
8869 struct breakpoint
*b
;
8871 *other_type_used
= 0;
8876 if (!breakpoint_enabled (b
))
8879 if (b
->type
== type
)
8880 i
+= hw_watchpoint_use_count (b
);
8881 else if (is_hardware_watchpoint (b
))
8882 *other_type_used
= 1;
8889 disable_watchpoints_before_interactive_call_start (void)
8891 struct breakpoint
*b
;
8895 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8897 b
->enable_state
= bp_call_disabled
;
8898 update_global_location_list (UGLL_DONT_INSERT
);
8904 enable_watchpoints_after_interactive_call_stop (void)
8906 struct breakpoint
*b
;
8910 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8912 b
->enable_state
= bp_enabled
;
8913 update_global_location_list (UGLL_MAY_INSERT
);
8919 disable_breakpoints_before_startup (void)
8921 current_program_space
->executing_startup
= 1;
8922 update_global_location_list (UGLL_DONT_INSERT
);
8926 enable_breakpoints_after_startup (void)
8928 current_program_space
->executing_startup
= 0;
8929 breakpoint_re_set ();
8932 /* Create a new single-step breakpoint for thread THREAD, with no
8935 static struct breakpoint
*
8936 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8938 struct breakpoint
*b
= XNEW (struct breakpoint
);
8940 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8941 &momentary_breakpoint_ops
);
8943 b
->disposition
= disp_donttouch
;
8944 b
->frame_id
= null_frame_id
;
8947 gdb_assert (b
->thread
!= 0);
8949 add_to_breakpoint_chain (b
);
8954 /* Set a momentary breakpoint of type TYPE at address specified by
8955 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8959 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8960 struct frame_id frame_id
, enum bptype type
)
8962 struct breakpoint
*b
;
8964 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8966 gdb_assert (!frame_id_artificial_p (frame_id
));
8968 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8969 b
->enable_state
= bp_enabled
;
8970 b
->disposition
= disp_donttouch
;
8971 b
->frame_id
= frame_id
;
8973 /* If we're debugging a multi-threaded program, then we want
8974 momentary breakpoints to be active in only a single thread of
8976 if (in_thread_list (inferior_ptid
))
8977 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8979 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8984 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8985 The new breakpoint will have type TYPE, use OPS as its
8986 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8988 static struct breakpoint
*
8989 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8991 const struct breakpoint_ops
*ops
,
8994 struct breakpoint
*copy
;
8996 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8997 copy
->loc
= allocate_bp_location (copy
);
8998 set_breakpoint_location_function (copy
->loc
, 1);
9000 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9001 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9002 copy
->loc
->address
= orig
->loc
->address
;
9003 copy
->loc
->section
= orig
->loc
->section
;
9004 copy
->loc
->pspace
= orig
->loc
->pspace
;
9005 copy
->loc
->probe
= orig
->loc
->probe
;
9006 copy
->loc
->line_number
= orig
->loc
->line_number
;
9007 copy
->loc
->symtab
= orig
->loc
->symtab
;
9008 copy
->loc
->enabled
= loc_enabled
;
9009 copy
->frame_id
= orig
->frame_id
;
9010 copy
->thread
= orig
->thread
;
9011 copy
->pspace
= orig
->pspace
;
9013 copy
->enable_state
= bp_enabled
;
9014 copy
->disposition
= disp_donttouch
;
9015 copy
->number
= internal_breakpoint_number
--;
9017 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
9021 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9025 clone_momentary_breakpoint (struct breakpoint
*orig
)
9027 /* If there's nothing to clone, then return nothing. */
9031 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9035 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9038 struct symtab_and_line sal
;
9040 sal
= find_pc_line (pc
, 0);
9042 sal
.section
= find_pc_overlay (pc
);
9043 sal
.explicit_pc
= 1;
9045 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9049 /* Tell the user we have just set a breakpoint B. */
9052 mention (struct breakpoint
*b
)
9054 b
->ops
->print_mention (b
);
9055 if (ui_out_is_mi_like_p (current_uiout
))
9057 printf_filtered ("\n");
9061 static int bp_loc_is_permanent (struct bp_location
*loc
);
9063 static struct bp_location
*
9064 add_location_to_breakpoint (struct breakpoint
*b
,
9065 const struct symtab_and_line
*sal
)
9067 struct bp_location
*loc
, **tmp
;
9068 CORE_ADDR adjusted_address
;
9069 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9071 if (loc_gdbarch
== NULL
)
9072 loc_gdbarch
= b
->gdbarch
;
9074 /* Adjust the breakpoint's address prior to allocating a location.
9075 Once we call allocate_bp_location(), that mostly uninitialized
9076 location will be placed on the location chain. Adjustment of the
9077 breakpoint may cause target_read_memory() to be called and we do
9078 not want its scan of the location chain to find a breakpoint and
9079 location that's only been partially initialized. */
9080 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9083 /* Sort the locations by their ADDRESS. */
9084 loc
= allocate_bp_location (b
);
9085 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9086 tmp
= &((*tmp
)->next
))
9091 loc
->requested_address
= sal
->pc
;
9092 loc
->address
= adjusted_address
;
9093 loc
->pspace
= sal
->pspace
;
9094 loc
->probe
.probe
= sal
->probe
;
9095 loc
->probe
.objfile
= sal
->objfile
;
9096 gdb_assert (loc
->pspace
!= NULL
);
9097 loc
->section
= sal
->section
;
9098 loc
->gdbarch
= loc_gdbarch
;
9099 loc
->line_number
= sal
->line
;
9100 loc
->symtab
= sal
->symtab
;
9102 set_breakpoint_location_function (loc
,
9103 sal
->explicit_pc
|| sal
->explicit_line
);
9105 /* While by definition, permanent breakpoints are already present in the
9106 code, we don't mark the location as inserted. Normally one would expect
9107 that GDB could rely on that breakpoint instruction to stop the program,
9108 thus removing the need to insert its own breakpoint, except that executing
9109 the breakpoint instruction can kill the target instead of reporting a
9110 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9111 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9112 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9113 breakpoint be inserted normally results in QEMU knowing about the GDB
9114 breakpoint, and thus trap before the breakpoint instruction is executed.
9115 (If GDB later needs to continue execution past the permanent breakpoint,
9116 it manually increments the PC, thus avoiding executing the breakpoint
9118 if (bp_loc_is_permanent (loc
))
9125 /* See breakpoint.h. */
9128 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9132 const gdb_byte
*bpoint
;
9133 gdb_byte
*target_mem
;
9134 struct cleanup
*cleanup
;
9138 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9140 /* Software breakpoints unsupported? */
9144 target_mem
= (gdb_byte
*) alloca (len
);
9146 /* Enable the automatic memory restoration from breakpoints while
9147 we read the memory. Otherwise we could say about our temporary
9148 breakpoints they are permanent. */
9149 cleanup
= make_show_memory_breakpoints_cleanup (0);
9151 if (target_read_memory (address
, target_mem
, len
) == 0
9152 && memcmp (target_mem
, bpoint
, len
) == 0)
9155 do_cleanups (cleanup
);
9160 /* Return 1 if LOC is pointing to a permanent breakpoint,
9161 return 0 otherwise. */
9164 bp_loc_is_permanent (struct bp_location
*loc
)
9166 struct cleanup
*cleanup
;
9169 gdb_assert (loc
!= NULL
);
9171 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9172 attempt to read from the addresses the locations of these breakpoint types
9173 point to. program_breakpoint_here_p, below, will attempt to read
9175 if (!breakpoint_address_is_meaningful (loc
->owner
))
9178 cleanup
= save_current_space_and_thread ();
9179 switch_to_program_space_and_thread (loc
->pspace
);
9181 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9183 do_cleanups (cleanup
);
9188 /* Build a command list for the dprintf corresponding to the current
9189 settings of the dprintf style options. */
9192 update_dprintf_command_list (struct breakpoint
*b
)
9194 char *dprintf_args
= b
->extra_string
;
9195 char *printf_line
= NULL
;
9200 dprintf_args
= skip_spaces (dprintf_args
);
9202 /* Allow a comma, as it may have terminated a location, but don't
9204 if (*dprintf_args
== ',')
9206 dprintf_args
= skip_spaces (dprintf_args
);
9208 if (*dprintf_args
!= '"')
9209 error (_("Bad format string, missing '\"'."));
9211 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9212 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9213 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9215 if (!dprintf_function
)
9216 error (_("No function supplied for dprintf call"));
9218 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9219 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9224 printf_line
= xstrprintf ("call (void) %s (%s)",
9228 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9230 if (target_can_run_breakpoint_commands ())
9231 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9234 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9235 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9239 internal_error (__FILE__
, __LINE__
,
9240 _("Invalid dprintf style."));
9242 gdb_assert (printf_line
!= NULL
);
9243 /* Manufacture a printf sequence. */
9245 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9247 printf_cmd_line
->control_type
= simple_control
;
9248 printf_cmd_line
->body_count
= 0;
9249 printf_cmd_line
->body_list
= NULL
;
9250 printf_cmd_line
->next
= NULL
;
9251 printf_cmd_line
->line
= printf_line
;
9253 breakpoint_set_commands (b
, printf_cmd_line
);
9257 /* Update all dprintf commands, making their command lists reflect
9258 current style settings. */
9261 update_dprintf_commands (char *args
, int from_tty
,
9262 struct cmd_list_element
*c
)
9264 struct breakpoint
*b
;
9268 if (b
->type
== bp_dprintf
)
9269 update_dprintf_command_list (b
);
9273 /* Create a breakpoint with SAL as location. Use LOCATION
9274 as a description of the location, and COND_STRING
9275 as condition expression. If LOCATION is NULL then create an
9276 "address location" from the address in the SAL. */
9279 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9280 struct symtabs_and_lines sals
,
9281 struct event_location
*location
,
9282 char *filter
, char *cond_string
,
9284 enum bptype type
, enum bpdisp disposition
,
9285 int thread
, int task
, int ignore_count
,
9286 const struct breakpoint_ops
*ops
, int from_tty
,
9287 int enabled
, int internal
, unsigned flags
,
9288 int display_canonical
)
9292 if (type
== bp_hardware_breakpoint
)
9294 int target_resources_ok
;
9296 i
= hw_breakpoint_used_count ();
9297 target_resources_ok
=
9298 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9300 if (target_resources_ok
== 0)
9301 error (_("No hardware breakpoint support in the target."));
9302 else if (target_resources_ok
< 0)
9303 error (_("Hardware breakpoints used exceeds limit."));
9306 gdb_assert (sals
.nelts
> 0);
9308 for (i
= 0; i
< sals
.nelts
; ++i
)
9310 struct symtab_and_line sal
= sals
.sals
[i
];
9311 struct bp_location
*loc
;
9315 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9317 loc_gdbarch
= gdbarch
;
9319 describe_other_breakpoints (loc_gdbarch
,
9320 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9325 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9329 b
->cond_string
= cond_string
;
9330 b
->extra_string
= extra_string
;
9331 b
->ignore_count
= ignore_count
;
9332 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9333 b
->disposition
= disposition
;
9335 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9336 b
->loc
->inserted
= 1;
9338 if (type
== bp_static_tracepoint
)
9340 struct tracepoint
*t
= (struct tracepoint
*) b
;
9341 struct static_tracepoint_marker marker
;
9343 if (strace_marker_p (b
))
9345 /* We already know the marker exists, otherwise, we
9346 wouldn't see a sal for it. */
9347 const char *p
= &event_location_to_string (b
->location
)[3];
9351 p
= skip_spaces_const (p
);
9353 endp
= skip_to_space_const (p
);
9355 marker_str
= savestring (p
, endp
- p
);
9356 t
->static_trace_marker_id
= marker_str
;
9358 printf_filtered (_("Probed static tracepoint "
9360 t
->static_trace_marker_id
);
9362 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9364 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9365 release_static_tracepoint_marker (&marker
);
9367 printf_filtered (_("Probed static tracepoint "
9369 t
->static_trace_marker_id
);
9372 warning (_("Couldn't determine the static "
9373 "tracepoint marker to probe"));
9380 loc
= add_location_to_breakpoint (b
, &sal
);
9381 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9387 const char *arg
= b
->cond_string
;
9389 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9390 block_for_pc (loc
->address
), 0);
9392 error (_("Garbage '%s' follows condition"), arg
);
9395 /* Dynamic printf requires and uses additional arguments on the
9396 command line, otherwise it's an error. */
9397 if (type
== bp_dprintf
)
9399 if (b
->extra_string
)
9400 update_dprintf_command_list (b
);
9402 error (_("Format string required"));
9404 else if (b
->extra_string
)
9405 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9408 b
->display_canonical
= display_canonical
;
9409 if (location
!= NULL
)
9410 b
->location
= location
;
9413 const char *addr_string
= NULL
;
9414 int addr_string_len
= 0;
9416 if (location
!= NULL
)
9417 addr_string
= event_location_to_string (location
);
9418 if (addr_string
!= NULL
)
9419 addr_string_len
= strlen (addr_string
);
9421 b
->location
= new_address_location (b
->loc
->address
,
9422 addr_string
, addr_string_len
);
9428 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9429 struct symtabs_and_lines sals
,
9430 struct event_location
*location
,
9431 char *filter
, char *cond_string
,
9433 enum bptype type
, enum bpdisp disposition
,
9434 int thread
, int task
, int ignore_count
,
9435 const struct breakpoint_ops
*ops
, int from_tty
,
9436 int enabled
, int internal
, unsigned flags
,
9437 int display_canonical
)
9439 struct breakpoint
*b
;
9440 struct cleanup
*old_chain
;
9442 if (is_tracepoint_type (type
))
9444 struct tracepoint
*t
;
9446 t
= XCNEW (struct tracepoint
);
9450 b
= XNEW (struct breakpoint
);
9452 old_chain
= make_cleanup (xfree
, b
);
9454 init_breakpoint_sal (b
, gdbarch
,
9456 filter
, cond_string
, extra_string
,
9458 thread
, task
, ignore_count
,
9460 enabled
, internal
, flags
,
9462 discard_cleanups (old_chain
);
9464 install_breakpoint (internal
, b
, 0);
9467 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9468 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9469 value. COND_STRING, if not NULL, specified the condition to be
9470 used for all breakpoints. Essentially the only case where
9471 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9472 function. In that case, it's still not possible to specify
9473 separate conditions for different overloaded functions, so
9474 we take just a single condition string.
9476 NOTE: If the function succeeds, the caller is expected to cleanup
9477 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9478 array contents). If the function fails (error() is called), the
9479 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9480 COND and SALS arrays and each of those arrays contents. */
9483 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9484 struct linespec_result
*canonical
,
9485 char *cond_string
, char *extra_string
,
9486 enum bptype type
, enum bpdisp disposition
,
9487 int thread
, int task
, int ignore_count
,
9488 const struct breakpoint_ops
*ops
, int from_tty
,
9489 int enabled
, int internal
, unsigned flags
)
9492 struct linespec_sals
*lsal
;
9494 if (canonical
->pre_expanded
)
9495 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9497 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9499 /* Note that 'location' can be NULL in the case of a plain
9500 'break', without arguments. */
9501 struct event_location
*location
9502 = (canonical
->location
!= NULL
9503 ? copy_event_location (canonical
->location
) : NULL
);
9504 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9505 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9507 make_cleanup (xfree
, filter_string
);
9508 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9511 cond_string
, extra_string
,
9513 thread
, task
, ignore_count
, ops
,
9514 from_tty
, enabled
, internal
, flags
,
9515 canonical
->special_display
);
9516 discard_cleanups (inner
);
9520 /* Parse LOCATION which is assumed to be a SAL specification possibly
9521 followed by conditionals. On return, SALS contains an array of SAL
9522 addresses found. LOCATION points to the end of the SAL (for
9523 linespec locations).
9525 The array and the line spec strings are allocated on the heap, it is
9526 the caller's responsibility to free them. */
9529 parse_breakpoint_sals (const struct event_location
*location
,
9530 struct linespec_result
*canonical
)
9532 struct symtab_and_line cursal
;
9534 if (event_location_type (location
) == LINESPEC_LOCATION
)
9536 const char *address
= get_linespec_location (location
);
9538 if (address
== NULL
)
9540 /* The last displayed codepoint, if it's valid, is our default
9541 breakpoint address. */
9542 if (last_displayed_sal_is_valid ())
9544 struct linespec_sals lsal
;
9545 struct symtab_and_line sal
;
9548 init_sal (&sal
); /* Initialize to zeroes. */
9549 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9551 /* Set sal's pspace, pc, symtab, and line to the values
9552 corresponding to the last call to print_frame_info.
9553 Be sure to reinitialize LINE with NOTCURRENT == 0
9554 as the breakpoint line number is inappropriate otherwise.
9555 find_pc_line would adjust PC, re-set it back. */
9556 get_last_displayed_sal (&sal
);
9558 sal
= find_pc_line (pc
, 0);
9560 /* "break" without arguments is equivalent to "break *PC"
9561 where PC is the last displayed codepoint's address. So
9562 make sure to set sal.explicit_pc to prevent GDB from
9563 trying to expand the list of sals to include all other
9564 instances with the same symtab and line. */
9566 sal
.explicit_pc
= 1;
9568 lsal
.sals
.sals
[0] = sal
;
9569 lsal
.sals
.nelts
= 1;
9570 lsal
.canonical
= NULL
;
9572 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9576 error (_("No default breakpoint address now."));
9580 /* Force almost all breakpoints to be in terms of the
9581 current_source_symtab (which is decode_line_1's default).
9582 This should produce the results we want almost all of the
9583 time while leaving default_breakpoint_* alone.
9585 ObjC: However, don't match an Objective-C method name which
9586 may have a '+' or '-' succeeded by a '['. */
9587 cursal
= get_current_source_symtab_and_line ();
9588 if (last_displayed_sal_is_valid ())
9590 const char *address
= NULL
;
9592 if (event_location_type (location
) == LINESPEC_LOCATION
)
9593 address
= get_linespec_location (location
);
9597 && strchr ("+-", address
[0]) != NULL
9598 && address
[1] != '['))
9600 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9601 get_last_displayed_symtab (),
9602 get_last_displayed_line (),
9603 canonical
, NULL
, NULL
);
9608 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9609 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9613 /* Convert each SAL into a real PC. Verify that the PC can be
9614 inserted as a breakpoint. If it can't throw an error. */
9617 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9621 for (i
= 0; i
< sals
->nelts
; i
++)
9622 resolve_sal_pc (&sals
->sals
[i
]);
9625 /* Fast tracepoints may have restrictions on valid locations. For
9626 instance, a fast tracepoint using a jump instead of a trap will
9627 likely have to overwrite more bytes than a trap would, and so can
9628 only be placed where the instruction is longer than the jump, or a
9629 multi-instruction sequence does not have a jump into the middle of
9633 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9634 struct symtabs_and_lines
*sals
)
9637 struct symtab_and_line
*sal
;
9639 struct cleanup
*old_chain
;
9641 for (i
= 0; i
< sals
->nelts
; i
++)
9643 struct gdbarch
*sarch
;
9645 sal
= &sals
->sals
[i
];
9647 sarch
= get_sal_arch (*sal
);
9648 /* We fall back to GDBARCH if there is no architecture
9649 associated with SAL. */
9652 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9653 old_chain
= make_cleanup (xfree
, msg
);
9656 error (_("May not have a fast tracepoint at %s%s"),
9657 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9659 do_cleanups (old_chain
);
9663 /* Given TOK, a string specification of condition and thread, as
9664 accepted by the 'break' command, extract the condition
9665 string and thread number and set *COND_STRING and *THREAD.
9666 PC identifies the context at which the condition should be parsed.
9667 If no condition is found, *COND_STRING is set to NULL.
9668 If no thread is found, *THREAD is set to -1. */
9671 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9672 char **cond_string
, int *thread
, int *task
,
9675 *cond_string
= NULL
;
9682 const char *end_tok
;
9684 const char *cond_start
= NULL
;
9685 const char *cond_end
= NULL
;
9687 tok
= skip_spaces_const (tok
);
9689 if ((*tok
== '"' || *tok
== ',') && rest
)
9691 *rest
= savestring (tok
, strlen (tok
));
9695 end_tok
= skip_to_space_const (tok
);
9697 toklen
= end_tok
- tok
;
9699 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9701 struct expression
*expr
;
9703 tok
= cond_start
= end_tok
+ 1;
9704 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9707 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9709 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9712 struct thread_info
*thr
;
9715 thr
= parse_thread_id (tok
, &tmptok
);
9717 error (_("Junk after thread keyword."));
9718 *thread
= thr
->global_num
;
9721 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9726 *task
= strtol (tok
, &tmptok
, 0);
9728 error (_("Junk after task keyword."));
9729 if (!valid_task_id (*task
))
9730 error (_("Unknown task %d."), *task
);
9735 *rest
= savestring (tok
, strlen (tok
));
9739 error (_("Junk at end of arguments."));
9743 /* Decode a static tracepoint marker spec. */
9745 static struct symtabs_and_lines
9746 decode_static_tracepoint_spec (const char **arg_p
)
9748 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9749 struct symtabs_and_lines sals
;
9750 struct cleanup
*old_chain
;
9751 const char *p
= &(*arg_p
)[3];
9756 p
= skip_spaces_const (p
);
9758 endp
= skip_to_space_const (p
);
9760 marker_str
= savestring (p
, endp
- p
);
9761 old_chain
= make_cleanup (xfree
, marker_str
);
9763 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9764 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9765 error (_("No known static tracepoint marker named %s"), marker_str
);
9767 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9768 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9770 for (i
= 0; i
< sals
.nelts
; i
++)
9772 struct static_tracepoint_marker
*marker
;
9774 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9776 init_sal (&sals
.sals
[i
]);
9778 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9779 sals
.sals
[i
].pc
= marker
->address
;
9781 release_static_tracepoint_marker (marker
);
9784 do_cleanups (old_chain
);
9790 /* See breakpoint.h. */
9793 create_breakpoint (struct gdbarch
*gdbarch
,
9794 const struct event_location
*location
, char *cond_string
,
9795 int thread
, char *extra_string
,
9797 int tempflag
, enum bptype type_wanted
,
9799 enum auto_boolean pending_break_support
,
9800 const struct breakpoint_ops
*ops
,
9801 int from_tty
, int enabled
, int internal
,
9804 struct linespec_result canonical
;
9805 struct cleanup
*old_chain
;
9806 struct cleanup
*bkpt_chain
= NULL
;
9809 int prev_bkpt_count
= breakpoint_count
;
9811 gdb_assert (ops
!= NULL
);
9813 /* If extra_string isn't useful, set it to NULL. */
9814 if (extra_string
!= NULL
&& *extra_string
== '\0')
9815 extra_string
= NULL
;
9817 init_linespec_result (&canonical
);
9821 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9823 CATCH (e
, RETURN_MASK_ERROR
)
9825 /* If caller is interested in rc value from parse, set
9827 if (e
.error
== NOT_FOUND_ERROR
)
9829 /* If pending breakpoint support is turned off, throw
9832 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9833 throw_exception (e
);
9835 exception_print (gdb_stderr
, e
);
9837 /* If pending breakpoint support is auto query and the user
9838 selects no, then simply return the error code. */
9839 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9840 && !nquery (_("Make %s pending on future shared library load? "),
9841 bptype_string (type_wanted
)))
9844 /* At this point, either the user was queried about setting
9845 a pending breakpoint and selected yes, or pending
9846 breakpoint behavior is on and thus a pending breakpoint
9847 is defaulted on behalf of the user. */
9851 throw_exception (e
);
9855 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9858 /* Create a chain of things that always need to be cleaned up. */
9859 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9861 /* ----------------------------- SNIP -----------------------------
9862 Anything added to the cleanup chain beyond this point is assumed
9863 to be part of a breakpoint. If the breakpoint create succeeds
9864 then the memory is not reclaimed. */
9865 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9867 /* Resolve all line numbers to PC's and verify that the addresses
9868 are ok for the target. */
9872 struct linespec_sals
*iter
;
9874 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9875 breakpoint_sals_to_pc (&iter
->sals
);
9878 /* Fast tracepoints may have additional restrictions on location. */
9879 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9882 struct linespec_sals
*iter
;
9884 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9885 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9888 /* Verify that condition can be parsed, before setting any
9889 breakpoints. Allocate a separate condition expression for each
9896 struct linespec_sals
*lsal
;
9898 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9900 /* Here we only parse 'arg' to separate condition
9901 from thread number, so parsing in context of first
9902 sal is OK. When setting the breakpoint we'll
9903 re-parse it in context of each sal. */
9905 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9906 &cond_string
, &thread
, &task
, &rest
);
9908 make_cleanup (xfree
, cond_string
);
9910 make_cleanup (xfree
, rest
);
9912 extra_string
= rest
;
9914 extra_string
= NULL
;
9918 if (type_wanted
!= bp_dprintf
9919 && extra_string
!= NULL
&& *extra_string
!= '\0')
9920 error (_("Garbage '%s' at end of location"), extra_string
);
9922 /* Create a private copy of condition string. */
9925 cond_string
= xstrdup (cond_string
);
9926 make_cleanup (xfree
, cond_string
);
9928 /* Create a private copy of any extra string. */
9931 extra_string
= xstrdup (extra_string
);
9932 make_cleanup (xfree
, extra_string
);
9936 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9937 cond_string
, extra_string
, type_wanted
,
9938 tempflag
? disp_del
: disp_donttouch
,
9939 thread
, task
, ignore_count
, ops
,
9940 from_tty
, enabled
, internal
, flags
);
9944 struct breakpoint
*b
;
9946 if (is_tracepoint_type (type_wanted
))
9948 struct tracepoint
*t
;
9950 t
= XCNEW (struct tracepoint
);
9954 b
= XNEW (struct breakpoint
);
9956 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9957 b
->location
= copy_event_location (location
);
9960 b
->cond_string
= NULL
;
9963 /* Create a private copy of condition string. */
9966 cond_string
= xstrdup (cond_string
);
9967 make_cleanup (xfree
, cond_string
);
9969 b
->cond_string
= cond_string
;
9973 /* Create a private copy of any extra string. */
9974 if (extra_string
!= NULL
)
9976 extra_string
= xstrdup (extra_string
);
9977 make_cleanup (xfree
, extra_string
);
9979 b
->extra_string
= extra_string
;
9980 b
->ignore_count
= ignore_count
;
9981 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9982 b
->condition_not_parsed
= 1;
9983 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9984 if ((type_wanted
!= bp_breakpoint
9985 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9986 b
->pspace
= current_program_space
;
9988 install_breakpoint (internal
, b
, 0);
9991 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9993 warning (_("Multiple breakpoints were set.\nUse the "
9994 "\"delete\" command to delete unwanted breakpoints."));
9995 prev_breakpoint_count
= prev_bkpt_count
;
9998 /* That's it. Discard the cleanups for data inserted into the
10000 discard_cleanups (bkpt_chain
);
10001 /* But cleanup everything else. */
10002 do_cleanups (old_chain
);
10004 /* error call may happen here - have BKPT_CHAIN already discarded. */
10005 update_global_location_list (UGLL_MAY_INSERT
);
10010 /* Set a breakpoint.
10011 ARG is a string describing breakpoint address,
10012 condition, and thread.
10013 FLAG specifies if a breakpoint is hardware on,
10014 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10015 and BP_TEMPFLAG. */
10018 break_command_1 (char *arg
, int flag
, int from_tty
)
10020 int tempflag
= flag
& BP_TEMPFLAG
;
10021 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10022 ? bp_hardware_breakpoint
10024 struct breakpoint_ops
*ops
;
10025 struct event_location
*location
;
10026 struct cleanup
*cleanup
;
10028 location
= string_to_event_location (&arg
, current_language
);
10029 cleanup
= make_cleanup_delete_event_location (location
);
10031 /* Matching breakpoints on probes. */
10032 if (location
!= NULL
10033 && event_location_type (location
) == PROBE_LOCATION
)
10034 ops
= &bkpt_probe_breakpoint_ops
;
10036 ops
= &bkpt_breakpoint_ops
;
10038 create_breakpoint (get_current_arch (),
10040 NULL
, 0, arg
, 1 /* parse arg */,
10041 tempflag
, type_wanted
,
10042 0 /* Ignore count */,
10043 pending_break_support
,
10049 do_cleanups (cleanup
);
10052 /* Helper function for break_command_1 and disassemble_command. */
10055 resolve_sal_pc (struct symtab_and_line
*sal
)
10059 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10061 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10062 error (_("No line %d in file \"%s\"."),
10063 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10066 /* If this SAL corresponds to a breakpoint inserted using a line
10067 number, then skip the function prologue if necessary. */
10068 if (sal
->explicit_line
)
10069 skip_prologue_sal (sal
);
10072 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10074 const struct blockvector
*bv
;
10075 const struct block
*b
;
10076 struct symbol
*sym
;
10078 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
10079 SYMTAB_COMPUNIT (sal
->symtab
));
10082 sym
= block_linkage_function (b
);
10085 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
10086 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10091 /* It really is worthwhile to have the section, so we'll
10092 just have to look harder. This case can be executed
10093 if we have line numbers but no functions (as can
10094 happen in assembly source). */
10096 struct bound_minimal_symbol msym
;
10097 struct cleanup
*old_chain
= save_current_space_and_thread ();
10099 switch_to_program_space_and_thread (sal
->pspace
);
10101 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10103 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10105 do_cleanups (old_chain
);
10112 break_command (char *arg
, int from_tty
)
10114 break_command_1 (arg
, 0, from_tty
);
10118 tbreak_command (char *arg
, int from_tty
)
10120 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10124 hbreak_command (char *arg
, int from_tty
)
10126 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10130 thbreak_command (char *arg
, int from_tty
)
10132 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10136 stop_command (char *arg
, int from_tty
)
10138 printf_filtered (_("Specify the type of breakpoint to set.\n\
10139 Usage: stop in <function | address>\n\
10140 stop at <line>\n"));
10144 stopin_command (char *arg
, int from_tty
)
10148 if (arg
== (char *) NULL
)
10150 else if (*arg
!= '*')
10152 char *argptr
= arg
;
10155 /* Look for a ':'. If this is a line number specification, then
10156 say it is bad, otherwise, it should be an address or
10157 function/method name. */
10158 while (*argptr
&& !hasColon
)
10160 hasColon
= (*argptr
== ':');
10165 badInput
= (*argptr
!= ':'); /* Not a class::method */
10167 badInput
= isdigit (*arg
); /* a simple line number */
10171 printf_filtered (_("Usage: stop in <function | address>\n"));
10173 break_command_1 (arg
, 0, from_tty
);
10177 stopat_command (char *arg
, int from_tty
)
10181 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10185 char *argptr
= arg
;
10188 /* Look for a ':'. If there is a '::' then get out, otherwise
10189 it is probably a line number. */
10190 while (*argptr
&& !hasColon
)
10192 hasColon
= (*argptr
== ':');
10197 badInput
= (*argptr
== ':'); /* we have class::method */
10199 badInput
= !isdigit (*arg
); /* not a line number */
10203 printf_filtered (_("Usage: stop at <line>\n"));
10205 break_command_1 (arg
, 0, from_tty
);
10208 /* The dynamic printf command is mostly like a regular breakpoint, but
10209 with a prewired command list consisting of a single output command,
10210 built from extra arguments supplied on the dprintf command
10214 dprintf_command (char *arg
, int from_tty
)
10216 struct event_location
*location
;
10217 struct cleanup
*cleanup
;
10219 location
= string_to_event_location (&arg
, current_language
);
10220 cleanup
= make_cleanup_delete_event_location (location
);
10222 /* If non-NULL, ARG should have been advanced past the location;
10223 the next character must be ','. */
10226 if (arg
[0] != ',' || arg
[1] == '\0')
10227 error (_("Format string required"));
10230 /* Skip the comma. */
10235 create_breakpoint (get_current_arch (),
10237 NULL
, 0, arg
, 1 /* parse arg */,
10239 0 /* Ignore count */,
10240 pending_break_support
,
10241 &dprintf_breakpoint_ops
,
10246 do_cleanups (cleanup
);
10250 agent_printf_command (char *arg
, int from_tty
)
10252 error (_("May only run agent-printf on the target"));
10255 /* Implement the "breakpoint_hit" breakpoint_ops method for
10256 ranged breakpoints. */
10259 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10260 struct address_space
*aspace
,
10262 const struct target_waitstatus
*ws
)
10264 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10265 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10268 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10269 bl
->length
, aspace
, bp_addr
);
10272 /* Implement the "resources_needed" breakpoint_ops method for
10273 ranged breakpoints. */
10276 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10278 return target_ranged_break_num_registers ();
10281 /* Implement the "print_it" breakpoint_ops method for
10282 ranged breakpoints. */
10284 static enum print_stop_action
10285 print_it_ranged_breakpoint (bpstat bs
)
10287 struct breakpoint
*b
= bs
->breakpoint_at
;
10288 struct bp_location
*bl
= b
->loc
;
10289 struct ui_out
*uiout
= current_uiout
;
10291 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10293 /* Ranged breakpoints have only one location. */
10294 gdb_assert (bl
&& bl
->next
== NULL
);
10296 annotate_breakpoint (b
->number
);
10298 maybe_print_thread_hit_breakpoint (uiout
);
10300 if (b
->disposition
== disp_del
)
10301 ui_out_text (uiout
, "Temporary ranged breakpoint ");
10303 ui_out_text (uiout
, "Ranged breakpoint ");
10304 if (ui_out_is_mi_like_p (uiout
))
10306 ui_out_field_string (uiout
, "reason",
10307 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10308 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10310 ui_out_field_int (uiout
, "bkptno", b
->number
);
10311 ui_out_text (uiout
, ", ");
10313 return PRINT_SRC_AND_LOC
;
10316 /* Implement the "print_one" breakpoint_ops method for
10317 ranged breakpoints. */
10320 print_one_ranged_breakpoint (struct breakpoint
*b
,
10321 struct bp_location
**last_loc
)
10323 struct bp_location
*bl
= b
->loc
;
10324 struct value_print_options opts
;
10325 struct ui_out
*uiout
= current_uiout
;
10327 /* Ranged breakpoints have only one location. */
10328 gdb_assert (bl
&& bl
->next
== NULL
);
10330 get_user_print_options (&opts
);
10332 if (opts
.addressprint
)
10333 /* We don't print the address range here, it will be printed later
10334 by print_one_detail_ranged_breakpoint. */
10335 ui_out_field_skip (uiout
, "addr");
10336 annotate_field (5);
10337 print_breakpoint_location (b
, bl
);
10341 /* Implement the "print_one_detail" breakpoint_ops method for
10342 ranged breakpoints. */
10345 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10346 struct ui_out
*uiout
)
10348 CORE_ADDR address_start
, address_end
;
10349 struct bp_location
*bl
= b
->loc
;
10350 struct ui_file
*stb
= mem_fileopen ();
10351 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10355 address_start
= bl
->address
;
10356 address_end
= address_start
+ bl
->length
- 1;
10358 ui_out_text (uiout
, "\taddress range: ");
10359 fprintf_unfiltered (stb
, "[%s, %s]",
10360 print_core_address (bl
->gdbarch
, address_start
),
10361 print_core_address (bl
->gdbarch
, address_end
));
10362 ui_out_field_stream (uiout
, "addr", stb
);
10363 ui_out_text (uiout
, "\n");
10365 do_cleanups (cleanup
);
10368 /* Implement the "print_mention" breakpoint_ops method for
10369 ranged breakpoints. */
10372 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10374 struct bp_location
*bl
= b
->loc
;
10375 struct ui_out
*uiout
= current_uiout
;
10378 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10380 if (ui_out_is_mi_like_p (uiout
))
10383 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10384 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10385 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10388 /* Implement the "print_recreate" breakpoint_ops method for
10389 ranged breakpoints. */
10392 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10394 fprintf_unfiltered (fp
, "break-range %s, %s",
10395 event_location_to_string (b
->location
),
10396 event_location_to_string (b
->location_range_end
));
10397 print_recreate_thread (b
, fp
);
10400 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10402 static struct breakpoint_ops ranged_breakpoint_ops
;
10404 /* Find the address where the end of the breakpoint range should be
10405 placed, given the SAL of the end of the range. This is so that if
10406 the user provides a line number, the end of the range is set to the
10407 last instruction of the given line. */
10410 find_breakpoint_range_end (struct symtab_and_line sal
)
10414 /* If the user provided a PC value, use it. Otherwise,
10415 find the address of the end of the given location. */
10416 if (sal
.explicit_pc
)
10423 ret
= find_line_pc_range (sal
, &start
, &end
);
10425 error (_("Could not find location of the end of the range."));
10427 /* find_line_pc_range returns the start of the next line. */
10434 /* Implement the "break-range" CLI command. */
10437 break_range_command (char *arg
, int from_tty
)
10439 char *arg_start
, *addr_string_start
;
10440 struct linespec_result canonical_start
, canonical_end
;
10441 int bp_count
, can_use_bp
, length
;
10443 struct breakpoint
*b
;
10444 struct symtab_and_line sal_start
, sal_end
;
10445 struct cleanup
*cleanup_bkpt
;
10446 struct linespec_sals
*lsal_start
, *lsal_end
;
10447 struct event_location
*start_location
, *end_location
;
10449 /* We don't support software ranged breakpoints. */
10450 if (target_ranged_break_num_registers () < 0)
10451 error (_("This target does not support hardware ranged breakpoints."));
10453 bp_count
= hw_breakpoint_used_count ();
10454 bp_count
+= target_ranged_break_num_registers ();
10455 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10457 if (can_use_bp
< 0)
10458 error (_("Hardware breakpoints used exceeds limit."));
10460 arg
= skip_spaces (arg
);
10461 if (arg
== NULL
|| arg
[0] == '\0')
10462 error(_("No address range specified."));
10464 init_linespec_result (&canonical_start
);
10467 start_location
= string_to_event_location (&arg
, current_language
);
10468 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10469 parse_breakpoint_sals (start_location
, &canonical_start
);
10470 make_cleanup_destroy_linespec_result (&canonical_start
);
10473 error (_("Too few arguments."));
10474 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10475 error (_("Could not find location of the beginning of the range."));
10477 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10479 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10480 || lsal_start
->sals
.nelts
!= 1)
10481 error (_("Cannot create a ranged breakpoint with multiple locations."));
10483 sal_start
= lsal_start
->sals
.sals
[0];
10484 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10485 make_cleanup (xfree
, addr_string_start
);
10487 arg
++; /* Skip the comma. */
10488 arg
= skip_spaces (arg
);
10490 /* Parse the end location. */
10492 init_linespec_result (&canonical_end
);
10495 /* We call decode_line_full directly here instead of using
10496 parse_breakpoint_sals because we need to specify the start location's
10497 symtab and line as the default symtab and line for the end of the
10498 range. This makes it possible to have ranges like "foo.c:27, +14",
10499 where +14 means 14 lines from the start location. */
10500 end_location
= string_to_event_location (&arg
, current_language
);
10501 make_cleanup_delete_event_location (end_location
);
10502 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
10503 sal_start
.symtab
, sal_start
.line
,
10504 &canonical_end
, NULL
, NULL
);
10506 make_cleanup_destroy_linespec_result (&canonical_end
);
10508 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10509 error (_("Could not find location of the end of the range."));
10511 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10512 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10513 || lsal_end
->sals
.nelts
!= 1)
10514 error (_("Cannot create a ranged breakpoint with multiple locations."));
10516 sal_end
= lsal_end
->sals
.sals
[0];
10518 end
= find_breakpoint_range_end (sal_end
);
10519 if (sal_start
.pc
> end
)
10520 error (_("Invalid address range, end precedes start."));
10522 length
= end
- sal_start
.pc
+ 1;
10524 /* Length overflowed. */
10525 error (_("Address range too large."));
10526 else if (length
== 1)
10528 /* This range is simple enough to be handled by
10529 the `hbreak' command. */
10530 hbreak_command (addr_string_start
, 1);
10532 do_cleanups (cleanup_bkpt
);
10537 /* Now set up the breakpoint. */
10538 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10539 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10540 set_breakpoint_count (breakpoint_count
+ 1);
10541 b
->number
= breakpoint_count
;
10542 b
->disposition
= disp_donttouch
;
10543 b
->location
= copy_event_location (start_location
);
10544 b
->location_range_end
= copy_event_location (end_location
);
10545 b
->loc
->length
= length
;
10547 do_cleanups (cleanup_bkpt
);
10550 observer_notify_breakpoint_created (b
);
10551 update_global_location_list (UGLL_MAY_INSERT
);
10554 /* Return non-zero if EXP is verified as constant. Returned zero
10555 means EXP is variable. Also the constant detection may fail for
10556 some constant expressions and in such case still falsely return
10560 watchpoint_exp_is_const (const struct expression
*exp
)
10562 int i
= exp
->nelts
;
10568 /* We are only interested in the descriptor of each element. */
10569 operator_length (exp
, i
, &oplenp
, &argsp
);
10572 switch (exp
->elts
[i
].opcode
)
10582 case BINOP_LOGICAL_AND
:
10583 case BINOP_LOGICAL_OR
:
10584 case BINOP_BITWISE_AND
:
10585 case BINOP_BITWISE_IOR
:
10586 case BINOP_BITWISE_XOR
:
10588 case BINOP_NOTEQUAL
:
10615 case OP_OBJC_NSSTRING
:
10618 case UNOP_LOGICAL_NOT
:
10619 case UNOP_COMPLEMENT
:
10624 case UNOP_CAST_TYPE
:
10625 case UNOP_REINTERPRET_CAST
:
10626 case UNOP_DYNAMIC_CAST
:
10627 /* Unary, binary and ternary operators: We have to check
10628 their operands. If they are constant, then so is the
10629 result of that operation. For instance, if A and B are
10630 determined to be constants, then so is "A + B".
10632 UNOP_IND is one exception to the rule above, because the
10633 value of *ADDR is not necessarily a constant, even when
10638 /* Check whether the associated symbol is a constant.
10640 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10641 possible that a buggy compiler could mark a variable as
10642 constant even when it is not, and TYPE_CONST would return
10643 true in this case, while SYMBOL_CLASS wouldn't.
10645 We also have to check for function symbols because they
10646 are always constant. */
10648 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10650 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10651 && SYMBOL_CLASS (s
) != LOC_CONST
10652 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10657 /* The default action is to return 0 because we are using
10658 the optimistic approach here: If we don't know something,
10659 then it is not a constant. */
10668 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10671 dtor_watchpoint (struct breakpoint
*self
)
10673 struct watchpoint
*w
= (struct watchpoint
*) self
;
10675 xfree (w
->cond_exp
);
10677 xfree (w
->exp_string
);
10678 xfree (w
->exp_string_reparse
);
10679 value_free (w
->val
);
10681 base_breakpoint_ops
.dtor (self
);
10684 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10687 re_set_watchpoint (struct breakpoint
*b
)
10689 struct watchpoint
*w
= (struct watchpoint
*) b
;
10691 /* Watchpoint can be either on expression using entirely global
10692 variables, or it can be on local variables.
10694 Watchpoints of the first kind are never auto-deleted, and even
10695 persist across program restarts. Since they can use variables
10696 from shared libraries, we need to reparse expression as libraries
10697 are loaded and unloaded.
10699 Watchpoints on local variables can also change meaning as result
10700 of solib event. For example, if a watchpoint uses both a local
10701 and a global variables in expression, it's a local watchpoint,
10702 but unloading of a shared library will make the expression
10703 invalid. This is not a very common use case, but we still
10704 re-evaluate expression, to avoid surprises to the user.
10706 Note that for local watchpoints, we re-evaluate it only if
10707 watchpoints frame id is still valid. If it's not, it means the
10708 watchpoint is out of scope and will be deleted soon. In fact,
10709 I'm not sure we'll ever be called in this case.
10711 If a local watchpoint's frame id is still valid, then
10712 w->exp_valid_block is likewise valid, and we can safely use it.
10714 Don't do anything about disabled watchpoints, since they will be
10715 reevaluated again when enabled. */
10716 update_watchpoint (w
, 1 /* reparse */);
10719 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10722 insert_watchpoint (struct bp_location
*bl
)
10724 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10725 int length
= w
->exact
? 1 : bl
->length
;
10727 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10731 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10734 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10736 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10737 int length
= w
->exact
? 1 : bl
->length
;
10739 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10744 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10745 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10746 const struct target_waitstatus
*ws
)
10748 struct breakpoint
*b
= bl
->owner
;
10749 struct watchpoint
*w
= (struct watchpoint
*) b
;
10751 /* Continuable hardware watchpoints are treated as non-existent if the
10752 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10753 some data address). Otherwise gdb won't stop on a break instruction
10754 in the code (not from a breakpoint) when a hardware watchpoint has
10755 been defined. Also skip watchpoints which we know did not trigger
10756 (did not match the data address). */
10757 if (is_hardware_watchpoint (b
)
10758 && w
->watchpoint_triggered
== watch_triggered_no
)
10765 check_status_watchpoint (bpstat bs
)
10767 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10769 bpstat_check_watchpoint (bs
);
10772 /* Implement the "resources_needed" breakpoint_ops method for
10773 hardware watchpoints. */
10776 resources_needed_watchpoint (const struct bp_location
*bl
)
10778 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10779 int length
= w
->exact
? 1 : bl
->length
;
10781 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10784 /* Implement the "works_in_software_mode" breakpoint_ops method for
10785 hardware watchpoints. */
10788 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10790 /* Read and access watchpoints only work with hardware support. */
10791 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10794 static enum print_stop_action
10795 print_it_watchpoint (bpstat bs
)
10797 struct cleanup
*old_chain
;
10798 struct breakpoint
*b
;
10799 struct ui_file
*stb
;
10800 enum print_stop_action result
;
10801 struct watchpoint
*w
;
10802 struct ui_out
*uiout
= current_uiout
;
10804 gdb_assert (bs
->bp_location_at
!= NULL
);
10806 b
= bs
->breakpoint_at
;
10807 w
= (struct watchpoint
*) b
;
10809 stb
= mem_fileopen ();
10810 old_chain
= make_cleanup_ui_file_delete (stb
);
10812 annotate_watchpoint (b
->number
);
10813 maybe_print_thread_hit_breakpoint (uiout
);
10817 case bp_watchpoint
:
10818 case bp_hardware_watchpoint
:
10819 if (ui_out_is_mi_like_p (uiout
))
10820 ui_out_field_string
10822 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10824 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10825 ui_out_text (uiout
, "\nOld value = ");
10826 watchpoint_value_print (bs
->old_val
, stb
);
10827 ui_out_field_stream (uiout
, "old", stb
);
10828 ui_out_text (uiout
, "\nNew value = ");
10829 watchpoint_value_print (w
->val
, stb
);
10830 ui_out_field_stream (uiout
, "new", stb
);
10831 ui_out_text (uiout
, "\n");
10832 /* More than one watchpoint may have been triggered. */
10833 result
= PRINT_UNKNOWN
;
10836 case bp_read_watchpoint
:
10837 if (ui_out_is_mi_like_p (uiout
))
10838 ui_out_field_string
10840 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10842 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10843 ui_out_text (uiout
, "\nValue = ");
10844 watchpoint_value_print (w
->val
, stb
);
10845 ui_out_field_stream (uiout
, "value", stb
);
10846 ui_out_text (uiout
, "\n");
10847 result
= PRINT_UNKNOWN
;
10850 case bp_access_watchpoint
:
10851 if (bs
->old_val
!= NULL
)
10853 if (ui_out_is_mi_like_p (uiout
))
10854 ui_out_field_string
10856 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10858 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10859 ui_out_text (uiout
, "\nOld value = ");
10860 watchpoint_value_print (bs
->old_val
, stb
);
10861 ui_out_field_stream (uiout
, "old", stb
);
10862 ui_out_text (uiout
, "\nNew value = ");
10867 if (ui_out_is_mi_like_p (uiout
))
10868 ui_out_field_string
10870 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10871 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10872 ui_out_text (uiout
, "\nValue = ");
10874 watchpoint_value_print (w
->val
, stb
);
10875 ui_out_field_stream (uiout
, "new", stb
);
10876 ui_out_text (uiout
, "\n");
10877 result
= PRINT_UNKNOWN
;
10880 result
= PRINT_UNKNOWN
;
10883 do_cleanups (old_chain
);
10887 /* Implement the "print_mention" breakpoint_ops method for hardware
10891 print_mention_watchpoint (struct breakpoint
*b
)
10893 struct cleanup
*ui_out_chain
;
10894 struct watchpoint
*w
= (struct watchpoint
*) b
;
10895 struct ui_out
*uiout
= current_uiout
;
10899 case bp_watchpoint
:
10900 ui_out_text (uiout
, "Watchpoint ");
10901 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10903 case bp_hardware_watchpoint
:
10904 ui_out_text (uiout
, "Hardware watchpoint ");
10905 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10907 case bp_read_watchpoint
:
10908 ui_out_text (uiout
, "Hardware read watchpoint ");
10909 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10911 case bp_access_watchpoint
:
10912 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10913 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10916 internal_error (__FILE__
, __LINE__
,
10917 _("Invalid hardware watchpoint type."));
10920 ui_out_field_int (uiout
, "number", b
->number
);
10921 ui_out_text (uiout
, ": ");
10922 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10923 do_cleanups (ui_out_chain
);
10926 /* Implement the "print_recreate" breakpoint_ops method for
10930 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10932 struct watchpoint
*w
= (struct watchpoint
*) b
;
10936 case bp_watchpoint
:
10937 case bp_hardware_watchpoint
:
10938 fprintf_unfiltered (fp
, "watch");
10940 case bp_read_watchpoint
:
10941 fprintf_unfiltered (fp
, "rwatch");
10943 case bp_access_watchpoint
:
10944 fprintf_unfiltered (fp
, "awatch");
10947 internal_error (__FILE__
, __LINE__
,
10948 _("Invalid watchpoint type."));
10951 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10952 print_recreate_thread (b
, fp
);
10955 /* Implement the "explains_signal" breakpoint_ops method for
10959 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10961 /* A software watchpoint cannot cause a signal other than
10962 GDB_SIGNAL_TRAP. */
10963 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10969 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10971 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10973 /* Implement the "insert" breakpoint_ops method for
10974 masked hardware watchpoints. */
10977 insert_masked_watchpoint (struct bp_location
*bl
)
10979 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10981 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10982 bl
->watchpoint_type
);
10985 /* Implement the "remove" breakpoint_ops method for
10986 masked hardware watchpoints. */
10989 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10991 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10993 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10994 bl
->watchpoint_type
);
10997 /* Implement the "resources_needed" breakpoint_ops method for
10998 masked hardware watchpoints. */
11001 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11003 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11005 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11008 /* Implement the "works_in_software_mode" breakpoint_ops method for
11009 masked hardware watchpoints. */
11012 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11017 /* Implement the "print_it" breakpoint_ops method for
11018 masked hardware watchpoints. */
11020 static enum print_stop_action
11021 print_it_masked_watchpoint (bpstat bs
)
11023 struct breakpoint
*b
= bs
->breakpoint_at
;
11024 struct ui_out
*uiout
= current_uiout
;
11026 /* Masked watchpoints have only one location. */
11027 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11029 annotate_watchpoint (b
->number
);
11030 maybe_print_thread_hit_breakpoint (uiout
);
11034 case bp_hardware_watchpoint
:
11035 if (ui_out_is_mi_like_p (uiout
))
11036 ui_out_field_string
11038 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11041 case bp_read_watchpoint
:
11042 if (ui_out_is_mi_like_p (uiout
))
11043 ui_out_field_string
11045 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11048 case bp_access_watchpoint
:
11049 if (ui_out_is_mi_like_p (uiout
))
11050 ui_out_field_string
11052 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11055 internal_error (__FILE__
, __LINE__
,
11056 _("Invalid hardware watchpoint type."));
11060 ui_out_text (uiout
, _("\n\
11061 Check the underlying instruction at PC for the memory\n\
11062 address and value which triggered this watchpoint.\n"));
11063 ui_out_text (uiout
, "\n");
11065 /* More than one watchpoint may have been triggered. */
11066 return PRINT_UNKNOWN
;
11069 /* Implement the "print_one_detail" breakpoint_ops method for
11070 masked hardware watchpoints. */
11073 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11074 struct ui_out
*uiout
)
11076 struct watchpoint
*w
= (struct watchpoint
*) b
;
11078 /* Masked watchpoints have only one location. */
11079 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11081 ui_out_text (uiout
, "\tmask ");
11082 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11083 ui_out_text (uiout
, "\n");
11086 /* Implement the "print_mention" breakpoint_ops method for
11087 masked hardware watchpoints. */
11090 print_mention_masked_watchpoint (struct breakpoint
*b
)
11092 struct watchpoint
*w
= (struct watchpoint
*) b
;
11093 struct ui_out
*uiout
= current_uiout
;
11094 struct cleanup
*ui_out_chain
;
11098 case bp_hardware_watchpoint
:
11099 ui_out_text (uiout
, "Masked hardware watchpoint ");
11100 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11102 case bp_read_watchpoint
:
11103 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11104 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11106 case bp_access_watchpoint
:
11107 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11108 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11111 internal_error (__FILE__
, __LINE__
,
11112 _("Invalid hardware watchpoint type."));
11115 ui_out_field_int (uiout
, "number", b
->number
);
11116 ui_out_text (uiout
, ": ");
11117 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11118 do_cleanups (ui_out_chain
);
11121 /* Implement the "print_recreate" breakpoint_ops method for
11122 masked hardware watchpoints. */
11125 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11127 struct watchpoint
*w
= (struct watchpoint
*) b
;
11132 case bp_hardware_watchpoint
:
11133 fprintf_unfiltered (fp
, "watch");
11135 case bp_read_watchpoint
:
11136 fprintf_unfiltered (fp
, "rwatch");
11138 case bp_access_watchpoint
:
11139 fprintf_unfiltered (fp
, "awatch");
11142 internal_error (__FILE__
, __LINE__
,
11143 _("Invalid hardware watchpoint type."));
11146 sprintf_vma (tmp
, w
->hw_wp_mask
);
11147 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11148 print_recreate_thread (b
, fp
);
11151 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11153 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11155 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11158 is_masked_watchpoint (const struct breakpoint
*b
)
11160 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11163 /* accessflag: hw_write: watch write,
11164 hw_read: watch read,
11165 hw_access: watch access (read or write) */
11167 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11168 int just_location
, int internal
)
11170 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11171 struct expression
*exp
;
11172 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11173 struct value
*val
, *mark
, *result
;
11174 int saved_bitpos
= 0, saved_bitsize
= 0;
11175 struct frame_info
*frame
;
11176 const char *exp_start
= NULL
;
11177 const char *exp_end
= NULL
;
11178 const char *tok
, *end_tok
;
11180 const char *cond_start
= NULL
;
11181 const char *cond_end
= NULL
;
11182 enum bptype bp_type
;
11185 /* Flag to indicate whether we are going to use masks for
11186 the hardware watchpoint. */
11188 CORE_ADDR mask
= 0;
11189 struct watchpoint
*w
;
11191 struct cleanup
*back_to
;
11193 /* Make sure that we actually have parameters to parse. */
11194 if (arg
!= NULL
&& arg
[0] != '\0')
11196 const char *value_start
;
11198 exp_end
= arg
+ strlen (arg
);
11200 /* Look for "parameter value" pairs at the end
11201 of the arguments string. */
11202 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11204 /* Skip whitespace at the end of the argument list. */
11205 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11208 /* Find the beginning of the last token.
11209 This is the value of the parameter. */
11210 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11212 value_start
= tok
+ 1;
11214 /* Skip whitespace. */
11215 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11220 /* Find the beginning of the second to last token.
11221 This is the parameter itself. */
11222 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11225 toklen
= end_tok
- tok
+ 1;
11227 if (toklen
== 6 && startswith (tok
, "thread"))
11229 struct thread_info
*thr
;
11230 /* At this point we've found a "thread" token, which means
11231 the user is trying to set a watchpoint that triggers
11232 only in a specific thread. */
11236 error(_("You can specify only one thread."));
11238 /* Extract the thread ID from the next token. */
11239 thr
= parse_thread_id (value_start
, &endp
);
11241 /* Check if the user provided a valid thread ID. */
11242 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11243 invalid_thread_id_error (value_start
);
11245 thread
= thr
->global_num
;
11247 else if (toklen
== 4 && startswith (tok
, "mask"))
11249 /* We've found a "mask" token, which means the user wants to
11250 create a hardware watchpoint that is going to have the mask
11252 struct value
*mask_value
, *mark
;
11255 error(_("You can specify only one mask."));
11257 use_mask
= just_location
= 1;
11259 mark
= value_mark ();
11260 mask_value
= parse_to_comma_and_eval (&value_start
);
11261 mask
= value_as_address (mask_value
);
11262 value_free_to_mark (mark
);
11265 /* We didn't recognize what we found. We should stop here. */
11268 /* Truncate the string and get rid of the "parameter value" pair before
11269 the arguments string is parsed by the parse_exp_1 function. */
11276 /* Parse the rest of the arguments. From here on out, everything
11277 is in terms of a newly allocated string instead of the original
11279 innermost_block
= NULL
;
11280 expression
= savestring (arg
, exp_end
- arg
);
11281 back_to
= make_cleanup (xfree
, expression
);
11282 exp_start
= arg
= expression
;
11283 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11285 /* Remove trailing whitespace from the expression before saving it.
11286 This makes the eventual display of the expression string a bit
11288 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11291 /* Checking if the expression is not constant. */
11292 if (watchpoint_exp_is_const (exp
))
11296 len
= exp_end
- exp_start
;
11297 while (len
> 0 && isspace (exp_start
[len
- 1]))
11299 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11302 exp_valid_block
= innermost_block
;
11303 mark
= value_mark ();
11304 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11306 if (val
!= NULL
&& just_location
)
11308 saved_bitpos
= value_bitpos (val
);
11309 saved_bitsize
= value_bitsize (val
);
11316 exp_valid_block
= NULL
;
11317 val
= value_addr (result
);
11318 release_value (val
);
11319 value_free_to_mark (mark
);
11323 ret
= target_masked_watch_num_registers (value_as_address (val
),
11326 error (_("This target does not support masked watchpoints."));
11327 else if (ret
== -2)
11328 error (_("Invalid mask or memory region."));
11331 else if (val
!= NULL
)
11332 release_value (val
);
11334 tok
= skip_spaces_const (arg
);
11335 end_tok
= skip_to_space_const (tok
);
11337 toklen
= end_tok
- tok
;
11338 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11340 struct expression
*cond
;
11342 innermost_block
= NULL
;
11343 tok
= cond_start
= end_tok
+ 1;
11344 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11346 /* The watchpoint expression may not be local, but the condition
11347 may still be. E.g.: `watch global if local > 0'. */
11348 cond_exp_valid_block
= innermost_block
;
11354 error (_("Junk at end of command."));
11356 frame
= block_innermost_frame (exp_valid_block
);
11358 /* If the expression is "local", then set up a "watchpoint scope"
11359 breakpoint at the point where we've left the scope of the watchpoint
11360 expression. Create the scope breakpoint before the watchpoint, so
11361 that we will encounter it first in bpstat_stop_status. */
11362 if (exp_valid_block
&& frame
)
11364 if (frame_id_p (frame_unwind_caller_id (frame
)))
11367 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11368 frame_unwind_caller_pc (frame
),
11369 bp_watchpoint_scope
,
11370 &momentary_breakpoint_ops
);
11372 scope_breakpoint
->enable_state
= bp_enabled
;
11374 /* Automatically delete the breakpoint when it hits. */
11375 scope_breakpoint
->disposition
= disp_del
;
11377 /* Only break in the proper frame (help with recursion). */
11378 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11380 /* Set the address at which we will stop. */
11381 scope_breakpoint
->loc
->gdbarch
11382 = frame_unwind_caller_arch (frame
);
11383 scope_breakpoint
->loc
->requested_address
11384 = frame_unwind_caller_pc (frame
);
11385 scope_breakpoint
->loc
->address
11386 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11387 scope_breakpoint
->loc
->requested_address
,
11388 scope_breakpoint
->type
);
11392 /* Now set up the breakpoint. We create all watchpoints as hardware
11393 watchpoints here even if hardware watchpoints are turned off, a call
11394 to update_watchpoint later in this function will cause the type to
11395 drop back to bp_watchpoint (software watchpoint) if required. */
11397 if (accessflag
== hw_read
)
11398 bp_type
= bp_read_watchpoint
;
11399 else if (accessflag
== hw_access
)
11400 bp_type
= bp_access_watchpoint
;
11402 bp_type
= bp_hardware_watchpoint
;
11404 w
= XCNEW (struct watchpoint
);
11407 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11408 &masked_watchpoint_breakpoint_ops
);
11410 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11411 &watchpoint_breakpoint_ops
);
11412 b
->thread
= thread
;
11413 b
->disposition
= disp_donttouch
;
11414 b
->pspace
= current_program_space
;
11416 w
->exp_valid_block
= exp_valid_block
;
11417 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11420 struct type
*t
= value_type (val
);
11421 CORE_ADDR addr
= value_as_address (val
);
11424 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11425 name
= type_to_string (t
);
11427 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11428 core_addr_to_string (addr
));
11431 w
->exp_string
= xstrprintf ("-location %.*s",
11432 (int) (exp_end
- exp_start
), exp_start
);
11434 /* The above expression is in C. */
11435 b
->language
= language_c
;
11438 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11442 w
->hw_wp_mask
= mask
;
11447 w
->val_bitpos
= saved_bitpos
;
11448 w
->val_bitsize
= saved_bitsize
;
11453 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11455 b
->cond_string
= 0;
11459 w
->watchpoint_frame
= get_frame_id (frame
);
11460 w
->watchpoint_thread
= inferior_ptid
;
11464 w
->watchpoint_frame
= null_frame_id
;
11465 w
->watchpoint_thread
= null_ptid
;
11468 if (scope_breakpoint
!= NULL
)
11470 /* The scope breakpoint is related to the watchpoint. We will
11471 need to act on them together. */
11472 b
->related_breakpoint
= scope_breakpoint
;
11473 scope_breakpoint
->related_breakpoint
= b
;
11476 if (!just_location
)
11477 value_free_to_mark (mark
);
11481 /* Finally update the new watchpoint. This creates the locations
11482 that should be inserted. */
11483 update_watchpoint (w
, 1);
11485 CATCH (e
, RETURN_MASK_ALL
)
11487 delete_breakpoint (b
);
11488 throw_exception (e
);
11492 install_breakpoint (internal
, b
, 1);
11493 do_cleanups (back_to
);
11496 /* Return count of debug registers needed to watch the given expression.
11497 If the watchpoint cannot be handled in hardware return zero. */
11500 can_use_hardware_watchpoint (struct value
*v
)
11502 int found_memory_cnt
= 0;
11503 struct value
*head
= v
;
11505 /* Did the user specifically forbid us to use hardware watchpoints? */
11506 if (!can_use_hw_watchpoints
)
11509 /* Make sure that the value of the expression depends only upon
11510 memory contents, and values computed from them within GDB. If we
11511 find any register references or function calls, we can't use a
11512 hardware watchpoint.
11514 The idea here is that evaluating an expression generates a series
11515 of values, one holding the value of every subexpression. (The
11516 expression a*b+c has five subexpressions: a, b, a*b, c, and
11517 a*b+c.) GDB's values hold almost enough information to establish
11518 the criteria given above --- they identify memory lvalues,
11519 register lvalues, computed values, etcetera. So we can evaluate
11520 the expression, and then scan the chain of values that leaves
11521 behind to decide whether we can detect any possible change to the
11522 expression's final value using only hardware watchpoints.
11524 However, I don't think that the values returned by inferior
11525 function calls are special in any way. So this function may not
11526 notice that an expression involving an inferior function call
11527 can't be watched with hardware watchpoints. FIXME. */
11528 for (; v
; v
= value_next (v
))
11530 if (VALUE_LVAL (v
) == lval_memory
)
11532 if (v
!= head
&& value_lazy (v
))
11533 /* A lazy memory lvalue in the chain is one that GDB never
11534 needed to fetch; we either just used its address (e.g.,
11535 `a' in `a.b') or we never needed it at all (e.g., `a'
11536 in `a,b'). This doesn't apply to HEAD; if that is
11537 lazy then it was not readable, but watch it anyway. */
11541 /* Ahh, memory we actually used! Check if we can cover
11542 it with hardware watchpoints. */
11543 struct type
*vtype
= check_typedef (value_type (v
));
11545 /* We only watch structs and arrays if user asked for it
11546 explicitly, never if they just happen to appear in a
11547 middle of some value chain. */
11549 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11550 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11552 CORE_ADDR vaddr
= value_address (v
);
11556 len
= (target_exact_watchpoints
11557 && is_scalar_type_recursive (vtype
))?
11558 1 : TYPE_LENGTH (value_type (v
));
11560 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11564 found_memory_cnt
+= num_regs
;
11568 else if (VALUE_LVAL (v
) != not_lval
11569 && deprecated_value_modifiable (v
) == 0)
11570 return 0; /* These are values from the history (e.g., $1). */
11571 else if (VALUE_LVAL (v
) == lval_register
)
11572 return 0; /* Cannot watch a register with a HW watchpoint. */
11575 /* The expression itself looks suitable for using a hardware
11576 watchpoint, but give the target machine a chance to reject it. */
11577 return found_memory_cnt
;
11581 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11583 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11586 /* A helper function that looks for the "-location" argument and then
11587 calls watch_command_1. */
11590 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11592 int just_location
= 0;
11595 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11596 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11598 arg
= skip_spaces (arg
);
11602 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11606 watch_command (char *arg
, int from_tty
)
11608 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11612 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11614 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11618 rwatch_command (char *arg
, int from_tty
)
11620 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11624 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11626 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11630 awatch_command (char *arg
, int from_tty
)
11632 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11636 /* Data for the FSM that manages the until(location)/advance commands
11637 in infcmd.c. Here because it uses the mechanisms of
11640 struct until_break_fsm
11642 /* The base class. */
11643 struct thread_fsm thread_fsm
;
11645 /* The thread that as current when the command was executed. */
11648 /* The breakpoint set at the destination location. */
11649 struct breakpoint
*location_breakpoint
;
11651 /* Breakpoint set at the return address in the caller frame. May be
11653 struct breakpoint
*caller_breakpoint
;
11656 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11657 struct thread_info
*thread
);
11658 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11659 struct thread_info
*thread
);
11660 static enum async_reply_reason
11661 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11663 /* until_break_fsm's vtable. */
11665 static struct thread_fsm_ops until_break_fsm_ops
=
11668 until_break_fsm_clean_up
,
11669 until_break_fsm_should_stop
,
11670 NULL
, /* return_value */
11671 until_break_fsm_async_reply_reason
,
11674 /* Allocate a new until_break_command_fsm. */
11676 static struct until_break_fsm
*
11677 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11678 struct breakpoint
*location_breakpoint
,
11679 struct breakpoint
*caller_breakpoint
)
11681 struct until_break_fsm
*sm
;
11683 sm
= XCNEW (struct until_break_fsm
);
11684 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11686 sm
->thread
= thread
;
11687 sm
->location_breakpoint
= location_breakpoint
;
11688 sm
->caller_breakpoint
= caller_breakpoint
;
11693 /* Implementation of the 'should_stop' FSM method for the
11694 until(location)/advance commands. */
11697 until_break_fsm_should_stop (struct thread_fsm
*self
,
11698 struct thread_info
*tp
)
11700 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11702 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11703 sm
->location_breakpoint
) != NULL
11704 || (sm
->caller_breakpoint
!= NULL
11705 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11706 sm
->caller_breakpoint
) != NULL
))
11707 thread_fsm_set_finished (self
);
11712 /* Implementation of the 'clean_up' FSM method for the
11713 until(location)/advance commands. */
11716 until_break_fsm_clean_up (struct thread_fsm
*self
,
11717 struct thread_info
*thread
)
11719 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11721 /* Clean up our temporary breakpoints. */
11722 if (sm
->location_breakpoint
!= NULL
)
11724 delete_breakpoint (sm
->location_breakpoint
);
11725 sm
->location_breakpoint
= NULL
;
11727 if (sm
->caller_breakpoint
!= NULL
)
11729 delete_breakpoint (sm
->caller_breakpoint
);
11730 sm
->caller_breakpoint
= NULL
;
11732 delete_longjmp_breakpoint (sm
->thread
);
11735 /* Implementation of the 'async_reply_reason' FSM method for the
11736 until(location)/advance commands. */
11738 static enum async_reply_reason
11739 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11741 return EXEC_ASYNC_LOCATION_REACHED
;
11745 until_break_command (char *arg
, int from_tty
, int anywhere
)
11747 struct symtabs_and_lines sals
;
11748 struct symtab_and_line sal
;
11749 struct frame_info
*frame
;
11750 struct gdbarch
*frame_gdbarch
;
11751 struct frame_id stack_frame_id
;
11752 struct frame_id caller_frame_id
;
11753 struct breakpoint
*location_breakpoint
;
11754 struct breakpoint
*caller_breakpoint
= NULL
;
11755 struct cleanup
*old_chain
, *cleanup
;
11757 struct thread_info
*tp
;
11758 struct event_location
*location
;
11759 struct until_break_fsm
*sm
;
11761 clear_proceed_status (0);
11763 /* Set a breakpoint where the user wants it and at return from
11766 location
= string_to_event_location (&arg
, current_language
);
11767 cleanup
= make_cleanup_delete_event_location (location
);
11769 if (last_displayed_sal_is_valid ())
11770 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
11771 get_last_displayed_symtab (),
11772 get_last_displayed_line ());
11774 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11775 NULL
, (struct symtab
*) NULL
, 0);
11777 if (sals
.nelts
!= 1)
11778 error (_("Couldn't get information on specified line."));
11780 sal
= sals
.sals
[0];
11781 xfree (sals
.sals
); /* malloc'd, so freed. */
11784 error (_("Junk at end of arguments."));
11786 resolve_sal_pc (&sal
);
11788 tp
= inferior_thread ();
11789 thread
= tp
->global_num
;
11791 old_chain
= make_cleanup (null_cleanup
, NULL
);
11793 /* Note linespec handling above invalidates the frame chain.
11794 Installing a breakpoint also invalidates the frame chain (as it
11795 may need to switch threads), so do any frame handling before
11798 frame
= get_selected_frame (NULL
);
11799 frame_gdbarch
= get_frame_arch (frame
);
11800 stack_frame_id
= get_stack_frame_id (frame
);
11801 caller_frame_id
= frame_unwind_caller_id (frame
);
11803 /* Keep within the current frame, or in frames called by the current
11806 if (frame_id_p (caller_frame_id
))
11808 struct symtab_and_line sal2
;
11809 struct gdbarch
*caller_gdbarch
;
11811 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11812 sal2
.pc
= frame_unwind_caller_pc (frame
);
11813 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11814 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11818 make_cleanup_delete_breakpoint (caller_breakpoint
);
11820 set_longjmp_breakpoint (tp
, caller_frame_id
);
11821 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11824 /* set_momentary_breakpoint could invalidate FRAME. */
11828 /* If the user told us to continue until a specified location,
11829 we don't specify a frame at which we need to stop. */
11830 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11831 null_frame_id
, bp_until
);
11833 /* Otherwise, specify the selected frame, because we want to stop
11834 only at the very same frame. */
11835 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11836 stack_frame_id
, bp_until
);
11837 make_cleanup_delete_breakpoint (location_breakpoint
);
11839 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11840 location_breakpoint
, caller_breakpoint
);
11841 tp
->thread_fsm
= &sm
->thread_fsm
;
11843 discard_cleanups (old_chain
);
11845 proceed (-1, GDB_SIGNAL_DEFAULT
);
11847 do_cleanups (cleanup
);
11850 /* This function attempts to parse an optional "if <cond>" clause
11851 from the arg string. If one is not found, it returns NULL.
11853 Else, it returns a pointer to the condition string. (It does not
11854 attempt to evaluate the string against a particular block.) And,
11855 it updates arg to point to the first character following the parsed
11856 if clause in the arg string. */
11859 ep_parse_optional_if_clause (char **arg
)
11863 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11866 /* Skip the "if" keyword. */
11869 /* Skip any extra leading whitespace, and record the start of the
11870 condition string. */
11871 *arg
= skip_spaces (*arg
);
11872 cond_string
= *arg
;
11874 /* Assume that the condition occupies the remainder of the arg
11876 (*arg
) += strlen (cond_string
);
11878 return cond_string
;
11881 /* Commands to deal with catching events, such as signals, exceptions,
11882 process start/exit, etc. */
11886 catch_fork_temporary
, catch_vfork_temporary
,
11887 catch_fork_permanent
, catch_vfork_permanent
11892 catch_fork_command_1 (char *arg
, int from_tty
,
11893 struct cmd_list_element
*command
)
11895 struct gdbarch
*gdbarch
= get_current_arch ();
11896 char *cond_string
= NULL
;
11897 catch_fork_kind fork_kind
;
11900 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11901 tempflag
= (fork_kind
== catch_fork_temporary
11902 || fork_kind
== catch_vfork_temporary
);
11906 arg
= skip_spaces (arg
);
11908 /* The allowed syntax is:
11910 catch [v]fork if <cond>
11912 First, check if there's an if clause. */
11913 cond_string
= ep_parse_optional_if_clause (&arg
);
11915 if ((*arg
!= '\0') && !isspace (*arg
))
11916 error (_("Junk at end of arguments."));
11918 /* If this target supports it, create a fork or vfork catchpoint
11919 and enable reporting of such events. */
11922 case catch_fork_temporary
:
11923 case catch_fork_permanent
:
11924 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11925 &catch_fork_breakpoint_ops
);
11927 case catch_vfork_temporary
:
11928 case catch_vfork_permanent
:
11929 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11930 &catch_vfork_breakpoint_ops
);
11933 error (_("unsupported or unknown fork kind; cannot catch it"));
11939 catch_exec_command_1 (char *arg
, int from_tty
,
11940 struct cmd_list_element
*command
)
11942 struct exec_catchpoint
*c
;
11943 struct gdbarch
*gdbarch
= get_current_arch ();
11945 char *cond_string
= NULL
;
11947 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11951 arg
= skip_spaces (arg
);
11953 /* The allowed syntax is:
11955 catch exec if <cond>
11957 First, check if there's an if clause. */
11958 cond_string
= ep_parse_optional_if_clause (&arg
);
11960 if ((*arg
!= '\0') && !isspace (*arg
))
11961 error (_("Junk at end of arguments."));
11963 c
= XNEW (struct exec_catchpoint
);
11964 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11965 &catch_exec_breakpoint_ops
);
11966 c
->exec_pathname
= NULL
;
11968 install_breakpoint (0, &c
->base
, 1);
11972 init_ada_exception_breakpoint (struct breakpoint
*b
,
11973 struct gdbarch
*gdbarch
,
11974 struct symtab_and_line sal
,
11976 const struct breakpoint_ops
*ops
,
11983 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11985 loc_gdbarch
= gdbarch
;
11987 describe_other_breakpoints (loc_gdbarch
,
11988 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11989 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11990 version for exception catchpoints, because two catchpoints
11991 used for different exception names will use the same address.
11992 In this case, a "breakpoint ... also set at..." warning is
11993 unproductive. Besides, the warning phrasing is also a bit
11994 inappropriate, we should use the word catchpoint, and tell
11995 the user what type of catchpoint it is. The above is good
11996 enough for now, though. */
11999 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12001 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12002 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12003 b
->location
= string_to_event_location (&addr_string
,
12004 language_def (language_ada
));
12005 b
->language
= language_ada
;
12009 catch_command (char *arg
, int from_tty
)
12011 error (_("Catch requires an event name."));
12016 tcatch_command (char *arg
, int from_tty
)
12018 error (_("Catch requires an event name."));
12021 /* A qsort comparison function that sorts breakpoints in order. */
12024 compare_breakpoints (const void *a
, const void *b
)
12026 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
12027 uintptr_t ua
= (uintptr_t) *ba
;
12028 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
12029 uintptr_t ub
= (uintptr_t) *bb
;
12031 if ((*ba
)->number
< (*bb
)->number
)
12033 else if ((*ba
)->number
> (*bb
)->number
)
12036 /* Now sort by address, in case we see, e..g, two breakpoints with
12040 return ua
> ub
? 1 : 0;
12043 /* Delete breakpoints by address or line. */
12046 clear_command (char *arg
, int from_tty
)
12048 struct breakpoint
*b
, *prev
;
12049 VEC(breakpoint_p
) *found
= 0;
12052 struct symtabs_and_lines sals
;
12053 struct symtab_and_line sal
;
12055 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12059 sals
= decode_line_with_current_source (arg
,
12060 (DECODE_LINE_FUNFIRSTLINE
12061 | DECODE_LINE_LIST_MODE
));
12062 make_cleanup (xfree
, sals
.sals
);
12067 sals
.sals
= XNEW (struct symtab_and_line
);
12068 make_cleanup (xfree
, sals
.sals
);
12069 init_sal (&sal
); /* Initialize to zeroes. */
12071 /* Set sal's line, symtab, pc, and pspace to the values
12072 corresponding to the last call to print_frame_info. If the
12073 codepoint is not valid, this will set all the fields to 0. */
12074 get_last_displayed_sal (&sal
);
12075 if (sal
.symtab
== 0)
12076 error (_("No source file specified."));
12078 sals
.sals
[0] = sal
;
12084 /* We don't call resolve_sal_pc here. That's not as bad as it
12085 seems, because all existing breakpoints typically have both
12086 file/line and pc set. So, if clear is given file/line, we can
12087 match this to existing breakpoint without obtaining pc at all.
12089 We only support clearing given the address explicitly
12090 present in breakpoint table. Say, we've set breakpoint
12091 at file:line. There were several PC values for that file:line,
12092 due to optimization, all in one block.
12094 We've picked one PC value. If "clear" is issued with another
12095 PC corresponding to the same file:line, the breakpoint won't
12096 be cleared. We probably can still clear the breakpoint, but
12097 since the other PC value is never presented to user, user
12098 can only find it by guessing, and it does not seem important
12099 to support that. */
12101 /* For each line spec given, delete bps which correspond to it. Do
12102 it in two passes, solely to preserve the current behavior that
12103 from_tty is forced true if we delete more than one
12107 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12108 for (i
= 0; i
< sals
.nelts
; i
++)
12110 const char *sal_fullname
;
12112 /* If exact pc given, clear bpts at that pc.
12113 If line given (pc == 0), clear all bpts on specified line.
12114 If defaulting, clear all bpts on default line
12117 defaulting sal.pc != 0 tests to do
12122 1 0 <can't happen> */
12124 sal
= sals
.sals
[i
];
12125 sal_fullname
= (sal
.symtab
== NULL
12126 ? NULL
: symtab_to_fullname (sal
.symtab
));
12128 /* Find all matching breakpoints and add them to 'found'. */
12129 ALL_BREAKPOINTS (b
)
12132 /* Are we going to delete b? */
12133 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12135 struct bp_location
*loc
= b
->loc
;
12136 for (; loc
; loc
= loc
->next
)
12138 /* If the user specified file:line, don't allow a PC
12139 match. This matches historical gdb behavior. */
12140 int pc_match
= (!sal
.explicit_line
12142 && (loc
->pspace
== sal
.pspace
)
12143 && (loc
->address
== sal
.pc
)
12144 && (!section_is_overlay (loc
->section
)
12145 || loc
->section
== sal
.section
));
12146 int line_match
= 0;
12148 if ((default_match
|| sal
.explicit_line
)
12149 && loc
->symtab
!= NULL
12150 && sal_fullname
!= NULL
12151 && sal
.pspace
== loc
->pspace
12152 && loc
->line_number
== sal
.line
12153 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12154 sal_fullname
) == 0)
12157 if (pc_match
|| line_match
)
12166 VEC_safe_push(breakpoint_p
, found
, b
);
12170 /* Now go thru the 'found' chain and delete them. */
12171 if (VEC_empty(breakpoint_p
, found
))
12174 error (_("No breakpoint at %s."), arg
);
12176 error (_("No breakpoint at this line."));
12179 /* Remove duplicates from the vec. */
12180 qsort (VEC_address (breakpoint_p
, found
),
12181 VEC_length (breakpoint_p
, found
),
12182 sizeof (breakpoint_p
),
12183 compare_breakpoints
);
12184 prev
= VEC_index (breakpoint_p
, found
, 0);
12185 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12189 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12194 if (VEC_length(breakpoint_p
, found
) > 1)
12195 from_tty
= 1; /* Always report if deleted more than one. */
12198 if (VEC_length(breakpoint_p
, found
) == 1)
12199 printf_unfiltered (_("Deleted breakpoint "));
12201 printf_unfiltered (_("Deleted breakpoints "));
12204 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12207 printf_unfiltered ("%d ", b
->number
);
12208 delete_breakpoint (b
);
12211 putchar_unfiltered ('\n');
12213 do_cleanups (cleanups
);
12216 /* Delete breakpoint in BS if they are `delete' breakpoints and
12217 all breakpoints that are marked for deletion, whether hit or not.
12218 This is called after any breakpoint is hit, or after errors. */
12221 breakpoint_auto_delete (bpstat bs
)
12223 struct breakpoint
*b
, *b_tmp
;
12225 for (; bs
; bs
= bs
->next
)
12226 if (bs
->breakpoint_at
12227 && bs
->breakpoint_at
->disposition
== disp_del
12229 delete_breakpoint (bs
->breakpoint_at
);
12231 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12233 if (b
->disposition
== disp_del_at_next_stop
)
12234 delete_breakpoint (b
);
12238 /* A comparison function for bp_location AP and BP being interfaced to
12239 qsort. Sort elements primarily by their ADDRESS (no matter what
12240 does breakpoint_address_is_meaningful say for its OWNER),
12241 secondarily by ordering first permanent elements and
12242 terciarily just ensuring the array is sorted stable way despite
12243 qsort being an unstable algorithm. */
12246 bp_location_compare (const void *ap
, const void *bp
)
12248 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12249 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12251 if (a
->address
!= b
->address
)
12252 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12254 /* Sort locations at the same address by their pspace number, keeping
12255 locations of the same inferior (in a multi-inferior environment)
12258 if (a
->pspace
->num
!= b
->pspace
->num
)
12259 return ((a
->pspace
->num
> b
->pspace
->num
)
12260 - (a
->pspace
->num
< b
->pspace
->num
));
12262 /* Sort permanent breakpoints first. */
12263 if (a
->permanent
!= b
->permanent
)
12264 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12266 /* Make the internal GDB representation stable across GDB runs
12267 where A and B memory inside GDB can differ. Breakpoint locations of
12268 the same type at the same address can be sorted in arbitrary order. */
12270 if (a
->owner
->number
!= b
->owner
->number
)
12271 return ((a
->owner
->number
> b
->owner
->number
)
12272 - (a
->owner
->number
< b
->owner
->number
));
12274 return (a
> b
) - (a
< b
);
12277 /* Set bp_location_placed_address_before_address_max and
12278 bp_location_shadow_len_after_address_max according to the current
12279 content of the bp_location array. */
12282 bp_location_target_extensions_update (void)
12284 struct bp_location
*bl
, **blp_tmp
;
12286 bp_location_placed_address_before_address_max
= 0;
12287 bp_location_shadow_len_after_address_max
= 0;
12289 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12291 CORE_ADDR start
, end
, addr
;
12293 if (!bp_location_has_shadow (bl
))
12296 start
= bl
->target_info
.placed_address
;
12297 end
= start
+ bl
->target_info
.shadow_len
;
12299 gdb_assert (bl
->address
>= start
);
12300 addr
= bl
->address
- start
;
12301 if (addr
> bp_location_placed_address_before_address_max
)
12302 bp_location_placed_address_before_address_max
= addr
;
12304 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12306 gdb_assert (bl
->address
< end
);
12307 addr
= end
- bl
->address
;
12308 if (addr
> bp_location_shadow_len_after_address_max
)
12309 bp_location_shadow_len_after_address_max
= addr
;
12313 /* Download tracepoint locations if they haven't been. */
12316 download_tracepoint_locations (void)
12318 struct breakpoint
*b
;
12319 struct cleanup
*old_chain
;
12320 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12322 old_chain
= save_current_space_and_thread ();
12324 ALL_TRACEPOINTS (b
)
12326 struct bp_location
*bl
;
12327 struct tracepoint
*t
;
12328 int bp_location_downloaded
= 0;
12330 if ((b
->type
== bp_fast_tracepoint
12331 ? !may_insert_fast_tracepoints
12332 : !may_insert_tracepoints
))
12335 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12337 if (target_can_download_tracepoint ())
12338 can_download_tracepoint
= TRIBOOL_TRUE
;
12340 can_download_tracepoint
= TRIBOOL_FALSE
;
12343 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12346 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12348 /* In tracepoint, locations are _never_ duplicated, so
12349 should_be_inserted is equivalent to
12350 unduplicated_should_be_inserted. */
12351 if (!should_be_inserted (bl
) || bl
->inserted
)
12354 switch_to_program_space_and_thread (bl
->pspace
);
12356 target_download_tracepoint (bl
);
12359 bp_location_downloaded
= 1;
12361 t
= (struct tracepoint
*) b
;
12362 t
->number_on_target
= b
->number
;
12363 if (bp_location_downloaded
)
12364 observer_notify_breakpoint_modified (b
);
12367 do_cleanups (old_chain
);
12370 /* Swap the insertion/duplication state between two locations. */
12373 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12375 const int left_inserted
= left
->inserted
;
12376 const int left_duplicate
= left
->duplicate
;
12377 const int left_needs_update
= left
->needs_update
;
12378 const struct bp_target_info left_target_info
= left
->target_info
;
12380 /* Locations of tracepoints can never be duplicated. */
12381 if (is_tracepoint (left
->owner
))
12382 gdb_assert (!left
->duplicate
);
12383 if (is_tracepoint (right
->owner
))
12384 gdb_assert (!right
->duplicate
);
12386 left
->inserted
= right
->inserted
;
12387 left
->duplicate
= right
->duplicate
;
12388 left
->needs_update
= right
->needs_update
;
12389 left
->target_info
= right
->target_info
;
12390 right
->inserted
= left_inserted
;
12391 right
->duplicate
= left_duplicate
;
12392 right
->needs_update
= left_needs_update
;
12393 right
->target_info
= left_target_info
;
12396 /* Force the re-insertion of the locations at ADDRESS. This is called
12397 once a new/deleted/modified duplicate location is found and we are evaluating
12398 conditions on the target's side. Such conditions need to be updated on
12402 force_breakpoint_reinsertion (struct bp_location
*bl
)
12404 struct bp_location
**locp
= NULL
, **loc2p
;
12405 struct bp_location
*loc
;
12406 CORE_ADDR address
= 0;
12409 address
= bl
->address
;
12410 pspace_num
= bl
->pspace
->num
;
12412 /* This is only meaningful if the target is
12413 evaluating conditions and if the user has
12414 opted for condition evaluation on the target's
12416 if (gdb_evaluates_breakpoint_condition_p ()
12417 || !target_supports_evaluation_of_breakpoint_conditions ())
12420 /* Flag all breakpoint locations with this address and
12421 the same program space as the location
12422 as "its condition has changed". We need to
12423 update the conditions on the target's side. */
12424 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12428 if (!is_breakpoint (loc
->owner
)
12429 || pspace_num
!= loc
->pspace
->num
)
12432 /* Flag the location appropriately. We use a different state to
12433 let everyone know that we already updated the set of locations
12434 with addr bl->address and program space bl->pspace. This is so
12435 we don't have to keep calling these functions just to mark locations
12436 that have already been marked. */
12437 loc
->condition_changed
= condition_updated
;
12439 /* Free the agent expression bytecode as well. We will compute
12441 if (loc
->cond_bytecode
)
12443 free_agent_expr (loc
->cond_bytecode
);
12444 loc
->cond_bytecode
= NULL
;
12448 /* Called whether new breakpoints are created, or existing breakpoints
12449 deleted, to update the global location list and recompute which
12450 locations are duplicate of which.
12452 The INSERT_MODE flag determines whether locations may not, may, or
12453 shall be inserted now. See 'enum ugll_insert_mode' for more
12457 update_global_location_list (enum ugll_insert_mode insert_mode
)
12459 struct breakpoint
*b
;
12460 struct bp_location
**locp
, *loc
;
12461 struct cleanup
*cleanups
;
12462 /* Last breakpoint location address that was marked for update. */
12463 CORE_ADDR last_addr
= 0;
12464 /* Last breakpoint location program space that was marked for update. */
12465 int last_pspace_num
= -1;
12467 /* Used in the duplicates detection below. When iterating over all
12468 bp_locations, points to the first bp_location of a given address.
12469 Breakpoints and watchpoints of different types are never
12470 duplicates of each other. Keep one pointer for each type of
12471 breakpoint/watchpoint, so we only need to loop over all locations
12473 struct bp_location
*bp_loc_first
; /* breakpoint */
12474 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12475 struct bp_location
*awp_loc_first
; /* access watchpoint */
12476 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12478 /* Saved former bp_location array which we compare against the newly
12479 built bp_location from the current state of ALL_BREAKPOINTS. */
12480 struct bp_location
**old_location
, **old_locp
;
12481 unsigned old_location_count
;
12483 old_location
= bp_location
;
12484 old_location_count
= bp_location_count
;
12485 bp_location
= NULL
;
12486 bp_location_count
= 0;
12487 cleanups
= make_cleanup (xfree
, old_location
);
12489 ALL_BREAKPOINTS (b
)
12490 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12491 bp_location_count
++;
12493 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12494 locp
= bp_location
;
12495 ALL_BREAKPOINTS (b
)
12496 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12498 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12499 bp_location_compare
);
12501 bp_location_target_extensions_update ();
12503 /* Identify bp_location instances that are no longer present in the
12504 new list, and therefore should be freed. Note that it's not
12505 necessary that those locations should be removed from inferior --
12506 if there's another location at the same address (previously
12507 marked as duplicate), we don't need to remove/insert the
12510 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12511 and former bp_location array state respectively. */
12513 locp
= bp_location
;
12514 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12517 struct bp_location
*old_loc
= *old_locp
;
12518 struct bp_location
**loc2p
;
12520 /* Tells if 'old_loc' is found among the new locations. If
12521 not, we have to free it. */
12522 int found_object
= 0;
12523 /* Tells if the location should remain inserted in the target. */
12524 int keep_in_target
= 0;
12527 /* Skip LOCP entries which will definitely never be needed.
12528 Stop either at or being the one matching OLD_LOC. */
12529 while (locp
< bp_location
+ bp_location_count
12530 && (*locp
)->address
< old_loc
->address
)
12534 (loc2p
< bp_location
+ bp_location_count
12535 && (*loc2p
)->address
== old_loc
->address
);
12538 /* Check if this is a new/duplicated location or a duplicated
12539 location that had its condition modified. If so, we want to send
12540 its condition to the target if evaluation of conditions is taking
12542 if ((*loc2p
)->condition_changed
== condition_modified
12543 && (last_addr
!= old_loc
->address
12544 || last_pspace_num
!= old_loc
->pspace
->num
))
12546 force_breakpoint_reinsertion (*loc2p
);
12547 last_pspace_num
= old_loc
->pspace
->num
;
12550 if (*loc2p
== old_loc
)
12554 /* We have already handled this address, update it so that we don't
12555 have to go through updates again. */
12556 last_addr
= old_loc
->address
;
12558 /* Target-side condition evaluation: Handle deleted locations. */
12560 force_breakpoint_reinsertion (old_loc
);
12562 /* If this location is no longer present, and inserted, look if
12563 there's maybe a new location at the same address. If so,
12564 mark that one inserted, and don't remove this one. This is
12565 needed so that we don't have a time window where a breakpoint
12566 at certain location is not inserted. */
12568 if (old_loc
->inserted
)
12570 /* If the location is inserted now, we might have to remove
12573 if (found_object
&& should_be_inserted (old_loc
))
12575 /* The location is still present in the location list,
12576 and still should be inserted. Don't do anything. */
12577 keep_in_target
= 1;
12581 /* This location still exists, but it won't be kept in the
12582 target since it may have been disabled. We proceed to
12583 remove its target-side condition. */
12585 /* The location is either no longer present, or got
12586 disabled. See if there's another location at the
12587 same address, in which case we don't need to remove
12588 this one from the target. */
12590 /* OLD_LOC comes from existing struct breakpoint. */
12591 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12594 (loc2p
< bp_location
+ bp_location_count
12595 && (*loc2p
)->address
== old_loc
->address
);
12598 struct bp_location
*loc2
= *loc2p
;
12600 if (breakpoint_locations_match (loc2
, old_loc
))
12602 /* Read watchpoint locations are switched to
12603 access watchpoints, if the former are not
12604 supported, but the latter are. */
12605 if (is_hardware_watchpoint (old_loc
->owner
))
12607 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12608 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12611 /* loc2 is a duplicated location. We need to check
12612 if it should be inserted in case it will be
12614 if (loc2
!= old_loc
12615 && unduplicated_should_be_inserted (loc2
))
12617 swap_insertion (old_loc
, loc2
);
12618 keep_in_target
= 1;
12626 if (!keep_in_target
)
12628 if (remove_breakpoint (old_loc
))
12630 /* This is just about all we can do. We could keep
12631 this location on the global list, and try to
12632 remove it next time, but there's no particular
12633 reason why we will succeed next time.
12635 Note that at this point, old_loc->owner is still
12636 valid, as delete_breakpoint frees the breakpoint
12637 only after calling us. */
12638 printf_filtered (_("warning: Error removing "
12639 "breakpoint %d\n"),
12640 old_loc
->owner
->number
);
12648 if (removed
&& target_is_non_stop_p ()
12649 && need_moribund_for_location_type (old_loc
))
12651 /* This location was removed from the target. In
12652 non-stop mode, a race condition is possible where
12653 we've removed a breakpoint, but stop events for that
12654 breakpoint are already queued and will arrive later.
12655 We apply an heuristic to be able to distinguish such
12656 SIGTRAPs from other random SIGTRAPs: we keep this
12657 breakpoint location for a bit, and will retire it
12658 after we see some number of events. The theory here
12659 is that reporting of events should, "on the average",
12660 be fair, so after a while we'll see events from all
12661 threads that have anything of interest, and no longer
12662 need to keep this breakpoint location around. We
12663 don't hold locations forever so to reduce chances of
12664 mistaking a non-breakpoint SIGTRAP for a breakpoint
12667 The heuristic failing can be disastrous on
12668 decr_pc_after_break targets.
12670 On decr_pc_after_break targets, like e.g., x86-linux,
12671 if we fail to recognize a late breakpoint SIGTRAP,
12672 because events_till_retirement has reached 0 too
12673 soon, we'll fail to do the PC adjustment, and report
12674 a random SIGTRAP to the user. When the user resumes
12675 the inferior, it will most likely immediately crash
12676 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12677 corrupted, because of being resumed e.g., in the
12678 middle of a multi-byte instruction, or skipped a
12679 one-byte instruction. This was actually seen happen
12680 on native x86-linux, and should be less rare on
12681 targets that do not support new thread events, like
12682 remote, due to the heuristic depending on
12685 Mistaking a random SIGTRAP for a breakpoint trap
12686 causes similar symptoms (PC adjustment applied when
12687 it shouldn't), but then again, playing with SIGTRAPs
12688 behind the debugger's back is asking for trouble.
12690 Since hardware watchpoint traps are always
12691 distinguishable from other traps, so we don't need to
12692 apply keep hardware watchpoint moribund locations
12693 around. We simply always ignore hardware watchpoint
12694 traps we can no longer explain. */
12696 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12697 old_loc
->owner
= NULL
;
12699 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12703 old_loc
->owner
= NULL
;
12704 decref_bp_location (&old_loc
);
12709 /* Rescan breakpoints at the same address and section, marking the
12710 first one as "first" and any others as "duplicates". This is so
12711 that the bpt instruction is only inserted once. If we have a
12712 permanent breakpoint at the same place as BPT, make that one the
12713 official one, and the rest as duplicates. Permanent breakpoints
12714 are sorted first for the same address.
12716 Do the same for hardware watchpoints, but also considering the
12717 watchpoint's type (regular/access/read) and length. */
12719 bp_loc_first
= NULL
;
12720 wp_loc_first
= NULL
;
12721 awp_loc_first
= NULL
;
12722 rwp_loc_first
= NULL
;
12723 ALL_BP_LOCATIONS (loc
, locp
)
12725 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12727 struct bp_location
**loc_first_p
;
12730 if (!unduplicated_should_be_inserted (loc
)
12731 || !breakpoint_address_is_meaningful (b
)
12732 /* Don't detect duplicate for tracepoint locations because they are
12733 never duplicated. See the comments in field `duplicate' of
12734 `struct bp_location'. */
12735 || is_tracepoint (b
))
12737 /* Clear the condition modification flag. */
12738 loc
->condition_changed
= condition_unchanged
;
12742 if (b
->type
== bp_hardware_watchpoint
)
12743 loc_first_p
= &wp_loc_first
;
12744 else if (b
->type
== bp_read_watchpoint
)
12745 loc_first_p
= &rwp_loc_first
;
12746 else if (b
->type
== bp_access_watchpoint
)
12747 loc_first_p
= &awp_loc_first
;
12749 loc_first_p
= &bp_loc_first
;
12751 if (*loc_first_p
== NULL
12752 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12753 || !breakpoint_locations_match (loc
, *loc_first_p
))
12755 *loc_first_p
= loc
;
12756 loc
->duplicate
= 0;
12758 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12760 loc
->needs_update
= 1;
12761 /* Clear the condition modification flag. */
12762 loc
->condition_changed
= condition_unchanged
;
12768 /* This and the above ensure the invariant that the first location
12769 is not duplicated, and is the inserted one.
12770 All following are marked as duplicated, and are not inserted. */
12772 swap_insertion (loc
, *loc_first_p
);
12773 loc
->duplicate
= 1;
12775 /* Clear the condition modification flag. */
12776 loc
->condition_changed
= condition_unchanged
;
12779 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12781 if (insert_mode
!= UGLL_DONT_INSERT
)
12782 insert_breakpoint_locations ();
12785 /* Even though the caller told us to not insert new
12786 locations, we may still need to update conditions on the
12787 target's side of breakpoints that were already inserted
12788 if the target is evaluating breakpoint conditions. We
12789 only update conditions for locations that are marked
12791 update_inserted_breakpoint_locations ();
12795 if (insert_mode
!= UGLL_DONT_INSERT
)
12796 download_tracepoint_locations ();
12798 do_cleanups (cleanups
);
12802 breakpoint_retire_moribund (void)
12804 struct bp_location
*loc
;
12807 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12808 if (--(loc
->events_till_retirement
) == 0)
12810 decref_bp_location (&loc
);
12811 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12817 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12822 update_global_location_list (insert_mode
);
12824 CATCH (e
, RETURN_MASK_ERROR
)
12830 /* Clear BKP from a BPS. */
12833 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12837 for (bs
= bps
; bs
; bs
= bs
->next
)
12838 if (bs
->breakpoint_at
== bpt
)
12840 bs
->breakpoint_at
= NULL
;
12841 bs
->old_val
= NULL
;
12842 /* bs->commands will be freed later. */
12846 /* Callback for iterate_over_threads. */
12848 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12850 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12852 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12856 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12860 say_where (struct breakpoint
*b
)
12862 struct value_print_options opts
;
12864 get_user_print_options (&opts
);
12866 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12868 if (b
->loc
== NULL
)
12870 /* For pending locations, the output differs slightly based
12871 on b->extra_string. If this is non-NULL, it contains either
12872 a condition or dprintf arguments. */
12873 if (b
->extra_string
== NULL
)
12875 printf_filtered (_(" (%s) pending."),
12876 event_location_to_string (b
->location
));
12878 else if (b
->type
== bp_dprintf
)
12880 printf_filtered (_(" (%s,%s) pending."),
12881 event_location_to_string (b
->location
),
12886 printf_filtered (_(" (%s %s) pending."),
12887 event_location_to_string (b
->location
),
12893 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12895 printf_filtered (" at ");
12896 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12899 if (b
->loc
->symtab
!= NULL
)
12901 /* If there is a single location, we can print the location
12903 if (b
->loc
->next
== NULL
)
12904 printf_filtered (": file %s, line %d.",
12905 symtab_to_filename_for_display (b
->loc
->symtab
),
12906 b
->loc
->line_number
);
12908 /* This is not ideal, but each location may have a
12909 different file name, and this at least reflects the
12910 real situation somewhat. */
12911 printf_filtered (": %s.",
12912 event_location_to_string (b
->location
));
12917 struct bp_location
*loc
= b
->loc
;
12919 for (; loc
; loc
= loc
->next
)
12921 printf_filtered (" (%d locations)", n
);
12926 /* Default bp_location_ops methods. */
12929 bp_location_dtor (struct bp_location
*self
)
12931 xfree (self
->cond
);
12932 if (self
->cond_bytecode
)
12933 free_agent_expr (self
->cond_bytecode
);
12934 xfree (self
->function_name
);
12936 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12937 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12940 static const struct bp_location_ops bp_location_ops
=
12945 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12949 base_breakpoint_dtor (struct breakpoint
*self
)
12951 decref_counted_command_line (&self
->commands
);
12952 xfree (self
->cond_string
);
12953 xfree (self
->extra_string
);
12954 xfree (self
->filter
);
12955 delete_event_location (self
->location
);
12956 delete_event_location (self
->location_range_end
);
12959 static struct bp_location
*
12960 base_breakpoint_allocate_location (struct breakpoint
*self
)
12962 struct bp_location
*loc
;
12964 loc
= XNEW (struct bp_location
);
12965 init_bp_location (loc
, &bp_location_ops
, self
);
12970 base_breakpoint_re_set (struct breakpoint
*b
)
12972 /* Nothing to re-set. */
12975 #define internal_error_pure_virtual_called() \
12976 gdb_assert_not_reached ("pure virtual function called")
12979 base_breakpoint_insert_location (struct bp_location
*bl
)
12981 internal_error_pure_virtual_called ();
12985 base_breakpoint_remove_location (struct bp_location
*bl
,
12986 enum remove_bp_reason reason
)
12988 internal_error_pure_virtual_called ();
12992 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12993 struct address_space
*aspace
,
12995 const struct target_waitstatus
*ws
)
12997 internal_error_pure_virtual_called ();
13001 base_breakpoint_check_status (bpstat bs
)
13006 /* A "works_in_software_mode" breakpoint_ops method that just internal
13010 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13012 internal_error_pure_virtual_called ();
13015 /* A "resources_needed" breakpoint_ops method that just internal
13019 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13021 internal_error_pure_virtual_called ();
13024 static enum print_stop_action
13025 base_breakpoint_print_it (bpstat bs
)
13027 internal_error_pure_virtual_called ();
13031 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13032 struct ui_out
*uiout
)
13038 base_breakpoint_print_mention (struct breakpoint
*b
)
13040 internal_error_pure_virtual_called ();
13044 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13046 internal_error_pure_virtual_called ();
13050 base_breakpoint_create_sals_from_location
13051 (const struct event_location
*location
,
13052 struct linespec_result
*canonical
,
13053 enum bptype type_wanted
)
13055 internal_error_pure_virtual_called ();
13059 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13060 struct linespec_result
*c
,
13062 char *extra_string
,
13063 enum bptype type_wanted
,
13064 enum bpdisp disposition
,
13066 int task
, int ignore_count
,
13067 const struct breakpoint_ops
*o
,
13068 int from_tty
, int enabled
,
13069 int internal
, unsigned flags
)
13071 internal_error_pure_virtual_called ();
13075 base_breakpoint_decode_location (struct breakpoint
*b
,
13076 const struct event_location
*location
,
13077 struct program_space
*search_pspace
,
13078 struct symtabs_and_lines
*sals
)
13080 internal_error_pure_virtual_called ();
13083 /* The default 'explains_signal' method. */
13086 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13091 /* The default "after_condition_true" method. */
13094 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13096 /* Nothing to do. */
13099 struct breakpoint_ops base_breakpoint_ops
=
13101 base_breakpoint_dtor
,
13102 base_breakpoint_allocate_location
,
13103 base_breakpoint_re_set
,
13104 base_breakpoint_insert_location
,
13105 base_breakpoint_remove_location
,
13106 base_breakpoint_breakpoint_hit
,
13107 base_breakpoint_check_status
,
13108 base_breakpoint_resources_needed
,
13109 base_breakpoint_works_in_software_mode
,
13110 base_breakpoint_print_it
,
13112 base_breakpoint_print_one_detail
,
13113 base_breakpoint_print_mention
,
13114 base_breakpoint_print_recreate
,
13115 base_breakpoint_create_sals_from_location
,
13116 base_breakpoint_create_breakpoints_sal
,
13117 base_breakpoint_decode_location
,
13118 base_breakpoint_explains_signal
,
13119 base_breakpoint_after_condition_true
,
13122 /* Default breakpoint_ops methods. */
13125 bkpt_re_set (struct breakpoint
*b
)
13127 /* FIXME: is this still reachable? */
13128 if (breakpoint_event_location_empty_p (b
))
13130 /* Anything without a location can't be re-set. */
13131 delete_breakpoint (b
);
13135 breakpoint_re_set_default (b
);
13139 bkpt_insert_location (struct bp_location
*bl
)
13141 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
13143 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
13144 bl
->target_info
.placed_address
= addr
;
13146 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13147 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13149 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13153 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13155 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13156 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13158 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13162 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13163 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13164 const struct target_waitstatus
*ws
)
13166 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13167 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13170 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13174 if (overlay_debugging
/* unmapped overlay section */
13175 && section_is_overlay (bl
->section
)
13176 && !section_is_mapped (bl
->section
))
13183 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13184 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13185 const struct target_waitstatus
*ws
)
13187 if (dprintf_style
== dprintf_style_agent
13188 && target_can_run_breakpoint_commands ())
13190 /* An agent-style dprintf never causes a stop. If we see a trap
13191 for this address it must be for a breakpoint that happens to
13192 be set at the same address. */
13196 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13200 bkpt_resources_needed (const struct bp_location
*bl
)
13202 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13207 static enum print_stop_action
13208 bkpt_print_it (bpstat bs
)
13210 struct breakpoint
*b
;
13211 const struct bp_location
*bl
;
13213 struct ui_out
*uiout
= current_uiout
;
13215 gdb_assert (bs
->bp_location_at
!= NULL
);
13217 bl
= bs
->bp_location_at
;
13218 b
= bs
->breakpoint_at
;
13220 bp_temp
= b
->disposition
== disp_del
;
13221 if (bl
->address
!= bl
->requested_address
)
13222 breakpoint_adjustment_warning (bl
->requested_address
,
13225 annotate_breakpoint (b
->number
);
13226 maybe_print_thread_hit_breakpoint (uiout
);
13229 ui_out_text (uiout
, "Temporary breakpoint ");
13231 ui_out_text (uiout
, "Breakpoint ");
13232 if (ui_out_is_mi_like_p (uiout
))
13234 ui_out_field_string (uiout
, "reason",
13235 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13236 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13238 ui_out_field_int (uiout
, "bkptno", b
->number
);
13239 ui_out_text (uiout
, ", ");
13241 return PRINT_SRC_AND_LOC
;
13245 bkpt_print_mention (struct breakpoint
*b
)
13247 if (ui_out_is_mi_like_p (current_uiout
))
13252 case bp_breakpoint
:
13253 case bp_gnu_ifunc_resolver
:
13254 if (b
->disposition
== disp_del
)
13255 printf_filtered (_("Temporary breakpoint"));
13257 printf_filtered (_("Breakpoint"));
13258 printf_filtered (_(" %d"), b
->number
);
13259 if (b
->type
== bp_gnu_ifunc_resolver
)
13260 printf_filtered (_(" at gnu-indirect-function resolver"));
13262 case bp_hardware_breakpoint
:
13263 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13266 printf_filtered (_("Dprintf %d"), b
->number
);
13274 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13276 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13277 fprintf_unfiltered (fp
, "tbreak");
13278 else if (tp
->type
== bp_breakpoint
)
13279 fprintf_unfiltered (fp
, "break");
13280 else if (tp
->type
== bp_hardware_breakpoint
13281 && tp
->disposition
== disp_del
)
13282 fprintf_unfiltered (fp
, "thbreak");
13283 else if (tp
->type
== bp_hardware_breakpoint
)
13284 fprintf_unfiltered (fp
, "hbreak");
13286 internal_error (__FILE__
, __LINE__
,
13287 _("unhandled breakpoint type %d"), (int) tp
->type
);
13289 fprintf_unfiltered (fp
, " %s",
13290 event_location_to_string (tp
->location
));
13292 /* Print out extra_string if this breakpoint is pending. It might
13293 contain, for example, conditions that were set by the user. */
13294 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13295 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13297 print_recreate_thread (tp
, fp
);
13301 bkpt_create_sals_from_location (const struct event_location
*location
,
13302 struct linespec_result
*canonical
,
13303 enum bptype type_wanted
)
13305 create_sals_from_location_default (location
, canonical
, type_wanted
);
13309 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13310 struct linespec_result
*canonical
,
13312 char *extra_string
,
13313 enum bptype type_wanted
,
13314 enum bpdisp disposition
,
13316 int task
, int ignore_count
,
13317 const struct breakpoint_ops
*ops
,
13318 int from_tty
, int enabled
,
13319 int internal
, unsigned flags
)
13321 create_breakpoints_sal_default (gdbarch
, canonical
,
13322 cond_string
, extra_string
,
13324 disposition
, thread
, task
,
13325 ignore_count
, ops
, from_tty
,
13326 enabled
, internal
, flags
);
13330 bkpt_decode_location (struct breakpoint
*b
,
13331 const struct event_location
*location
,
13332 struct program_space
*search_pspace
,
13333 struct symtabs_and_lines
*sals
)
13335 decode_location_default (b
, location
, search_pspace
, sals
);
13338 /* Virtual table for internal breakpoints. */
13341 internal_bkpt_re_set (struct breakpoint
*b
)
13345 /* Delete overlay event and longjmp master breakpoints; they
13346 will be reset later by breakpoint_re_set. */
13347 case bp_overlay_event
:
13348 case bp_longjmp_master
:
13349 case bp_std_terminate_master
:
13350 case bp_exception_master
:
13351 delete_breakpoint (b
);
13354 /* This breakpoint is special, it's set up when the inferior
13355 starts and we really don't want to touch it. */
13356 case bp_shlib_event
:
13358 /* Like bp_shlib_event, this breakpoint type is special. Once
13359 it is set up, we do not want to touch it. */
13360 case bp_thread_event
:
13366 internal_bkpt_check_status (bpstat bs
)
13368 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13370 /* If requested, stop when the dynamic linker notifies GDB of
13371 events. This allows the user to get control and place
13372 breakpoints in initializer routines for dynamically loaded
13373 objects (among other things). */
13374 bs
->stop
= stop_on_solib_events
;
13375 bs
->print
= stop_on_solib_events
;
13381 static enum print_stop_action
13382 internal_bkpt_print_it (bpstat bs
)
13384 struct breakpoint
*b
;
13386 b
= bs
->breakpoint_at
;
13390 case bp_shlib_event
:
13391 /* Did we stop because the user set the stop_on_solib_events
13392 variable? (If so, we report this as a generic, "Stopped due
13393 to shlib event" message.) */
13394 print_solib_event (0);
13397 case bp_thread_event
:
13398 /* Not sure how we will get here.
13399 GDB should not stop for these breakpoints. */
13400 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13403 case bp_overlay_event
:
13404 /* By analogy with the thread event, GDB should not stop for these. */
13405 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13408 case bp_longjmp_master
:
13409 /* These should never be enabled. */
13410 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13413 case bp_std_terminate_master
:
13414 /* These should never be enabled. */
13415 printf_filtered (_("std::terminate Master Breakpoint: "
13416 "gdb should not stop!\n"));
13419 case bp_exception_master
:
13420 /* These should never be enabled. */
13421 printf_filtered (_("Exception Master Breakpoint: "
13422 "gdb should not stop!\n"));
13426 return PRINT_NOTHING
;
13430 internal_bkpt_print_mention (struct breakpoint
*b
)
13432 /* Nothing to mention. These breakpoints are internal. */
13435 /* Virtual table for momentary breakpoints */
13438 momentary_bkpt_re_set (struct breakpoint
*b
)
13440 /* Keep temporary breakpoints, which can be encountered when we step
13441 over a dlopen call and solib_add is resetting the breakpoints.
13442 Otherwise these should have been blown away via the cleanup chain
13443 or by breakpoint_init_inferior when we rerun the executable. */
13447 momentary_bkpt_check_status (bpstat bs
)
13449 /* Nothing. The point of these breakpoints is causing a stop. */
13452 static enum print_stop_action
13453 momentary_bkpt_print_it (bpstat bs
)
13455 return PRINT_UNKNOWN
;
13459 momentary_bkpt_print_mention (struct breakpoint
*b
)
13461 /* Nothing to mention. These breakpoints are internal. */
13464 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13466 It gets cleared already on the removal of the first one of such placed
13467 breakpoints. This is OK as they get all removed altogether. */
13470 longjmp_bkpt_dtor (struct breakpoint
*self
)
13472 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13475 tp
->initiating_frame
= null_frame_id
;
13477 momentary_breakpoint_ops
.dtor (self
);
13480 /* Specific methods for probe breakpoints. */
13483 bkpt_probe_insert_location (struct bp_location
*bl
)
13485 int v
= bkpt_insert_location (bl
);
13489 /* The insertion was successful, now let's set the probe's semaphore
13491 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13492 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13501 bkpt_probe_remove_location (struct bp_location
*bl
,
13502 enum remove_bp_reason reason
)
13504 /* Let's clear the semaphore before removing the location. */
13505 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13506 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13510 return bkpt_remove_location (bl
, reason
);
13514 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13515 struct linespec_result
*canonical
,
13516 enum bptype type_wanted
)
13518 struct linespec_sals lsal
;
13520 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13521 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13522 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13526 bkpt_probe_decode_location (struct breakpoint
*b
,
13527 const struct event_location
*location
,
13528 struct program_space
*search_pspace
,
13529 struct symtabs_and_lines
*sals
)
13531 *sals
= parse_probes (location
, search_pspace
, NULL
);
13533 error (_("probe not found"));
13536 /* The breakpoint_ops structure to be used in tracepoints. */
13539 tracepoint_re_set (struct breakpoint
*b
)
13541 breakpoint_re_set_default (b
);
13545 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13546 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13547 const struct target_waitstatus
*ws
)
13549 /* By definition, the inferior does not report stops at
13555 tracepoint_print_one_detail (const struct breakpoint
*self
,
13556 struct ui_out
*uiout
)
13558 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13559 if (tp
->static_trace_marker_id
)
13561 gdb_assert (self
->type
== bp_static_tracepoint
);
13563 ui_out_text (uiout
, "\tmarker id is ");
13564 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13565 tp
->static_trace_marker_id
);
13566 ui_out_text (uiout
, "\n");
13571 tracepoint_print_mention (struct breakpoint
*b
)
13573 if (ui_out_is_mi_like_p (current_uiout
))
13578 case bp_tracepoint
:
13579 printf_filtered (_("Tracepoint"));
13580 printf_filtered (_(" %d"), b
->number
);
13582 case bp_fast_tracepoint
:
13583 printf_filtered (_("Fast tracepoint"));
13584 printf_filtered (_(" %d"), b
->number
);
13586 case bp_static_tracepoint
:
13587 printf_filtered (_("Static tracepoint"));
13588 printf_filtered (_(" %d"), b
->number
);
13591 internal_error (__FILE__
, __LINE__
,
13592 _("unhandled tracepoint type %d"), (int) b
->type
);
13599 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13601 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13603 if (self
->type
== bp_fast_tracepoint
)
13604 fprintf_unfiltered (fp
, "ftrace");
13605 else if (self
->type
== bp_static_tracepoint
)
13606 fprintf_unfiltered (fp
, "strace");
13607 else if (self
->type
== bp_tracepoint
)
13608 fprintf_unfiltered (fp
, "trace");
13610 internal_error (__FILE__
, __LINE__
,
13611 _("unhandled tracepoint type %d"), (int) self
->type
);
13613 fprintf_unfiltered (fp
, " %s",
13614 event_location_to_string (self
->location
));
13615 print_recreate_thread (self
, fp
);
13617 if (tp
->pass_count
)
13618 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13622 tracepoint_create_sals_from_location (const struct event_location
*location
,
13623 struct linespec_result
*canonical
,
13624 enum bptype type_wanted
)
13626 create_sals_from_location_default (location
, canonical
, type_wanted
);
13630 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13631 struct linespec_result
*canonical
,
13633 char *extra_string
,
13634 enum bptype type_wanted
,
13635 enum bpdisp disposition
,
13637 int task
, int ignore_count
,
13638 const struct breakpoint_ops
*ops
,
13639 int from_tty
, int enabled
,
13640 int internal
, unsigned flags
)
13642 create_breakpoints_sal_default (gdbarch
, canonical
,
13643 cond_string
, extra_string
,
13645 disposition
, thread
, task
,
13646 ignore_count
, ops
, from_tty
,
13647 enabled
, internal
, flags
);
13651 tracepoint_decode_location (struct breakpoint
*b
,
13652 const struct event_location
*location
,
13653 struct program_space
*search_pspace
,
13654 struct symtabs_and_lines
*sals
)
13656 decode_location_default (b
, location
, search_pspace
, sals
);
13659 struct breakpoint_ops tracepoint_breakpoint_ops
;
13661 /* The breakpoint_ops structure to be use on tracepoints placed in a
13665 tracepoint_probe_create_sals_from_location
13666 (const struct event_location
*location
,
13667 struct linespec_result
*canonical
,
13668 enum bptype type_wanted
)
13670 /* We use the same method for breakpoint on probes. */
13671 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13675 tracepoint_probe_decode_location (struct breakpoint
*b
,
13676 const struct event_location
*location
,
13677 struct program_space
*search_pspace
,
13678 struct symtabs_and_lines
*sals
)
13680 /* We use the same method for breakpoint on probes. */
13681 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13684 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13686 /* Dprintf breakpoint_ops methods. */
13689 dprintf_re_set (struct breakpoint
*b
)
13691 breakpoint_re_set_default (b
);
13693 /* extra_string should never be non-NULL for dprintf. */
13694 gdb_assert (b
->extra_string
!= NULL
);
13696 /* 1 - connect to target 1, that can run breakpoint commands.
13697 2 - create a dprintf, which resolves fine.
13698 3 - disconnect from target 1
13699 4 - connect to target 2, that can NOT run breakpoint commands.
13701 After steps #3/#4, you'll want the dprintf command list to
13702 be updated, because target 1 and 2 may well return different
13703 answers for target_can_run_breakpoint_commands().
13704 Given absence of finer grained resetting, we get to do
13705 it all the time. */
13706 if (b
->extra_string
!= NULL
)
13707 update_dprintf_command_list (b
);
13710 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13713 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13715 fprintf_unfiltered (fp
, "dprintf %s,%s",
13716 event_location_to_string (tp
->location
),
13718 print_recreate_thread (tp
, fp
);
13721 /* Implement the "after_condition_true" breakpoint_ops method for
13724 dprintf's are implemented with regular commands in their command
13725 list, but we run the commands here instead of before presenting the
13726 stop to the user, as dprintf's don't actually cause a stop. This
13727 also makes it so that the commands of multiple dprintfs at the same
13728 address are all handled. */
13731 dprintf_after_condition_true (struct bpstats
*bs
)
13733 struct cleanup
*old_chain
;
13734 struct bpstats tmp_bs
= { NULL
};
13735 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13737 /* dprintf's never cause a stop. This wasn't set in the
13738 check_status hook instead because that would make the dprintf's
13739 condition not be evaluated. */
13742 /* Run the command list here. Take ownership of it instead of
13743 copying. We never want these commands to run later in
13744 bpstat_do_actions, if a breakpoint that causes a stop happens to
13745 be set at same address as this dprintf, or even if running the
13746 commands here throws. */
13747 tmp_bs
.commands
= bs
->commands
;
13748 bs
->commands
= NULL
;
13749 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13751 bpstat_do_actions_1 (&tmp_bs_p
);
13753 /* 'tmp_bs.commands' will usually be NULL by now, but
13754 bpstat_do_actions_1 may return early without processing the whole
13756 do_cleanups (old_chain
);
13759 /* The breakpoint_ops structure to be used on static tracepoints with
13763 strace_marker_create_sals_from_location (const struct event_location
*location
,
13764 struct linespec_result
*canonical
,
13765 enum bptype type_wanted
)
13767 struct linespec_sals lsal
;
13768 const char *arg_start
, *arg
;
13770 struct cleanup
*cleanup
;
13772 arg
= arg_start
= get_linespec_location (location
);
13773 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13775 str
= savestring (arg_start
, arg
- arg_start
);
13776 cleanup
= make_cleanup (xfree
, str
);
13777 canonical
->location
= new_linespec_location (&str
);
13778 do_cleanups (cleanup
);
13780 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13781 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13785 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13786 struct linespec_result
*canonical
,
13788 char *extra_string
,
13789 enum bptype type_wanted
,
13790 enum bpdisp disposition
,
13792 int task
, int ignore_count
,
13793 const struct breakpoint_ops
*ops
,
13794 int from_tty
, int enabled
,
13795 int internal
, unsigned flags
)
13798 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13799 canonical
->sals
, 0);
13801 /* If the user is creating a static tracepoint by marker id
13802 (strace -m MARKER_ID), then store the sals index, so that
13803 breakpoint_re_set can try to match up which of the newly
13804 found markers corresponds to this one, and, don't try to
13805 expand multiple locations for each sal, given than SALS
13806 already should contain all sals for MARKER_ID. */
13808 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13810 struct symtabs_and_lines expanded
;
13811 struct tracepoint
*tp
;
13812 struct cleanup
*old_chain
;
13813 struct event_location
*location
;
13815 expanded
.nelts
= 1;
13816 expanded
.sals
= &lsal
->sals
.sals
[i
];
13818 location
= copy_event_location (canonical
->location
);
13819 old_chain
= make_cleanup_delete_event_location (location
);
13821 tp
= XCNEW (struct tracepoint
);
13822 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13824 cond_string
, extra_string
,
13825 type_wanted
, disposition
,
13826 thread
, task
, ignore_count
, ops
,
13827 from_tty
, enabled
, internal
, flags
,
13828 canonical
->special_display
);
13829 /* Given that its possible to have multiple markers with
13830 the same string id, if the user is creating a static
13831 tracepoint by marker id ("strace -m MARKER_ID"), then
13832 store the sals index, so that breakpoint_re_set can
13833 try to match up which of the newly found markers
13834 corresponds to this one */
13835 tp
->static_trace_marker_id_idx
= i
;
13837 install_breakpoint (internal
, &tp
->base
, 0);
13839 discard_cleanups (old_chain
);
13844 strace_marker_decode_location (struct breakpoint
*b
,
13845 const struct event_location
*location
,
13846 struct program_space
*search_pspace
,
13847 struct symtabs_and_lines
*sals
)
13849 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13850 const char *s
= get_linespec_location (location
);
13852 *sals
= decode_static_tracepoint_spec (&s
);
13853 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13855 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13859 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13862 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13865 strace_marker_p (struct breakpoint
*b
)
13867 return b
->ops
== &strace_marker_breakpoint_ops
;
13870 /* Delete a breakpoint and clean up all traces of it in the data
13874 delete_breakpoint (struct breakpoint
*bpt
)
13876 struct breakpoint
*b
;
13878 gdb_assert (bpt
!= NULL
);
13880 /* Has this bp already been deleted? This can happen because
13881 multiple lists can hold pointers to bp's. bpstat lists are
13884 One example of this happening is a watchpoint's scope bp. When
13885 the scope bp triggers, we notice that the watchpoint is out of
13886 scope, and delete it. We also delete its scope bp. But the
13887 scope bp is marked "auto-deleting", and is already on a bpstat.
13888 That bpstat is then checked for auto-deleting bp's, which are
13891 A real solution to this problem might involve reference counts in
13892 bp's, and/or giving them pointers back to their referencing
13893 bpstat's, and teaching delete_breakpoint to only free a bp's
13894 storage when no more references were extent. A cheaper bandaid
13896 if (bpt
->type
== bp_none
)
13899 /* At least avoid this stale reference until the reference counting
13900 of breakpoints gets resolved. */
13901 if (bpt
->related_breakpoint
!= bpt
)
13903 struct breakpoint
*related
;
13904 struct watchpoint
*w
;
13906 if (bpt
->type
== bp_watchpoint_scope
)
13907 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13908 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13909 w
= (struct watchpoint
*) bpt
;
13913 watchpoint_del_at_next_stop (w
);
13915 /* Unlink bpt from the bpt->related_breakpoint ring. */
13916 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13917 related
= related
->related_breakpoint
);
13918 related
->related_breakpoint
= bpt
->related_breakpoint
;
13919 bpt
->related_breakpoint
= bpt
;
13922 /* watch_command_1 creates a watchpoint but only sets its number if
13923 update_watchpoint succeeds in creating its bp_locations. If there's
13924 a problem in that process, we'll be asked to delete the half-created
13925 watchpoint. In that case, don't announce the deletion. */
13927 observer_notify_breakpoint_deleted (bpt
);
13929 if (breakpoint_chain
== bpt
)
13930 breakpoint_chain
= bpt
->next
;
13932 ALL_BREAKPOINTS (b
)
13933 if (b
->next
== bpt
)
13935 b
->next
= bpt
->next
;
13939 /* Be sure no bpstat's are pointing at the breakpoint after it's
13941 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13942 in all threads for now. Note that we cannot just remove bpstats
13943 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13944 commands are associated with the bpstat; if we remove it here,
13945 then the later call to bpstat_do_actions (&stop_bpstat); in
13946 event-top.c won't do anything, and temporary breakpoints with
13947 commands won't work. */
13949 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13951 /* Now that breakpoint is removed from breakpoint list, update the
13952 global location list. This will remove locations that used to
13953 belong to this breakpoint. Do this before freeing the breakpoint
13954 itself, since remove_breakpoint looks at location's owner. It
13955 might be better design to have location completely
13956 self-contained, but it's not the case now. */
13957 update_global_location_list (UGLL_DONT_INSERT
);
13959 bpt
->ops
->dtor (bpt
);
13960 /* On the chance that someone will soon try again to delete this
13961 same bp, we mark it as deleted before freeing its storage. */
13962 bpt
->type
= bp_none
;
13967 do_delete_breakpoint_cleanup (void *b
)
13969 delete_breakpoint ((struct breakpoint
*) b
);
13973 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13975 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13978 /* Iterator function to call a user-provided callback function once
13979 for each of B and its related breakpoints. */
13982 iterate_over_related_breakpoints (struct breakpoint
*b
,
13983 void (*function
) (struct breakpoint
*,
13987 struct breakpoint
*related
;
13992 struct breakpoint
*next
;
13994 /* FUNCTION may delete RELATED. */
13995 next
= related
->related_breakpoint
;
13997 if (next
== related
)
13999 /* RELATED is the last ring entry. */
14000 function (related
, data
);
14002 /* FUNCTION may have deleted it, so we'd never reach back to
14003 B. There's nothing left to do anyway, so just break
14008 function (related
, data
);
14012 while (related
!= b
);
14016 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14018 delete_breakpoint (b
);
14021 /* A callback for map_breakpoint_numbers that calls
14022 delete_breakpoint. */
14025 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14027 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14031 delete_command (char *arg
, int from_tty
)
14033 struct breakpoint
*b
, *b_tmp
;
14039 int breaks_to_delete
= 0;
14041 /* Delete all breakpoints if no argument. Do not delete
14042 internal breakpoints, these have to be deleted with an
14043 explicit breakpoint number argument. */
14044 ALL_BREAKPOINTS (b
)
14045 if (user_breakpoint_p (b
))
14047 breaks_to_delete
= 1;
14051 /* Ask user only if there are some breakpoints to delete. */
14053 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14055 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14056 if (user_breakpoint_p (b
))
14057 delete_breakpoint (b
);
14061 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14064 /* Return true if all locations of B bound to PSPACE are pending. If
14065 PSPACE is NULL, all locations of all program spaces are
14069 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
14071 struct bp_location
*loc
;
14073 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14074 if ((pspace
== NULL
14075 || loc
->pspace
== pspace
)
14076 && !loc
->shlib_disabled
14077 && !loc
->pspace
->executing_startup
)
14082 /* Subroutine of update_breakpoint_locations to simplify it.
14083 Return non-zero if multiple fns in list LOC have the same name.
14084 Null names are ignored. */
14087 ambiguous_names_p (struct bp_location
*loc
)
14089 struct bp_location
*l
;
14090 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14091 (int (*) (const void *,
14092 const void *)) streq
,
14093 NULL
, xcalloc
, xfree
);
14095 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14098 const char *name
= l
->function_name
;
14100 /* Allow for some names to be NULL, ignore them. */
14104 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14106 /* NOTE: We can assume slot != NULL here because xcalloc never
14110 htab_delete (htab
);
14116 htab_delete (htab
);
14120 /* When symbols change, it probably means the sources changed as well,
14121 and it might mean the static tracepoint markers are no longer at
14122 the same address or line numbers they used to be at last we
14123 checked. Losing your static tracepoints whenever you rebuild is
14124 undesirable. This function tries to resync/rematch gdb static
14125 tracepoints with the markers on the target, for static tracepoints
14126 that have not been set by marker id. Static tracepoint that have
14127 been set by marker id are reset by marker id in breakpoint_re_set.
14130 1) For a tracepoint set at a specific address, look for a marker at
14131 the old PC. If one is found there, assume to be the same marker.
14132 If the name / string id of the marker found is different from the
14133 previous known name, assume that means the user renamed the marker
14134 in the sources, and output a warning.
14136 2) For a tracepoint set at a given line number, look for a marker
14137 at the new address of the old line number. If one is found there,
14138 assume to be the same marker. If the name / string id of the
14139 marker found is different from the previous known name, assume that
14140 means the user renamed the marker in the sources, and output a
14143 3) If a marker is no longer found at the same address or line, it
14144 may mean the marker no longer exists. But it may also just mean
14145 the code changed a bit. Maybe the user added a few lines of code
14146 that made the marker move up or down (in line number terms). Ask
14147 the target for info about the marker with the string id as we knew
14148 it. If found, update line number and address in the matching
14149 static tracepoint. This will get confused if there's more than one
14150 marker with the same ID (possible in UST, although unadvised
14151 precisely because it confuses tools). */
14153 static struct symtab_and_line
14154 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14156 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14157 struct static_tracepoint_marker marker
;
14162 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14164 if (target_static_tracepoint_marker_at (pc
, &marker
))
14166 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14167 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14169 tp
->static_trace_marker_id
, marker
.str_id
);
14171 xfree (tp
->static_trace_marker_id
);
14172 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14173 release_static_tracepoint_marker (&marker
);
14178 /* Old marker wasn't found on target at lineno. Try looking it up
14180 if (!sal
.explicit_pc
14182 && sal
.symtab
!= NULL
14183 && tp
->static_trace_marker_id
!= NULL
)
14185 VEC(static_tracepoint_marker_p
) *markers
;
14188 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14190 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14192 struct symtab_and_line sal2
;
14193 struct symbol
*sym
;
14194 struct static_tracepoint_marker
*tpmarker
;
14195 struct ui_out
*uiout
= current_uiout
;
14196 struct explicit_location explicit_loc
;
14198 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14200 xfree (tp
->static_trace_marker_id
);
14201 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14203 warning (_("marker for static tracepoint %d (%s) not "
14204 "found at previous line number"),
14205 b
->number
, tp
->static_trace_marker_id
);
14209 sal2
.pc
= tpmarker
->address
;
14211 sal2
= find_pc_line (tpmarker
->address
, 0);
14212 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14213 ui_out_text (uiout
, "Now in ");
14216 ui_out_field_string (uiout
, "func",
14217 SYMBOL_PRINT_NAME (sym
));
14218 ui_out_text (uiout
, " at ");
14220 ui_out_field_string (uiout
, "file",
14221 symtab_to_filename_for_display (sal2
.symtab
));
14222 ui_out_text (uiout
, ":");
14224 if (ui_out_is_mi_like_p (uiout
))
14226 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14228 ui_out_field_string (uiout
, "fullname", fullname
);
14231 ui_out_field_int (uiout
, "line", sal2
.line
);
14232 ui_out_text (uiout
, "\n");
14234 b
->loc
->line_number
= sal2
.line
;
14235 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14237 delete_event_location (b
->location
);
14238 initialize_explicit_location (&explicit_loc
);
14239 explicit_loc
.source_filename
14240 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14241 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14242 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14243 b
->location
= new_explicit_location (&explicit_loc
);
14245 /* Might be nice to check if function changed, and warn if
14248 release_static_tracepoint_marker (tpmarker
);
14254 /* Returns 1 iff locations A and B are sufficiently same that
14255 we don't need to report breakpoint as changed. */
14258 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14262 if (a
->address
!= b
->address
)
14265 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14268 if (a
->enabled
!= b
->enabled
)
14275 if ((a
== NULL
) != (b
== NULL
))
14281 /* Split all locations of B that are bound to PSPACE out of B's
14282 location list to a separate list and return that list's head. If
14283 PSPACE is NULL, hoist out all locations of B. */
14285 static struct bp_location
*
14286 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14288 struct bp_location head
;
14289 struct bp_location
*i
= b
->loc
;
14290 struct bp_location
**i_link
= &b
->loc
;
14291 struct bp_location
*hoisted
= &head
;
14293 if (pspace
== NULL
)
14304 if (i
->pspace
== pspace
)
14319 /* Create new breakpoint locations for B (a hardware or software
14320 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14321 zero, then B is a ranged breakpoint. Only recreates locations for
14322 FILTER_PSPACE. Locations of other program spaces are left
14326 update_breakpoint_locations (struct breakpoint
*b
,
14327 struct program_space
*filter_pspace
,
14328 struct symtabs_and_lines sals
,
14329 struct symtabs_and_lines sals_end
)
14332 struct bp_location
*existing_locations
;
14334 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14336 /* Ranged breakpoints have only one start location and one end
14338 b
->enable_state
= bp_disabled
;
14339 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14340 "multiple locations found\n"),
14345 /* If there's no new locations, and all existing locations are
14346 pending, don't do anything. This optimizes the common case where
14347 all locations are in the same shared library, that was unloaded.
14348 We'd like to retain the location, so that when the library is
14349 loaded again, we don't loose the enabled/disabled status of the
14350 individual locations. */
14351 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14354 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14356 for (i
= 0; i
< sals
.nelts
; ++i
)
14358 struct bp_location
*new_loc
;
14360 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14362 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14364 /* Reparse conditions, they might contain references to the
14366 if (b
->cond_string
!= NULL
)
14370 s
= b
->cond_string
;
14373 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14374 block_for_pc (sals
.sals
[i
].pc
),
14377 CATCH (e
, RETURN_MASK_ERROR
)
14379 warning (_("failed to reevaluate condition "
14380 "for breakpoint %d: %s"),
14381 b
->number
, e
.message
);
14382 new_loc
->enabled
= 0;
14387 if (sals_end
.nelts
)
14389 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14391 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14395 /* If possible, carry over 'disable' status from existing
14398 struct bp_location
*e
= existing_locations
;
14399 /* If there are multiple breakpoints with the same function name,
14400 e.g. for inline functions, comparing function names won't work.
14401 Instead compare pc addresses; this is just a heuristic as things
14402 may have moved, but in practice it gives the correct answer
14403 often enough until a better solution is found. */
14404 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14406 for (; e
; e
= e
->next
)
14408 if (!e
->enabled
&& e
->function_name
)
14410 struct bp_location
*l
= b
->loc
;
14411 if (have_ambiguous_names
)
14413 for (; l
; l
= l
->next
)
14414 if (breakpoint_locations_match (e
, l
))
14422 for (; l
; l
= l
->next
)
14423 if (l
->function_name
14424 && strcmp (e
->function_name
, l
->function_name
) == 0)
14434 if (!locations_are_equal (existing_locations
, b
->loc
))
14435 observer_notify_breakpoint_modified (b
);
14438 /* Find the SaL locations corresponding to the given LOCATION.
14439 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14441 static struct symtabs_and_lines
14442 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14443 struct program_space
*search_pspace
, int *found
)
14445 struct symtabs_and_lines sals
= {0};
14446 struct gdb_exception exception
= exception_none
;
14448 gdb_assert (b
->ops
!= NULL
);
14452 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14454 CATCH (e
, RETURN_MASK_ERROR
)
14456 int not_found_and_ok
= 0;
14460 /* For pending breakpoints, it's expected that parsing will
14461 fail until the right shared library is loaded. User has
14462 already told to create pending breakpoints and don't need
14463 extra messages. If breakpoint is in bp_shlib_disabled
14464 state, then user already saw the message about that
14465 breakpoint being disabled, and don't want to see more
14467 if (e
.error
== NOT_FOUND_ERROR
14468 && (b
->condition_not_parsed
14470 && search_pspace
!= NULL
14471 && b
->loc
->pspace
!= search_pspace
)
14472 || (b
->loc
&& b
->loc
->shlib_disabled
)
14473 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14474 || b
->enable_state
== bp_disabled
))
14475 not_found_and_ok
= 1;
14477 if (!not_found_and_ok
)
14479 /* We surely don't want to warn about the same breakpoint
14480 10 times. One solution, implemented here, is disable
14481 the breakpoint on error. Another solution would be to
14482 have separate 'warning emitted' flag. Since this
14483 happens only when a binary has changed, I don't know
14484 which approach is better. */
14485 b
->enable_state
= bp_disabled
;
14486 throw_exception (e
);
14491 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14495 for (i
= 0; i
< sals
.nelts
; ++i
)
14496 resolve_sal_pc (&sals
.sals
[i
]);
14497 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14499 char *cond_string
, *extra_string
;
14502 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14503 &cond_string
, &thread
, &task
,
14505 gdb_assert (b
->cond_string
== NULL
);
14507 b
->cond_string
= cond_string
;
14508 b
->thread
= thread
;
14512 xfree (b
->extra_string
);
14513 b
->extra_string
= extra_string
;
14515 b
->condition_not_parsed
= 0;
14518 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14519 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14529 /* The default re_set method, for typical hardware or software
14530 breakpoints. Reevaluate the breakpoint and recreate its
14534 breakpoint_re_set_default (struct breakpoint
*b
)
14537 struct symtabs_and_lines sals
, sals_end
;
14538 struct symtabs_and_lines expanded
= {0};
14539 struct symtabs_and_lines expanded_end
= {0};
14540 struct program_space
*filter_pspace
= current_program_space
;
14542 sals
= location_to_sals (b
, b
->location
, filter_pspace
, &found
);
14545 make_cleanup (xfree
, sals
.sals
);
14549 if (b
->location_range_end
!= NULL
)
14551 sals_end
= location_to_sals (b
, b
->location_range_end
,
14552 filter_pspace
, &found
);
14555 make_cleanup (xfree
, sals_end
.sals
);
14556 expanded_end
= sals_end
;
14560 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14563 /* Default method for creating SALs from an address string. It basically
14564 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14567 create_sals_from_location_default (const struct event_location
*location
,
14568 struct linespec_result
*canonical
,
14569 enum bptype type_wanted
)
14571 parse_breakpoint_sals (location
, canonical
);
14574 /* Call create_breakpoints_sal for the given arguments. This is the default
14575 function for the `create_breakpoints_sal' method of
14579 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14580 struct linespec_result
*canonical
,
14582 char *extra_string
,
14583 enum bptype type_wanted
,
14584 enum bpdisp disposition
,
14586 int task
, int ignore_count
,
14587 const struct breakpoint_ops
*ops
,
14588 int from_tty
, int enabled
,
14589 int internal
, unsigned flags
)
14591 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14593 type_wanted
, disposition
,
14594 thread
, task
, ignore_count
, ops
, from_tty
,
14595 enabled
, internal
, flags
);
14598 /* Decode the line represented by S by calling decode_line_full. This is the
14599 default function for the `decode_location' method of breakpoint_ops. */
14602 decode_location_default (struct breakpoint
*b
,
14603 const struct event_location
*location
,
14604 struct program_space
*search_pspace
,
14605 struct symtabs_and_lines
*sals
)
14607 struct linespec_result canonical
;
14609 init_linespec_result (&canonical
);
14610 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14611 (struct symtab
*) NULL
, 0,
14612 &canonical
, multiple_symbols_all
,
14615 /* We should get 0 or 1 resulting SALs. */
14616 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14618 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14620 struct linespec_sals
*lsal
;
14622 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14623 *sals
= lsal
->sals
;
14624 /* Arrange it so the destructor does not free the
14626 lsal
->sals
.sals
= NULL
;
14629 destroy_linespec_result (&canonical
);
14632 /* Prepare the global context for a re-set of breakpoint B. */
14634 static struct cleanup
*
14635 prepare_re_set_context (struct breakpoint
*b
)
14637 input_radix
= b
->input_radix
;
14638 set_language (b
->language
);
14640 return make_cleanup (null_cleanup
, NULL
);
14643 /* Reset a breakpoint given it's struct breakpoint * BINT.
14644 The value we return ends up being the return value from catch_errors.
14645 Unused in this case. */
14648 breakpoint_re_set_one (void *bint
)
14650 /* Get past catch_errs. */
14651 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14652 struct cleanup
*cleanups
;
14654 cleanups
= prepare_re_set_context (b
);
14655 b
->ops
->re_set (b
);
14656 do_cleanups (cleanups
);
14660 /* Re-set breakpoint locations for the current program space.
14661 Locations bound to other program spaces are left untouched. */
14664 breakpoint_re_set (void)
14666 struct breakpoint
*b
, *b_tmp
;
14667 enum language save_language
;
14668 int save_input_radix
;
14669 struct cleanup
*old_chain
;
14671 save_language
= current_language
->la_language
;
14672 save_input_radix
= input_radix
;
14673 old_chain
= save_current_space_and_thread ();
14675 /* Note: we must not try to insert locations until after all
14676 breakpoints have been re-set. Otherwise, e.g., when re-setting
14677 breakpoint 1, we'd insert the locations of breakpoint 2, which
14678 hadn't been re-set yet, and thus may have stale locations. */
14680 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14682 /* Format possible error msg. */
14683 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14685 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14686 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14687 do_cleanups (cleanups
);
14689 set_language (save_language
);
14690 input_radix
= save_input_radix
;
14692 jit_breakpoint_re_set ();
14694 do_cleanups (old_chain
);
14696 create_overlay_event_breakpoint ();
14697 create_longjmp_master_breakpoint ();
14698 create_std_terminate_master_breakpoint ();
14699 create_exception_master_breakpoint ();
14701 /* Now we can insert. */
14702 update_global_location_list (UGLL_MAY_INSERT
);
14705 /* Reset the thread number of this breakpoint:
14707 - If the breakpoint is for all threads, leave it as-is.
14708 - Else, reset it to the current thread for inferior_ptid. */
14710 breakpoint_re_set_thread (struct breakpoint
*b
)
14712 if (b
->thread
!= -1)
14714 if (in_thread_list (inferior_ptid
))
14715 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14717 /* We're being called after following a fork. The new fork is
14718 selected as current, and unless this was a vfork will have a
14719 different program space from the original thread. Reset that
14721 b
->loc
->pspace
= current_program_space
;
14725 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14726 If from_tty is nonzero, it prints a message to that effect,
14727 which ends with a period (no newline). */
14730 set_ignore_count (int bptnum
, int count
, int from_tty
)
14732 struct breakpoint
*b
;
14737 ALL_BREAKPOINTS (b
)
14738 if (b
->number
== bptnum
)
14740 if (is_tracepoint (b
))
14742 if (from_tty
&& count
!= 0)
14743 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14748 b
->ignore_count
= count
;
14752 printf_filtered (_("Will stop next time "
14753 "breakpoint %d is reached."),
14755 else if (count
== 1)
14756 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14759 printf_filtered (_("Will ignore next %d "
14760 "crossings of breakpoint %d."),
14763 observer_notify_breakpoint_modified (b
);
14767 error (_("No breakpoint number %d."), bptnum
);
14770 /* Command to set ignore-count of breakpoint N to COUNT. */
14773 ignore_command (char *args
, int from_tty
)
14779 error_no_arg (_("a breakpoint number"));
14781 num
= get_number (&p
);
14783 error (_("bad breakpoint number: '%s'"), args
);
14785 error (_("Second argument (specified ignore-count) is missing."));
14787 set_ignore_count (num
,
14788 longest_to_int (value_as_long (parse_and_eval (p
))),
14791 printf_filtered ("\n");
14794 /* Call FUNCTION on each of the breakpoints
14795 whose numbers are given in ARGS. */
14798 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14803 struct breakpoint
*b
, *tmp
;
14805 if (args
== 0 || *args
== '\0')
14806 error_no_arg (_("one or more breakpoint numbers"));
14808 number_or_range_parser
parser (args
);
14810 while (!parser
.finished ())
14812 const char *p
= parser
.cur_tok ();
14813 bool match
= false;
14815 num
= parser
.get_number ();
14818 warning (_("bad breakpoint number at or near '%s'"), p
);
14822 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14823 if (b
->number
== num
)
14826 function (b
, data
);
14830 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14835 static struct bp_location
*
14836 find_location_by_number (char *number
)
14838 char *dot
= strchr (number
, '.');
14842 struct breakpoint
*b
;
14843 struct bp_location
*loc
;
14848 bp_num
= get_number (&p1
);
14850 error (_("Bad breakpoint number '%s'"), number
);
14852 ALL_BREAKPOINTS (b
)
14853 if (b
->number
== bp_num
)
14858 if (!b
|| b
->number
!= bp_num
)
14859 error (_("Bad breakpoint number '%s'"), number
);
14862 loc_num
= get_number (&p1
);
14864 error (_("Bad breakpoint location number '%s'"), number
);
14868 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14871 error (_("Bad breakpoint location number '%s'"), dot
+1);
14877 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14878 If from_tty is nonzero, it prints a message to that effect,
14879 which ends with a period (no newline). */
14882 disable_breakpoint (struct breakpoint
*bpt
)
14884 /* Never disable a watchpoint scope breakpoint; we want to
14885 hit them when we leave scope so we can delete both the
14886 watchpoint and its scope breakpoint at that time. */
14887 if (bpt
->type
== bp_watchpoint_scope
)
14890 bpt
->enable_state
= bp_disabled
;
14892 /* Mark breakpoint locations modified. */
14893 mark_breakpoint_modified (bpt
);
14895 if (target_supports_enable_disable_tracepoint ()
14896 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14898 struct bp_location
*location
;
14900 for (location
= bpt
->loc
; location
; location
= location
->next
)
14901 target_disable_tracepoint (location
);
14904 update_global_location_list (UGLL_DONT_INSERT
);
14906 observer_notify_breakpoint_modified (bpt
);
14909 /* A callback for iterate_over_related_breakpoints. */
14912 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14914 disable_breakpoint (b
);
14917 /* A callback for map_breakpoint_numbers that calls
14918 disable_breakpoint. */
14921 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14923 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14927 disable_command (char *args
, int from_tty
)
14931 struct breakpoint
*bpt
;
14933 ALL_BREAKPOINTS (bpt
)
14934 if (user_breakpoint_p (bpt
))
14935 disable_breakpoint (bpt
);
14939 char *num
= extract_arg (&args
);
14943 if (strchr (num
, '.'))
14945 struct bp_location
*loc
= find_location_by_number (num
);
14952 mark_breakpoint_location_modified (loc
);
14954 if (target_supports_enable_disable_tracepoint ()
14955 && current_trace_status ()->running
&& loc
->owner
14956 && is_tracepoint (loc
->owner
))
14957 target_disable_tracepoint (loc
);
14959 update_global_location_list (UGLL_DONT_INSERT
);
14962 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14963 num
= extract_arg (&args
);
14969 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14972 int target_resources_ok
;
14974 if (bpt
->type
== bp_hardware_breakpoint
)
14977 i
= hw_breakpoint_used_count ();
14978 target_resources_ok
=
14979 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14981 if (target_resources_ok
== 0)
14982 error (_("No hardware breakpoint support in the target."));
14983 else if (target_resources_ok
< 0)
14984 error (_("Hardware breakpoints used exceeds limit."));
14987 if (is_watchpoint (bpt
))
14989 /* Initialize it just to avoid a GCC false warning. */
14990 enum enable_state orig_enable_state
= bp_disabled
;
14994 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14996 orig_enable_state
= bpt
->enable_state
;
14997 bpt
->enable_state
= bp_enabled
;
14998 update_watchpoint (w
, 1 /* reparse */);
15000 CATCH (e
, RETURN_MASK_ALL
)
15002 bpt
->enable_state
= orig_enable_state
;
15003 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15010 bpt
->enable_state
= bp_enabled
;
15012 /* Mark breakpoint locations modified. */
15013 mark_breakpoint_modified (bpt
);
15015 if (target_supports_enable_disable_tracepoint ()
15016 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15018 struct bp_location
*location
;
15020 for (location
= bpt
->loc
; location
; location
= location
->next
)
15021 target_enable_tracepoint (location
);
15024 bpt
->disposition
= disposition
;
15025 bpt
->enable_count
= count
;
15026 update_global_location_list (UGLL_MAY_INSERT
);
15028 observer_notify_breakpoint_modified (bpt
);
15033 enable_breakpoint (struct breakpoint
*bpt
)
15035 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15039 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15041 enable_breakpoint (bpt
);
15044 /* A callback for map_breakpoint_numbers that calls
15045 enable_breakpoint. */
15048 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15050 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15053 /* The enable command enables the specified breakpoints (or all defined
15054 breakpoints) so they once again become (or continue to be) effective
15055 in stopping the inferior. */
15058 enable_command (char *args
, int from_tty
)
15062 struct breakpoint
*bpt
;
15064 ALL_BREAKPOINTS (bpt
)
15065 if (user_breakpoint_p (bpt
))
15066 enable_breakpoint (bpt
);
15070 char *num
= extract_arg (&args
);
15074 if (strchr (num
, '.'))
15076 struct bp_location
*loc
= find_location_by_number (num
);
15083 mark_breakpoint_location_modified (loc
);
15085 if (target_supports_enable_disable_tracepoint ()
15086 && current_trace_status ()->running
&& loc
->owner
15087 && is_tracepoint (loc
->owner
))
15088 target_enable_tracepoint (loc
);
15090 update_global_location_list (UGLL_MAY_INSERT
);
15093 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15094 num
= extract_arg (&args
);
15099 /* This struct packages up disposition data for application to multiple
15109 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15111 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15113 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15117 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15119 struct disp_data disp
= { disp_disable
, 1 };
15121 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15125 enable_once_command (char *args
, int from_tty
)
15127 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15131 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15133 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15135 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15139 enable_count_command (char *args
, int from_tty
)
15144 error_no_arg (_("hit count"));
15146 count
= get_number (&args
);
15148 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15152 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15154 struct disp_data disp
= { disp_del
, 1 };
15156 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15160 enable_delete_command (char *args
, int from_tty
)
15162 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15166 set_breakpoint_cmd (char *args
, int from_tty
)
15171 show_breakpoint_cmd (char *args
, int from_tty
)
15175 /* Invalidate last known value of any hardware watchpoint if
15176 the memory which that value represents has been written to by
15180 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15181 CORE_ADDR addr
, ssize_t len
,
15182 const bfd_byte
*data
)
15184 struct breakpoint
*bp
;
15186 ALL_BREAKPOINTS (bp
)
15187 if (bp
->enable_state
== bp_enabled
15188 && bp
->type
== bp_hardware_watchpoint
)
15190 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15192 if (wp
->val_valid
&& wp
->val
)
15194 struct bp_location
*loc
;
15196 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15197 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15198 && loc
->address
+ loc
->length
> addr
15199 && addr
+ len
> loc
->address
)
15201 value_free (wp
->val
);
15209 /* Create and insert a breakpoint for software single step. */
15212 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15213 struct address_space
*aspace
,
15216 struct thread_info
*tp
= inferior_thread ();
15217 struct symtab_and_line sal
;
15218 CORE_ADDR pc
= next_pc
;
15220 if (tp
->control
.single_step_breakpoints
== NULL
)
15222 tp
->control
.single_step_breakpoints
15223 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15226 sal
= find_pc_line (pc
, 0);
15228 sal
.section
= find_pc_overlay (pc
);
15229 sal
.explicit_pc
= 1;
15230 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15232 update_global_location_list (UGLL_INSERT
);
15235 /* See breakpoint.h. */
15238 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15239 struct address_space
*aspace
,
15242 struct bp_location
*loc
;
15244 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15246 && breakpoint_location_address_match (loc
, aspace
, pc
))
15252 /* Check whether a software single-step breakpoint is inserted at
15256 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15259 struct breakpoint
*bpt
;
15261 ALL_BREAKPOINTS (bpt
)
15263 if (bpt
->type
== bp_single_step
15264 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15270 /* Tracepoint-specific operations. */
15272 /* Set tracepoint count to NUM. */
15274 set_tracepoint_count (int num
)
15276 tracepoint_count
= num
;
15277 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15281 trace_command (char *arg
, int from_tty
)
15283 struct breakpoint_ops
*ops
;
15284 struct event_location
*location
;
15285 struct cleanup
*back_to
;
15287 location
= string_to_event_location (&arg
, current_language
);
15288 back_to
= make_cleanup_delete_event_location (location
);
15289 if (location
!= NULL
15290 && event_location_type (location
) == PROBE_LOCATION
)
15291 ops
= &tracepoint_probe_breakpoint_ops
;
15293 ops
= &tracepoint_breakpoint_ops
;
15295 create_breakpoint (get_current_arch (),
15297 NULL
, 0, arg
, 1 /* parse arg */,
15299 bp_tracepoint
/* type_wanted */,
15300 0 /* Ignore count */,
15301 pending_break_support
,
15305 0 /* internal */, 0);
15306 do_cleanups (back_to
);
15310 ftrace_command (char *arg
, int from_tty
)
15312 struct event_location
*location
;
15313 struct cleanup
*back_to
;
15315 location
= string_to_event_location (&arg
, current_language
);
15316 back_to
= make_cleanup_delete_event_location (location
);
15317 create_breakpoint (get_current_arch (),
15319 NULL
, 0, arg
, 1 /* parse arg */,
15321 bp_fast_tracepoint
/* type_wanted */,
15322 0 /* Ignore count */,
15323 pending_break_support
,
15324 &tracepoint_breakpoint_ops
,
15327 0 /* internal */, 0);
15328 do_cleanups (back_to
);
15331 /* strace command implementation. Creates a static tracepoint. */
15334 strace_command (char *arg
, int from_tty
)
15336 struct breakpoint_ops
*ops
;
15337 struct event_location
*location
;
15338 struct cleanup
*back_to
;
15340 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15341 or with a normal static tracepoint. */
15342 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15344 ops
= &strace_marker_breakpoint_ops
;
15345 location
= new_linespec_location (&arg
);
15349 ops
= &tracepoint_breakpoint_ops
;
15350 location
= string_to_event_location (&arg
, current_language
);
15353 back_to
= make_cleanup_delete_event_location (location
);
15354 create_breakpoint (get_current_arch (),
15356 NULL
, 0, arg
, 1 /* parse arg */,
15358 bp_static_tracepoint
/* type_wanted */,
15359 0 /* Ignore count */,
15360 pending_break_support
,
15364 0 /* internal */, 0);
15365 do_cleanups (back_to
);
15368 /* Set up a fake reader function that gets command lines from a linked
15369 list that was acquired during tracepoint uploading. */
15371 static struct uploaded_tp
*this_utp
;
15372 static int next_cmd
;
15375 read_uploaded_action (void)
15379 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15386 /* Given information about a tracepoint as recorded on a target (which
15387 can be either a live system or a trace file), attempt to create an
15388 equivalent GDB tracepoint. This is not a reliable process, since
15389 the target does not necessarily have all the information used when
15390 the tracepoint was originally defined. */
15392 struct tracepoint
*
15393 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15395 char *addr_str
, small_buf
[100];
15396 struct tracepoint
*tp
;
15397 struct event_location
*location
;
15398 struct cleanup
*cleanup
;
15400 if (utp
->at_string
)
15401 addr_str
= utp
->at_string
;
15404 /* In the absence of a source location, fall back to raw
15405 address. Since there is no way to confirm that the address
15406 means the same thing as when the trace was started, warn the
15408 warning (_("Uploaded tracepoint %d has no "
15409 "source location, using raw address"),
15411 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15412 addr_str
= small_buf
;
15415 /* There's not much we can do with a sequence of bytecodes. */
15416 if (utp
->cond
&& !utp
->cond_string
)
15417 warning (_("Uploaded tracepoint %d condition "
15418 "has no source form, ignoring it"),
15421 location
= string_to_event_location (&addr_str
, current_language
);
15422 cleanup
= make_cleanup_delete_event_location (location
);
15423 if (!create_breakpoint (get_current_arch (),
15425 utp
->cond_string
, -1, addr_str
,
15426 0 /* parse cond/thread */,
15428 utp
->type
/* type_wanted */,
15429 0 /* Ignore count */,
15430 pending_break_support
,
15431 &tracepoint_breakpoint_ops
,
15433 utp
->enabled
/* enabled */,
15435 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15437 do_cleanups (cleanup
);
15441 do_cleanups (cleanup
);
15443 /* Get the tracepoint we just created. */
15444 tp
= get_tracepoint (tracepoint_count
);
15445 gdb_assert (tp
!= NULL
);
15449 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15452 trace_pass_command (small_buf
, 0);
15455 /* If we have uploaded versions of the original commands, set up a
15456 special-purpose "reader" function and call the usual command line
15457 reader, then pass the result to the breakpoint command-setting
15459 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15461 struct command_line
*cmd_list
;
15466 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15468 breakpoint_set_commands (&tp
->base
, cmd_list
);
15470 else if (!VEC_empty (char_ptr
, utp
->actions
)
15471 || !VEC_empty (char_ptr
, utp
->step_actions
))
15472 warning (_("Uploaded tracepoint %d actions "
15473 "have no source form, ignoring them"),
15476 /* Copy any status information that might be available. */
15477 tp
->base
.hit_count
= utp
->hit_count
;
15478 tp
->traceframe_usage
= utp
->traceframe_usage
;
15483 /* Print information on tracepoint number TPNUM_EXP, or all if
15487 tracepoints_info (char *args
, int from_tty
)
15489 struct ui_out
*uiout
= current_uiout
;
15492 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15494 if (num_printed
== 0)
15496 if (args
== NULL
|| *args
== '\0')
15497 ui_out_message (uiout
, 0, "No tracepoints.\n");
15499 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15502 default_collect_info ();
15505 /* The 'enable trace' command enables tracepoints.
15506 Not supported by all targets. */
15508 enable_trace_command (char *args
, int from_tty
)
15510 enable_command (args
, from_tty
);
15513 /* The 'disable trace' command disables tracepoints.
15514 Not supported by all targets. */
15516 disable_trace_command (char *args
, int from_tty
)
15518 disable_command (args
, from_tty
);
15521 /* Remove a tracepoint (or all if no argument). */
15523 delete_trace_command (char *arg
, int from_tty
)
15525 struct breakpoint
*b
, *b_tmp
;
15531 int breaks_to_delete
= 0;
15533 /* Delete all breakpoints if no argument.
15534 Do not delete internal or call-dummy breakpoints, these
15535 have to be deleted with an explicit breakpoint number
15537 ALL_TRACEPOINTS (b
)
15538 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15540 breaks_to_delete
= 1;
15544 /* Ask user only if there are some breakpoints to delete. */
15546 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15548 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15549 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15550 delete_breakpoint (b
);
15554 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15557 /* Helper function for trace_pass_command. */
15560 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15562 tp
->pass_count
= count
;
15563 observer_notify_breakpoint_modified (&tp
->base
);
15565 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15566 tp
->base
.number
, count
);
15569 /* Set passcount for tracepoint.
15571 First command argument is passcount, second is tracepoint number.
15572 If tracepoint number omitted, apply to most recently defined.
15573 Also accepts special argument "all". */
15576 trace_pass_command (char *args
, int from_tty
)
15578 struct tracepoint
*t1
;
15579 unsigned int count
;
15581 if (args
== 0 || *args
== 0)
15582 error (_("passcount command requires an "
15583 "argument (count + optional TP num)"));
15585 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15587 args
= skip_spaces (args
);
15588 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15590 struct breakpoint
*b
;
15592 args
+= 3; /* Skip special argument "all". */
15594 error (_("Junk at end of arguments."));
15596 ALL_TRACEPOINTS (b
)
15598 t1
= (struct tracepoint
*) b
;
15599 trace_pass_set_count (t1
, count
, from_tty
);
15602 else if (*args
== '\0')
15604 t1
= get_tracepoint_by_number (&args
, NULL
);
15606 trace_pass_set_count (t1
, count
, from_tty
);
15610 number_or_range_parser
parser (args
);
15611 while (!parser
.finished ())
15613 t1
= get_tracepoint_by_number (&args
, &parser
);
15615 trace_pass_set_count (t1
, count
, from_tty
);
15620 struct tracepoint
*
15621 get_tracepoint (int num
)
15623 struct breakpoint
*t
;
15625 ALL_TRACEPOINTS (t
)
15626 if (t
->number
== num
)
15627 return (struct tracepoint
*) t
;
15632 /* Find the tracepoint with the given target-side number (which may be
15633 different from the tracepoint number after disconnecting and
15636 struct tracepoint
*
15637 get_tracepoint_by_number_on_target (int num
)
15639 struct breakpoint
*b
;
15641 ALL_TRACEPOINTS (b
)
15643 struct tracepoint
*t
= (struct tracepoint
*) b
;
15645 if (t
->number_on_target
== num
)
15652 /* Utility: parse a tracepoint number and look it up in the list.
15653 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15654 If the argument is missing, the most recent tracepoint
15655 (tracepoint_count) is returned. */
15657 struct tracepoint
*
15658 get_tracepoint_by_number (char **arg
,
15659 number_or_range_parser
*parser
)
15661 struct breakpoint
*t
;
15663 char *instring
= arg
== NULL
? NULL
: *arg
;
15665 if (parser
!= NULL
)
15667 gdb_assert (!parser
->finished ());
15668 tpnum
= parser
->get_number ();
15670 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15671 tpnum
= tracepoint_count
;
15673 tpnum
= get_number (arg
);
15677 if (instring
&& *instring
)
15678 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15681 printf_filtered (_("No previous tracepoint\n"));
15685 ALL_TRACEPOINTS (t
)
15686 if (t
->number
== tpnum
)
15688 return (struct tracepoint
*) t
;
15691 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15696 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15698 if (b
->thread
!= -1)
15699 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15702 fprintf_unfiltered (fp
, " task %d", b
->task
);
15704 fprintf_unfiltered (fp
, "\n");
15707 /* Save information on user settable breakpoints (watchpoints, etc) to
15708 a new script file named FILENAME. If FILTER is non-NULL, call it
15709 on each breakpoint and only include the ones for which it returns
15713 save_breakpoints (char *filename
, int from_tty
,
15714 int (*filter
) (const struct breakpoint
*))
15716 struct breakpoint
*tp
;
15718 struct cleanup
*cleanup
;
15719 struct ui_file
*fp
;
15720 int extra_trace_bits
= 0;
15722 if (filename
== 0 || *filename
== 0)
15723 error (_("Argument required (file name in which to save)"));
15725 /* See if we have anything to save. */
15726 ALL_BREAKPOINTS (tp
)
15728 /* Skip internal and momentary breakpoints. */
15729 if (!user_breakpoint_p (tp
))
15732 /* If we have a filter, only save the breakpoints it accepts. */
15733 if (filter
&& !filter (tp
))
15738 if (is_tracepoint (tp
))
15740 extra_trace_bits
= 1;
15742 /* We can stop searching. */
15749 warning (_("Nothing to save."));
15753 filename
= tilde_expand (filename
);
15754 cleanup
= make_cleanup (xfree
, filename
);
15755 fp
= gdb_fopen (filename
, "w");
15757 error (_("Unable to open file '%s' for saving (%s)"),
15758 filename
, safe_strerror (errno
));
15759 make_cleanup_ui_file_delete (fp
);
15761 if (extra_trace_bits
)
15762 save_trace_state_variables (fp
);
15764 ALL_BREAKPOINTS (tp
)
15766 /* Skip internal and momentary breakpoints. */
15767 if (!user_breakpoint_p (tp
))
15770 /* If we have a filter, only save the breakpoints it accepts. */
15771 if (filter
&& !filter (tp
))
15774 tp
->ops
->print_recreate (tp
, fp
);
15776 /* Note, we can't rely on tp->number for anything, as we can't
15777 assume the recreated breakpoint numbers will match. Use $bpnum
15780 if (tp
->cond_string
)
15781 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15783 if (tp
->ignore_count
)
15784 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15786 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15788 fprintf_unfiltered (fp
, " commands\n");
15790 ui_out_redirect (current_uiout
, fp
);
15793 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15795 CATCH (ex
, RETURN_MASK_ALL
)
15797 ui_out_redirect (current_uiout
, NULL
);
15798 throw_exception (ex
);
15802 ui_out_redirect (current_uiout
, NULL
);
15803 fprintf_unfiltered (fp
, " end\n");
15806 if (tp
->enable_state
== bp_disabled
)
15807 fprintf_unfiltered (fp
, "disable $bpnum\n");
15809 /* If this is a multi-location breakpoint, check if the locations
15810 should be individually disabled. Watchpoint locations are
15811 special, and not user visible. */
15812 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15814 struct bp_location
*loc
;
15817 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15819 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15823 if (extra_trace_bits
&& *default_collect
)
15824 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15827 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15828 do_cleanups (cleanup
);
15831 /* The `save breakpoints' command. */
15834 save_breakpoints_command (char *args
, int from_tty
)
15836 save_breakpoints (args
, from_tty
, NULL
);
15839 /* The `save tracepoints' command. */
15842 save_tracepoints_command (char *args
, int from_tty
)
15844 save_breakpoints (args
, from_tty
, is_tracepoint
);
15847 /* Create a vector of all tracepoints. */
15849 VEC(breakpoint_p
) *
15850 all_tracepoints (void)
15852 VEC(breakpoint_p
) *tp_vec
= 0;
15853 struct breakpoint
*tp
;
15855 ALL_TRACEPOINTS (tp
)
15857 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15864 /* This help string is used to consolidate all the help string for specifying
15865 locations used by several commands. */
15867 #define LOCATION_HELP_STRING \
15868 "Linespecs are colon-separated lists of location parameters, such as\n\
15869 source filename, function name, label name, and line number.\n\
15870 Example: To specify the start of a label named \"the_top\" in the\n\
15871 function \"fact\" in the file \"factorial.c\", use\n\
15872 \"factorial.c:fact:the_top\".\n\
15874 Address locations begin with \"*\" and specify an exact address in the\n\
15875 program. Example: To specify the fourth byte past the start function\n\
15876 \"main\", use \"*main + 4\".\n\
15878 Explicit locations are similar to linespecs but use an option/argument\n\
15879 syntax to specify location parameters.\n\
15880 Example: To specify the start of the label named \"the_top\" in the\n\
15881 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15882 -function fact -label the_top\".\n"
15884 /* This help string is used for the break, hbreak, tbreak and thbreak
15885 commands. It is defined as a macro to prevent duplication.
15886 COMMAND should be a string constant containing the name of the
15889 #define BREAK_ARGS_HELP(command) \
15890 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15891 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15892 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15893 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15894 `-probe-dtrace' (for a DTrace probe).\n\
15895 LOCATION may be a linespec, address, or explicit location as described\n\
15898 With no LOCATION, uses current execution address of the selected\n\
15899 stack frame. This is useful for breaking on return to a stack frame.\n\
15901 THREADNUM is the number from \"info threads\".\n\
15902 CONDITION is a boolean expression.\n\
15903 \n" LOCATION_HELP_STRING "\n\
15904 Multiple breakpoints at one place are permitted, and useful if their\n\
15905 conditions are different.\n\
15907 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15909 /* List of subcommands for "catch". */
15910 static struct cmd_list_element
*catch_cmdlist
;
15912 /* List of subcommands for "tcatch". */
15913 static struct cmd_list_element
*tcatch_cmdlist
;
15916 add_catch_command (char *name
, char *docstring
,
15917 cmd_sfunc_ftype
*sfunc
,
15918 completer_ftype
*completer
,
15919 void *user_data_catch
,
15920 void *user_data_tcatch
)
15922 struct cmd_list_element
*command
;
15924 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15926 set_cmd_sfunc (command
, sfunc
);
15927 set_cmd_context (command
, user_data_catch
);
15928 set_cmd_completer (command
, completer
);
15930 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15932 set_cmd_sfunc (command
, sfunc
);
15933 set_cmd_context (command
, user_data_tcatch
);
15934 set_cmd_completer (command
, completer
);
15938 save_command (char *arg
, int from_tty
)
15940 printf_unfiltered (_("\"save\" must be followed by "
15941 "the name of a save subcommand.\n"));
15942 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15945 struct breakpoint
*
15946 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15949 struct breakpoint
*b
, *b_tmp
;
15951 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15953 if ((*callback
) (b
, data
))
15960 /* Zero if any of the breakpoint's locations could be a location where
15961 functions have been inlined, nonzero otherwise. */
15964 is_non_inline_function (struct breakpoint
*b
)
15966 /* The shared library event breakpoint is set on the address of a
15967 non-inline function. */
15968 if (b
->type
== bp_shlib_event
)
15974 /* Nonzero if the specified PC cannot be a location where functions
15975 have been inlined. */
15978 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15979 const struct target_waitstatus
*ws
)
15981 struct breakpoint
*b
;
15982 struct bp_location
*bl
;
15984 ALL_BREAKPOINTS (b
)
15986 if (!is_non_inline_function (b
))
15989 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15991 if (!bl
->shlib_disabled
15992 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16000 /* Remove any references to OBJFILE which is going to be freed. */
16003 breakpoint_free_objfile (struct objfile
*objfile
)
16005 struct bp_location
**locp
, *loc
;
16007 ALL_BP_LOCATIONS (loc
, locp
)
16008 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
16009 loc
->symtab
= NULL
;
16013 initialize_breakpoint_ops (void)
16015 static int initialized
= 0;
16017 struct breakpoint_ops
*ops
;
16023 /* The breakpoint_ops structure to be inherit by all kinds of
16024 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16025 internal and momentary breakpoints, etc.). */
16026 ops
= &bkpt_base_breakpoint_ops
;
16027 *ops
= base_breakpoint_ops
;
16028 ops
->re_set
= bkpt_re_set
;
16029 ops
->insert_location
= bkpt_insert_location
;
16030 ops
->remove_location
= bkpt_remove_location
;
16031 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16032 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
16033 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16034 ops
->decode_location
= bkpt_decode_location
;
16036 /* The breakpoint_ops structure to be used in regular breakpoints. */
16037 ops
= &bkpt_breakpoint_ops
;
16038 *ops
= bkpt_base_breakpoint_ops
;
16039 ops
->re_set
= bkpt_re_set
;
16040 ops
->resources_needed
= bkpt_resources_needed
;
16041 ops
->print_it
= bkpt_print_it
;
16042 ops
->print_mention
= bkpt_print_mention
;
16043 ops
->print_recreate
= bkpt_print_recreate
;
16045 /* Ranged breakpoints. */
16046 ops
= &ranged_breakpoint_ops
;
16047 *ops
= bkpt_breakpoint_ops
;
16048 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16049 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16050 ops
->print_it
= print_it_ranged_breakpoint
;
16051 ops
->print_one
= print_one_ranged_breakpoint
;
16052 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16053 ops
->print_mention
= print_mention_ranged_breakpoint
;
16054 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16056 /* Internal breakpoints. */
16057 ops
= &internal_breakpoint_ops
;
16058 *ops
= bkpt_base_breakpoint_ops
;
16059 ops
->re_set
= internal_bkpt_re_set
;
16060 ops
->check_status
= internal_bkpt_check_status
;
16061 ops
->print_it
= internal_bkpt_print_it
;
16062 ops
->print_mention
= internal_bkpt_print_mention
;
16064 /* Momentary breakpoints. */
16065 ops
= &momentary_breakpoint_ops
;
16066 *ops
= bkpt_base_breakpoint_ops
;
16067 ops
->re_set
= momentary_bkpt_re_set
;
16068 ops
->check_status
= momentary_bkpt_check_status
;
16069 ops
->print_it
= momentary_bkpt_print_it
;
16070 ops
->print_mention
= momentary_bkpt_print_mention
;
16072 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16073 ops
= &longjmp_breakpoint_ops
;
16074 *ops
= momentary_breakpoint_ops
;
16075 ops
->dtor
= longjmp_bkpt_dtor
;
16077 /* Probe breakpoints. */
16078 ops
= &bkpt_probe_breakpoint_ops
;
16079 *ops
= bkpt_breakpoint_ops
;
16080 ops
->insert_location
= bkpt_probe_insert_location
;
16081 ops
->remove_location
= bkpt_probe_remove_location
;
16082 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
16083 ops
->decode_location
= bkpt_probe_decode_location
;
16086 ops
= &watchpoint_breakpoint_ops
;
16087 *ops
= base_breakpoint_ops
;
16088 ops
->dtor
= dtor_watchpoint
;
16089 ops
->re_set
= re_set_watchpoint
;
16090 ops
->insert_location
= insert_watchpoint
;
16091 ops
->remove_location
= remove_watchpoint
;
16092 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16093 ops
->check_status
= check_status_watchpoint
;
16094 ops
->resources_needed
= resources_needed_watchpoint
;
16095 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16096 ops
->print_it
= print_it_watchpoint
;
16097 ops
->print_mention
= print_mention_watchpoint
;
16098 ops
->print_recreate
= print_recreate_watchpoint
;
16099 ops
->explains_signal
= explains_signal_watchpoint
;
16101 /* Masked watchpoints. */
16102 ops
= &masked_watchpoint_breakpoint_ops
;
16103 *ops
= watchpoint_breakpoint_ops
;
16104 ops
->insert_location
= insert_masked_watchpoint
;
16105 ops
->remove_location
= remove_masked_watchpoint
;
16106 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16107 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16108 ops
->print_it
= print_it_masked_watchpoint
;
16109 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16110 ops
->print_mention
= print_mention_masked_watchpoint
;
16111 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16114 ops
= &tracepoint_breakpoint_ops
;
16115 *ops
= base_breakpoint_ops
;
16116 ops
->re_set
= tracepoint_re_set
;
16117 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16118 ops
->print_one_detail
= tracepoint_print_one_detail
;
16119 ops
->print_mention
= tracepoint_print_mention
;
16120 ops
->print_recreate
= tracepoint_print_recreate
;
16121 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
16122 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16123 ops
->decode_location
= tracepoint_decode_location
;
16125 /* Probe tracepoints. */
16126 ops
= &tracepoint_probe_breakpoint_ops
;
16127 *ops
= tracepoint_breakpoint_ops
;
16128 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
16129 ops
->decode_location
= tracepoint_probe_decode_location
;
16131 /* Static tracepoints with marker (`-m'). */
16132 ops
= &strace_marker_breakpoint_ops
;
16133 *ops
= tracepoint_breakpoint_ops
;
16134 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16135 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16136 ops
->decode_location
= strace_marker_decode_location
;
16138 /* Fork catchpoints. */
16139 ops
= &catch_fork_breakpoint_ops
;
16140 *ops
= base_breakpoint_ops
;
16141 ops
->insert_location
= insert_catch_fork
;
16142 ops
->remove_location
= remove_catch_fork
;
16143 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16144 ops
->print_it
= print_it_catch_fork
;
16145 ops
->print_one
= print_one_catch_fork
;
16146 ops
->print_mention
= print_mention_catch_fork
;
16147 ops
->print_recreate
= print_recreate_catch_fork
;
16149 /* Vfork catchpoints. */
16150 ops
= &catch_vfork_breakpoint_ops
;
16151 *ops
= base_breakpoint_ops
;
16152 ops
->insert_location
= insert_catch_vfork
;
16153 ops
->remove_location
= remove_catch_vfork
;
16154 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16155 ops
->print_it
= print_it_catch_vfork
;
16156 ops
->print_one
= print_one_catch_vfork
;
16157 ops
->print_mention
= print_mention_catch_vfork
;
16158 ops
->print_recreate
= print_recreate_catch_vfork
;
16160 /* Exec catchpoints. */
16161 ops
= &catch_exec_breakpoint_ops
;
16162 *ops
= base_breakpoint_ops
;
16163 ops
->dtor
= dtor_catch_exec
;
16164 ops
->insert_location
= insert_catch_exec
;
16165 ops
->remove_location
= remove_catch_exec
;
16166 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16167 ops
->print_it
= print_it_catch_exec
;
16168 ops
->print_one
= print_one_catch_exec
;
16169 ops
->print_mention
= print_mention_catch_exec
;
16170 ops
->print_recreate
= print_recreate_catch_exec
;
16172 /* Solib-related catchpoints. */
16173 ops
= &catch_solib_breakpoint_ops
;
16174 *ops
= base_breakpoint_ops
;
16175 ops
->dtor
= dtor_catch_solib
;
16176 ops
->insert_location
= insert_catch_solib
;
16177 ops
->remove_location
= remove_catch_solib
;
16178 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16179 ops
->check_status
= check_status_catch_solib
;
16180 ops
->print_it
= print_it_catch_solib
;
16181 ops
->print_one
= print_one_catch_solib
;
16182 ops
->print_mention
= print_mention_catch_solib
;
16183 ops
->print_recreate
= print_recreate_catch_solib
;
16185 ops
= &dprintf_breakpoint_ops
;
16186 *ops
= bkpt_base_breakpoint_ops
;
16187 ops
->re_set
= dprintf_re_set
;
16188 ops
->resources_needed
= bkpt_resources_needed
;
16189 ops
->print_it
= bkpt_print_it
;
16190 ops
->print_mention
= bkpt_print_mention
;
16191 ops
->print_recreate
= dprintf_print_recreate
;
16192 ops
->after_condition_true
= dprintf_after_condition_true
;
16193 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16196 /* Chain containing all defined "enable breakpoint" subcommands. */
16198 static struct cmd_list_element
*enablebreaklist
= NULL
;
16201 _initialize_breakpoint (void)
16203 struct cmd_list_element
*c
;
16205 initialize_breakpoint_ops ();
16207 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16208 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16209 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16211 breakpoint_objfile_key
16212 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16214 breakpoint_chain
= 0;
16215 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16216 before a breakpoint is set. */
16217 breakpoint_count
= 0;
16219 tracepoint_count
= 0;
16221 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16222 Set ignore-count of breakpoint number N to COUNT.\n\
16223 Usage is `ignore N COUNT'."));
16225 add_com ("commands", class_breakpoint
, commands_command
, _("\
16226 Set commands to be executed when a breakpoint is hit.\n\
16227 Give breakpoint number as argument after \"commands\".\n\
16228 With no argument, the targeted breakpoint is the last one set.\n\
16229 The commands themselves follow starting on the next line.\n\
16230 Type a line containing \"end\" to indicate the end of them.\n\
16231 Give \"silent\" as the first line to make the breakpoint silent;\n\
16232 then no output is printed when it is hit, except what the commands print."));
16234 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16235 Specify breakpoint number N to break only if COND is true.\n\
16236 Usage is `condition N COND', where N is an integer and COND is an\n\
16237 expression to be evaluated whenever breakpoint N is reached."));
16238 set_cmd_completer (c
, condition_completer
);
16240 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16241 Set a temporary breakpoint.\n\
16242 Like \"break\" except the breakpoint is only temporary,\n\
16243 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16244 by using \"enable delete\" on the breakpoint number.\n\
16246 BREAK_ARGS_HELP ("tbreak")));
16247 set_cmd_completer (c
, location_completer
);
16249 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16250 Set a hardware assisted breakpoint.\n\
16251 Like \"break\" except the breakpoint requires hardware support,\n\
16252 some target hardware may not have this support.\n\
16254 BREAK_ARGS_HELP ("hbreak")));
16255 set_cmd_completer (c
, location_completer
);
16257 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16258 Set a temporary hardware assisted breakpoint.\n\
16259 Like \"hbreak\" except the breakpoint is only temporary,\n\
16260 so it will be deleted when hit.\n\
16262 BREAK_ARGS_HELP ("thbreak")));
16263 set_cmd_completer (c
, location_completer
);
16265 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16266 Enable some breakpoints.\n\
16267 Give breakpoint numbers (separated by spaces) as arguments.\n\
16268 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16269 This is used to cancel the effect of the \"disable\" command.\n\
16270 With a subcommand you can enable temporarily."),
16271 &enablelist
, "enable ", 1, &cmdlist
);
16273 add_com_alias ("en", "enable", class_breakpoint
, 1);
16275 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16276 Enable some breakpoints.\n\
16277 Give breakpoint numbers (separated by spaces) as arguments.\n\
16278 This is used to cancel the effect of the \"disable\" command.\n\
16279 May be abbreviated to simply \"enable\".\n"),
16280 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16282 add_cmd ("once", no_class
, enable_once_command
, _("\
16283 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16284 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16287 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16288 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16289 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16292 add_cmd ("count", no_class
, enable_count_command
, _("\
16293 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16294 If a breakpoint is hit while enabled in this fashion,\n\
16295 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16298 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16299 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16300 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16303 add_cmd ("once", no_class
, enable_once_command
, _("\
16304 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16305 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16308 add_cmd ("count", no_class
, enable_count_command
, _("\
16309 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16310 If a breakpoint is hit while enabled in this fashion,\n\
16311 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16314 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16315 Disable some breakpoints.\n\
16316 Arguments are breakpoint numbers with spaces in between.\n\
16317 To disable all breakpoints, give no argument.\n\
16318 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16319 &disablelist
, "disable ", 1, &cmdlist
);
16320 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16321 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16323 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16324 Disable some breakpoints.\n\
16325 Arguments are breakpoint numbers with spaces in between.\n\
16326 To disable all breakpoints, give no argument.\n\
16327 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16328 This command may be abbreviated \"disable\"."),
16331 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16332 Delete some breakpoints or auto-display expressions.\n\
16333 Arguments are breakpoint numbers with spaces in between.\n\
16334 To delete all breakpoints, give no argument.\n\
16336 Also a prefix command for deletion of other GDB objects.\n\
16337 The \"unset\" command is also an alias for \"delete\"."),
16338 &deletelist
, "delete ", 1, &cmdlist
);
16339 add_com_alias ("d", "delete", class_breakpoint
, 1);
16340 add_com_alias ("del", "delete", class_breakpoint
, 1);
16342 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16343 Delete some breakpoints or auto-display expressions.\n\
16344 Arguments are breakpoint numbers with spaces in between.\n\
16345 To delete all breakpoints, give no argument.\n\
16346 This command may be abbreviated \"delete\"."),
16349 add_com ("clear", class_breakpoint
, clear_command
, _("\
16350 Clear breakpoint at specified location.\n\
16351 Argument may be a linespec, explicit, or address location as described below.\n\
16353 With no argument, clears all breakpoints in the line that the selected frame\n\
16354 is executing in.\n"
16355 "\n" LOCATION_HELP_STRING
"\n\
16356 See also the \"delete\" command which clears breakpoints by number."));
16357 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16359 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16360 Set breakpoint at specified location.\n"
16361 BREAK_ARGS_HELP ("break")));
16362 set_cmd_completer (c
, location_completer
);
16364 add_com_alias ("b", "break", class_run
, 1);
16365 add_com_alias ("br", "break", class_run
, 1);
16366 add_com_alias ("bre", "break", class_run
, 1);
16367 add_com_alias ("brea", "break", class_run
, 1);
16371 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16372 Break in function/address or break at a line in the current file."),
16373 &stoplist
, "stop ", 1, &cmdlist
);
16374 add_cmd ("in", class_breakpoint
, stopin_command
,
16375 _("Break in function or address."), &stoplist
);
16376 add_cmd ("at", class_breakpoint
, stopat_command
,
16377 _("Break at a line in the current file."), &stoplist
);
16378 add_com ("status", class_info
, breakpoints_info
, _("\
16379 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16380 The \"Type\" column indicates one of:\n\
16381 \tbreakpoint - normal breakpoint\n\
16382 \twatchpoint - watchpoint\n\
16383 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16384 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16385 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16386 address and file/line number respectively.\n\
16388 Convenience variable \"$_\" and default examine address for \"x\"\n\
16389 are set to the address of the last breakpoint listed unless the command\n\
16390 is prefixed with \"server \".\n\n\
16391 Convenience variable \"$bpnum\" contains the number of the last\n\
16392 breakpoint set."));
16395 add_info ("breakpoints", breakpoints_info
, _("\
16396 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16397 The \"Type\" column indicates one of:\n\
16398 \tbreakpoint - normal breakpoint\n\
16399 \twatchpoint - watchpoint\n\
16400 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16401 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16402 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16403 address and file/line number respectively.\n\
16405 Convenience variable \"$_\" and default examine address for \"x\"\n\
16406 are set to the address of the last breakpoint listed unless the command\n\
16407 is prefixed with \"server \".\n\n\
16408 Convenience variable \"$bpnum\" contains the number of the last\n\
16409 breakpoint set."));
16411 add_info_alias ("b", "breakpoints", 1);
16413 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16414 Status of all breakpoints, or breakpoint number NUMBER.\n\
16415 The \"Type\" column indicates one of:\n\
16416 \tbreakpoint - normal breakpoint\n\
16417 \twatchpoint - watchpoint\n\
16418 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16419 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16420 \tuntil - internal breakpoint used by the \"until\" command\n\
16421 \tfinish - internal breakpoint used by the \"finish\" command\n\
16422 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16423 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16424 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16425 address and file/line number respectively.\n\
16427 Convenience variable \"$_\" and default examine address for \"x\"\n\
16428 are set to the address of the last breakpoint listed unless the command\n\
16429 is prefixed with \"server \".\n\n\
16430 Convenience variable \"$bpnum\" contains the number of the last\n\
16432 &maintenanceinfolist
);
16434 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16435 Set catchpoints to catch events."),
16436 &catch_cmdlist
, "catch ",
16437 0/*allow-unknown*/, &cmdlist
);
16439 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16440 Set temporary catchpoints to catch events."),
16441 &tcatch_cmdlist
, "tcatch ",
16442 0/*allow-unknown*/, &cmdlist
);
16444 add_catch_command ("fork", _("Catch calls to fork."),
16445 catch_fork_command_1
,
16447 (void *) (uintptr_t) catch_fork_permanent
,
16448 (void *) (uintptr_t) catch_fork_temporary
);
16449 add_catch_command ("vfork", _("Catch calls to vfork."),
16450 catch_fork_command_1
,
16452 (void *) (uintptr_t) catch_vfork_permanent
,
16453 (void *) (uintptr_t) catch_vfork_temporary
);
16454 add_catch_command ("exec", _("Catch calls to exec."),
16455 catch_exec_command_1
,
16459 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16460 Usage: catch load [REGEX]\n\
16461 If REGEX is given, only stop for libraries matching the regular expression."),
16462 catch_load_command_1
,
16466 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16467 Usage: catch unload [REGEX]\n\
16468 If REGEX is given, only stop for libraries matching the regular expression."),
16469 catch_unload_command_1
,
16474 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16475 Set a watchpoint for an expression.\n\
16476 Usage: watch [-l|-location] EXPRESSION\n\
16477 A watchpoint stops execution of your program whenever the value of\n\
16478 an expression changes.\n\
16479 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16480 the memory to which it refers."));
16481 set_cmd_completer (c
, expression_completer
);
16483 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16484 Set a read watchpoint for an expression.\n\
16485 Usage: rwatch [-l|-location] EXPRESSION\n\
16486 A watchpoint stops execution of your program whenever the value of\n\
16487 an expression is read.\n\
16488 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16489 the memory to which it refers."));
16490 set_cmd_completer (c
, expression_completer
);
16492 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16493 Set a watchpoint for an expression.\n\
16494 Usage: awatch [-l|-location] EXPRESSION\n\
16495 A watchpoint stops execution of your program whenever the value of\n\
16496 an expression is either read or written.\n\
16497 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16498 the memory to which it refers."));
16499 set_cmd_completer (c
, expression_completer
);
16501 add_info ("watchpoints", watchpoints_info
, _("\
16502 Status of specified watchpoints (all watchpoints if no argument)."));
16504 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16505 respond to changes - contrary to the description. */
16506 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16507 &can_use_hw_watchpoints
, _("\
16508 Set debugger's willingness to use watchpoint hardware."), _("\
16509 Show debugger's willingness to use watchpoint hardware."), _("\
16510 If zero, gdb will not use hardware for new watchpoints, even if\n\
16511 such is available. (However, any hardware watchpoints that were\n\
16512 created before setting this to nonzero, will continue to use watchpoint\n\
16515 show_can_use_hw_watchpoints
,
16516 &setlist
, &showlist
);
16518 can_use_hw_watchpoints
= 1;
16520 /* Tracepoint manipulation commands. */
16522 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16523 Set a tracepoint at specified location.\n\
16525 BREAK_ARGS_HELP ("trace") "\n\
16526 Do \"help tracepoints\" for info on other tracepoint commands."));
16527 set_cmd_completer (c
, location_completer
);
16529 add_com_alias ("tp", "trace", class_alias
, 0);
16530 add_com_alias ("tr", "trace", class_alias
, 1);
16531 add_com_alias ("tra", "trace", class_alias
, 1);
16532 add_com_alias ("trac", "trace", class_alias
, 1);
16534 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16535 Set a fast tracepoint at specified location.\n\
16537 BREAK_ARGS_HELP ("ftrace") "\n\
16538 Do \"help tracepoints\" for info on other tracepoint commands."));
16539 set_cmd_completer (c
, location_completer
);
16541 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16542 Set a static tracepoint at location or marker.\n\
16544 strace [LOCATION] [if CONDITION]\n\
16545 LOCATION may be a linespec, explicit, or address location (described below) \n\
16546 or -m MARKER_ID.\n\n\
16547 If a marker id is specified, probe the marker with that name. With\n\
16548 no LOCATION, uses current execution address of the selected stack frame.\n\
16549 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16550 This collects arbitrary user data passed in the probe point call to the\n\
16551 tracing library. You can inspect it when analyzing the trace buffer,\n\
16552 by printing the $_sdata variable like any other convenience variable.\n\
16554 CONDITION is a boolean expression.\n\
16555 \n" LOCATION_HELP_STRING
"\n\
16556 Multiple tracepoints at one place are permitted, and useful if their\n\
16557 conditions are different.\n\
16559 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16560 Do \"help tracepoints\" for info on other tracepoint commands."));
16561 set_cmd_completer (c
, location_completer
);
16563 add_info ("tracepoints", tracepoints_info
, _("\
16564 Status of specified tracepoints (all tracepoints if no argument).\n\
16565 Convenience variable \"$tpnum\" contains the number of the\n\
16566 last tracepoint set."));
16568 add_info_alias ("tp", "tracepoints", 1);
16570 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16571 Delete specified tracepoints.\n\
16572 Arguments are tracepoint numbers, separated by spaces.\n\
16573 No argument means delete all tracepoints."),
16575 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16577 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16578 Disable specified tracepoints.\n\
16579 Arguments are tracepoint numbers, separated by spaces.\n\
16580 No argument means disable all tracepoints."),
16582 deprecate_cmd (c
, "disable");
16584 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16585 Enable specified tracepoints.\n\
16586 Arguments are tracepoint numbers, separated by spaces.\n\
16587 No argument means enable all tracepoints."),
16589 deprecate_cmd (c
, "enable");
16591 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16592 Set the passcount for a tracepoint.\n\
16593 The trace will end when the tracepoint has been passed 'count' times.\n\
16594 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16595 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16597 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16598 _("Save breakpoint definitions as a script."),
16599 &save_cmdlist
, "save ",
16600 0/*allow-unknown*/, &cmdlist
);
16602 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16603 Save current breakpoint definitions as a script.\n\
16604 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16605 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16606 session to restore them."),
16608 set_cmd_completer (c
, filename_completer
);
16610 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16611 Save current tracepoint definitions as a script.\n\
16612 Use the 'source' command in another debug session to restore them."),
16614 set_cmd_completer (c
, filename_completer
);
16616 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16617 deprecate_cmd (c
, "save tracepoints");
16619 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16620 Breakpoint specific settings\n\
16621 Configure various breakpoint-specific variables such as\n\
16622 pending breakpoint behavior"),
16623 &breakpoint_set_cmdlist
, "set breakpoint ",
16624 0/*allow-unknown*/, &setlist
);
16625 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16626 Breakpoint specific settings\n\
16627 Configure various breakpoint-specific variables such as\n\
16628 pending breakpoint behavior"),
16629 &breakpoint_show_cmdlist
, "show breakpoint ",
16630 0/*allow-unknown*/, &showlist
);
16632 add_setshow_auto_boolean_cmd ("pending", no_class
,
16633 &pending_break_support
, _("\
16634 Set debugger's behavior regarding pending breakpoints."), _("\
16635 Show debugger's behavior regarding pending breakpoints."), _("\
16636 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16637 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16638 an error. If auto, an unrecognized breakpoint location results in a\n\
16639 user-query to see if a pending breakpoint should be created."),
16641 show_pending_break_support
,
16642 &breakpoint_set_cmdlist
,
16643 &breakpoint_show_cmdlist
);
16645 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16647 add_setshow_boolean_cmd ("auto-hw", no_class
,
16648 &automatic_hardware_breakpoints
, _("\
16649 Set automatic usage of hardware breakpoints."), _("\
16650 Show automatic usage of hardware breakpoints."), _("\
16651 If set, the debugger will automatically use hardware breakpoints for\n\
16652 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16653 a warning will be emitted for such breakpoints."),
16655 show_automatic_hardware_breakpoints
,
16656 &breakpoint_set_cmdlist
,
16657 &breakpoint_show_cmdlist
);
16659 add_setshow_boolean_cmd ("always-inserted", class_support
,
16660 &always_inserted_mode
, _("\
16661 Set mode for inserting breakpoints."), _("\
16662 Show mode for inserting breakpoints."), _("\
16663 When this mode is on, breakpoints are inserted immediately as soon as\n\
16664 they're created, kept inserted even when execution stops, and removed\n\
16665 only when the user deletes them. When this mode is off (the default),\n\
16666 breakpoints are inserted only when execution continues, and removed\n\
16667 when execution stops."),
16669 &show_always_inserted_mode
,
16670 &breakpoint_set_cmdlist
,
16671 &breakpoint_show_cmdlist
);
16673 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16674 condition_evaluation_enums
,
16675 &condition_evaluation_mode_1
, _("\
16676 Set mode of breakpoint condition evaluation."), _("\
16677 Show mode of breakpoint condition evaluation."), _("\
16678 When this is set to \"host\", breakpoint conditions will be\n\
16679 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16680 breakpoint conditions will be downloaded to the target (if the target\n\
16681 supports such feature) and conditions will be evaluated on the target's side.\n\
16682 If this is set to \"auto\" (default), this will be automatically set to\n\
16683 \"target\" if it supports condition evaluation, otherwise it will\n\
16684 be set to \"gdb\""),
16685 &set_condition_evaluation_mode
,
16686 &show_condition_evaluation_mode
,
16687 &breakpoint_set_cmdlist
,
16688 &breakpoint_show_cmdlist
);
16690 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16691 Set a breakpoint for an address range.\n\
16692 break-range START-LOCATION, END-LOCATION\n\
16693 where START-LOCATION and END-LOCATION can be one of the following:\n\
16694 LINENUM, for that line in the current file,\n\
16695 FILE:LINENUM, for that line in that file,\n\
16696 +OFFSET, for that number of lines after the current line\n\
16697 or the start of the range\n\
16698 FUNCTION, for the first line in that function,\n\
16699 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16700 *ADDRESS, for the instruction at that address.\n\
16702 The breakpoint will stop execution of the inferior whenever it executes\n\
16703 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16704 range (including START-LOCATION and END-LOCATION)."));
16706 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16707 Set a dynamic printf at specified location.\n\
16708 dprintf location,format string,arg1,arg2,...\n\
16709 location may be a linespec, explicit, or address location.\n"
16710 "\n" LOCATION_HELP_STRING
));
16711 set_cmd_completer (c
, location_completer
);
16713 add_setshow_enum_cmd ("dprintf-style", class_support
,
16714 dprintf_style_enums
, &dprintf_style
, _("\
16715 Set the style of usage for dynamic printf."), _("\
16716 Show the style of usage for dynamic printf."), _("\
16717 This setting chooses how GDB will do a dynamic printf.\n\
16718 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16719 console, as with the \"printf\" command.\n\
16720 If the value is \"call\", the print is done by calling a function in your\n\
16721 program; by default printf(), but you can choose a different function or\n\
16722 output stream by setting dprintf-function and dprintf-channel."),
16723 update_dprintf_commands
, NULL
,
16724 &setlist
, &showlist
);
16726 dprintf_function
= xstrdup ("printf");
16727 add_setshow_string_cmd ("dprintf-function", class_support
,
16728 &dprintf_function
, _("\
16729 Set the function to use for dynamic printf"), _("\
16730 Show the function to use for dynamic printf"), NULL
,
16731 update_dprintf_commands
, NULL
,
16732 &setlist
, &showlist
);
16734 dprintf_channel
= xstrdup ("");
16735 add_setshow_string_cmd ("dprintf-channel", class_support
,
16736 &dprintf_channel
, _("\
16737 Set the channel to use for dynamic printf"), _("\
16738 Show the channel to use for dynamic printf"), NULL
,
16739 update_dprintf_commands
, NULL
,
16740 &setlist
, &showlist
);
16742 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16743 &disconnected_dprintf
, _("\
16744 Set whether dprintf continues after GDB disconnects."), _("\
16745 Show whether dprintf continues after GDB disconnects."), _("\
16746 Use this to let dprintf commands continue to hit and produce output\n\
16747 even if GDB disconnects or detaches from the target."),
16750 &setlist
, &showlist
);
16752 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16753 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16754 (target agent only) This is useful for formatted output in user-defined commands."));
16756 automatic_hardware_breakpoints
= 1;
16758 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16759 observer_attach_thread_exit (remove_threaded_breakpoints
);